Commit 377d131b authored by Hiroshi Inoue's avatar Hiroshi Inoue

1) Most driver options could be set per DSN.

2) Keep FE/BE protocol more precisely.
3) Improve procedure calls.
4) A trial to avoid PREMATURE execution(#ifdef'd now).

Hiroshi Inoue
parent 3bdd67a2
......@@ -335,8 +335,14 @@ PGAPI_ParamOptions(
static char *func = "PGAPI_ParamOptions";
StatementClass *stmt = (StatementClass *) hstmt;
mylog("%s: entering...\n", func);
mylog("%s: entering... %d %x\n", func, crow, pirow);
if (crow == 1) /* temporary solution and must be rewritten later */
{
if (pirow)
*pirow = 1;
return SQL_SUCCESS;
}
stmt->errornumber = CONN_UNSUPPORTED_OPTION;
stmt->errormsg = "Function not implemented";
SC_log_error(func, "Function not implemented", (StatementClass *) hstmt);
......
This diff is collapsed.
......@@ -159,6 +159,7 @@ typedef struct
char translation_dll[MEDIUM_REGISTRY_LEN];
char translation_option[SMALL_REGISTRY_LEN];
char focus_password;
GLOBAL_VALUES drivers; /* moved from driver's option */
} ConnInfo;
/* Macro to determine is the connection using 6.2 protocol? */
......
This diff is collapsed.
......@@ -29,8 +29,8 @@ typedef struct
int ss;
} SIMPLE_TIME;
int copy_and_convert_field_bindinfo(StatementClass *stmt, Int4 field_type, void *value, int col);
int copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2 fCType,
int copy_and_convert_field_bindinfo(StatementClass *stmt, Int4 field_type, const void *value, int col);
int copy_and_convert_field(StatementClass *stmt, Int4 field_type, const void *value, Int2 fCType,
PTR rgbValue, SDWORD cbValueMax, SDWORD *pcbValue);
int copy_statement_with_parameters(StatementClass *stmt);
......@@ -38,14 +38,14 @@ char *convert_escape(char *value);
char *convert_money(char *s);
char parse_datetime(char *buf, SIMPLE_TIME *st);
int convert_linefeeds(const char *s, char *dst, size_t max, BOOL *changed);
int 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,
int convert_special_chars(const char *si, char *dst, int used);
int convert_pgbinary_to_char(const char *value, char *rgbValue, int cbValueMax);
int convert_from_pgbinary(const unsigned char *value, unsigned char *rgbValue, int cbValueMax);
int convert_to_pgbinary(const unsigned char *in, char *out, int len);
void encode(const char *in, char *out);
void decode(const char *in, char *out);
int convert_lo(StatementClass *stmt, const void *value, Int2 fCType, PTR rgbValue,
SDWORD cbValueMax, SDWORD *pcbValue);
#endif
This diff is collapsed.
......@@ -126,10 +126,10 @@
#define DEFAULT_EXTRASYSTABLEPREFIXES "dd_;"
/* prototypes */
void getGlobalDefaults(char *section, char *filename, char override);
void getCommonDefaults(const char *section, const char *filename, ConnInfo *ci);
#ifdef WIN32
void SetDlgStuff(HWND hdlg, ConnInfo *ci);
void SetDlgStuff(HWND hdlg, const ConnInfo *ci);
void GetDlgStuff(HWND hdlg, ConnInfo *ci);
int CALLBACK driver_optionsProc(HWND hdlg,
......@@ -144,11 +144,12 @@ int CALLBACK ds_optionsProc(HWND hdlg,
#endif /* WIN32 */
void updateGlobals(void);
void writeDSNinfo(ConnInfo *ci);
void writeDSNinfo(const 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 makeConnectString(char *connect_string, const ConnInfo *ci, UWORD);
void copyAttributes(ConnInfo *ci, const char *attribute, const char *value);
void copyCommonAttributes(ConnInfo *ci, const char *attribute, const char *value);
#endif
......@@ -51,7 +51,8 @@
#include "dlg_specific.h"
/* prototypes */
void dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci);
void dconn_get_connect_attributes(const UCHAR FAR *connect_string, ConnInfo *ci);
static void dconn_get_common_attributes(const UCHAR FAR *connect_string, ConnInfo *ci);
#ifdef WIN32
BOOL FAR PASCAL dconn_FDriverConnectProc(HWND hdlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
......@@ -61,8 +62,6 @@ extern HINSTANCE NEAR s_hModule;/* Saved module handle. */
#endif
extern GLOBAL_VALUES globals;
RETCODE SQL_API
PGAPI_DriverConnect(
......@@ -115,6 +114,8 @@ PGAPI_DriverConnect(
* given -- if not, it does nothing!)
*/
getDSNinfo(ci, CONN_DONT_OVERWRITE);
dconn_get_common_attributes(connStrIn, ci);
logs_on_off(1, ci->drivers.debug, ci->drivers.commlog);
/* Fill in any default parameters if they are not there. */
getDSNdefaults(ci);
......@@ -210,7 +211,7 @@ dialog:
*/
result = SQL_SUCCESS;
makeConnectString(connStrOut, ci);
makeConnectString(connStrOut, ci, cbConnStrOutMax);
len = strlen(connStrOut);
if (szConnStrOut)
......@@ -238,7 +239,7 @@ dialog:
if (pcbConnStrOut)
*pcbConnStrOut = len;
mylog("szConnStrOut = '%s'\n", szConnStrOut);
mylog("szConnStrOut = '%s' len=%d,%d\n", szConnStrOut, len, cbConnStrOutMax);
qlog("conn=%u, PGAPI_DriverConnect(out)='%s'\n", conn, szConnStrOut);
......@@ -323,8 +324,9 @@ dconn_FDriverConnectProc(
return TRUE;
case IDC_DRIVER:
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV),
hdlg, driver_optionsProc, (LPARAM) NULL);
hdlg, driver_optionsProc, (LPARAM) ci);
break;
case IDC_DATASOURCE:
......@@ -342,7 +344,7 @@ dconn_FDriverConnectProc(
void
dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci)
dconn_get_connect_attributes(const UCHAR FAR *connect_string, ConnInfo *ci)
{
char *our_connect_string;
char *pair,
......@@ -386,3 +388,47 @@ dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci)
free(our_connect_string);
}
static void
dconn_get_common_attributes(const UCHAR FAR *connect_string, ConnInfo *ci)
{
char *our_connect_string;
char *pair,
*attribute,
*value,
*equals;
char *strtok_arg;
our_connect_string = strdup(connect_string);
strtok_arg = our_connect_string;
mylog("our_connect_string = '%s'\n", our_connect_string);
while (1)
{
pair = strtok(strtok_arg, ";");
if (strtok_arg)
strtok_arg = 0;
if (!pair)
break;
equals = strchr(pair, '=');
if (!equals)
continue;
*equals = '\0';
attribute = pair; /* ex. DSN */
value = equals + 1; /* ex. 'CEO co1' */
mylog("attribute = '%s', value = '%s'\n", attribute, value);
if (!attribute || !value)
continue;
/* Copy the appropriate value to the conninfo */
copyCommonAttributes(ci, attribute, value);
}
free(our_connect_string);
}
......@@ -43,7 +43,7 @@ PGAPI_AllocEnv(HENV FAR *phenv)
* should work.
*/
if (globals.socket_buffersize <= 0)
getGlobalDefaults(DBMS_NAME, ODBCINST_INI, FALSE);
getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
*phenv = (HENV) EN_Constructor();
if (!*phenv)
......
......@@ -34,7 +34,7 @@
#include "lobj.h"
#include "pgapifunc.h"
extern GLOBAL_VALUES globals;
/*extern GLOBAL_VALUES globals;*/
/* Perform a Prepare on the SQL statement */
......@@ -340,7 +340,32 @@ PGAPI_Execute(
return retval;
mylog(" stmt_with_params = '%s'\n", stmt->stmt_with_params);
#ifdef PREPARE_TRIAL
if (stmt->inaccurate_result)
if (SC_is_pre_executable(stmt))
{
BOOL in_trans = CC_is_in_trans(conn);
QResultClass *res;
CC_set_in_trans(conn);
stmt->result = res = CC_send_query(conn, stmt->stmt_with_params, NULL);
if (res && QR_aborted(res))
{
CC_abort(conn);
stmt->errornumber = STMT_EXEC_ERROR;
stmt->errormsg = "Handle prepare error";
return SQL_ERROR;
}
else
{
if (!in_trans)
CC_set_no_trans(conn);
stmt->status =STMT_FINISHED;
return SQL_SUCCESS;
}
}
else
return SQL_SUCCESS;
#endif /* PREPARE_TRIAL */
return SC_execute(stmt);
}
......@@ -437,6 +462,7 @@ PGAPI_Cancel(
#ifdef WIN32
HMODULE hmodule;
FARPROC addr;
ConnInfo *ci;
#endif
......@@ -448,6 +474,7 @@ PGAPI_Cancel(
SC_log_error(func, "", NULL);
return SQL_INVALID_HANDLE;
}
ci = &(SC_get_conn(stmt)->connInfo);
/*
* Not in the middle of SQLParamData/SQLPutData so cancel like a
......@@ -466,7 +493,7 @@ PGAPI_Cancel(
*/
#ifdef WIN32
if (globals.cancel_as_freestmt)
if (ci->drivers.cancel_as_freestmt)
{
hmodule = GetModuleHandle("ODBC32");
addr = GetProcAddress(hmodule, "SQLFreeStmt");
......@@ -569,6 +596,7 @@ PGAPI_ParamData(
StatementClass *stmt = (StatementClass *) hstmt;
int i,
retval;
ConnInfo *ci;
mylog("%s: entering...\n", func);
......@@ -577,6 +605,7 @@ PGAPI_ParamData(
SC_log_error(func, "", NULL);
return SQL_INVALID_HANDLE;
}
ci = &(SC_get_conn(stmt)->connInfo);
mylog("%s: data_at_exec=%d, params_alloc=%d\n", func, stmt->data_at_exec, stmt->parameters_allocated);
......@@ -602,7 +631,7 @@ PGAPI_ParamData(
lo_close(stmt->hdbc, stmt->lobj_fd);
/* commit transaction if needed */
if (!globals.use_declarefetch && CC_is_in_autocommit(stmt->hdbc))
if (!ci->drivers.use_declarefetch && CC_is_in_autocommit(stmt->hdbc))
{
QResultClass *res;
char ok;
......
......@@ -54,7 +54,7 @@
#define TRIGGER_UPDATE 0x02
extern GLOBAL_VALUES globals;
/* extern GLOBAL_VALUES globals; */
......@@ -83,7 +83,7 @@ PGAPI_GetInfo(
return SQL_INVALID_HANDLE;
}
ci = &conn->connInfo;
ci = &(conn->connInfo);
switch (fInfoType)
{
......@@ -113,7 +113,7 @@ PGAPI_GetInfo(
case SQL_BOOKMARK_PERSISTENCE: /* ODBC 2.0 */
/* very simple bookmark support */
len = 4;
value = globals.use_declarefetch ? 0 : (SQL_BP_SCROLL);
value = ci->drivers.use_declarefetch ? 0 : (SQL_BP_SCROLL);
break;
case SQL_COLUMN_ALIAS: /* ODBC 2.0 */
......@@ -167,7 +167,7 @@ PGAPI_GetInfo(
len = 2;
value = SQL_CB_CLOSE;
#ifdef DRIVER_CURSOR_IMPLEMENT
if (!globals.use_declarefetch)
if (!ci->drivers.use_declarefetch)
value = SQL_CB_PRESERVE;
#endif /* DRIVER_CURSOR_IMPLEMENT */
break;
......@@ -176,7 +176,7 @@ PGAPI_GetInfo(
len = 2;
value = SQL_CB_CLOSE;
#ifdef DRIVER_CURSOR_IMPLEMENT
if (!globals.use_declarefetch)
if (!ci->drivers.use_declarefetch)
value = SQL_CB_PRESERVE;
#endif /* DRIVER_CURSOR_IMPLEMENT */
break;
......@@ -261,7 +261,7 @@ PGAPI_GetInfo(
case SQL_FETCH_DIRECTION: /* ODBC 1.0 */
len = 4;
value = globals.use_declarefetch ? (SQL_FD_FETCH_NEXT) : (SQL_FD_FETCH_NEXT |
value = ci->drivers.use_declarefetch ? (SQL_FD_FETCH_NEXT) : (SQL_FD_FETCH_NEXT |
SQL_FD_FETCH_FIRST |
SQL_FD_FETCH_LAST |
SQL_FD_FETCH_PRIOR |
......@@ -315,7 +315,7 @@ PGAPI_GetInfo(
case SQL_LOCK_TYPES: /* ODBC 2.0 */
len = 4;
value = globals.lie ? (SQL_LCK_NO_CHANGE | SQL_LCK_EXCLUSIVE | SQL_LCK_UNLOCK) : SQL_LCK_NO_CHANGE;
value = ci->drivers.lie ? (SQL_LCK_NO_CHANGE | SQL_LCK_EXCLUSIVE | SQL_LCK_UNLOCK) : SQL_LCK_NO_CHANGE;
break;
case SQL_MAX_BINARY_LITERAL_LEN: /* ODBC 2.0 */
......@@ -523,12 +523,12 @@ PGAPI_GetInfo(
case SQL_POS_OPERATIONS: /* ODBC 2.0 */
len = 4;
value = globals.lie ? (SQL_POS_POSITION | SQL_POS_REFRESH | SQL_POS_UPDATE | SQL_POS_DELETE | SQL_POS_ADD) : (SQL_POS_POSITION | SQL_POS_REFRESH);
value = ci->drivers.lie ? (SQL_POS_POSITION | SQL_POS_REFRESH | SQL_POS_UPDATE | SQL_POS_DELETE | SQL_POS_ADD) : (SQL_POS_POSITION | SQL_POS_REFRESH);
break;
case SQL_POSITIONED_STATEMENTS: /* ODBC 2.0 */
len = 4;
value = globals.lie ? (SQL_PS_POSITIONED_DELETE |
value = ci->drivers.lie ? (SQL_PS_POSITIONED_DELETE |
SQL_PS_POSITIONED_UPDATE |
SQL_PS_SELECT_FOR_UPDATE) : 0;
break;
......@@ -571,12 +571,12 @@ PGAPI_GetInfo(
* Driver doesn't support keyset-driven or mixed cursors, so
* not much point in saying row updates are supported
*/
p = globals.lie ? "Y" : "N";
p = ci->drivers.lie ? "Y" : "N";
break;
case SQL_SCROLL_CONCURRENCY: /* ODBC 1.0 */
len = 4;
value = globals.lie ? (SQL_SCCO_READ_ONLY |
value = ci->drivers.lie ? (SQL_SCCO_READ_ONLY |
SQL_SCCO_LOCK |
SQL_SCCO_OPT_ROWVER |
SQL_SCCO_OPT_VALUES) : (SQL_SCCO_READ_ONLY);
......@@ -584,11 +584,11 @@ PGAPI_GetInfo(
case SQL_SCROLL_OPTIONS: /* ODBC 1.0 */
len = 4;
value = globals.lie ? (SQL_SO_FORWARD_ONLY |
value = ci->drivers.lie ? (SQL_SO_FORWARD_ONLY |
SQL_SO_STATIC |
SQL_SO_KEYSET_DRIVEN |
SQL_SO_DYNAMIC |
SQL_SO_MIXED) : (globals.use_declarefetch ? SQL_SO_FORWARD_ONLY : (SQL_SO_FORWARD_ONLY | SQL_SO_STATIC));
SQL_SO_MIXED) : (ci->drivers.use_declarefetch ? SQL_SO_FORWARD_ONLY : (SQL_SO_FORWARD_ONLY | SQL_SO_STATIC));
break;
case SQL_SEARCH_PATTERN_ESCAPE: /* ODBC 1.0 */
......@@ -605,7 +605,7 @@ PGAPI_GetInfo(
case SQL_STATIC_SENSITIVITY: /* ODBC 2.0 */
len = 4;
value = globals.lie ? (SQL_SS_ADDITIONS | SQL_SS_DELETIONS | SQL_SS_UPDATES) : 0;
value = ci->drivers.lie ? (SQL_SS_ADDITIONS | SQL_SS_DELETIONS | SQL_SS_UPDATES) : 0;
break;
case SQL_STRING_FUNCTIONS: /* ODBC 1.0 */
......@@ -782,7 +782,7 @@ PGAPI_GetTypeInfo(
for (i = 0, sqlType = sqlTypes[0]; sqlType; sqlType = sqlTypes[++i])
{
pgType = sqltype_to_pgtype(sqlType);
pgType = sqltype_to_pgtype(stmt, sqlType);
if (fSqlType == SQL_ALL_TYPES || fSqlType == sqlType)
{
......@@ -833,12 +833,13 @@ PGAPI_GetFunctions(
UWORD FAR *pfExists)
{
static char *func = "PGAPI_GetFunctions";
ConnInfo *ci = &(((ConnectionClass *)hdbc)->connInfo);
mylog("%s: entering...%u\n", func, fFunction);
if (fFunction == SQL_API_ALL_FUNCTIONS)
{
if (globals.lie)
if (ci->drivers.lie)
{
int i;
......@@ -923,7 +924,7 @@ PGAPI_GetFunctions(
}
else
{
if (globals.lie)
if (ci->drivers.lie)
*pfExists = TRUE;
else
{
......@@ -1156,8 +1157,8 @@ PGAPI_Tables(
stmt->manual_result = TRUE;
stmt->errormsg_created = TRUE;
conn = (ConnectionClass *) (stmt->hdbc);
ci = &stmt->hdbc->connInfo;
conn = SC_get_conn(stmt);
ci = &(conn->connInfo);
result = PGAPI_AllocStmt(stmt->hdbc, &htbl_stmt);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
......@@ -1188,7 +1189,7 @@ PGAPI_Tables(
my_strcat(tables_query, " and relname like '%.*s'", szTableName, cbTableName);
/* Parse the extra systable prefix */
strcpy(prefixes, globals.extra_systable_prefixes);
strcpy(prefixes, ci->drivers.extra_systable_prefixes);
i = 0;
prefix[i] = strtok(prefixes, ";");
while (prefix[i] && i < 32)
......@@ -1477,8 +1478,8 @@ PGAPI_Columns(
stmt->manual_result = TRUE;
stmt->errormsg_created = TRUE;
conn = (ConnectionClass *) (stmt->hdbc);
ci = &stmt->hdbc->connInfo;
conn = SC_get_conn(stmt);
ci = &(conn->connInfo);
/*
* Create the query to find out the columns (Note: pre 6.3 did not
......@@ -1778,8 +1779,8 @@ PGAPI_Columns(
if (mod_length >= 4)
mod_length -= 4;/* the length is in atttypmod - 4 */
if (mod_length > globals.max_varchar_size || mod_length <= 0)
mod_length = globals.max_varchar_size;
if (mod_length > ci->drivers.max_varchar_size || mod_length <= 0)
mod_length = ci->drivers.max_varchar_size;
mylog("%s: field type is VARCHAR,BPCHAR: field_type = %d, mod_length = %d\n", func, field_type, mod_length);
......@@ -1896,7 +1897,7 @@ PGAPI_SpecialColumns(
SC_log_error(func, "", NULL);
return SQL_INVALID_HANDLE;
}
ci = &stmt->hdbc->connInfo;
ci = &(SC_get_conn(stmt)->connInfo);
stmt->manual_result = TRUE;
......@@ -2062,7 +2063,7 @@ PGAPI_Statistics(
stmt->manual_result = TRUE;
stmt->errormsg_created = TRUE;
ci = &stmt->hdbc->connInfo;
ci = &(SC_get_conn(stmt)->connInfo);
stmt->result = QR_Constructor();
if (!stmt->result)
......@@ -2301,7 +2302,7 @@ PGAPI_Statistics(
set_tuplefield_string(&row->tuple[2], table_name);
/* non-unique index? */
set_tuplefield_int2(&row->tuple[3], (Int2) (globals.unique_index ? FALSE : TRUE));
set_tuplefield_int2(&row->tuple[3], (Int2) (ci->drivers.unique_index ? FALSE : TRUE));
/* no index qualifier */
set_tuplefield_string(&row->tuple[4], "");
......@@ -2345,7 +2346,7 @@ PGAPI_Statistics(
set_tuplefield_string(&row->tuple[2], table_name);
/* non-unique index? */
if (globals.unique_index)
if (ci->drivers.unique_index)
set_tuplefield_int2(&row->tuple[3], (Int2) (atoi(isunique) ? FALSE : TRUE));
else
set_tuplefield_int2(&row->tuple[3], TRUE);
......@@ -2556,7 +2557,7 @@ PGAPI_PrimaryKeys(
return SQL_ERROR;
}
conn = (ConnectionClass *) (stmt->hdbc);
conn = SC_get_conn(stmt);
if (PG_VERSION_LE(conn, 6.4))
qstart = 2;
else
......
......@@ -30,11 +30,11 @@
#endif
extern GLOBAL_VALUES globals;
void generate_filename(char *, char *, char *);
void generate_filename(const char *, const char *, char *);
void
generate_filename(char *dirname, char *prefix, char *filename)
generate_filename(const char *dirname, const char *prefix, char *filename)
{
int pid = 0;
......@@ -58,6 +58,33 @@ generate_filename(char *dirname, char *prefix, char *filename)
return;
}
static int mylog_on = 0, qlog_on = 0;
void logs_on_off(int cnopen, int mylog_onoff, int qlog_onoff)
{
static int mylog_on_count = 0, mylog_off_count = 0,
qlog_on_count = 0, qlog_off_count = 0;
if (mylog_onoff)
mylog_on_count += cnopen;
else
mylog_off_count += cnopen;
if (mylog_on_count > 0)
mylog_on = 1;
else if (mylog_off_count > 0)
mylog_on = 0;
else
mylog_on = globals.debug;
if (qlog_onoff)
qlog_on_count += cnopen;
else
qlog_off_count += cnopen;
if (qlog_on_count > 0)
qlog_on = 1;
else if (qlog_off_count > 0)
qlog_on = 0;
else
qlog_on = globals.commlog;
}
#ifdef MY_LOG
void
......@@ -65,9 +92,9 @@ mylog(char *fmt,...)
{
va_list args;
char filebuf[80];
FILE *LOGFP = globals.mylogFP;
static FILE *LOGFP = NULL;
if (globals.debug)
if (mylog_on)
{
va_start(args, fmt);
......@@ -75,7 +102,6 @@ mylog(char *fmt,...)
{
generate_filename(MYLOGDIR, MYLOGFILE, filebuf);
LOGFP = fopen(filebuf, PG_BINARY_W);
globals.mylogFP = LOGFP;
setbuf(LOGFP, NULL);
}
......@@ -95,9 +121,9 @@ qlog(char *fmt,...)
{
va_list args;
char filebuf[80];
FILE *LOGFP = globals.qlogFP;
static FILE *LOGFP = NULL;
if (globals.commlog)
if (qlog_on)
{
va_start(args, fmt);
......@@ -105,7 +131,6 @@ qlog(char *fmt,...)
{
generate_filename(QLOGDIR, QLOGFILE, filebuf);
LOGFP = fopen(filebuf, PG_BINARY_W);
globals.qlogFP = LOGFP;
setbuf(LOGFP, NULL);
}
......@@ -139,7 +164,7 @@ qlog(char *fmt,...)
* (not including null term)
*/
int
my_strcpy(char *dst, int dst_len, char *src, int src_len)
my_strcpy(char *dst, int dst_len, const char *src, int src_len)
{
if (dst_len <= 0)
return STRCPY_FAIL;
......@@ -214,7 +239,7 @@ strncpy_null(char *dst, const char *src, int len)
*------
*/
char *
make_string(char *s, int len, char *buf)
make_string(const char *s, int len, char *buf)
{
int length;
char *str;
......@@ -248,7 +273,7 @@ make_string(char *s, int len, char *buf)
* This routine could be modified to use vsprintf() to handle multiple arguments.
*/
char *
my_strcat(char *buf, char *fmt, char *s, int len)
my_strcat(char *buf, const char *fmt, const char *s, int len)
{
if (s && (len > 0 || (len == SQL_NTS && strlen(s) > 0)))
{
......
......@@ -89,8 +89,8 @@ extern void qlog(char *fmt,...);
void remove_newlines(char *string);
char *strncpy_null(char *dst, const char *src, int len);
char *trim(char *string);
char *make_string(char *s, int len, char *buf);
char *my_strcat(char *buf, char *fmt, char *s, int len);
char *make_string(const char *s, int len, char *buf);
char *my_strcat(char *buf, const char *fmt, const char *s, int len);
/* defines for return value of my_strcpy */
#define STRCPY_SUCCESS 1
......@@ -98,6 +98,6 @@ char *my_strcat(char *buf, char *fmt, char *s, int len);
#define STRCPY_TRUNCATED (-1)
#define STRCPY_NULL (-2)
int my_strcpy(char *dst, int dst_len, char *src, int src_len);
int my_strcpy(char *dst, int dst_len, const char *src, int src_len);
#endif
......@@ -88,7 +88,7 @@ check_client_encoding(unsigned char *str)
multibyte_client_encoding = BIG5;
return ("BIG5");
}
return ("OHTER");
return ("OTHER");
}
......
......@@ -254,7 +254,7 @@ RETCODE SQL_API SQLGetData(HSTMT StatementHandle,
RETCODE SQL_API SQLGetFunctions(HDBC ConnectionHandle,
SQLUSMALLINT FunctionId, SQLUSMALLINT *Supported)
{
mylog("[SQLGetFunctions");
mylog("[SQLGetFunctions]");
#if (ODBCVER >= 0x3000)
if (FunctionId == SQL_API_ODBC3_ALL_FUNCTIONS)
return PGAPI_GetFunctions30(ConnectionHandle, FunctionId, Supported);
......@@ -270,10 +270,12 @@ RETCODE SQL_API SQLGetInfo(HDBC ConnectionHandle,
mylog("[SQLGetInfo(30)]");
if ((ret = PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue,
BufferLength, StringLength)) == SQL_ERROR)
return PGAPI_GetInfo30(ConnectionHandle, InfoType, InfoValue,
BufferLength, StringLength);
else
return ret;
{
if (((ConnectionClass *) ConnectionHandle)->driver_version >= 0x3000)
return PGAPI_GetInfo30(ConnectionHandle, InfoType, InfoValue,
BufferLength, StringLength);
}
return ret;
#else
mylog("[SQLGetInfo]");
return PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue,
......
......@@ -395,7 +395,7 @@ RETCODE SQL_API SQLSetEnvAttr(HENV EnvironmentHandle,
/* *((unsigned int *) Value) = SQL_CP_RELAXED_MATCH; */
return SQL_SUCCESS;
case SQL_ATTR_ODBC_VERSION:
if ((SQLUINTEGER) Value == SQL_OV_ODBC3)
if ((SQLUINTEGER) Value == SQL_OV_ODBC2)
return SQL_SUCCESS;
break;
case SQL_ATTR_OUTPUT_NTS:
......
......@@ -33,7 +33,6 @@
#include "pgapifunc.h"
extern GLOBAL_VALUES globals;
RETCODE set_statement_option(ConnectionClass *conn,
StatementClass *stmt,
......@@ -49,7 +48,12 @@ set_statement_option(ConnectionClass *conn,
{
static char *func = "set_statement_option";
char changed = FALSE;
ConnInfo *ci = NULL;
if (conn)
ci = &(conn->connInfo);
else if (stmt)
ci = &(SC_get_conn(stmt)->connInfo);
switch (fOption)
{
case SQL_ASYNC_ENABLE: /* ignored */
......@@ -70,7 +74,7 @@ set_statement_option(ConnectionClass *conn,
* read-only
*/
mylog("SetStmtOption(): SQL_CONCURRENCY = %d\n", vParam);
if (globals.lie || vParam == SQL_CONCUR_READ_ONLY || vParam == SQL_CONCUR_ROWVER)
if (ci->drivers.lie || vParam == SQL_CONCUR_READ_ONLY || vParam == SQL_CONCUR_ROWVER)
{
if (conn)
conn->stmtOptions.scroll_concurrency = vParam;
......@@ -95,7 +99,7 @@ set_statement_option(ConnectionClass *conn,
*/
mylog("SetStmtOption(): SQL_CURSOR_TYPE = %d\n", vParam);
if (globals.lie)
if (ci->drivers.lie)
{
if (conn)
conn->stmtOptions.cursor_type = vParam;
......@@ -104,7 +108,7 @@ set_statement_option(ConnectionClass *conn,
}
else
{
if (globals.use_declarefetch)
if (ci->drivers.use_declarefetch)
{
if (conn)
conn->stmtOptions.cursor_type = SQL_CURSOR_FORWARD_ONLY;
......@@ -147,7 +151,7 @@ set_statement_option(ConnectionClass *conn,
break;
/*-------
* if (globals.lie)
* if (ci->drivers.lie)
* stmt->keyset_size = vParam;
* else
* {
......@@ -433,6 +437,7 @@ PGAPI_GetConnectOption(
{
static char *func = "PGAPI_GetConnectOption";
ConnectionClass *conn = (ConnectionClass *) hdbc;
ConnInfo *ci = &(conn->connInfo);
mylog("%s: entering...\n", func);
......@@ -464,7 +469,7 @@ PGAPI_GetConnectOption(
break;
case SQL_PACKET_SIZE: /* NOT SUPPORTED */
*((UDWORD *) pvParam) = globals.socket_buffersize;
*((UDWORD *) pvParam) = ci->drivers.socket_buffersize;
break;
case SQL_QUIET_MODE: /* NOT SUPPORTED */
......@@ -536,6 +541,7 @@ PGAPI_GetStmtOption(
static char *func = "PGAPI_GetStmtOption";
StatementClass *stmt = (StatementClass *) hstmt;
QResultClass *res;
ConnInfo *ci = &(SC_get_conn(stmt)->connInfo);
mylog("%s: entering...\n", func);
......@@ -557,7 +563,7 @@ PGAPI_GetStmtOption(
res = stmt->result;
if (stmt->manual_result || !globals.use_declarefetch)
if (stmt->manual_result || !ci->drivers.use_declarefetch)
{
/* make sure we're positioned on a valid row */
if ((stmt->currTuple < 0) ||
......
......@@ -34,7 +34,6 @@
#endif
extern GLOBAL_VALUES globals;
Int4 getCharPrecision(StatementClass *stmt, Int4 type, int col, int handle_unknown_size_as);
......@@ -105,9 +104,10 @@ Int2 sqlTypes[] = {
Int4
sqltype_to_pgtype(SWORD fSqlType)
sqltype_to_pgtype(StatementClass *stmt, SWORD fSqlType)
{
Int4 pgType;
ConnInfo *ci = &(SC_get_conn(stmt)->connInfo);
switch (fSqlType)
{
......@@ -120,7 +120,7 @@ sqltype_to_pgtype(SWORD fSqlType)
break;
case SQL_BIT:
pgType = globals.bools_as_char ? PG_TYPE_CHAR : PG_TYPE_BOOL;
pgType = ci->drivers.bools_as_char ? PG_TYPE_CHAR : PG_TYPE_BOOL;
break;
case SQL_DATE:
......@@ -150,7 +150,7 @@ sqltype_to_pgtype(SWORD fSqlType)
break;
case SQL_LONGVARCHAR:
pgType = globals.text_as_longvarchar ? PG_TYPE_TEXT : PG_TYPE_VARCHAR;
pgType = ci->drivers.text_as_longvarchar ? PG_TYPE_TEXT : PG_TYPE_VARCHAR;
break;
case SQL_REAL:
......@@ -202,6 +202,7 @@ sqltype_to_pgtype(SWORD fSqlType)
Int2
pgtype_to_sqltype(StatementClass *stmt, Int4 type)
{
ConnInfo *ci = &(SC_get_conn(stmt)->connInfo);
switch (type)
{
case PG_TYPE_CHAR:
......@@ -218,7 +219,7 @@ pgtype_to_sqltype(StatementClass *stmt, Int4 type)
return SQL_VARCHAR;
case PG_TYPE_TEXT:
return globals.text_as_longvarchar ? SQL_LONGVARCHAR : SQL_VARCHAR;
return ci->drivers.text_as_longvarchar ? SQL_LONGVARCHAR : SQL_VARCHAR;
case PG_TYPE_BYTEA:
return SQL_VARBINARY;
......@@ -255,7 +256,7 @@ pgtype_to_sqltype(StatementClass *stmt, Int4 type)
case PG_TYPE_MONEY:
return SQL_FLOAT;
case PG_TYPE_BOOL:
return globals.bools_as_char ? SQL_CHAR : SQL_BIT;
return ci->drivers.bools_as_char ? SQL_CHAR : SQL_BIT;
default:
......@@ -268,7 +269,7 @@ pgtype_to_sqltype(StatementClass *stmt, Int4 type)
if (type == stmt->hdbc->lobj_type)
return SQL_LONGVARBINARY;
return globals.unknowns_as_longvarchar ? SQL_LONGVARCHAR : SQL_VARCHAR;
return ci->drivers.unknowns_as_longvarchar ? SQL_LONGVARCHAR : SQL_VARCHAR;
}
}
......@@ -276,6 +277,7 @@ pgtype_to_sqltype(StatementClass *stmt, Int4 type)
Int2
pgtype_to_ctype(StatementClass *stmt, Int4 type)
{
ConnInfo *ci = &(SC_get_conn(stmt)->connInfo);
switch (type)
{
case PG_TYPE_INT8:
......@@ -303,7 +305,7 @@ pgtype_to_ctype(StatementClass *stmt, Int4 type)
case PG_TYPE_MONEY:
return SQL_C_FLOAT;
case PG_TYPE_BOOL:
return globals.bools_as_char ? SQL_C_CHAR : SQL_C_BIT;
return ci->drivers.bools_as_char ? SQL_C_CHAR : SQL_C_BIT;
case PG_TYPE_BYTEA:
return SQL_C_BINARY;
......@@ -470,6 +472,7 @@ getCharPrecision(StatementClass *stmt, Int4 type, int col, int handle_unknown_si
maxsize;
QResultClass *result;
ColumnInfoClass *flds;
ConnInfo *ci = &(SC_get_conn(stmt)->connInfo);
mylog("getCharPrecision: type=%d, col=%d, unknown = %d\n", type, col, handle_unknown_size_as);
......@@ -477,22 +480,22 @@ getCharPrecision(StatementClass *stmt, Int4 type, int col, int handle_unknown_si
switch (type)
{
case PG_TYPE_TEXT:
if (globals.text_as_longvarchar)
maxsize = globals.max_longvarchar_size;
if (ci->drivers.text_as_longvarchar)
maxsize = ci->drivers.max_longvarchar_size;
else
maxsize = globals.max_varchar_size;
maxsize = ci->drivers.max_varchar_size;
break;
case PG_TYPE_VARCHAR:
case PG_TYPE_BPCHAR:
maxsize = globals.max_varchar_size;
maxsize = ci->drivers.max_varchar_size;
break;
default:
if (globals.unknowns_as_longvarchar)
maxsize = globals.max_longvarchar_size;
if (ci->drivers.unknowns_as_longvarchar)
maxsize = ci->drivers.max_longvarchar_size;
else
maxsize = globals.max_varchar_size;
maxsize = ci->drivers.max_varchar_size;
break;
}
......
......@@ -68,7 +68,7 @@ extern Int2 sqlTypes[];
/* Defines for pgtype_precision */
#define PG_STATIC (-1)
Int4 sqltype_to_pgtype(Int2 fSqlType);
Int4 sqltype_to_pgtype(StatementClass *stmt, Int2 fSqlType);
Int2 pgtype_to_sqltype(StatementClass *stmt, Int4 type);
Int2 pgtype_to_ctype(StatementClass *stmt, Int4 type);
......
......@@ -60,7 +60,7 @@ DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
return FALSE;
}
getGlobalDefaults(DBMS_NAME, ODBCINST_INI, FALSE);
getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
break;
case DLL_THREAD_ATTACH:
......@@ -99,7 +99,7 @@ static BOOL
__attribute__((constructor))
init(void)
{
getGlobalDefaults(DBMS_NAME, ODBCINST_INI, FALSE);
getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
return TRUE;
}
......@@ -112,7 +112,7 @@ init(void)
BOOL
_init(void)
{
getGlobalDefaults(DBMS_NAME, ODBCINST_INI, FALSE);
getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
return TRUE;
}
......
......@@ -5,7 +5,7 @@
*
* Comments: See "notice.txt" for copyright and license information.
*
* $Id: psqlodbc.h,v 1.46 2001/08/24 14:07:50 petere Exp $
* $Id: psqlodbc.h,v 1.47 2001/09/07 06:02:22 inoue Exp $
*
*/
......@@ -145,10 +145,6 @@ typedef struct GlobalValues_
char extra_systable_prefixes[MEDIUM_REGISTRY_LEN];
char conn_settings[LARGE_REGISTRY_LEN];
char protocol[SMALL_REGISTRY_LEN];
FILE *mylogFP;
FILE *qlogFP;
} GLOBAL_VALUES;
typedef struct StatementOptions_
......@@ -176,6 +172,7 @@ typedef struct QueryInfo_
char *cursor;
} QueryInfo;
void logs_on_off(int cnopen, int, int);
#define PG_TYPE_LO (-999) /* hack until permanent
* type available */
......
......@@ -83,7 +83,7 @@ BEGIN
DRV_MSG_LABEL,25,4,238,10
END
DLG_OPTIONS_DRV DIALOG DISCARDABLE 0, 0, 306, 213
DLG_OPTIONS_DRV DIALOG DISCARDABLE 0, 0, 306, 226
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Advanced Options (Driver)"
FONT 10, "Terminal"
......@@ -104,34 +104,38 @@ BEGIN
BS_AUTOCHECKBOX | WS_TABSTOP,13,47,84,10
CONTROL "Cancel as FreeStmt (Exp)",DRV_CANCELASFREESTMT,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,164,50,112,10
GROUPBOX "Unknown Sizes",IDC_STATIC,13,63,175,24
CONTROL "Mylog(Debug ouput",DRV_DEBUG,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,164,63,112,10
GROUPBOX "Unknown Sizes",IDC_STATIC,13,76,175,24
CONTROL "Maximum",DRV_UNKNOWN_MAX,"Button",BS_AUTORADIOBUTTON |
WS_GROUP | WS_TABSTOP,21,71,44,10
WS_GROUP | WS_TABSTOP,21,84,44,10
CONTROL "Don't Know",DRV_UNKNOWN_DONTKNOW,"Button",
BS_AUTORADIOBUTTON | WS_TABSTOP,72,71,56,10
BS_AUTORADIOBUTTON | WS_TABSTOP,72,84,56,10
CONTROL "Longest",DRV_UNKNOWN_LONGEST,"Button",
BS_AUTORADIOBUTTON | WS_TABSTOP,135,71,44,10
GROUPBOX "Data Type Options",IDC_STATIC,13,91,282,23
BS_AUTORADIOBUTTON | WS_TABSTOP,135,84,44,10
GROUPBOX "Data Type Options",IDC_STATIC,13,104,282,23
CONTROL "Text as LongVarChar",DRV_TEXT_LONGVARCHAR,"Button",
BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,15,102,92,10
BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,15,115,92,10
CONTROL "Unknowns as LongVarChar",DRV_UNKNOWNS_LONGVARCHAR,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,112,102,108,10
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,112,115,108,10
CONTROL "Bools as Char",DRV_BOOLS_CHAR,"Button",BS_AUTOCHECKBOX |
WS_TABSTOP,225,102,68,10
LTEXT "&Cache Size:",IDC_STATIC,15,120,45,8
EDITTEXT DRV_CACHE_SIZE,61,116,35,12,ES_AUTOHSCROLL
LTEXT "Max &Varchar:",IDC_STATIC,99,120,49,8
EDITTEXT DRV_VARCHAR_SIZE,149,116,35,12,ES_AUTOHSCROLL
LTEXT "Max Lon&gVarChar:",IDC_STATIC,192,120,65,8
EDITTEXT DRV_LONGVARCHAR_SIZE,259,116,35,12,ES_AUTOHSCROLL
LTEXT "SysTable &Prefixes:",IDC_STATIC,23,131,36,20
EDITTEXT DRV_EXTRASYSTABLEPREFIXES,61,137,75,12,ES_AUTOHSCROLL
LTEXT "Connect &Settings:",IDC_STATIC,22,152,35,20
EDITTEXT DRV_CONNSETTINGS,61,153,225,25,ES_MULTILINE |
WS_TABSTOP,225,115,68,10
LTEXT "&Cache Size:",IDC_STATIC,15,133,45,8
EDITTEXT DRV_CACHE_SIZE,61,129,35,12,ES_AUTOHSCROLL
LTEXT "Max &Varchar:",IDC_STATIC,99,133,49,8
EDITTEXT DRV_VARCHAR_SIZE,149,129,35,12,ES_AUTOHSCROLL
LTEXT "Max Lon&gVarChar:",IDC_STATIC,192,133,65,8
EDITTEXT DRV_LONGVARCHAR_SIZE,259,129,35,12,ES_AUTOHSCROLL
LTEXT "SysTable &Prefixes:",IDC_STATIC,23,144,36,20
EDITTEXT DRV_EXTRASYSTABLEPREFIXES,61,153,75,12,ES_AUTOHSCROLL
LTEXT "Connect &Settings:",IDC_STATIC,22,165,35,20
EDITTEXT DRV_CONNSETTINGS,61,165,225,25,ES_MULTILINE |
ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
DEFPUSHBUTTON "OK",IDOK,59,188,50,14,WS_GROUP
PUSHBUTTON "Cancel",IDCANCEL,129,188,50,14
PUSHBUTTON "Defaults",IDDEFAULTS,199,188,50,15
DEFPUSHBUTTON "OK",IDOK,59,201,50,14,WS_GROUP
PUSHBUTTON "Cancel",IDCANCEL,129,201,50,14
PUSHBUTTON "Defaults",IDDEFAULTS,199,201,50,15
CONTROL "DSN",DRV_OR_DSN,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT |
BS_NOTIFY | WS_TABSTOP,243,208,30,10
END
DLG_OPTIONS_DS DIALOG DISCARDABLE 0, 0, 267, 161
......@@ -194,7 +198,7 @@ BEGIN
DRV_MSG_LABEL,36,5,220,15
END
DLG_OPTIONS_DRV DIALOG DISCARDABLE 0, 0, 287, 226
DLG_OPTIONS_DRV DIALOG DISCARDABLE 0, 0, 287, 241
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Advanced Options (Driver)"
FONT 8, "MS Sans Serif"
......@@ -215,34 +219,38 @@ BEGIN
BS_AUTOCHECKBOX | WS_TABSTOP,15,50,80,10
CONTROL "Cancel as FreeStmt (Exp)",DRV_CANCELASFREESTMT,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,140,50,105,10
GROUPBOX "Unknown Sizes",IDC_STATIC,10,65,175,25
CONTROL "Mylog(Debug ouput)",DRV_DEBUG,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,140,65,112,10
GROUPBOX "Unknown Sizes",IDC_STATIC,10,80,175,25
CONTROL "Maximum",DRV_UNKNOWN_MAX,"Button",BS_AUTORADIOBUTTON |
WS_GROUP | WS_TABSTOP,15,76,45,10
WS_GROUP | WS_TABSTOP,15,91,45,10
CONTROL "Don't Know",DRV_UNKNOWN_DONTKNOW,"Button",
BS_AUTORADIOBUTTON | WS_TABSTOP,70,76,53,10
BS_AUTORADIOBUTTON | WS_TABSTOP,70,91,53,10
CONTROL "Longest",DRV_UNKNOWN_LONGEST,"Button",
BS_AUTORADIOBUTTON | WS_TABSTOP,130,76,50,10
GROUPBOX "Data Type Options",IDC_STATIC,10,95,270,25
BS_AUTORADIOBUTTON | WS_TABSTOP,130,91,50,10
GROUPBOX "Data Type Options",IDC_STATIC,10,110,270,25
CONTROL "Text as LongVarChar",DRV_TEXT_LONGVARCHAR,"Button",
BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,15,105,80,10
BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,15,120,80,10
CONTROL "Unknowns as LongVarChar",DRV_UNKNOWNS_LONGVARCHAR,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,105,105,100,10
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,105,120,100,10
CONTROL "Bools as Char",DRV_BOOLS_CHAR,"Button",BS_AUTOCHECKBOX |
WS_TABSTOP,215,105,60,10
LTEXT "&Cache Size:",IDC_STATIC,10,130,40,10
EDITTEXT DRV_CACHE_SIZE,50,130,35,12,ES_AUTOHSCROLL
LTEXT "Max &Varchar:",IDC_STATIC,90,130,45,10
EDITTEXT DRV_VARCHAR_SIZE,135,130,35,12,ES_AUTOHSCROLL
LTEXT "Max Lon&gVarChar:",IDC_STATIC,180,130,60,10
EDITTEXT DRV_LONGVARCHAR_SIZE,240,130,35,12,ES_AUTOHSCROLL
LTEXT "SysTable &Prefixes:",IDC_STATIC,15,145,35,20
EDITTEXT DRV_EXTRASYSTABLEPREFIXES,50,151,75,12,ES_AUTOHSCROLL
RTEXT "Connect &Settings:",IDC_STATIC,10,170,35,20
EDITTEXT DRV_CONNSETTINGS,50,170,225,25,ES_MULTILINE |
WS_TABSTOP,215,120,60,10
LTEXT "&Cache Size:",IDC_STATIC,10,145,40,10
EDITTEXT DRV_CACHE_SIZE,50,145,35,12,ES_AUTOHSCROLL
LTEXT "Max &Varchar:",IDC_STATIC,90,145,45,10
EDITTEXT DRV_VARCHAR_SIZE,135,145,35,12,ES_AUTOHSCROLL
LTEXT "Max Lon&gVarChar:",IDC_STATIC,180,145,60,10
EDITTEXT DRV_LONGVARCHAR_SIZE,240,145,35,12,ES_AUTOHSCROLL
LTEXT "SysTable &Prefixes:",IDC_STATIC,15,160,35,20
EDITTEXT DRV_EXTRASYSTABLEPREFIXES,50,166,75,12,ES_AUTOHSCROLL
RTEXT "Connect &Settings:",IDC_STATIC,10,185,35,20
EDITTEXT DRV_CONNSETTINGS,50,185,225,25,ES_MULTILINE |
ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
DEFPUSHBUTTON "OK",IDOK,45,205,50,14,WS_GROUP
PUSHBUTTON "Cancel",IDCANCEL,115,205,50,14
PUSHBUTTON "Defaults",IDDEFAULTS,185,205,50,15
DEFPUSHBUTTON "OK",IDOK,45,220,50,14,WS_GROUP
PUSHBUTTON "Cancel",IDCANCEL,115,220,50,14
PUSHBUTTON "Defaults",IDDEFAULTS,185,220,50,15
CONTROL "DSN",DRV_OR_DSN,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT |
BS_NOTIFY | WS_TABSTOP,243,224,30,10
END
DLG_OPTIONS_DS DIALOG DISCARDABLE 0, 0, 267, 161
......
......@@ -86,7 +86,7 @@ QR_inc_base(QResultClass *self, int base_inc)
* CLASS QResult
*/
QResultClass *
QR_Constructor(void)
QR_Constructor()
{
QResultClass *rv;
......@@ -239,6 +239,7 @@ QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, char *cursor)
*/
if (conn != NULL)
{
ConnInfo *ci = &(conn->connInfo);
self->conn = conn;
mylog("QR_fetch_tuples: cursor = '%s', self->cursor=%u\n", (cursor == NULL) ? "" : cursor, self->cursor);
......@@ -246,7 +247,7 @@ QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, char *cursor)
if (self->cursor)
free(self->cursor);
if (globals.use_declarefetch)
if (ci->drivers.use_declarefetch)
{
if (!cursor || cursor[0] == '\0')
{
......@@ -276,13 +277,14 @@ QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, char *cursor)
mylog("QR_fetch_tuples: past CI_read_fields: num_fields = %d\n", self->num_fields);
if (globals.use_declarefetch)
if (ci->drivers.use_declarefetch)
tuple_size = self->cache_size;
else
tuple_size = TUPLE_MALLOC_INC;
/* allocate memory for the tuple cache */
mylog("MALLOC: tuple_size = %d, size = %d\n", tuple_size, self->num_fields * sizeof(TupleField) * tuple_size);
self->count_allocated = 0;
self->backend_tuples = (TupleField *) malloc(self->num_fields * sizeof(TupleField) * tuple_size);
if (!self->backend_tuples)
{
......@@ -329,7 +331,7 @@ QR_close(QResultClass *self)
{
QResultClass *res;
if (globals.use_declarefetch && self->conn && self->cursor)
if (self->conn && self->cursor && self->conn->connInfo.drivers.use_declarefetch)
{
char buf[64];
......@@ -399,6 +401,7 @@ QR_next_tuple(QResultClass *self)
char cmdbuffer[ERROR_MSG_LENGTH + 1];
char fetch[128];
QueryInfo qi;
ConnInfo *ci = NULL;
if (fetch_count < fcount)
{
......@@ -430,7 +433,8 @@ QR_next_tuple(QResultClass *self)
if (!self->inTuples)
{
if (!globals.use_declarefetch)
ci = &(self->conn->connInfo);
if (!ci->drivers.use_declarefetch)
{
mylog("next_tuple: ALL_ROWS: done, fcount = %d, fetch_count = %d\n", fcount, fetch_count);
self->tupleField = NULL;
......@@ -442,10 +446,10 @@ QR_next_tuple(QResultClass *self)
{
/* not a correction */
/* Determine the optimum cache size. */
if (globals.fetch_max % self->rowset_size == 0)
fetch_size = globals.fetch_max;
else if (self->rowset_size < globals.fetch_max)
fetch_size = (globals.fetch_max / self->rowset_size) * self->rowset_size;
if (ci->drivers.fetch_max % self->rowset_size == 0)
fetch_size = ci->drivers.fetch_max;
else if (self->rowset_size < ci->drivers.fetch_max)
fetch_size = (ci->drivers.fetch_max / self->rowset_size) * self->rowset_size;
else
fetch_size = self->rowset_size;
......@@ -465,13 +469,17 @@ QR_next_tuple(QResultClass *self)
self->fetch_count++;
}
if (self->cache_size > self->count_allocated)
self->backend_tuples = (TupleField *) realloc(self->backend_tuples, self->num_fields * sizeof(TupleField) * self->cache_size);
if (!self->backend_tuples)
if (!self->backend_tuples || self->cache_size > self->count_allocated)
{
self->status = PGRES_FATAL_ERROR;
QR_set_message(self, "Out of memory while reading tuples.");
return FALSE;
self->count_allocated = 0;
self->backend_tuples = (TupleField *) realloc(self->backend_tuples, self->num_fields * sizeof(TupleField) * self->cache_size);
if (!self->backend_tuples)
{
self->status = PGRES_FATAL_ERROR;
QR_set_message(self, "Out of memory while reading tuples.");
return FALSE;
}
self->count_allocated = self->cache_size;
}
sprintf(fetch, "fetch %d in %s", fetch_size, self->cursor);
......@@ -482,10 +490,12 @@ QR_next_tuple(QResultClass *self)
qi.result_in = self;
qi.cursor = NULL;
res = CC_send_query(self->conn, fetch, &qi);
if (res == NULL)
if (res == NULL || QR_get_aborted(res))
{
self->status = PGRES_FATAL_ERROR;
QR_set_message(self, "Error fetching next group.");
if (res)
QR_Destructor(res);
return FALSE;
}
self->inTuples = TRUE;
......@@ -511,6 +521,7 @@ QR_next_tuple(QResultClass *self)
sock = CC_get_socket(self->conn);
self->tupleField = NULL;
ci = &(self->conn->connInfo);
for (;;)
{
......@@ -526,7 +537,7 @@ QR_next_tuple(QResultClass *self)
case 'B': /* Tuples in binary format */
case 'D': /* Tuples in ASCII format */
if (!globals.use_declarefetch && self->fcount >= self->count_allocated)
if (!ci->drivers.use_declarefetch && self->fcount >= self->count_allocated)
{
int tuple_size = self->count_allocated;
......
/* {{NO_DEPENDENCIES}} */
/* Microsoft Developer Studio generated include file. */
/* Used by psqlodbc.rc */
#define IDS_BADDSN 1
#define IDS_MSGTITLE 2
#define DLG_OPTIONS_DRV 102
#define DLG_OPTIONS_DS 103
#define IDC_DSNAME 400
#define IDC_DSNAMETEXT 401
#define IDC_DESC 404
#define IDC_SERVER 407
#define IDC_DATABASE 408
#define DLG_CONFIG 1001
#define IDC_PORT 1002
#define IDC_USER 1006
#define IDC_PASSWORD 1009
#define DS_READONLY 1011
#define DS_SHOWOIDCOLUMN 1012
#define DS_FAKEOIDINDEX 1013
#define DRV_COMMLOG 1014
#define DS_PG62 1016
#define IDC_DATASOURCE 1018
#define DRV_OPTIMIZER 1019
#define DS_CONNSETTINGS 1020
#define IDC_DRIVER 1021
#define DRV_CONNSETTINGS 1031
#define DRV_UNIQUEINDEX 1032
#define DRV_UNKNOWN_MAX 1035
#define DRV_UNKNOWN_DONTKNOW 1036
#define DRV_READONLY 1037
#define IDC_DESCTEXT 1039
#define DRV_MSG_LABEL 1040
#define DRV_UNKNOWN_LONGEST 1041
#define DRV_TEXT_LONGVARCHAR 1043
#define DRV_UNKNOWNS_LONGVARCHAR 1044
#define DRV_CACHE_SIZE 1045
#define DRV_VARCHAR_SIZE 1046
#define DRV_LONGVARCHAR_SIZE 1047
#define IDDEFAULTS 1048
#define DRV_USEDECLAREFETCH 1049
#define DRV_BOOLS_CHAR 1050
#define DS_SHOWSYSTEMTABLES 1051
#define DRV_EXTRASYSTABLEPREFIXES 1051
#define DS_ROWVERSIONING 1052
#define DRV_PARSE 1052
#define DRV_CANCELASFREESTMT 1053
#define IDC_OPTIONS 1054
#define DRV_KSQO 1055
#define DS_PG64 1057
#define DS_PG63 1058
/* Next default values for new objects */
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 104
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1060
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by psqlodbc.rc
//
#define IDS_BADDSN 1
#define IDS_MSGTITLE 2
#define DLG_OPTIONS_DRV 102
#define DLG_OPTIONS_DS 103
#define IDC_DSNAME 400
#define IDC_DSNAMETEXT 401
#define IDC_DESC 404
#define IDC_SERVER 407
#define IDC_DATABASE 408
#define DLG_CONFIG 1001
#define IDC_PORT 1002
#define IDC_USER 1006
#define IDC_PASSWORD 1009
#define DS_READONLY 1011
#define DS_SHOWOIDCOLUMN 1012
#define DS_FAKEOIDINDEX 1013
#define DRV_COMMLOG 1014
#define DS_PG62 1016
#define IDC_DATASOURCE 1018
#define DRV_OPTIMIZER 1019
#define DS_CONNSETTINGS 1020
#define IDC_DRIVER 1021
#define DRV_CONNSETTINGS 1031
#define DRV_UNIQUEINDEX 1032
#define DRV_UNKNOWN_MAX 1035
#define DRV_UNKNOWN_DONTKNOW 1036
#define DRV_READONLY 1037
#define IDC_DESCTEXT 1039
#define DRV_MSG_LABEL 1040
#define DRV_UNKNOWN_LONGEST 1041
#define DRV_TEXT_LONGVARCHAR 1043
#define DRV_UNKNOWNS_LONGVARCHAR 1044
#define DRV_CACHE_SIZE 1045
#define DRV_VARCHAR_SIZE 1046
#define DRV_LONGVARCHAR_SIZE 1047
#define IDDEFAULTS 1048
#define DRV_USEDECLAREFETCH 1049
#define DRV_BOOLS_CHAR 1050
#define DS_SHOWSYSTEMTABLES 1051
#define DRV_EXTRASYSTABLEPREFIXES 1051
#define DS_ROWVERSIONING 1052
#define DRV_PARSE 1052
#define DRV_CANCELASFREESTMT 1053
#define IDC_OPTIONS 1054
#define DRV_KSQO 1055
#define DS_PG64 1057
#define DS_PG63 1058
#define DRV_OR_DSN 1059
#define DRV_DEBUG 1060
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1061
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
......@@ -38,7 +38,6 @@
#endif
#include "pgapifunc.h"
extern GLOBAL_VALUES globals;
RETCODE SQL_API
......@@ -51,12 +50,14 @@ PGAPI_RowCount(
QResultClass *res;
char *msg,
*ptr;
ConnInfo *ci;
if (!stmt)
{
SC_log_error(func, "", NULL);
return SQL_INVALID_HANDLE;
}
ci = &(SC_get_conn(stmt)->connInfo);
if (stmt->manual_result)
{
if (pcrow)
......@@ -72,7 +73,7 @@ PGAPI_RowCount(
if (res && pcrow)
{
*pcrow = globals.use_declarefetch ? -1 : QR_get_num_tuples(res);
*pcrow = ci->drivers.use_declarefetch ? -1 : QR_get_num_tuples(res);
return SQL_SUCCESS;
}
}
......@@ -119,17 +120,19 @@ PGAPI_NumResultCols(
StatementClass *stmt = (StatementClass *) hstmt;
QResultClass *result;
char parse_ok;
ConnInfo *ci;
if (!stmt)
{
SC_log_error(func, "", NULL);
return SQL_INVALID_HANDLE;
}
ci = &(SC_get_conn(stmt)->connInfo);
SC_clear_error(stmt);
parse_ok = FALSE;
if (globals.parse && stmt->statement_type == STMT_TYPE_SELECT)
if (ci->drivers.parse && stmt->statement_type == STMT_TYPE_SELECT)
{
if (stmt->parse_status == STMT_PARSE_NONE)
{
......@@ -211,7 +214,7 @@ PGAPI_DescribeCol(
return SQL_INVALID_HANDLE;
}
ci = &(stmt->hdbc->connInfo);
ci = &(SC_get_conn(stmt)->connInfo);
SC_clear_error(stmt);
......@@ -223,7 +226,7 @@ PGAPI_DescribeCol(
icol--; /* use zero based column numbers */
parse_ok = FALSE;
if (globals.parse && stmt->statement_type == STMT_TYPE_SELECT)
if (ci->drivers.parse && stmt->statement_type == STMT_TYPE_SELECT)
{
if (stmt->parse_status == STMT_PARSE_NONE)
{
......@@ -288,7 +291,7 @@ PGAPI_DescribeCol(
fieldtype = QR_get_field_type(res, icol);
/* atoi(ci->unknown_sizes) */
precision = pgtype_precision(stmt, fieldtype, icol, globals.unknown_sizes);
precision = pgtype_precision(stmt, fieldtype, icol, ci->drivers.unknown_sizes);
}
mylog("describeCol: col %d fieldname = '%s'\n", icol, col_name);
......@@ -400,7 +403,7 @@ PGAPI_ColAttributes(
return SQL_INVALID_HANDLE;
}
ci = &(stmt->hdbc->connInfo);
ci = &(SC_get_conn(stmt)->connInfo);
/*
* Dont check for bookmark column. This is the responsibility of the
......@@ -411,14 +414,14 @@ PGAPI_ColAttributes(
icol--;
/* atoi(ci->unknown_sizes); */
unknown_sizes = globals.unknown_sizes;
unknown_sizes = ci->drivers.unknown_sizes;
/* not appropriate for SQLColAttributes() */
if (unknown_sizes == UNKNOWNS_AS_DONTKNOW)
unknown_sizes = UNKNOWNS_AS_MAX;
parse_ok = FALSE;
if (globals.parse && stmt->statement_type == STMT_TYPE_SELECT)
if (ci->drivers.parse && stmt->statement_type == STMT_TYPE_SELECT)
{
if (stmt->parse_status == STMT_PARSE_NONE)
{
......@@ -660,6 +663,7 @@ PGAPI_GetData(
void *value = NULL;
int result;
char get_bookmark = FALSE;
ConnInfo *ci;
mylog("PGAPI_GetData: enter, stmt=%u\n", stmt);
......@@ -668,6 +672,7 @@ PGAPI_GetData(
SC_log_error(func, "", NULL);
return SQL_INVALID_HANDLE;
}
ci = &(SC_get_conn(stmt)->connInfo);
res = stmt->result;
if (STMT_EXECUTING == stmt->status)
......@@ -723,7 +728,7 @@ PGAPI_GetData(
}
}
if (stmt->manual_result || !globals.use_declarefetch)
if (stmt->manual_result || !ci->drivers.use_declarefetch)
{
/* make sure we're positioned on a valid row */
num_rows = QR_get_num_tuples(res);
......@@ -913,6 +918,7 @@ PGAPI_ExtendedFetch(
RETCODE result;
char truncated,
error;
ConnInfo *ci;
mylog("PGAPI_ExtendedFetch: stmt=%u\n", stmt);
......@@ -921,8 +927,9 @@ PGAPI_ExtendedFetch(
SC_log_error(func, "", NULL);
return SQL_INVALID_HANDLE;
}
ci = &(SC_get_conn(stmt)->connInfo);
if (globals.use_declarefetch && !stmt->manual_result)
if (ci->drivers.use_declarefetch && !stmt->manual_result)
{
if (fFetchType != SQL_FETCH_NEXT)
{
......@@ -1101,7 +1108,7 @@ PGAPI_ExtendedFetch(
* Handle Declare Fetch style specially because the end is not really
* the end...
*/
if (globals.use_declarefetch && !stmt->manual_result)
if (ci->drivers.use_declarefetch && !stmt->manual_result)
{
if (QR_end_tuples(res))
return SQL_NO_DATA_FOUND;
......@@ -1183,7 +1190,7 @@ PGAPI_ExtendedFetch(
stmt->currTuple = stmt->rowset_start;
/* For declare/fetch, need to reset cursor to beginning of rowset */
if (globals.use_declarefetch && !stmt->manual_result)
if (ci->drivers.use_declarefetch && !stmt->manual_result)
QR_set_position(res, 0);
/* Set the number of rows retrieved */
......
......@@ -27,7 +27,6 @@
#define INTFUNC __stdcall
extern HINSTANCE NEAR s_hModule;/* Saved module handle. */
extern GLOBAL_VALUES globals;
/* Constants */
#define MIN(x,y) ((x) < (y) ? (x) : (y))
......@@ -218,48 +217,48 @@ ConfigDlgProc(HWND hdlg,
WPARAM wParam,
LPARAM lParam)
{
LPSETUPDLG lpsetupdlg;
ConnInfo *ci;
switch (wMsg)
{
/* Initialize the dialog */
case WM_INITDIALOG:
/* Initialize the dialog */
case WM_INITDIALOG:
lpsetupdlg = (LPSETUPDLG) lParam;
ci = &lpsetupdlg->ci;
/* Hide the driver connect message */
ShowWindow(GetDlgItem(hdlg, DRV_MSG_LABEL), SW_HIDE);
SetWindowLong(hdlg, DWL_USER, lParam);
CenterDialog(hdlg); /* Center dialog */
/*
* NOTE: Values supplied in the attribute string will
* always
*/
/* override settings in ODBC.INI */
/* Get the rest of the common attributes */
getDSNinfo(ci, CONN_DONT_OVERWRITE);
/* Fill in any defaults */
getDSNdefaults(ci);
/* Initialize dialog fields */
SetDlgStuff(hdlg, ci);
if (lpsetupdlg->fDefault)
{
LPSETUPDLG lpsetupdlg = (LPSETUPDLG) lParam;
ConnInfo *ci = &lpsetupdlg->ci;
/* Hide the driver connect message */
ShowWindow(GetDlgItem(hdlg, DRV_MSG_LABEL), SW_HIDE);
SetWindowLong(hdlg, DWL_USER, lParam);
CenterDialog(hdlg); /* Center dialog */
/*
* NOTE: Values supplied in the attribute string will
* always
*/
/* override settings in ODBC.INI */
/* Get the rest of the common attributes */
getDSNinfo(ci, CONN_DONT_OVERWRITE);
/* Fill in any defaults */
getDSNdefaults(ci);
/* Initialize dialog fields */
SetDlgStuff(hdlg, ci);
if (lpsetupdlg->fDefault)
{
EnableWindow(GetDlgItem(hdlg, IDC_DSNAME), FALSE);
EnableWindow(GetDlgItem(hdlg, IDC_DSNAMETEXT), FALSE);
}
else
SendDlgItemMessage(hdlg, IDC_DSNAME,
EM_LIMITTEXT, (WPARAM) (MAXDSNAME - 1), 0L);
SendDlgItemMessage(hdlg, IDC_DESC,
EM_LIMITTEXT, (WPARAM) (MAXDESC - 1), 0L);
return TRUE; /* Focus was not set */
EnableWindow(GetDlgItem(hdlg, IDC_DSNAME), FALSE);
EnableWindow(GetDlgItem(hdlg, IDC_DSNAMETEXT), FALSE);
}
else
SendDlgItemMessage(hdlg, IDC_DSNAME,
EM_LIMITTEXT, (WPARAM) (MAXDSNAME - 1), 0L);
SendDlgItemMessage(hdlg, IDC_DESC,
EM_LIMITTEXT, (WPARAM) (MAXDESC - 1), 0L);
return TRUE; /* Focus was not set */
/* Process buttons */
case WM_COMMAND:
......@@ -286,21 +285,17 @@ ConfigDlgProc(HWND hdlg,
/* Accept results */
case IDOK:
{
LPSETUPDLG lpsetupdlg;
lpsetupdlg = (LPSETUPDLG) GetWindowLong(hdlg, DWL_USER);
/* Retrieve dialog values */
if (!lpsetupdlg->fDefault)
GetDlgItemText(hdlg, IDC_DSNAME,
lpsetupdlg = (LPSETUPDLG) GetWindowLong(hdlg, DWL_USER);
/* Retrieve dialog values */
if (!lpsetupdlg->fDefault)
GetDlgItemText(hdlg, IDC_DSNAME,
lpsetupdlg->ci.dsn,
sizeof(lpsetupdlg->ci.dsn));
/* Get Dialog Values */
GetDlgStuff(hdlg, &lpsetupdlg->ci);
/* Get Dialog Values */
GetDlgStuff(hdlg, &lpsetupdlg->ci);
/* Update ODBC.INI */
SetDSNAttributes(hdlg, lpsetupdlg);
}
/* Update ODBC.INI */
SetDSNAttributes(hdlg, lpsetupdlg);
/* Return to caller */
case IDCANCEL:
......@@ -308,22 +303,18 @@ ConfigDlgProc(HWND hdlg,
return TRUE;
case IDC_DRIVER:
lpsetupdlg = (LPSETUPDLG) GetWindowLong(hdlg, DWL_USER);
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV),
hdlg, driver_optionsProc, (LPARAM) NULL);
hdlg, driver_optionsProc, (LPARAM) &lpsetupdlg->ci);
return TRUE;
case IDC_DATASOURCE:
{
LPSETUPDLG lpsetupdlg;
lpsetupdlg = (LPSETUPDLG) GetWindowLong(hdlg, DWL_USER);
lpsetupdlg = (LPSETUPDLG) GetWindowLong(hdlg, DWL_USER);
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DS),
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DS),
hdlg, ds_optionsProc, (LPARAM) &lpsetupdlg->ci);
return TRUE;
}
return TRUE;
}
break;
}
......
......@@ -13,6 +13,7 @@
*/
#include "socket.h"
#include "connection.h"
#ifndef WIN32
#include <stdlib.h>
......@@ -41,7 +42,7 @@ SOCK_clear_error(SocketClass *self)
SocketClass *
SOCK_Constructor()
SOCK_Constructor(const ConnectionClass *conn)
{
SocketClass *rv;
......@@ -54,14 +55,18 @@ SOCK_Constructor()
rv->buffer_filled_out = 0;
rv->buffer_read_in = 0;
rv->buffer_in = (unsigned char *) malloc(globals.socket_buffersize);
if (rv)
rv->buffer_size = conn->connInfo.drivers.socket_buffersize;
else
rv->buffer_size = globals.socket_buffersize;
rv->buffer_in = (unsigned char *) malloc(rv->buffer_size);
if (!rv->buffer_in)
{
free(rv);
return NULL;
}
rv->buffer_out = (unsigned char *) malloc(globals.socket_buffersize);
rv->buffer_out = (unsigned char *) malloc(rv->buffer_size);
if (!rv->buffer_out)
{
free(rv->buffer_in);
......@@ -79,6 +84,7 @@ SOCK_Constructor()
void
SOCK_Destructor(SocketClass *self)
{
mylog("SOCK_Destructor\n");
if (self->socket != -1)
{
SOCK_put_char(self, 'X');
......@@ -305,9 +311,9 @@ SOCK_get_next_byte(SocketClass *self)
* there are no more bytes left in the buffer so reload the buffer
*/
self->buffer_read_in = 0;
self->buffer_filled_in = recv(self->socket, (char *) self->buffer_in, globals.socket_buffersize, 0);
self->buffer_filled_in = recv(self->socket, (char *) self->buffer_in, self->buffer_size, 0);
mylog("read %d, global_socket_buffersize=%d\n", self->buffer_filled_in, globals.socket_buffersize);
mylog("read %d, global_socket_buffersize=%d\n", self->buffer_filled_in, self->buffer_size);
if (self->buffer_filled_in < 0)
{
......@@ -335,11 +341,11 @@ SOCK_put_next_byte(SocketClass *self, unsigned char next_byte)
self->buffer_out[self->buffer_filled_out++] = next_byte;
if (self->buffer_filled_out == globals.socket_buffersize)
if (self->buffer_filled_out == self->buffer_size)
{
/* buffer is full, so write it out */
bytes_sent = send(self->socket, (char *) self->buffer_out, globals.socket_buffersize, 0);
if (bytes_sent != globals.socket_buffersize)
bytes_sent = send(self->socket, (char *) self->buffer_out, self->buffer_size, 0);
if (bytes_sent != self->buffer_size)
{
self->errornumber = SOCKET_WRITE_ERROR;
self->errormsg = "Error while writing to the socket.";
......
......@@ -53,6 +53,7 @@ typedef unsigned int in_addr_t;
struct SocketClass_
{
int buffer_size;
int buffer_filled_in;
int buffer_filled_out;
int buffer_read_in;
......@@ -79,7 +80,7 @@ struct SocketClass_
/* Socket prototypes */
SocketClass *SOCK_Constructor(void);
SocketClass *SOCK_Constructor(const ConnectionClass *conn);
void SOCK_Destructor(SocketClass *self);
char SOCK_connect_to(SocketClass *self, unsigned short port, char *hostname);
void SOCK_get_n_char(SocketClass *self, char *buffer, int len);
......
......@@ -32,7 +32,6 @@
#endif
#include "pgapifunc.h"
extern GLOBAL_VALUES globals;
#ifndef WIN32
#ifndef HAVE_STRICMP
......@@ -291,6 +290,7 @@ SC_Constructor(void)
rv->pre_executing = FALSE;
rv->inaccurate_result = FALSE;
rv->miscinfo = 0;
}
return rv;
}
......@@ -560,6 +560,7 @@ SC_pre_execute(StatementClass *self)
{
mylog(" preprocess: status = READY\n");
self->miscinfo = 0;
if (self->statement_type == STMT_TYPE_SELECT)
{
char old_pre_executing = self->pre_executing;
......@@ -577,7 +578,7 @@ SC_pre_execute(StatementClass *self)
self->status = STMT_PREMATURE;
}
}
else
if (!SC_is_pre_executable(self))
{
self->result = QR_Constructor();
QR_set_status(self->result, PGRES_TUPLES_OK);
......@@ -718,15 +719,16 @@ SC_fetch(StatementClass *self)
lf;
Oid type;
char *value;
ColumnInfoClass *ci;
ColumnInfoClass *coli;
/* TupleField *tupleField; */
ConnInfo *ci = &(SC_get_conn(self)->connInfo);
self->last_fetch_count = 0;
ci = QR_get_fields(res); /* the column info */
coli = QR_get_fields(res); /* the column info */
mylog("manual_result = %d, use_declarefetch = %d\n", self->manual_result, globals.use_declarefetch);
mylog("manual_result = %d, use_declarefetch = %d\n", self->manual_result, ci->drivers.use_declarefetch);
if (self->manual_result || !globals.use_declarefetch)
if (self->manual_result || !ci->drivers.use_declarefetch)
{
if (self->currTuple >= QR_get_num_tuples(res) - 1 ||
(self->options.maxRows > 0 && self->currTuple == self->options.maxRows - 1))
......@@ -807,7 +809,7 @@ SC_fetch(StatementClass *self)
/* this column has a binding */
/* type = QR_get_field_type(res, lf); */
type = CI_get_oid(ci, lf); /* speed things up */
type = CI_get_oid(coli, lf); /* speed things up */
mylog("type = %d\n", type);
......@@ -816,7 +818,7 @@ SC_fetch(StatementClass *self)
value = QR_get_value_manual(res, self->currTuple, lf);
mylog("manual_result\n");
}
else if (globals.use_declarefetch)
else if (ci->drivers.use_declarefetch)
value = QR_get_value_backend(res, lf);
else
value = QR_get_value_backend_row(res, self->currTuple, lf);
......@@ -895,9 +897,11 @@ SC_execute(StatementClass *self)
Int2 oldstatus,
numcols;
QueryInfo qi;
ConnInfo *ci;
conn = SC_get_conn(self);
ci = &(conn->connInfo);
/* Begin a transaction if one is not already in progress */
......@@ -910,7 +914,8 @@ SC_execute(StatementClass *self)
* OTHER.
*/
if (!self->internal && !CC_is_in_trans(conn) &&
((globals.use_declarefetch && self->statement_type == STMT_TYPE_SELECT) || (!CC_is_in_autocommit(conn) && self->statement_type != STMT_TYPE_OTHER)))
((ci->drivers.use_declarefetch && self->statement_type == STMT_TYPE_SELECT) ||
(!CC_is_in_autocommit(conn) && self->statement_type != STMT_TYPE_OTHER)))
{
mylog(" about to begin a transaction on statement = %u\n", self);
res = CC_send_query(conn, "BEGIN", NULL);
......@@ -959,7 +964,7 @@ SC_execute(StatementClass *self)
/* send the declare/select */
self->result = CC_send_query(conn, self->stmt_with_params, NULL);
if (globals.use_declarefetch && self->result != NULL &&
if (ci->drivers.use_declarefetch && self->result != NULL &&
QR_command_successful(self->result))
{
QR_Destructor(self->result);
......@@ -970,7 +975,7 @@ SC_execute(StatementClass *self)
*/
qi.result_in = NULL;
qi.cursor = self->cursor_name;
qi.row_size = globals.fetch_max;
qi.row_size = ci->drivers.fetch_max;
/*
* Most likely the rowset size will not be set by the
......@@ -1075,21 +1080,21 @@ SC_execute(StatementClass *self)
(self->errornumber == STMT_OK ||
self->errornumber == STMT_INFO_ONLY) &&
self->parameters &&
self->parameters[0].buflen > 0 &&
self->parameters[0].buffer &&
self->parameters[0].paramType == SQL_PARAM_OUTPUT)
{ /* get the return value of the procedure call */
RETCODE ret;
HSTMT hstmt = (HSTMT) self;
ret = PGAPI_BindCol(hstmt, 1, self->parameters[0].CType, self->parameters[0].buffer, self->parameters[0].buflen, self->parameters[0].used);
if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO)
SC_fetch(hstmt);
else
{
self->errornumber = STMT_EXEC_ERROR;
self->errormsg = "BindCol to Procedure return failed.";
ret = SC_fetch(hstmt);
if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO)
{
ret = PGAPI_GetData(hstmt, 1, self->parameters[0].CType, self->parameters[0].buffer, self->parameters[0].buflen, self->parameters[0].used);
if (ret != SQL_SUCCESS)
{
self->errornumber = STMT_EXEC_ERROR;
self->errormsg = "GetData to Procedure return failed.";
}
}
if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO)
PGAPI_BindCol(hstmt, 1, self->parameters[0].CType, NULL, 0, NULL);
else
{
self->errornumber = STMT_EXEC_ERROR;
......
......@@ -216,10 +216,10 @@ struct StatementClass_
int stmt_size_limit;
char pre_executing; /* This statement is prematurely executing */
char inaccurate_result; /* Current status is PREMATURE but
* result is inaccurate */
char errormsg_malloced; /* Current status is PREMATURE but
char inaccurate_result; /* Current status is PREMATURE but
* result is inaccurate */
char errormsg_malloced; /* Current error message is malloed (not in a static variable) ? */
char miscinfo;
};
#define SC_get_conn(a) (a->hdbc)
......@@ -229,6 +229,14 @@ struct StatementClass_
#define STMT_FREE_PARAMS_ALL 0
#define STMT_FREE_PARAMS_DATA_AT_EXEC_ONLY 1
/* misc info */
#define SC_set_pre_executable(a) (a->miscinfo |= 1L)
#define SC_no_pre_executable(a) (a->miscinfo &= ~1L)
#define SC_is_pre_executable(a) (a->miscinfo & 1L != 0)
#define SC_set_fetchcursor(a) (a->miscinfo |= 2L)
#define SC_no_fetchcursor(a) (a->miscinfo &= ~2L)
#define SC_is_fetchcursor(a) (a->miscinfo & 2L != 0)
/* Statement prototypes */
StatementClass *SC_Constructor(void);
void InitializeStatementOptions(StatementOptions *opt);
......
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