Commit 6e66468f authored by Byron Nikolaidis's avatar Byron Nikolaidis

Version 06-30-0248

parent 2a677424
#
#
#
#============ Default for all system ==============
OS = UNX
SHELL = /bin/sh
AR = ar r
DLSUFFIX= so
INCDIR = /include
OBJX =
RANLIB = ranlib
INSTALL = /usr/bin/install
INSTALL_DATA = $(INSTALL) -c -m 644
MKDIR = mkdir
DESTDIR = /usr/local
LIBDIR = /lib
INSTHEADERS = isql.h isqlext.h iodbc.h
DESTLIBDIR = $(DESTDIR)$(LIBDIR)
DESTINCDIR = $(DESTDIR)$(INCDIR)/iodbc
ODBCSYSTEMDIR = /usr/home/gryschuk
# Remove the comment characters from the section you want to
# use below, make sure all other sections are commented out.
#============== Linux ELF =========================
CC = gcc
PIC = -fPIC
CFLAGSX = -g
#CFLAGSX = -g -Wall -DMY_LOG -DQ_LOG
LDFLAGS = -shared
LIBS = -ldl
#============= FreeBSD 2.x ========================
# I don't know if this would work but you can always just try it.
# PIC = -fPIC
# CFLAGSX = -g -Wall
# LDFLAGS = -Bshareable
# LIBS =
#===| end of file 'Config.mk' |===
# .include "Version.mk"
# .include "Config.mk"
include Version.mk
include Config.mk
#==============================================================================
# Makefile
#
# UNIX Makefile to build the CLI for PostgreSQL/Postgres95
#
#==============================================================================
# Site specific configuration (UNIX)
#==============================================================================
#
# option switches
#
# debug: select this to enable debugging of the software
#DEBUG = -D_DEBUG
#
#==============================================================================
#---| definitions |------------------------------------------------------------
# NAME = cli
NAME = psqlodbc
OBJECTS = info.o bind.o columninfo.o connection.o convert.o drvconn.o \
environ.o execute.o lobj.o misc.o options.o \
pgtypes.o psqlodbc.o qresult.o results.o socket.o statement.o \
gpps.o tuple.o tuplelist.o dlg_specific.o $(OBJX)
#CFLAGS = -c $(DEBUG) -D$(PG_ENV) -O $(PIC) $(ANSI) -I$(PG_INCLUDE) \
# -I$(ODBC_INCLUDE) -D$(DLDAPI) $(CFLAGSX) -DHAVE_CONFIG_H \
# -DVERSION=\"$(VERSION)$(EXTVER)\"
CFLAGS = -g -c -Wall $(DEBUG) -O $(PIC) $(ANSI) -I. -I.. \
-I$(PG_INCLUDE) -I$(ODBC_INCLUDE) $(CFLAGSX) -DHAVE_CONFIG_H
shlib = lib$(NAME)-$(VERSION).$(DLSUFFIX)
DESTDIR = /usr/local
LIBDIR = /lib
#---| global dependencies |----------------------------------------------------
#all: $(OBJECTS) lib dll
all: $(OBJECTS) dll
clean:
-rm -f core *.o *~ *.core
delete: clean
delete_all: delete
-rm -f /usr/local/lib/lib$(NAME)_$(MSQL_ENV).a
-rm -f /usr/local/lib/lib$(NAME)_$(MSQL_ENV).$(DLSUFFIX)
#---| local dependencies |-----------------------------------------------------
#log.o: ../SRC_LOG/log.c ../SRC_LOG/log.h
# $(CC) $(CFLAGS) -I../SRC_LOG ../SRC_LOG/log.c
lib:
$(AR) lib$(NAME)$(PG_ENV).a $(OBJECTS)
$(RANLIB) lib$(NAME)$(PG_ENV).a
dll: $(OBJECTS)
$(LD) $(LDFLAGS) -L$(PG_LIBPATH) $(OBJECTS) \
-o $(shlib) $(LIBS) $(PG_LIBS)
install-shlib: $(shlib)
$(INSTALL_DATA) $(shlib) $(DESTDIR)$(LIBDIR)/$(shlib)
rm -f $(DESTDIR)$(LIBDIR)/lib$(NAME).so
ln -sf $(shlib) $(DESTDIR)$(LIBDIR)/lib$(NAME).so
install-headers: $(INSTHEADERS)
if [ -d $(DESTDIR)$(INCDIR)/iodbc ]; then : ; else $(MKDIR) $(DESTDIR)$(INCDIR)/iodbc; fi
$(INSTALL_DATA) $(INSTHEADERS) $(DESTDIR)$(INCDIR)/iodbc
install-ini: odbcinst.ini
$(INSTALL_DATA) odbcinst.ini /etc
install: install-headers install-shlib install-ini
#==============================================================================
Unix port of psqlodbc, brought to you by:
Gerald Gryschuk(ggryschuk@home.com)
This is the first release of a port of psqlodbc to Unix(specifically Linux),
as such the installation may not be as straight forward as it could be(then
again it might be). As well the only testing of the driver has been with
the real project I'm working on, since it seems to be working there I assumed
it was ready to go out. This port works with Ke Jin's iodbc driver manager
although there is no theoretical reason why it couldn't work with other
driver managers for UNIX(I know of none though). The FreeODBC site
(http://users.ids.net/~bjepson/freeODBC/) has a link to download the current
version of iodbc(iodbc-2.12).
This driver has been successfully compiled and tested on a RedHat 4.1 system
using both gcc 2.7.2 and egcs 1.0.2.
INSTALLATION:
If you have a system any where close to mine this will be easy, just
copy Makefile.lnx to Makefile then type 'make' and see what happens. Note
that if you have not enabled logging(read the file misc.h) then you
may get alot of warning messages, just ignore these, they shouldn't be
a problem. If this doesn't work, well... I don't know what to say, see if
you can figure out what's wrong,fix it and send me a message. If everything
makes o.k. you can 'make install' which will install the shared library
(in /usr/local/lib) and a WINDOWS type INI file in /etc (called odbcinst.ini,
see CONFIGURATION below). If you want to program using this driver do a
'make install-headers' which will install programming header files in
/usr/local/include/iodbc. If you don't like these install locations edit
Config.mk and change the environment variable DESTDIR(and possible DESTINCDIR
to get rid of the /iodbc) to suit your system.
CONFIGURATION:
The psqlodbc driver reads two Windows type INI files for configuration,
one called odbcinst.ini located in /etc which is used for system wide
configuration of the driver and one in the users home directory called
.odbc.ini, which can be used to override the system wide settings. Note that
the location of odbcinst is currently hardcoded into the source so if you
want to change this you have to change it in the source as well. This latter
file is also searched for by iodbc and is where
the DataSource definitions are placed. The format of both files is exactly
like that of a Windows INI file using key,value pairs. A DataSource definition
is started with a section name enclosed in square brackets i.e. [PostODBC].
Comments are started using a ';' character and are restricted to being
only on seperate lines(i.e. no comments are allowed on definition lines).
The important keywords for psqlodbc are:
Driver = (location where the psqlodbc library was installed)
ex. Driver = /usr/local/lib/libpspqlodbc.so
ServerName = hostname or ip-address of postgreSQL server
ex. ServerName = simpsons.springfield.com
or ServerName = 192.1.1.1
Database = name of database to connect to
ex. Database = template1
Port = tcp port that the postgreSQL server is listening on, note
that this need not be set as the driver defaults to the
default postgreSQL port of 5432. Of course if your server
is listening on a different port than you need to say
what it is here.
Username = name of authorized postgreSQL user
ex. Username = homer
Password = the password for the user named in Username. Note
that if you have password checking on in postgreSQL
you have to have this field. Unfortunately this means
storing clear text passwords in a file. If this bothers
you, well... write a dialog box routine and send it
to me.
ex. Password = Doh!
ReadOnly = 0 or 1. Default is 1 => database IS readonly. If
set to 0, database is read-write.
ex. ReadOnly = 0
Protocol = 6.2 to force the use of Postgres 6.2 protocol
The odbcinst.ini file is where sytem wide settings are kept. There are
quite a number of these, all of which have built-in defaults. Since I'm
not even sure what they are all for I won't try to describe them, check
the file dlg_specific.h for a list and some explanation. Two that I found
useful are Debug and CommLog, which can be used to tailor logging of messages
by the driver(note that you have to have defined MY_LOG and Q_LOG during
compilation of the driver, see the file misc.h for an explanation). If
you have logging On(ie. CommLog = 1 and/or Debug = 1) then logging will
occur to the files /tmp/mylog.log(Debug, only developers will be
interested) and /tmp/psqlodbc.log(end user log file).
USE:
run an ODBC enabled application :-) .
O.k. Well, the only ODBC compliant applications that I can
"guarantee" to work are those that are compiled using the following
headers that come with this driver, iodbc.h, isql.h and isqlext.h.
BUGS,etc.
If you have problems with compiling/installing or making this
package send e-mail to me at:
gerald.gryschuk@home.com or to the pgsql-interfaces mailing list
pgsql-interfaces@postgresql.org .
Ports to different Unices are greatly appreciated and can probably be
sent to me for now(although this may change shortly).
Bugs of a general nature should still be sent to the current
maintainer or to the interfaces list.
VERSION = 0.24
EXTVER = .2
......@@ -12,6 +12,11 @@
* Comments: See "notice.txt" for copyright and license information.
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "bind.h"
#include "environ.h"
#include "statement.h"
......@@ -19,8 +24,15 @@
#include "pgtypes.h"
#include <stdlib.h>
#include <malloc.h>
#ifdef HAVE_IODBC
#include "iodbc.h"
#include "isql.h"
#include "isqlext.h"
#else
#include <sql.h>
#include <sqlext.h>
#endif
// Bind parameters on a statement handle
......
......@@ -16,6 +16,7 @@
#include "socket.h"
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
ColumnInfoClass *
CI_Constructor()
......
#define HAVE_IODBC 1
#define UNIX 1
#define HAVE_PARAM_H 1
#define HAVE_PWD_H 1
#define HAVE_STRICMP 0
......@@ -21,7 +21,11 @@
#include "lobj.h"
#include "dlg_specific.h"
#include <stdio.h>
#include <string.h>
#ifndef UNIX
#include <odbcinst.h>
#endif
#define STMT_INCREMENT 16 /* how many statement holders to allocate at a time */
......@@ -99,7 +103,7 @@ char *func = "SQLConnect";
/* fill in any defaults */
getDSNdefaults(ci);
qlog("conn = %u, SQLConnect(DSN='%s', UID='%s', PWD='%s')\n", ci->dsn, ci->username, ci->password);
qlog("conn = %u, SQLConnect(DSN='%s', UID='%s', PWD='%s')\n", conn, ci->dsn, ci->username, ci->password);
if ( CC_connect(conn, FALSE) <= 0) {
// Error messages are filled in
......@@ -229,6 +233,14 @@ ConnectionClass *rv;
rv->num_stmts = STMT_INCREMENT;
rv->lobj_type = PG_TYPE_LO;
rv->ntables = 0;
rv->col_info = NULL;
rv->translation_option = 0;
rv->translation_handle = NULL;
rv->DataSourceToDriver = NULL;
rv->DriverToDataSource = NULL;
}
return rv;
}
......@@ -254,6 +266,19 @@ CC_Destructor(ConnectionClass *self)
}
mylog("after free statement holders\n");
/* Free cached table info */
if (self->col_info) {
int i;
for (i = 0; i < self->ntables; i++) {
if (self->col_info[i]->result) /* Free the SQLColumns result structure */
QR_Destructor(self->col_info[i]->result);
free(self->col_info[i]);
}
free(self->col_info);
}
free(self);
mylog("exit CC_Destructor\n");
......@@ -354,11 +379,54 @@ StatementClass *stmt;
self->stmts[i] = NULL;
}
}
/* Check for translation dll */
if ( self->translation_handle) {
FreeLibrary (self->translation_handle);
self->translation_handle = NULL;
}
mylog("exit CC_Cleanup\n");
return TRUE;
}
int
CC_set_translation (ConnectionClass *self)
{
if (self->translation_handle != NULL) {
FreeLibrary (self->translation_handle);
self->translation_handle = NULL;
}
if (self->connInfo.translation_dll[0] == 0)
return TRUE;
self->translation_option = atoi (self->connInfo.translation_option);
self->translation_handle = LoadLibrary (self->connInfo.translation_dll);
if (self->translation_handle == NULL) {
self->errornumber = CONN_UNABLE_TO_LOAD_DLL;
self->errormsg = "Could not load the translation DLL.";
return FALSE;
}
self->DataSourceToDriver
= (DataSourceToDriverProc) GetProcAddress (self->translation_handle,
"SQLDataSourceToDriver");
self->DriverToDataSource
= (DriverToDataSourceProc) GetProcAddress (self->translation_handle,
"SQLDriverToDataSource");
if (self->DataSourceToDriver == NULL || self->DriverToDataSource == NULL) {
self->errornumber = CONN_UNABLE_TO_LOAD_DLL;
self->errormsg = "Could not find translation DLL functions.";
return FALSE;
}
return TRUE;
}
char
CC_connect(ConnectionClass *self, char do_password)
......@@ -587,15 +655,17 @@ char salt[2];
mylog("empty query seems to be OK.\n");
CC_set_translation (self);
/**********************************************/
/******* Send any initial settings *********/
/**********************************************/
// The Unix iodbc errors out on this call because it allocates a statement
// before the connection is established. Therefore, don't check for error here.
/* Since these functions allocate statements, and since the connection is not
established yet, it would violate odbc state transition rules. Therefore,
these functions call the corresponding local function instead.
*/
CC_send_settings(self);
CC_lookup_lo(self); /* a hack to get the oid of our large object oid type */
// CC_test(self);
......@@ -1074,6 +1144,7 @@ int i;
}
}
char
CC_send_settings(ConnectionClass *self)
{
......@@ -1085,7 +1156,10 @@ StatementClass *stmt;
RETCODE result;
SWORD cols = 0;
result = SQLAllocStmt( self, &hstmt);
/* This function must use the local odbc API functions since the odbc state
has not transitioned to "connected" yet.
*/
result = _SQLAllocStmt( self, &hstmt);
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
return FALSE;
}
......@@ -1116,13 +1190,13 @@ SWORD cols = 0;
if (ini_query[0] != '\0') {
mylog("Sending Initial Connection query: '%s'\n", ini_query);
result = SQLExecDirect(hstmt, ini_query, SQL_NTS);
result = _SQLExecDirect(hstmt, ini_query, SQL_NTS);
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
SQLFreeStmt(hstmt, SQL_DROP);
_SQLFreeStmt(hstmt, SQL_DROP);
return FALSE;
}
SQLFreeStmt(hstmt, SQL_DROP);
_SQLFreeStmt(hstmt, SQL_DROP);
}
return TRUE;
......@@ -1139,36 +1213,39 @@ HSTMT hstmt;
StatementClass *stmt;
RETCODE result;
result = SQLAllocStmt( self, &hstmt);
/* This function must use the local odbc API functions since the odbc state
has not transitioned to "connected" yet.
*/
result = _SQLAllocStmt( self, &hstmt);
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
return;
}
stmt = (StatementClass *) hstmt;
result = SQLExecDirect(hstmt, "select oid from pg_type where typname='" \
result = _SQLExecDirect(hstmt, "select oid from pg_type where typname='" \
PG_TYPE_LO_NAME \
"'", SQL_NTS);
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
SQLFreeStmt(hstmt, SQL_DROP);
_SQLFreeStmt(hstmt, SQL_DROP);
return;
}
result = SQLFetch(hstmt);
result = _SQLFetch(hstmt);
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
SQLFreeStmt(hstmt, SQL_DROP);
_SQLFreeStmt(hstmt, SQL_DROP);
return;
}
result = SQLGetData(hstmt, 1, SQL_C_SLONG, &self->lobj_type, sizeof(self->lobj_type), NULL);
result = _SQLGetData(hstmt, 1, SQL_C_SLONG, &self->lobj_type, sizeof(self->lobj_type), NULL);
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
SQLFreeStmt(hstmt, SQL_DROP);
_SQLFreeStmt(hstmt, SQL_DROP);
return;
}
mylog("Got the large object oid: %d\n", self->lobj_type);
qlog(" [ Large Object oid = %d ]\n", self->lobj_type);
result = SQLFreeStmt(hstmt, SQL_DROP);
result = _SQLFreeStmt(hstmt, SQL_DROP);
}
void
......@@ -1201,29 +1278,38 @@ RETCODE result;
SDWORD pcbValue;
UDWORD pcrow;
UWORD rgfRowStatus;
char buf[255];
SDWORD buflen;
DATE_STRUCT *ds;
char name[255], type[255];
SDWORD namelen, typelen;
SWORD cols;
result = SQLAllocStmt( self, &hstmt1);
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
return;
}
result = SQLExecDirect(hstmt1, "select * from cpar", SQL_NTS);
qlog("exec result = %d\n", result);
result = SQLTables(hstmt1, "", SQL_NTS, "", SQL_NTS, "", SQL_NTS, "", SQL_NTS);
qlog("SQLTables result = %d\n", result);
result = SQLNumResultCols(hstmt1, &cols);
qlog("cols SQLTables result = %d\n", result);
result = SQLBindCol(hstmt1, 2, SQL_C_DATE, buf, 0, &buflen);
result = SQLBindCol(hstmt1, 3, SQL_C_CHAR, name, sizeof(name), &namelen);
qlog("bind result = %d\n", result);
result = SQLBindCol(hstmt1, 4, SQL_C_CHAR, type, sizeof(type), &typelen);
qlog("bind result = %d\n", result);
result = SQLFetch(hstmt1);
qlog("SQLFetch result = %d\n", result);
while (result != SQL_NO_DATA_FOUND) {
ds = (DATE_STRUCT *) buf;
qlog("fetch on stmt1: result=%d, buflen=%d: year=%d, month=%d, day=%d\n", result, buflen, ds->year, ds->month, ds->day);
qlog("fetch on stmt1: result=%d, namelen=%d: name='%s', typelen=%d, type='%s'\n", result, namelen, name, typelen, type);
result = SQLFetch(hstmt1);
}
qlog("SQLFetch result = %d\n", result);
SQLFreeStmt(hstmt1, SQL_DROP);
}
*/
......@@ -10,9 +10,20 @@
#ifndef __CONNECTION_H__
#define __CONNECTION_H__
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_IODBC
#include "iodbc.h"
#include "isql.h"
#include "isqlext.h"
#else
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#endif
#include "psqlodbc.h"
typedef enum {
......@@ -48,6 +59,7 @@ typedef enum {
#define CONN_NOT_IMPLEMENTED_ERROR 9
#define CONN_INVALID_AUTHENTICATION 10
#define CONN_AUTH_TYPE_UNSUPPORTED 11
#define CONN_UNABLE_TO_LOAD_DLL 12
/* Conn_status defines */
......@@ -83,7 +95,7 @@ typedef enum {
#define NO_AUTHENTICATION 7
#define PATH_SIZE 64
#define ARGV_SIZE 64
#define NAMEDATALEN 32
#define NAMEDATALEN 16
typedef unsigned int ProtocolVersion;
......@@ -130,11 +142,12 @@ typedef struct {
char protocol[SMALL_REGISTRY_LEN];
char port[SMALL_REGISTRY_LEN];
char readonly[SMALL_REGISTRY_LEN];
// char unknown_sizes[SMALL_REGISTRY_LEN];
char fake_oid_index[SMALL_REGISTRY_LEN];
char show_oid_column[SMALL_REGISTRY_LEN];
char row_versioning[SMALL_REGISTRY_LEN];
char show_system_tables[SMALL_REGISTRY_LEN];
char translation_dll[MEDIUM_REGISTRY_LEN];
char translation_option[SMALL_REGISTRY_LEN];
char focus_password;
} ConnInfo;
......@@ -143,6 +156,35 @@ typedef struct {
/* This is used to store cached table information in the connection */
struct col_info {
QResultClass *result;
char name[MAX_TABLE_LEN+1];
};
/* Translation DLL entry points */
typedef BOOL (FAR WINAPI *DataSourceToDriverProc) (UDWORD,
SWORD,
PTR,
SDWORD,
PTR,
SDWORD,
SDWORD FAR *,
UCHAR FAR *,
SWORD,
SWORD FAR *);
typedef BOOL (FAR WINAPI *DriverToDataSourceProc) (UDWORD,
SWORD,
PTR,
SDWORD,
PTR,
SDWORD,
SDWORD FAR *,
UCHAR FAR *,
SWORD,
SWORD FAR *);
/******* The Connection handle ************/
struct ConnectionClass_ {
HENV henv; /* environment this connection was created on */
......@@ -154,6 +196,12 @@ struct ConnectionClass_ {
int num_stmts;
SocketClass *sock;
int lobj_type;
int ntables;
COL_INFO **col_info;
long translation_option;
HINSTANCE translation_handle;
DataSourceToDriverProc DataSourceToDriver;
DriverToDataSourceProc DriverToDataSource;
char transact_status; /* Is a transaction is currently in progress */
char errormsg_created; /* has an informative error msg been created? */
};
......@@ -179,6 +227,7 @@ char CC_Destructor(ConnectionClass *self);
int CC_cursor_count(ConnectionClass *self);
char CC_cleanup(ConnectionClass *self);
char CC_abort(ConnectionClass *self);
int CC_set_translation (ConnectionClass *self);
char CC_connect(ConnectionClass *self, char do_password);
char CC_add_statement(ConnectionClass *self, StatementClass *stmt);
char CC_remove_statement(ConnectionClass *self, StatementClass *stmt);
......@@ -191,4 +240,5 @@ char CC_send_settings(ConnectionClass *self);
void CC_lookup_lo(ConnectionClass *conn);
void CC_log_error(char *func, char *desc, ConnectionClass *self);
#endif
......@@ -16,11 +16,23 @@
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#ifdef HAVE_IODBC
#include "iodbc.h"
#include "isql.h"
#include "isqlext.h"
#else
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#endif
#include <time.h>
#include <math.h>
#include "convert.h"
......@@ -30,6 +42,16 @@
#include "lobj.h"
#include "connection.h"
#ifdef UNIX
#if !HAVE_STRICMP
#define stricmp(s1,s2) strcasecmp(s1,s2)
#define strnicmp(s1,s2,n) strncasecmp(s1,s2,n)
#endif
#ifndef SCHAR
typedef signed char SCHAR;
#endif
#endif
extern GLOBAL_VALUES globals;
/* How to map ODBC scalar functions {fn func(args)} to Postgres */
......@@ -104,6 +126,15 @@ struct tm *tim;
return COPY_OK;
}
if (stmt->hdbc->DataSourceToDriver != NULL) {
int length = strlen (value);
stmt->hdbc->DataSourceToDriver (stmt->hdbc->translation_option,
SQL_CHAR,
value, length,
value, length, NULL,
NULL, 0, NULL);
}
/********************************************************************
First convert any specific postgres types into more
useable data.
......@@ -738,6 +769,15 @@ char in_quote = FALSE;
// make sure new_statement is always null-terminated
new_statement[npos] = '\0';
if(stmt->hdbc->DriverToDataSource != NULL) {
int length = strlen (new_statement);
stmt->hdbc->DriverToDataSource (stmt->hdbc->translation_option,
SQL_CHAR,
new_statement, length,
new_statement, length, NULL,
NULL, 0, NULL);
}
return SQL_SUCCESS;
}
......@@ -881,6 +921,12 @@ char *p;
for (i = 0; i < strlen(si) && out < max; i++) {
if (si[i] == '\n') {
/* Only add the carriage-return if needed */
if (i > 0 && si[i-1] == '\r') {
p[out++] = si[i];
continue;
}
p[out++] = '\r';
p[out++] = '\n';
}
......@@ -945,6 +991,26 @@ int i, y=0;
}
unsigned int
conv_from_hex(unsigned char *s)
{
int i, y=0, val;
for (i = 1; i <= 2; i++) {
if (s[i] >= 'a' && s[i] <= 'f')
val = s[i] - 'a' + 10;
else if (s[i] >= 'A' && s[i] <= 'F')
val = s[i] - 'A' + 10;
else
val = s[i] - '0';
y += val * (int) pow(16, 2-i);
}
return y;
}
// convert octal escapes to bytes
int
convert_from_pgbinary(unsigned char *value, unsigned char *rgbValue, int cbValueMax)
......@@ -1009,6 +1075,50 @@ int i, o=0;
}
void
encode(char *in, char *out)
{
unsigned int i, o = 0;
for (i = 0; i < strlen(in); i++) {
if ( in[i] == '+') {
sprintf(&out[o], "%%2B");
o += 3;
}
else if ( isspace(in[i])) {
out[o++] = '+';
}
else if ( ! isalnum(in[i])) {
sprintf(&out[o], "%%%02x", in[i]);
o += 3;
}
else
out[o++] = in[i];
}
out[o++] = '\0';
}
void
decode(char *in, char *out)
{
unsigned int i, o = 0;
for (i = 0; i < strlen(in); i++) {
if (in[i] == '+')
out[o++] = ' ';
else if (in[i] == '%') {
sprintf(&out[o++], "%c", conv_from_hex(&in[i]));
i+=2;
}
else
out[o++] = in[i];
}
out[o++] = '\0';
}
/* 1. get oid (from 'value')
2. open the large object
3. read from the large object (handle multiple GetData)
......
......@@ -43,6 +43,8 @@ char *convert_special_chars(char *si, char *dst, int used);
int convert_pgbinary_to_char(char *value, char *rgbValue, int cbValueMax);
int convert_from_pgbinary(unsigned char *value, unsigned char *rgbValue, int cbValueMax);
int convert_to_pgbinary(unsigned char *in, char *out, int len);
void encode(char *in, char *out);
void decode(char *in, char *out);
int convert_lo(StatementClass *stmt, void *value, Int2 fCType, PTR rgbValue,
SDWORD cbValueMax, SDWORD *pcbValue, char multiple);
......
This diff is collapsed.
......@@ -10,12 +10,19 @@
#ifndef __DLG_SPECIFIC_H__
#define __DLG_SPECIFIC_H__
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "psqlodbc.h"
#include "connection.h"
#ifndef UNIX
#include <windows.h>
#include <windowsx.h>
#include <odbcinst.h>
#include "resource.h"
#endif
/* Unknown data type sizes */
#define UNKNOWNS_AS_MAX 0
......@@ -23,8 +30,13 @@
#define UNKNOWNS_AS_LONGEST 2
/* INI File Stuff */
#define ODBC_INI "ODBC.INI" /* ODBC initialization file */
#define ODBCINST_INI "ODBCINST.INI" /* ODBC Installation file */
#ifdef UNIX
#define ODBC_INI ".odbc.ini"
#define ODBCINST_INI "/etc/odbcinst.ini"
#else
#define ODBC_INI "ODBC.INI" /* ODBC initialization file */
#define ODBCINST_INI "ODBCINST.INI" /* ODBC Installation file */
#endif
#define INI_DSN DBMS_NAME /* Name of default Datasource in ini file (not used?) */
#define INI_KDESC "Description" /* Data source description */
......@@ -58,8 +70,14 @@
#define INI_ROWVERSIONING "RowVersioning"
#define INI_SHOWSYSTEMTABLES "ShowSystemTables"
#define INI_LIE "Lie"
#define INI_PARSE "Parse"
#define INI_EXTRASYSTABLEPREFIXES "ExtraSysTablePrefixes"
#define INI_TRANSLATIONNAME "TranslationName"
#define INI_TRANSLATIONDLL "TranslationDLL"
#define INI_TRANSLATIONOPTION "TranslationOption"
/* Connection Defaults */
#define DEFAULT_PORT "5432"
#define DEFAULT_READONLY 1
......@@ -78,13 +96,14 @@
#define DEFAULT_ROWVERSIONING 0
#define DEFAULT_SHOWSYSTEMTABLES 0 // dont show system tables
#define DEFAULT_LIE 0
#define DEFAULT_PARSE 0
#define DEFAULT_EXTRASYSTABLEPREFIXES "dd_;"
/* prototypes */
void updateGlobals(void);
void getGlobalDefaults(void);
#ifndef UNIX
void SetDlgStuff(HWND hdlg, ConnInfo *ci);
void GetDlgStuff(HWND hdlg, ConnInfo *ci);
......@@ -96,12 +115,14 @@ int CALLBACK ds_optionsProc(HWND hdlg,
WORD wMsg,
WPARAM wParam,
LPARAM lParam);
#endif /* ! UNIX */
void updateGlobals(void);
void writeDSNinfo(ConnInfo *ci);
void getDSNdefaults(ConnInfo *ci);
void getDSNinfo(ConnInfo *ci, char overwrite);
void makeConnectString(char *connect_string, ConnInfo *ci);
void copyAttributes(ConnInfo *ci, char *attribute, char *value);
void getDSNdefaults(ConnInfo *ci);
void getDSNinfo(ConnInfo *ci, char overwrite);
void writeDSNinfo(ConnInfo *ci);
#endif
......@@ -12,28 +12,56 @@
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include "psqlodbc.h"
#include "connection.h"
#ifdef UNIX
#include <sys/types.h>
#include <sys/socket.h>
#define NEAR
#else
#include <winsock.h>
#include <sqlext.h>
#endif
#include <string.h>
#ifdef UNIX
#define stricmp(s1,s2) strcasecmp(s1,s2)
#define strnicmp(s1,s2,n) strncasecmp(s1,s2,n)
#else
#include <windows.h>
#include <windowsx.h>
#include <odbcinst.h>
#include "resource.h"
#endif
#ifndef TRUE
#define TRUE (BOOL)1
#endif
#ifndef FALSE
#define FALSE (BOOL)0
#endif
#include "dlg_specific.h"
/* prototypes */
void dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci);
#ifndef UNIX /* should be something like ifdef WINDOWS */
BOOL FAR PASCAL dconn_FDriverConnectProc(HWND hdlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
RETCODE dconn_DoDialog(HWND hwnd, ConnInfo *ci);
void dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci);
extern HINSTANCE NEAR s_hModule; /* Saved module handle. */
#endif
extern GLOBAL_VALUES globals;
......@@ -51,23 +79,25 @@ char *func = "SQLDriverConnect";
ConnectionClass *conn = (ConnectionClass *) hdbc;
ConnInfo *ci;
RETCODE dialog_result;
char connect_string[MAX_CONNECT_STRING];
char connStrIn[MAX_CONNECT_STRING];
char connStrOut[MAX_CONNECT_STRING];
int retval;
char password_required = FALSE;
mylog("**** SQLDriverConnect: fDriverCompletion=%d, connStrIn='%s'\n", fDriverCompletion, szConnStrIn);
if ( ! conn) {
CC_log_error(func, "", NULL);
return SQL_INVALID_HANDLE;
}
qlog("conn=%u, SQLDriverConnect( in)='%s'\n", conn, szConnStrIn);
make_string(szConnStrIn, cbConnStrIn, connStrIn);
mylog("**** SQLDriverConnect: fDriverCompletion=%d, connStrIn='%s'\n", fDriverCompletion, connStrIn);
qlog("conn=%u, SQLDriverConnect( in)='%s', fDriverCompletion=%d\n", conn, connStrIn, fDriverCompletion);
ci = &(conn->connInfo);
// Parse the connect string and fill in conninfo for this hdbc.
dconn_get_connect_attributes(szConnStrIn, ci);
dconn_get_connect_attributes(connStrIn, ci);
// If the ConnInfo in the hdbc is missing anything,
// this function will fill them in from the registry (assuming
......@@ -81,6 +111,7 @@ dialog:
ci->focus_password = password_required;
switch(fDriverCompletion) {
#ifndef UNIX /* again should be ifdef WINDOWS like */
case SQL_DRIVER_PROMPT:
dialog_result = dconn_DoDialog(hwnd, ci);
if(dialog_result != SQL_SUCCESS) {
......@@ -88,9 +119,13 @@ dialog:
}
break;
case SQL_DRIVER_COMPLETE:
case SQL_DRIVER_COMPLETE_REQUIRED:
/* Password is not a required parameter. */
/* Fall through */
case SQL_DRIVER_COMPLETE:
/* Password is not a required parameter. */
if( ci->username[0] == '\0' ||
ci->server[0] == '\0' ||
ci->database[0] == '\0' ||
......@@ -103,6 +138,11 @@ dialog:
}
}
break;
#else
case SQL_DRIVER_PROMPT:
case SQL_DRIVER_COMPLETE:
case SQL_DRIVER_COMPLETE_REQUIRED:
#endif
case SQL_DRIVER_NOPROMPT:
break;
}
......@@ -122,14 +162,16 @@ dialog:
if(szConnStrOut) {
// return the completed string to the caller.
makeConnectString(connect_string, ci);
/* Return the completed string to the caller.
Only construct the connect string if a dialog was put up,
otherwise, just copy the connection input string to the output.
*/
makeConnectString(connStrOut, ci);
if(pcbConnStrOut) {
*pcbConnStrOut = strlen(connect_string);
*pcbConnStrOut = strlen(connStrOut);
}
strncpy_null(szConnStrOut, connect_string, cbConnStrOutMax);
strncpy_null(szConnStrOut, connStrOut, cbConnStrOutMax);
}
mylog("szConnStrOut = '%s'\n", szConnStrOut);
......@@ -143,8 +185,12 @@ dialog:
return SQL_ERROR; /* need a password but not allowed to prompt so error */
}
else {
#ifndef UNIX
password_required = TRUE;
goto dialog;
#else
return SQL_ERROR; /* until a better solution is found. */
#endif
}
}
else if (retval == 0) {
......@@ -157,7 +203,7 @@ dialog:
return SQL_SUCCESS;
}
#ifndef UNIX /* yet another candidate for ifdef WINDOWS */
RETCODE dconn_DoDialog(HWND hwnd, ConnInfo *ci)
{
int dialog_result;
......@@ -216,6 +262,7 @@ ConnInfo *ci;
else if (ci->focus_password)
SetFocus(GetDlgItem(hdlg, IDC_PASSWORD));
break;
case WM_COMMAND:
......@@ -252,7 +299,7 @@ ConnInfo *ci;
return FALSE;
}
#endif /* ! UNIX */
void dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci)
{
......
......@@ -10,10 +10,21 @@
#ifndef __ENVIRON_H__
#define __ENVIRON_H__
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "psqlodbc.h"
#ifdef HAVE_IODBC
#include "iodbc.h"
#include "isql.h"
#include "isqlext.h"
#else
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#endif
#define ENV_ALLOC_ERROR 1
......
......@@ -13,11 +13,21 @@
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "psqlodbc.h"
#include <stdio.h>
#include <string.h>
#ifdef HAVE_IODBC
#include "iodbc.h"
#include "isqlext.h"
#else
#include <windows.h>
#include <sqlext.h>
#endif
#include "connection.h"
#include "statement.h"
......@@ -27,6 +37,15 @@
#include "lobj.h"
RETCODE SQL_API SQLExecDirect(
HSTMT hstmt,
UCHAR FAR *szSqlStr,
SDWORD cbSqlStr)
{
return _SQLExecDirect(hstmt, szSqlStr, cbSqlStr);
}
// Perform a Prepare on the SQL statement
RETCODE SQL_API SQLPrepare(HSTMT hstmt,
UCHAR FAR *szSqlStr,
......@@ -111,7 +130,7 @@ StatementClass *self = (StatementClass *) hstmt;
// Performs the equivalent of SQLPrepare, followed by SQLExecute.
RETCODE SQL_API SQLExecDirect(
RETCODE SQL_API _SQLExecDirect(
HSTMT hstmt,
UCHAR FAR *szSqlStr,
SDWORD cbSqlStr)
......@@ -359,6 +378,8 @@ StatementClass *stmt = (StatementClass *) hstmt;
stmt->current_exec_param = -1;
stmt->put_data = FALSE;
return SQL_SUCCESS;
}
// - - - - - - - - -
......
This diff is collapsed.
// GetPrivateProfileString
// for UNIX use
#ifndef GPPS_H
#define GPPS_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef UNIX
#include <sys/types.h>
#include "iodbc.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
DWORD
GetPrivateProfileString(char *theSection, // section name
char *theKey, // search key name
char *theDefault, // default value if not found
char *theReturnBuffer, // return valuse stored here
size_t theBufferLength, // byte length of return buffer
char *theIniFileName); // pathname of ini file to search
DWORD
WritePrivateProfileString(char *theSection, // section name
char *theKey, // write key name
char *theBuffer, // input buffer
char *theIniFileName); // pathname of ini file to write
#ifdef __cplusplus
}
#endif
#ifdef UNIX
#undef DWORD
#endif
#endif
......@@ -16,12 +16,24 @@
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <stdio.h>
#include "psqlodbc.h"
#ifdef HAVE_IODBC
#include "iodbc.h"
#include "isql.h"
#include "isqlext.h"
#else
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#endif
#include "tuple.h"
#include "pgtypes.h"
......@@ -282,7 +294,7 @@ char *p;
// examples of identifiers. it says return a blank for no
// quote character, we'll try that...
if (pcbInfoValue) *pcbInfoValue = 1;
strncpy_null((char *)rgbInfoValue, " ", (size_t)cbInfoValueMax);
strncpy_null((char *)rgbInfoValue, "\"", (size_t)cbInfoValueMax);
break;
case SQL_KEYWORDS: /* ODBC 2.0 */
......@@ -325,7 +337,7 @@ char *p;
case SQL_MAX_COLUMN_NAME_LEN: /* ODBC 1.0 */
// maximum length of a column name
*((WORD *)rgbInfoValue) = 32;
*((WORD *)rgbInfoValue) = MAX_COLUMN_LEN;
if(pcbInfoValue) { *pcbInfoValue = 2; }
break;
......@@ -358,7 +370,7 @@ char *p;
break;
case SQL_MAX_CURSOR_NAME_LEN: /* ODBC 1.0 */
*((WORD *)rgbInfoValue) = 32;
*((WORD *)rgbInfoValue) = MAX_CURSOR_LEN;
if(pcbInfoValue) { *pcbInfoValue = 2; }
break;
......@@ -405,7 +417,7 @@ char *p;
break;
case SQL_MAX_TABLE_NAME_LEN: /* ODBC 1.0 */
*((WORD *)rgbInfoValue) = 32;
*((WORD *)rgbInfoValue) = MAX_TABLE_LEN;
if(pcbInfoValue) { *pcbInfoValue = 2; }
break;
......@@ -1036,7 +1048,7 @@ mylog("**** SQLTables(): ENTER, stmt=%u\n", stmt);
show_regular_tables = FALSE;
show_views = FALSE;
// make_string mallocs memory
/* make_string mallocs memory */
tableType = make_string(szTableType, cbTableType, NULL);
if (tableType) {
strcpy(table_types, tableType);
......@@ -1059,7 +1071,10 @@ mylog("**** SQLTables(): ENTER, stmt=%u\n", stmt);
i++;
}
}
else {
show_regular_tables = TRUE;
show_views = TRUE;
}
/* If not interested in SYSTEM TABLES then filter them out
......@@ -1228,6 +1243,9 @@ mylog("**** SQLTables(): ENTER, stmt=%u\n", stmt);
return SQL_SUCCESS;
}
RETCODE SQL_API SQLColumns(
HSTMT hstmt,
UCHAR FAR * szTableQualifier,
......@@ -1247,9 +1265,8 @@ StatementClass *col_stmt;
char columns_query[MAX_STATEMENT_LEN];
RETCODE result;
char table_owner[MAX_INFO_STRING], table_name[MAX_INFO_STRING], field_name[MAX_INFO_STRING], field_type_name[MAX_INFO_STRING];
Int2 field_number, field_length, mod_length;
Int4 field_type;
Int2 the_type;
Int2 field_number, field_length, mod_length, result_cols;
Int4 field_type, the_type;
char not_null[MAX_INFO_STRING];
ConnInfo *ci;
......@@ -1403,10 +1420,11 @@ mylog("**** SQLColumns(): ENTER, stmt=%u\n", stmt);
// the binding structure for a statement is not set up until
// a statement is actually executed, so we'll have to do this ourselves.
extend_bindings(stmt, 12);
result_cols = 14;
extend_bindings(stmt, result_cols);
// set the field names
QR_set_num_fields(stmt->result, 12);
QR_set_num_fields(stmt->result, result_cols);
QR_set_field_info(stmt->result, 0, "TABLE_QUALIFIER", PG_TYPE_TEXT, MAX_INFO_STRING);
QR_set_field_info(stmt->result, 1, "TABLE_OWNER", PG_TYPE_TEXT, MAX_INFO_STRING);
QR_set_field_info(stmt->result, 2, "TABLE_NAME", PG_TYPE_TEXT, MAX_INFO_STRING);
......@@ -1420,6 +1438,10 @@ mylog("**** SQLColumns(): ENTER, stmt=%u\n", stmt);
QR_set_field_info(stmt->result, 10, "NULLABLE", PG_TYPE_INT2, 2);
QR_set_field_info(stmt->result, 11, "REMARKS", PG_TYPE_TEXT, 254);
// User defined fields
QR_set_field_info(stmt->result, 12, "DISPLAY_SIZE", PG_TYPE_INT4, 4);
QR_set_field_info(stmt->result, 13, "FIELD_TYPE", PG_TYPE_INT4, 4);
result = SQLFetch(hcol_stmt);
......@@ -1435,7 +1457,7 @@ mylog("**** SQLColumns(): ENTER, stmt=%u\n", stmt);
/* For OID fields */
the_type = PG_TYPE_OID;
row = (TupleNode *)malloc(sizeof(TupleNode) +
(12 - 1) * sizeof(TupleField));
(result_cols - 1) * sizeof(TupleField));
set_tuplefield_string(&row->tuple[0], "");
// see note in SQLTables()
......@@ -1446,16 +1468,17 @@ mylog("**** SQLColumns(): ENTER, stmt=%u\n", stmt);
set_tuplefield_int2(&row->tuple[4], pgtype_to_sqltype(stmt, the_type));
set_tuplefield_string(&row->tuple[5], "OID");
set_tuplefield_int4(&row->tuple[7], pgtype_length(stmt, the_type, PG_STATIC,
PG_STATIC));
set_tuplefield_int4(&row->tuple[6], pgtype_precision(stmt, the_type, PG_STATIC,
PG_STATIC));
set_tuplefield_int4(&row->tuple[7], pgtype_length(stmt, the_type, PG_STATIC, PG_STATIC));
set_tuplefield_int4(&row->tuple[6], pgtype_precision(stmt, the_type, PG_STATIC, PG_STATIC));
set_nullfield_int2(&row->tuple[8], pgtype_scale(stmt, the_type));
set_nullfield_int2(&row->tuple[9], pgtype_radix(stmt, the_type));
set_tuplefield_int2(&row->tuple[10], SQL_NO_NULLS);
set_tuplefield_string(&row->tuple[11], "");
set_tuplefield_int4(&row->tuple[12], pgtype_display_size(stmt, the_type, PG_STATIC, PG_STATIC));
set_tuplefield_int4(&row->tuple[13], the_type);
QR_add_tuple(stmt->result, row);
}
......@@ -1463,7 +1486,7 @@ mylog("**** SQLColumns(): ENTER, stmt=%u\n", stmt);
while((result == SQL_SUCCESS) || (result == SQL_SUCCESS_WITH_INFO)) {
row = (TupleNode *)malloc(sizeof(TupleNode) +
(12 - 1) * sizeof(TupleField));
(result_cols - 1) * sizeof(TupleField));
set_tuplefield_string(&row->tuple[0], "");
// see note in SQLTables()
......@@ -1494,11 +1517,13 @@ mylog("**** SQLColumns(): ENTER, stmt=%u\n", stmt);
set_tuplefield_int4(&row->tuple[7], mod_length);
set_tuplefield_int4(&row->tuple[6], mod_length);
set_tuplefield_int4(&row->tuple[12], mod_length);
} else {
mylog("SQLColumns: field type is OTHER: field_type = %d, pgtype_length = %d\n", field_type, pgtype_length(stmt, field_type, PG_STATIC, PG_STATIC));
set_tuplefield_int4(&row->tuple[7], pgtype_length(stmt, field_type, PG_STATIC, PG_STATIC));
set_tuplefield_int4(&row->tuple[6], pgtype_precision(stmt, field_type, PG_STATIC, PG_STATIC));
set_tuplefield_int4(&row->tuple[12], pgtype_display_size(stmt, field_type, PG_STATIC, PG_STATIC));
}
......@@ -1506,6 +1531,7 @@ mylog("**** SQLColumns(): ENTER, stmt=%u\n", stmt);
set_nullfield_int2(&row->tuple[9], pgtype_radix(stmt, field_type));
set_tuplefield_int2(&row->tuple[10], (Int2) (not_null[0] == '1' ? SQL_NO_NULLS : pgtype_nullable(stmt, field_type)));
set_tuplefield_string(&row->tuple[11], "");
set_tuplefield_int4(&row->tuple[13], field_type);
QR_add_tuple(stmt->result, row);
......@@ -1526,7 +1552,7 @@ mylog("**** SQLColumns(): ENTER, stmt=%u\n", stmt);
the_type = PG_TYPE_INT4;
row = (TupleNode *)malloc(sizeof(TupleNode) +
(12 - 1) * sizeof(TupleField));
(result_cols - 1) * sizeof(TupleField));
set_tuplefield_string(&row->tuple[0], "");
set_tuplefield_string(&row->tuple[1], "");
......@@ -1540,6 +1566,8 @@ mylog("**** SQLColumns(): ENTER, stmt=%u\n", stmt);
set_nullfield_int2(&row->tuple[9], pgtype_radix(stmt, the_type));
set_tuplefield_int2(&row->tuple[10], SQL_NO_NULLS);
set_tuplefield_string(&row->tuple[11], "");
set_tuplefield_int4(&row->tuple[12], pgtype_display_size(stmt, the_type, PG_STATIC, PG_STATIC));
set_tuplefield_int4(&row->tuple[13], the_type);
QR_add_tuple(stmt->result, row);
}
......
#ifndef _IODBC_H
#define _IODBC_H
# if !defined(WINDOWS) && !defined(WIN32_SYSTEM)
# define _UNIX_
# include <stdlib.h>
# include <sys/types.h>
# define MEM_ALLOC(size) (malloc((size_t)(size)))
# define MEM_FREE(ptr) {if(ptr) free(ptr);}
# define STRCPY(t, s) (strcpy((char*)(t), (char*)(s)))
# define STRNCPY(t,s,n) (strncpy((char*)(t), (char*)(s), (size_t)(n)))
# define STRCAT(t, s) (strcat((char*)(t), (char*)(s)))
# define STRNCAT(t,s,n) (strncat((char*)(t), (char*)(s), (size_t)(n)))
# define STREQ(a, b) (strcmp((char*)(a), (char*)(b)) == 0)
# define STRLEN(str) ((str)? strlen((char*)(str)):0)
# define EXPORT
# define CALLBACK
# define FAR
typedef signed short SSHOR;
typedef short WORD;
typedef long DWORD;
typedef WORD WPARAM;
typedef DWORD LPARAM;
typedef void* HWND;
typedef int BOOL;
# endif /* _UNIX_ */
# if defined(WINDOWS) || defined(WIN32_SYSTEM)
# include <windows.h>
# include <windowsx.h>
# ifdef _MSVC_
# define MEM_ALLOC(size) (fmalloc((size_t)(size)))
# define MEM_FREE(ptr) ((ptr)? ffree((PTR)(ptr)):0))
# define STRCPY(t, s) (fstrcpy((char FAR*)(t), (char FAR*)(s)))
# define STRNCPY(t,s,n) (fstrncpy((char FAR*)(t), (char FAR*)(s), (size_t)(n)))
# define STRLEN(str) ((str)? fstrlen((char FAR*)(str)):0)
# define STREQ(a, b) (fstrcmp((char FAR*)(a), (char FAR*)(b) == 0)
# endif
# ifdef _BORLAND_
# define MEM_ALLOC(size) (farmalloc((unsigned long)(size))
# define MEM_FREE(ptr) ((ptr)? farfree((void far*)(ptr)):0)
# define STRCPY(t, s) (_fstrcpy((char FAR*)(t), (char FAR*)(s)))
# define STRNCPY(t,s,n) (_fstrncpy((char FAR*)(t), (char FAR*)(s), (size_t)(n)))
# define STRLEN(str) ((str)? _fstrlen((char FAR*)(str)):0)
# define STREQ(a, b) (_fstrcmp((char FAR*)(a), (char FAR*)(b) == 0)
# endif
# endif /* WINDOWS */
# define SYSERR (-1)
# ifndef NULL
# define NULL ((void FAR*)0UL)
# endif
#endif
/* Modified isql.h file from iodbc. This file should be placed in the
* include path to be used to create ODBC compliant applications.
*/
#ifndef _INTRINSIC_SQL_H
# define _INTRINSIC_SQL_H
typedef unsigned char UCHAR;
typedef long int SDWORD;
typedef short int SWORD;
typedef unsigned long int UDWORD;
typedef unsigned short int UWORD;
typedef void FAR* PTR;
typedef void FAR* HENV;
typedef void FAR* HDBC;
typedef void FAR* HSTMT;
typedef signed short RETCODE;
# ifdef WIN32
# define SQL_API __stdcall
# else
# define SQL_API EXPORT CALLBACK
# endif
# define ODBCVER 0x0200
# define SQL_MAX_MESSAGE_LENGTH 512
# define SQL_MAX_DSN_LENGTH 32
/* return code */
# define SQL_INVALID_HANDLE (-2)
# define SQL_ERROR (-1)
# define SQL_SUCCESS 0
# define SQL_SUCCESS_WITH_INFO 1
# define SQL_NO_DATA_FOUND 100
/* standard SQL datatypes (agree with ANSI type numbering) */
# define SQL_CHAR 1
# define SQL_NUMERIC 2
# define SQL_DECIMAL 3
# define SQL_INTEGER 4
# define SQL_SMALLINT 5
# define SQL_FLOAT 6
# define SQL_REAL 7
# define SQL_DOUBLE 8
# define SQL_VARCHAR 12
# define SQL_TYPE_MIN SQL_CHAR
# define SQL_TYPE_NULL 0
# define SQL_TYPE_MAX SQL_VARCHAR
/* C to SQL datatype mapping */
# define SQL_C_CHAR SQL_CHAR
# define SQL_C_LONG SQL_INTEGER
# define SQL_C_SHORT SQL_SMALLINT
# define SQL_C_FLOAT SQL_REAL
# define SQL_C_DOUBLE SQL_DOUBLE
# define SQL_C_DEFAULT 99
# define SQL_NO_NULLS 0
# define SQL_NULLABLE 1
# define SQL_NULLABLE_UNKNOWN 2
/* some special length values */
# define SQL_NULL_DATA (-1)
# define SQL_DATA_AT_EXEC (-2)
# define SQL_NTS (-3)
/* SQLFreeStmt flag values */
# define SQL_CLOSE 0
# define SQL_DROP 1
# define SQL_UNBIND 2
# define SQL_RESET_PARAMS 3
/* SQLTransact flag values */
# define SQL_COMMIT 0
# define SQL_ROLLBACK 1
/* SQLColAttributes flag values */
# define SQL_COLUMN_COUNT 0
# define SQL_COLUMN_LABEL 18
# define SQL_COLATT_OPT_MAX SQL_COLUMN_LABEL
# define SQL_COLUMN_DRIVER_START 1000
# define SQL_COLATT_OPT_MIN SQL_COLUMN_COUNT
/* Null handles */
# define SQL_NULL_HENV 0
# define SQL_NULL_HDBC 0
# define SQL_NULL_HSTMT 0
/* All code below has been added to the original isql.h coming from iodbc */
typedef unsigned char BYTE;
/* More SQLColAttributes flag values */
#define SQL_COLUMN_NAME 1
#define SQL_COLUMN_TYPE 2
#define SQL_COLUMN_LENGTH 3
#define SQL_COLUMN_PRECISION 4
#define SQL_COLUMN_SCALE 5
#define SQL_COLUMN_DISPLAY_SIZE 6
#define SQL_COLUMN_NULLABLE 7
#define SQL_COLUMN_UNSIGNED 8
#define SQL_COLUMN_MONEY 9
#define SQL_COLUMN_UPDATABLE 10
#define SQL_COLUMN_AUTO_INCREMENT 11
#define SQL_COLUMN_CASE_SENSITIVE 12
#define SQL_COLUMN_SEARCHABLE 13
#define SQL_COLUMN_TYPE_NAME 14
#define SQL_COLUMN_TABLE_NAME 15
#define SQL_COLUMN_OWNER_NAME 16
#define SQL_COLUMN_QUALIFIER_NAME 17
/* SQLColAttributes Searchable flags */
#define SQL_UNSEARCHABLE 0
#define SQL_LIKE_ONLY 1
#define SQL_ALL_EXCEPT_LIKE 2
#define SQL_SEARCHABLE 3
#define SQL_PRED_SEARCHABLE SQL_SEARCHABLE
/* SQLColAttributes Updateable flags */
#define SQL_ATTR_READONLY 0
#define SQL_ATTR_WRITE 1
#define SQL_ATTR_READWRITE_UNKNOWN 2
/*
* function prototypes previously not contained in isql.h
*/
#ifdef __cplusplus
extern "C"
{
#endif
RETCODE SQL_API SQLAllocConnect (HENV henv,
HDBC FAR * phdbc);
RETCODE SQL_API SQLAllocEnv (HENV FAR * phenv);
RETCODE SQL_API SQLAllocStmt (HDBC hdbc,
HSTMT FAR * phstmt);
RETCODE SQL_API SQLBindCol (HSTMT hstmt,
UWORD icol,
SWORD fCType,
PTR rgbValue,
SDWORD cbValueMax,
SDWORD FAR * pcbValue);
RETCODE SQL_API SQLCancel (HSTMT hstmt);
RETCODE SQL_API SQLColAttributes (HSTMT hstmt,
UWORD icol,
UWORD fDescType,
PTR rgbDesc,
SWORD cbDescMax,
SWORD FAR * pcbDesc,
SDWORD FAR * pfDesc);
RETCODE SQL_API SQLConnect (HDBC hdbc,
UCHAR FAR * szDSN,
SWORD cbDSN,
UCHAR FAR * szUID,
SWORD cbUID,
UCHAR FAR * szAuthStr,
SWORD cbAuthStr);
RETCODE SQL_API SQLDescribeCol (HSTMT hstmt,
UWORD icol,
UCHAR FAR * szColName,
SWORD cbColNameMax,
SWORD FAR * pcbColName,
SWORD FAR * pfSqlType,
UDWORD FAR * pcbColDef,
SWORD FAR * pibScale,
SWORD FAR * pfNullable);
RETCODE SQL_API SQLDisconnect (HDBC hdbc);
RETCODE SQL_API SQLError (HENV henv,
HDBC hdbc,
HSTMT hstmt,
UCHAR FAR * szSqlState,
SDWORD FAR * pfNativeError,
UCHAR FAR * szErrorMsg,
SWORD cbErrorMsgMax,
SWORD FAR * pcbErrorMsg);
RETCODE SQL_API SQLExecDirect (HSTMT hstmt,
UCHAR FAR * szSqlStr,
SDWORD cbSqlStr);
RETCODE SQL_API SQLExecute (HSTMT hstmt);
RETCODE SQL_API SQLFetch (HSTMT hstmt);
RETCODE SQL_API SQLFreeConnect (HDBC hdbc);
RETCODE SQL_API SQLFreeEnv (HENV henv);
RETCODE SQL_API SQLFreeStmt (HSTMT hstmt,
UWORD fOption);
RETCODE SQL_API SQLGetCursorName (HSTMT hstmt,
UCHAR FAR * szCursor,
SWORD cbCursorMax,
SWORD FAR * pcbCursor);
RETCODE SQL_API SQLNumResultCols (HSTMT hstmt,
SWORD FAR * pccol);
RETCODE SQL_API SQLPrepare (HSTMT hstmt,
UCHAR FAR * szSqlStr,
SDWORD cbSqlStr);
RETCODE SQL_API SQLRowCount (HSTMT hstmt,
SDWORD FAR * pcrow);
RETCODE SQL_API SQLSetCursorName (HSTMT hstmt,
UCHAR FAR * szCursor,
SWORD cbCursor);
RETCODE SQL_API SQLTransact (HENV henv,
HDBC hdbc,
UWORD fType);
RETCODE SQL_API SQLSetParam (HSTMT hstmt,
UWORD ipar,
SWORD fCType,
SWORD fSqlType,
UDWORD cbColDef,
SWORD ibScale,
PTR rgbValue,
SDWORD FAR * pcbValue);
#ifdef __cplusplus
}
#endif
#endif
This diff is collapsed.
......@@ -13,7 +13,7 @@
#include "psqlodbc.h"
typedef struct lo_arg {
struct lo_arg {
int isint;
int len;
union
......
......@@ -37,7 +37,7 @@ static FILE *LOGFP = 0;
fmt = va_arg(args, char *);
if (! LOGFP) {
LOGFP = fopen("c:\\mylog.log", "w");
LOGFP = fopen(MYLOGFILE, "w");
setbuf(LOGFP, NULL);
}
......@@ -64,7 +64,7 @@ static FILE *LOGFP = 0;
fmt = va_arg(args, char *);
if (! LOGFP) {
LOGFP = fopen("c:\\psqlodbc.log", "w");
LOGFP = fopen(QLOGFILE, "w");
setbuf(LOGFP, NULL);
}
......@@ -77,12 +77,24 @@ static FILE *LOGFP = 0;
#endif
/* Undefine these because windows.h will redefine and cause a warning */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifndef UNIX
#undef va_start
#undef va_end
#endif
#ifdef HAVE_IODBC
#include "iodbc.h"
#include "isql.h"
#else
#include <windows.h>
#include <sql.h>
#endif
/* returns STRCPY_FAIL, STRCPY_TRUNCATED, or #bytes copied (not including null term) */
int
......@@ -155,7 +167,7 @@ make_string(char *s, int len, char *buf)
int length;
char *str;
if(s && (len > 0 || len == SQL_NTS)) {
if(s && (len > 0 || (len == SQL_NTS && strlen(s) > 0))) {
length = (len > 0) ? len : strlen(s);
if (buf) {
......
......@@ -10,6 +10,15 @@
#ifndef __MISC_H__
#define __MISC_H__
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef UNIX
#include "gpps.h"
#define SQLGetPrivateProfileString(a,b,c,d,e,f) GetPrivateProfileString(a,b,c,d,e,f)
#endif
#include <stdio.h>
/* Uncomment MY_LOG define to compile in the mylog() statements.
......@@ -30,12 +39,22 @@
#ifdef MY_LOG
#ifdef UNIX
#define MYLOGFILE "/tmp/mylog.log"
#else
#define MYLOGFILE "c:\\mylog.log"
#endif
void mylog(); /* prototype */
#else
#define mylog // mylog
#endif
#ifdef Q_LOG
#ifdef UNIX
#define QLOGFILE "/tmp/psqlodbc.log"
#else
#define QLOGFILE "c:\\psqlodbc.log"
#endif
void qlog(); /* prototype */
#else
#define qlog // qlog
......
[PostgreSQL]
Debug = 0
CommLog = 1
......@@ -13,10 +13,22 @@
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "psqlodbc.h"
#ifdef HAVE_IODBC
#include "iodbc.h"
#include "isql.h"
#include "isqlext.h"
#else
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#endif
#include "environ.h"
#include "connection.h"
#include "statement.h"
......@@ -81,12 +93,15 @@ ConnectionClass *conn = (ConnectionClass *) hdbc;
case SQL_ACCESS_MODE:
break;
case SQL_TXN_ISOLATION:
break;
default:
{
char option[32];
conn->errormsg = "This option is currently unsupported by the driver";
char option[64];
conn->errormsg = "Driver does not support setting this connect option";
conn->errornumber = CONN_UNSUPPORTED_OPTION;
sprintf(option, "fOption=%d", fOption);
sprintf(option, "fOption=%d, vParam=%d", fOption, vParam);
CC_log_error(func, option, conn);
return SQL_ERROR;
}
......@@ -126,8 +141,8 @@ ConnectionClass *conn = (ConnectionClass *) hdbc;
default:
{
char option[32];
conn->errormsg = "This option is currently unsupported by the driver";
char option[64];
conn->errormsg = "Driver does not support getting this connect option";
conn->errornumber = CONN_UNSUPPORTED_OPTION;
sprintf(option, "fOption=%d", fOption);
CC_log_error(func, option, conn);
......@@ -242,10 +257,10 @@ char changed = FALSE;
default:
{
char option[32];
char option[64];
stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
stmt->errormsg = "Driver does not support this statement option";
sprintf(option, "fOption=%d", fOption);
stmt->errormsg = "Driver does not support setting this statement option";
sprintf(option, "fOption=%d, vParam=%d", fOption, vParam);
SC_log_error(func, option, stmt);
return SQL_ERROR;
}
......@@ -326,9 +341,9 @@ StatementClass *stmt = (StatementClass *) hstmt;
default:
{
char option[32];
char option[64];
stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
stmt->errormsg = "Driver does not support this statement option";
stmt->errormsg = "Driver does not support getting this statement option";
sprintf(option, "fOption=%d", fOption);
SC_log_error(func, option, stmt);
return SQL_ERROR;
......
This diff is collapsed.
......@@ -15,15 +15,26 @@
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "psqlodbc.h"
#include "dlg_specific.h"
#include "pgtypes.h"
#include "statement.h"
#include "connection.h"
#include "qresult.h"
#ifdef HAVE_IODBC
#include "iodbc.h"
#include "isql.h"
#include "isqlext.h"
#else
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#endif
extern GLOBAL_VALUES globals;
......@@ -223,7 +234,7 @@ mylog("getCharPrecision: type=%d, col=%d, unknown = %d\n", type,col,handle_unkno
if (stmt->manual_result) {
flds = result->fields;
if (flds)
return flds->typlen[col];
return flds->adtsize[col];
else
return maxsize;
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -74,7 +74,8 @@ BEGIN
EDITTEXT IDC_PASSWORD,175,55,72,12,ES_PASSWORD | ES_AUTOHSCROLL
DEFPUSHBUTTON "OK",IDOK,25,90,40,14,WS_GROUP
PUSHBUTTON "Cancel",IDCANCEL,80,90,40,14
GROUPBOX "Options (Advanced):",IDC_STATIC,140,74,140,35,BS_CENTER
GROUPBOX "Options (Advanced):",IDC_OPTIONS,140,74,140,35,
BS_CENTER
PUSHBUTTON "Driver",IDC_DRIVER,160,90,50,14
PUSHBUTTON "DataSource",IDC_DATASOURCE,220,90,50,14
CTEXT "Please supply any missing information needed to connect.",
......@@ -96,6 +97,8 @@ BEGIN
BS_AUTOCHECKBOX | WS_TABSTOP,140,25,80,10
CONTROL "&Use Declare/Fetch",DRV_USEDECLAREFETCH,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,15,40,80,10
CONTROL "P&arse Statements",DRV_PARSE,"Button",BS_AUTOCHECKBOX |
WS_TABSTOP,140,40,80,10
GROUPBOX "Unknown Sizes",IDC_STATIC,10,55,175,25
CONTROL "Maximum",DRV_UNKNOWN_MAX,"Button",BS_AUTORADIOBUTTON |
WS_GROUP | WS_TABSTOP,15,65,45,10
......@@ -200,8 +203,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 6,30,2,46
PRODUCTVERSION 6,30,2,46
FILEVERSION 6,30,2,48
PRODUCTVERSION 6,30,2,48
FILEFLAGSMASK 0x3L
#ifdef _DEBUG
FILEFLAGS 0x1L
......@@ -219,12 +222,12 @@ BEGIN
VALUE "Comments", "PostgreSQL ODBC driver for Windows 95\0"
VALUE "CompanyName", "Insight Distribution Systems\0"
VALUE "FileDescription", "PostgreSQL Driver\0"
VALUE "FileVersion", " 6.30.0246\0"
VALUE "FileVersion", " 6.30.0248\0"
VALUE "InternalName", "psqlodbc\0"
VALUE "LegalTrademarks", "ODBC(TM) is a trademark of Microsoft Corporation. Microsoft is a registered trademark of Microsoft Corporation. Windows(TM) is a trademark of Microsoft Corporation.\0"
VALUE "OriginalFilename", "psqlodbc.dll\0"
VALUE "ProductName", "Microsoft Open Database Connectivity\0"
VALUE "ProductVersion", " 6.30.0246\0"
VALUE "ProductVersion", " 6.30.0248\0"
END
END
BLOCK "VarFileInfo"
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment