diff options
| author | Hiroshi Inoue | 2007-06-02 05:32:19 +0000 |
|---|---|---|
| committer | Hiroshi Inoue | 2007-06-02 05:32:19 +0000 |
| commit | 92a075cb7c009ac5770973c87e0097e8c23aeaad (patch) | |
| tree | 8483779a837e2ef3fc7442047974edc6cb195722 | |
| parent | ccbd87ed3e18456afafa6c3a4b4c8d829e2bb050 (diff) | |
The version is now 8.2.0402.
. Fix some bugs in case without MSDTC support.
. Refine the realloc handling.
. Put back the @@IDENTITY implementation so as not to use lastval().
. Change SQLColumns() to return correct column length in the Unicode driver.
. Remove the connection count limitation.
. Fix Protocol=7.4--1 notation (should be Protocol=7.4).
. Fix a typo in socket.c (bug report from Rainer bauer).
| -rw-r--r-- | connection.c | 2 | ||||
| -rw-r--r-- | connection.h | 6 | ||||
| -rw-r--r-- | convert.c | 5 | ||||
| -rw-r--r-- | dlg_specific.c | 7 | ||||
| -rw-r--r-- | dlg_wingui.c | 12 | ||||
| -rw-r--r-- | environ.c | 51 | ||||
| -rw-r--r-- | environ.h | 2 | ||||
| -rw-r--r-- | execute.c | 7 | ||||
| -rw-r--r-- | info.c | 7 | ||||
| -rw-r--r-- | inouealc.c | 15 | ||||
| -rw-r--r-- | loadlib.c | 8 | ||||
| -rw-r--r-- | options.c | 5 | ||||
| -rw-r--r-- | parse.c | 7 | ||||
| -rw-r--r-- | pgapi30.c | 3 | ||||
| -rw-r--r-- | pgtypes.c | 18 | ||||
| -rw-r--r-- | psqlodbc.h | 8 | ||||
| -rw-r--r-- | qresult.c | 2 | ||||
| -rw-r--r-- | qresult.h | 4 | ||||
| -rw-r--r-- | results.c | 71 | ||||
| -rw-r--r-- | socket.c | 2 | ||||
| -rw-r--r-- | statement.c | 4 | ||||
| -rw-r--r-- | statement.h | 4 | ||||
| -rw-r--r-- | version.h | 8 | ||||
| -rw-r--r-- | win32.mak | 7 |
24 files changed, 142 insertions, 123 deletions
diff --git a/connection.c b/connection.c index 11104aa..c76e64f 100644 --- a/connection.c +++ b/connection.c @@ -285,9 +285,9 @@ CC_conninfo_init(ConnInfo *conninfo) conninfo->bde_environment = -1; conninfo->fake_mss = -1; conninfo->cvt_null_date_string = -1; + conninfo->autocommit_public = SQL_AUTOCOMMIT_ON; #ifdef _HANDLE_ENLIST_IN_DTC_ conninfo->xa_opt = -1; - conninfo->autocommit_public = SQL_AUTOCOMMIT_ON; #endif /* _HANDLE_ENLIST_IN_DTC_ */ memcpy(&(conninfo->drivers), &globals, sizeof(globals)); } diff --git a/connection.h b/connection.h index 1958d63..f831ddd 100644 --- a/connection.h +++ b/connection.h @@ -125,11 +125,13 @@ do { \ } while (0) #define CC_REALLOC_return_with_error(t, tp, s, x, m, ret) \ do { \ - if (t = (tp *) realloc(t, s), NULL == t) \ + tp *tmp; \ + if (tmp = (tp *) realloc(t, s), NULL == tmp) \ { \ CC_set_error(x, CONN_NO_MEMORY_ERROR, m, ""); \ return ret; \ } \ + t = tmp; \ } while (0) /* For Multi-thread */ @@ -303,9 +305,9 @@ typedef struct signed char bde_environment; signed char fake_mss; signed char cvt_null_date_string; + signed char autocommit_public; #ifdef _HANDLE_ENLIST_IN_DTC_ signed char xa_opt; - signed char autocommit_public; #endif /* _HANDLE_ENLIST_IN_DTC_ */ GLOBAL_VALUES drivers; /* moved from driver's option */ } ConnInfo; @@ -2797,12 +2797,15 @@ inner_process_tokens(QueryParse *qp, QueryBuild *qb) BOOL converted = FALSE; COL_INFO *coli; +#ifdef NOT_USED /* lastval() isn't always appropriate */ if (PG_VERSION_GE(conn, 8.1)) { CVT_APPEND_STR(qb, "lastval()"); converted = TRUE; } - else if (NAME_IS_VALID(conn->tableIns)) + else +#endif /* NOT_USED */ + if (NAME_IS_VALID(conn->tableIns)) { TABLE_INFO ti, *pti = &ti; diff --git a/dlg_specific.c b/dlg_specific.c index a4b6e5f..3fe352d 100644 --- a/dlg_specific.c +++ b/dlg_specific.c @@ -449,9 +449,9 @@ copyAttributes(ConnInfo *ci, const char *attribute, const char *value) ptr = strchr(value, '-'); if (ptr) { - *ptr = '\0'; if ('-' != *value) { + *ptr = '\0'; strcpy(ci->protocol, value); } ci->rollback_on_error = atoi(ptr + 1); @@ -1054,7 +1054,10 @@ writeDSNinfo(const ConnInfo *ci) ci->show_system_tables, ODBC_INI); - sprintf(temp, "%s-%d", ci->protocol, ci->rollback_on_error); + if (ci->rollback_on_error >= 0) + sprintf(temp, "%s-%d", ci->protocol, ci->rollback_on_error); + else + strncpy(temp, ci->protocol, sizeof(temp)); SQLWritePrivateProfileString(DSN, INI_PROTOCOL, temp, diff --git a/dlg_wingui.c b/dlg_wingui.c index 70ca7f5..e9e7899 100644 --- a/dlg_wingui.c +++ b/dlg_wingui.c @@ -332,8 +332,10 @@ global_optionsProc(HWND hdlg, WPARAM wParam, LPARAM lParam) { +#ifdef _HANDLE_ENLIST_IN_DTC_ HMODULE hmodule; FARPROC proc; +#endif /* _HANDLE_ENLIST_IN_DTC_ */ switch (wMsg) { @@ -371,11 +373,11 @@ global_optionsProc(HWND hdlg, if (writeDriverCommoninfo(ODBCINST_INI, NULL, &globals) < 0) MessageBox(hdlg, "Sorry, impossible to update the values\nWrite permission seems to be needed", "Update Error", MB_ICONEXCLAMATION | MB_OK); #ifdef _HANDLE_ENLIST_IN_DTC_ - hmodule = DtcProc("SetMsdtclog", &proc); - if (proc) - (*proc)(IsDlgButtonChecked(hdlg, DRV_DTCLOG)); - if (hmodule) - FreeLibrary(hmodule); + hmodule = DtcProc("SetMsdtclog", &proc); + if (proc) + (*proc)(IsDlgButtonChecked(hdlg, DRV_DTCLOG)); + if (hmodule) + FreeLibrary(hmodule); #endif /* _HANDLE_ENLIST_IN_DTC_ */ case IDCANCEL: @@ -31,7 +31,9 @@ extern GLOBAL_VALUES globals; /* The one instance of the handles */ -ConnectionClass *conns[MAX_CONNECTIONS]; +static int conns_count = 0; +static ConnectionClass **conns = NULL; + #if defined(WIN_MULTITHREAD_SUPPORT) CRITICAL_SECTION conns_cs; CRITICAL_SECTION common_cs; /* commonly used for short term blocking */ @@ -40,6 +42,14 @@ pthread_mutex_t conns_cs; pthread_mutex_t common_cs; #endif /* WIN_MULTITHREAD_SUPPORT */ +int getConnCount() +{ + return conns_count; +} +ConnectionClass * const *getConnList() +{ + return conns; +} RETCODE SQL_API PGAPI_AllocEnv(HENV FAR * phenv) @@ -555,7 +565,7 @@ EN_Destructor(EnvironmentClass *self) */ /* Free any connections belonging to this environment */ - for (lf = 0; lf < MAX_CONNECTIONS; lf++) + for (lf = 0; lf < conns_count; lf++) { if (conns[lf] && conns[lf]->henv == self) { @@ -565,6 +575,8 @@ EN_Destructor(EnvironmentClass *self) rv = 0; } } + if (conns) + free(conns); DELETE_ENV_CS(self); free(self); @@ -596,31 +608,46 @@ EN_get_error(EnvironmentClass *self, int *number, char **message) return 0; } +#define INIT_CONN_COUNT 128 char EN_add_connection(EnvironmentClass *self, ConnectionClass *conn) { - int i; + int i, alloc; + ConnectionClass **newa; + char ret = FALSE; mylog("EN_add_connection: self = %p, conn = %p\n", self, conn); ENTER_CONNS_CS; - for (i = 0; i < MAX_CONNECTIONS; i++) + for (i = 0; i < conns_count; i++) { if (!conns[i]) { conn->henv = self; conns[i] = conn; - LEAVE_CONNS_CS; - - mylog(" added at i =%d, conn->henv = %p, conns[i]->henv = %p\n", i, conn->henv, conns[i]->henv); - - return TRUE; + ret = TRUE; + mylog(" added at i=%d, conn->henv = %p, conns[i]->henv = %p\n", i, conn->henv, conns[i]->henv); + goto cleanup; } } + if (conns_count > 0) + alloc = 2 * conns_count; + else + alloc = INIT_CONN_COUNT; + if (newa = (ConnectionClass **) realloc(conns, alloc * sizeof(ConnectionClass *)), NULL == newa) + goto cleanup; + conn->henv = self; + newa[conns_count] = conn; + conns = newa; + ret = TRUE; + mylog(" added at %d, conn->henv = %p, conns[%d]->henv = %p\n", conns_count, conn->henv, conns_count, conns[conns_count]->henv); + for (i = conns_count + 1; i < alloc; i++) + conns[i] = NULL; + conns_count = alloc; +cleanup: LEAVE_CONNS_CS; - - return FALSE; + return ret; } @@ -629,7 +656,7 @@ EN_remove_connection(EnvironmentClass *self, ConnectionClass *conn) { int i; - for (i = 0; i < MAX_CONNECTIONS; i++) + for (i = 0; i < conns_count; i++) if (conns[i] == conn && conns[i]->status != CONN_EXECUTING) { ENTER_CONNS_CS; @@ -41,6 +41,8 @@ char EN_get_error(EnvironmentClass *self, int *number, char **message); char EN_add_connection(EnvironmentClass *self, ConnectionClass *conn); char EN_remove_connection(EnvironmentClass *self, ConnectionClass *conn); void EN_log_error(const char *func, char *desc, EnvironmentClass *self); +int getConnCount(); +ConnectionClass * const *getConnList(); #define EN_OV_ODBC2 1L #define EN_CONN_POOLING (1L<<1) @@ -700,8 +700,10 @@ SC_setInsertedTable(StatementClass *stmt, RETCODE retval) if (SQL_NEED_DATA == retval) return; conn = SC_get_conn(stmt); +#ifdef NOT_USED /* give up the use of lastval() */ if (PG_VERSION_GE(conn, 8.1)) /* lastval() is available */ return; +#endif /* NOT_USED */ /*if (!CC_fake_mss(conn)) return;*/ while (isspace((UCHAR) *cmd)) cmd++; @@ -1073,7 +1075,6 @@ PGAPI_Transact( SQLUSMALLINT fType) { CSTR func = "PGAPI_Transact"; - extern ConnectionClass *conns[]; ConnectionClass *conn; QResultClass *res; char ok, @@ -1094,7 +1095,9 @@ PGAPI_Transact( */ if (hdbc == SQL_NULL_HDBC && henv != SQL_NULL_HENV) { - for (lf = 0; lf < MAX_CONNECTIONS; lf++) + ConnectionClass * const *conns = getConnList(); + const int conn_count = getConnCount(); + for (lf = 0; lf < conn_count; lf++) { conn = conns[lf]; @@ -96,7 +96,7 @@ PGAPI_GetInfo( case SQL_ACTIVE_CONNECTIONS: /* ODBC 1.0 */ len = 2; - value = MAX_CONNECTIONS; + value = 0; break; case SQL_ACTIVE_STATEMENTS: /* ODBC 1.0 */ @@ -2472,6 +2472,10 @@ mylog(" and the data=%s\n", attdef); mylog("%s: field type is VARCHAR,BPCHAR: field_type = %d, mod_length = %d\n", func, field_type, mod_length); set_tuplefield_int4(&tuple[COLUMNS_PRECISION], mod_length); +#ifdef UNICODE_SUPPORT + if (0 < mod_length && ALLOW_WCHAR(conn)) + mod_length *= WCLEN; +#endif /* UNICODE_SUPPORT */ set_tuplefield_int4(&tuple[COLUMNS_LENGTH], mod_length); #if (ODBCVER >= 0x0300) set_tuplefield_int4(&tuple[COLUMNS_CHAR_OCTET_LENGTH], pgtype_transfer_octet_length(stmt, field_type, PG_STATIC, PG_STATIC)); @@ -4852,6 +4856,7 @@ PGAPI_ProcedureColumns( result_cols = NUM_OF_PROCOLS_FIELDS; extend_column_bindings(SC_get_ARDF(stmt), result_cols); + stmt->catalog_result = TRUE; /* set the field names */ QR_set_num_fields(res, result_cols); QR_set_field_info_v(res, PROCOLS_PROCEDURE_CAT, "PROCEDURE_CAT", PG_TYPE_VARCHAR, MAX_INFO_STRING); @@ -37,8 +37,11 @@ inolog(" alloced=%p(%d)\n", alloced, size); } else if (tbsize >= alsize) { + ALADR *al; alsize *= 2; - altbl = (ALADR *) realloc(altbl, alsize * sizeof(ALADR)); + if (al = (ALADR *) realloc(altbl, alsize * sizeof(ALADR)), NULL == al) + return alloced; + altbl = al; } altbl[tbsize].aladr = alloced; altbl[tbsize].len = size; @@ -61,8 +64,11 @@ void * debug_calloc(size_t n, size_t size) } else if (tbsize >= alsize) { + ALADR *al; alsize *= 2; - altbl = (ALADR *) realloc(altbl, alsize * sizeof(ALADR)); + if (al = (ALADR *) realloc(altbl, alsize * sizeof(ALADR)), NULL == al) + return alloced; + altbl = al; } altbl[tbsize].aladr = alloced; altbl[tbsize].len = n * size; @@ -119,8 +125,11 @@ char * debug_strdup(const char * ptr) } else if (tbsize >= alsize) { + ALADR *al; alsize *= 2; - altbl = (ALADR *) realloc(altbl, alsize * sizeof(ALADR)); + if (al = (ALADR *) realloc(altbl, alsize * sizeof(ALADR)), NULL == al) + return alloced; + altbl = al; } altbl[tbsize].aladr = alloced; altbl[tbsize].len = strlen(ptr) + 1; @@ -23,11 +23,13 @@ #pragma comment(lib, "Delayimp") #pragma comment(lib, "libpq") #pragma comment(lib, "ssleay32") +#ifdef _HANDLE_ENLIST_IN_DTC_ #ifdef UNICODE_SUPPORT #pragma comment(lib, "pgenlist") #else #pragma comment(lib, "pgenlista") #endif /* UNICODE_SUPPORT */ +#endif /* _HANDLE_ENLIST_IN_DTC_ */ // The followings works under VC++6.0 but doesn't work under VC++7.0. // Please add the equivalent linker options using command line etc. #if (_MSC_VER == 1200) && defined(DYNAMIC_LOAD) // VC6.0 @@ -77,7 +79,7 @@ static HMODULE MODULE_load_from_psqlodbc_path(const char *module_name) _splitpath(szFileName, drive, dir, NULL, NULL); GetSystemDirectory(sysdir, MAX_PATH); snprintf(szFileName, sizeof(szFileName), "%s%s%s.dll", drive, dir, module_name); - if (strnicmp(szFileName, sysdir, strlen(sysdir)) != 0) + if (_strnicmp(szFileName, sysdir, strlen(sysdir)) != 0) { hmodule = LoadLibraryEx(szFileName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); mylog("psqlodbc path based %s loaded module=%p\n", module_name, hmodule); @@ -117,12 +119,12 @@ DliErrorHook(unsigned dliNotify, #else __pfnDliNotifyHook2 = NULL; #endif /* _MSC_VER */ - if (strnicmp(pdli->szDll, libpq, 5) == 0) + if (_strnicmp(pdli->szDll, libpq, 5) == 0) { if (hmodule = MODULE_load_from_psqlodbc_path(libpq), NULL == hmodule) hmodule = LoadLibrary(libpq); } - else if (strnicmp(pdli->szDll, pgenlist, strlen(pgenlist)) == 0) + else if (_strnicmp(pdli->szDll, pgenlist, strlen(pgenlist)) == 0) { if (hmodule = MODULE_load_from_psqlodbc_path(pgenlist), NULL == hmodule) hmodule = LoadLibrary(pgenlist); @@ -365,7 +365,6 @@ PGAPI_SetConnectOption( CC_set_error(conn, CONN_INVALID_ARGUMENT_NO, "Illegal parameter value for SQL_AUTOCOMMIT", func); return SQL_ERROR; } -#ifdef _HANDLE_ENLIST_IN_DTC_ if (autocomm_on && SQL_AUTOCOMMIT_OFF != ci->autocommit_public) break; else if (!autocomm_on && SQL_AUTOCOMMIT_OFF == ci->autocommit_public) @@ -373,6 +372,7 @@ PGAPI_SetConnectOption( ci->autocommit_public = (autocomm_on ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF); mylog("%s: AUTOCOMMIT: transact_status=%d, vparam=%d\n", func, conn->transact_status, vParam); +#ifdef _HANDLE_ENLIST_IN_DTC_ if (NULL != conn->asdum) { mylog("%s: Ignored AUTOCOMMIT in a distributed transaction, OK ?"); @@ -527,11 +527,10 @@ PGAPI_GetConnectOption( *((SQLUINTEGER *) pvParam) = SQL_MODE_READ_WRITE; break; -#ifdef _HANDLE_ENLIST_IN_DTC_ case SQL_AUTOCOMMIT: *((SQLUINTEGER *) pvParam) = ci->autocommit_public; break; -#endif + case SQL_CURRENT_QUALIFIER: /* don't use qualifiers */ len = 0; p = CurrCatString(conn); @@ -431,12 +431,7 @@ static BOOL increaseNtab(StatementClass *stmt, const char *func) if (!(stmt->ntab % TAB_INCR)) { - ti = (TABLE_INFO **) realloc(ti, (stmt->ntab + TAB_INCR) * sizeof(TABLE_INFO *)); - if (!ti) - { - SC_set_error(stmt, STMT_NO_MEMORY_ERROR, "PGAPI_AllocStmt failed in parse_statement for TABLE_INFO.", func); - return FALSE; - } + SC_REALLOC_return_with_error(ti, TABLE_INFO *, (stmt->ntab + TAB_INCR) * sizeof(TABLE_INFO *), stmt, "PGAPI_AllocStmt failed in parse_statement for TABLE_INFO", FALSE); stmt->ti = ti; } wti = ti[stmt->ntab] = (TABLE_INFO *) malloc(sizeof(TABLE_INFO)); @@ -1944,7 +1944,8 @@ RETCODE bulk_ope_callback(RETCODE retcode, void *para) bop_cdata *cbdata = (bop_cdata *) malloc(sizeof(bop_cdata)); memcpy(cbdata, s, sizeof(bop_cdata)); cbdata->need_data_callback = TRUE; - enqueueNeedDataCallback(s->stmt, bulk_ope_callback, cbdata); + if (0 == enqueueNeedDataCallback(s->stmt, bulk_ope_callback, cbdata)) + ret = SQL_ERROR; return ret; } s->processed++; @@ -673,12 +673,13 @@ getNumericColumnSize(StatementClass *stmt, OID type, int col) Int4 getCharColumnSize(StatementClass *stmt, OID type, int col, int handle_unknown_size_as) { + CSTR func = "getCharColumnSize"; int p = -1, attlen = -1, adtsize = -1, maxsize; QResultClass *result; ConnectionClass *conn = SC_get_conn(stmt); ConnInfo *ci = &(conn->connInfo); - mylog("getCharColumnSize: type=%d, col=%d, unknown = %d\n", type, col, handle_unknown_size_as); + mylog("%s: type=%d, col=%d, unknown = %d\n", func, type, col, handle_unknown_size_as); /* Assign Maximum size based on parameters */ switch (type) @@ -725,10 +726,10 @@ getCharColumnSize(StatementClass *stmt, OID type, int col, int handle_unknown_si * set_tuplefield_string) */ adtsize = QR_get_fieldsize(result, col); - if (adtsize > 0) - return adtsize; if (stmt->catalog_result) { + if (adtsize > 0) + return adtsize; return maxsize; } @@ -743,12 +744,13 @@ getCharColumnSize(StatementClass *stmt, OID type, int col, int handle_unknown_si { case PG_TYPE_VARCHAR: case PG_TYPE_BPCHAR: - if (CC_is_in_unicode_driver(conn) || conn->ms_jet) - return attlen; #if (ODBCVER >= 0x0300) return attlen; -#endif /* ODBCVER */ +#else + if (CC_is_in_unicode_driver(conn) || conn->ms_jet) + return attlen; return p; +#endif /* ODBCVER */ } } @@ -757,7 +759,7 @@ getCharColumnSize(StatementClass *stmt, OID type, int col, int handle_unknown_si /* The type is really unknown */ if (type == PG_TYPE_BPCHAR) { - mylog("getCharColumnSize: BP_CHAR LONGEST: p = %d\n", p); + mylog("%s: BP_CHAR LONGEST: p = %d\n", func, p); if (p > 0) return p; } @@ -770,7 +772,7 @@ getCharColumnSize(StatementClass *stmt, OID type, int col, int handle_unknown_si } if (handle_unknown_size_as == UNKNOWNS_AS_LONGEST) { - mylog("getCharColumnSize: LONGEST: p = %d\n", p); + mylog("%s: LONGEST: p = %d\n", func, p); if (p > 0) return p; } @@ -5,7 +5,7 @@ * * Comments: See "notice.txt" for copyright and license information. * - * $Id: psqlodbc.h,v 1.119 2007/05/02 21:44:12 hinoue Exp $ + * $Id: psqlodbc.h,v 1.121 2007/12/26 13:28:36 hinoue Exp $ * */ @@ -31,7 +31,9 @@ #ifdef _DEBUG #ifndef _MEMORY_DEBUG_ #include <stdlib.h> +#if (_MSC_VER < 1400) /* in case of VC7 or under */ #include <malloc.h> +#endif /* _MSC_VER */ #define _CRTDBG_MAP_ALLOC #include <crtdbg.h> #endif /* _MEMORY_DEBUG_ */ @@ -177,7 +179,9 @@ typedef double SDOUBLE; #endif /* FALSE */ #else #define snprintf _snprintf +#ifndef strdup #define strdup _strdup +#endif /* strdup */ #define strnicmp _strnicmp #define stricmp _stricmp #define vsnprintf _vsnprintf @@ -479,8 +483,6 @@ void debug_memory_check(void); #ifdef WIN32 #undef strdup -#undef strnicmp -#undef stricmp #endif /* WIN32 */ #define malloc debug_alloc #define realloc debug_realloc @@ -382,7 +382,7 @@ inolog("QR_AddNew %dth row(%d fields) alloc=%d\n", self->num_cached_rows, QR_Num else if (self->num_cached_rows >= self->count_backend_allocated) { alloc = self->count_backend_allocated * 2; - self->backend_tuples = realloc(self->backend_tuples, alloc * sizeof(TupleField) * num_fields); + QR_REALLOC_return_with_error(self->backend_tuples, TupleField, alloc * sizeof(TupleField) * num_fields, self, "Out of memory in QR_AddNew.", NULL); } self->count_backend_allocated = alloc; @@ -248,12 +248,14 @@ do { \ } while (0) #define QR_REALLOC_return_with_error(t, tp, s, a, m, r) \ do { \ - if (t = (tp *) realloc(t, s), NULL == t) \ + tp *tmp; \ + if (tmp = (tp *) realloc(t, s), NULL == tmp) \ { \ QR_set_rstatus(a, PORES_FATAL_ERROR); \ QR_set_message(a, m); \ return r; \ } \ + t = tmp; \ } while (0) #ifdef __cplusplus @@ -2148,8 +2148,6 @@ static BOOL tupleIsDeleting(const StatementClass *stmt, const QResultClass *res, static BOOL enlargeAdded(QResultClass *res, UInt4 number, const StatementClass *stmt) { UInt4 alloc; - KeySet *added_keyset; - TupleField *added_tuples; int num_fields = res->num_fields; alloc = res->ad_alloc; @@ -2163,26 +2161,9 @@ static BOOL enlargeAdded(QResultClass *res, UInt4 number, const StatementClass * if (alloc <= res->ad_alloc) return TRUE; - if (added_keyset = realloc(res->added_keyset, sizeof(KeySet) * alloc), !added_keyset) - { - res->ad_alloc = 0; - return FALSE; - } - added_tuples = res->added_tuples; + QR_REALLOC_return_with_error(res->added_keyset, KeySet, sizeof(KeySet) * alloc, res, "enlargeAdded failed", FALSE); if (SQL_CURSOR_KEYSET_DRIVEN != stmt->options.cursor_type) - if (added_tuples = realloc(res->added_tuples, sizeof(TupleField) * num_fields * alloc), !added_tuples) - { - if (added_keyset) - free(added_keyset); - added_keyset = NULL; - } - res->added_keyset = added_keyset; - res->added_tuples = added_tuples; - if (!added_keyset) - { - res->ad_alloc = 0; - return FALSE; - } + QR_REALLOC_return_with_error(res->added_tuples, TupleField, sizeof(TupleField) * num_fields * alloc, res, "enlargeAdded failed 2", FALSE); res->ad_alloc = alloc; return TRUE; } @@ -2445,9 +2426,6 @@ inolog("!!Commit Deleted=%d(%d)\n", *deleted, i); static BOOL enlargeUpdated(QResultClass *res, Int4 number, const StatementClass *stmt) { Int2 alloc; - SQLULEN *updated; - KeySet *updated_keyset; - TupleField *updated_tuples = NULL; alloc = res->up_alloc; if (0 == alloc) @@ -2460,36 +2438,10 @@ static BOOL enlargeUpdated(QResultClass *res, Int4 number, const StatementClass if (alloc <= res->up_alloc) return TRUE; - if (updated = realloc(res->updated, sizeof(UInt4) * alloc), !updated) - { - if (res->updated_keyset) - { - free(res->updated_keyset); - res->updated_keyset = NULL; - } - res->up_alloc = 0; - return FALSE; - } - if (updated_keyset = realloc(res->updated_keyset, sizeof(KeySet) * alloc), !updated_keyset) - { - free(res->updated); - res->updated = NULL; - res->up_alloc = 0; - return FALSE; - } + QR_REALLOC_return_with_error(res->updated, UInt4, sizeof(UInt4) * alloc, res, "enlargeUpdated failed", FALSE); + QR_REALLOC_return_with_error(res->updated_keyset, KeySet, sizeof(KeySet) * alloc, res, "enlargeUpdated failed 2", FALSE); if (SQL_CURSOR_KEYSET_DRIVEN != stmt->options.cursor_type) - if (updated_tuples = realloc(res->updated_tuples, sizeof(TupleField) * res->num_fields * alloc), !updated_tuples) - { - free(res->updated); - res->updated = NULL; - free(res->updated_keyset); - res->updated_keyset = NULL; - res->up_alloc = 0; - return FALSE; - } - res->updated = updated; - res->updated_keyset = updated_keyset; - res->updated_tuples = updated_tuples; + QR_REALLOC_return_with_error(res->updated_tuples, TupleField, sizeof(TupleField) * res->num_fields * alloc, res, "enlargeUpdated 3", FALSE); res->up_alloc = alloc; return TRUE; @@ -3443,7 +3395,7 @@ SC_pos_reload_needed(StatementClass *stmt, SQLULEN req_size, UDWORD flag) brows = GIdx2RowIdx(limitrow, stmt); if (brows > res->count_backend_allocated) { - res->backend_tuples = realloc(res->backend_tuples, sizeof(TupleField) * res->num_fields * brows); + QR_REALLOC_return_with_error(res->backend_tuples, TupleField, sizeof(TupleField) * res->num_fields * brows, res, "pos_reload_needed failed", SQL_ERROR); res->count_backend_allocated = brows; } if (brows > 0) @@ -3554,7 +3506,7 @@ QR_get_rowstart_in_cache(res), SC_get_rowset_start(stmt), stmt->options.cursor_t tuple_size = TUPLE_MALLOC_INC; else tuple_size = res->count_keyset_allocated * 2; - res->keyset = (KeySet *) realloc(res->keyset, sizeof(KeySet) * tuple_size); + QR_REALLOC_return_with_error(res->keyset, KeySet, sizeof(KeySet) * tuple_size, res, "pos_newload failed", SQL_ERROR); res->count_keyset_allocated = tuple_size; } KeySetSet(tuple_new, qres->num_fields, res->num_key_fields, res->keyset + kres_ridx); @@ -3868,7 +3820,8 @@ SC_pos_update(StatementClass *stmt, { pup_cdata *cbdata = (pup_cdata *) malloc(sizeof(pup_cdata)); memcpy(cbdata, &s, sizeof(pup_cdata)); - enqueueNeedDataCallback(s.stmt, pos_update_callback, cbdata); + if (0 == enqueueNeedDataCallback(s.stmt, pos_update_callback, cbdata)) + ret = SQL_ERROR; return ret; } /* else if (ret != SQL_SUCCESS) this is unneccesary @@ -4276,7 +4229,8 @@ SC_pos_add(StatementClass *stmt, { padd_cdata *cbdata = (padd_cdata *) malloc(sizeof(padd_cdata)); memcpy(cbdata, &s, sizeof(padd_cdata)); - enqueueNeedDataCallback(s.stmt, pos_add_callback, cbdata); + if (0 == enqueueNeedDataCallback(s.stmt, pos_add_callback, cbdata)) + ret = SQL_ERROR; goto cleanup; } /* else if (ret != SQL_SUCCESS) this is unneccesary @@ -4457,7 +4411,8 @@ RETCODE spos_callback(RETCODE retcode, void *para) memcpy(cbdata, s, sizeof(spos_cdata)); cbdata->need_data_callback = TRUE; - enqueueNeedDataCallback(s->stmt, spos_callback, cbdata); + if (0 == enqueueNeedDataCallback(s->stmt, spos_callback, cbdata)) + ret = SQL_ERROR; return ret; } s->processed++; @@ -78,7 +78,7 @@ SOCK_Constructor(const ConnectionClass *conn) rv->buffer_filled_out = 0; rv->buffer_read_in = 0; - if (rv) + if (conn) rv->buffer_size = conn->connInfo.drivers.socket_buffersize; else rv->buffer_size = globals.socket_buffersize; diff --git a/statement.c b/statement.c index 577accd..ac6ee8a 100644 --- a/statement.c +++ b/statement.c @@ -2069,9 +2069,9 @@ int enqueueNeedDataCallback(StatementClass *stmt, NeedDataCallfunc func, void *d { if (stmt->num_callbacks >= stmt->allocated_callbacks) { - stmt->callbacks = (NeedDataCallback *) realloc(stmt->callbacks, + SC_REALLOC_return_with_error(stmt->callbacks, NeedDataCallback, sizeof(NeedDataCallback) * (stmt->allocated_callbacks + - CALLBACK_ALLOC_ONCE)); + CALLBACK_ALLOC_ONCE), stmt, "NeedDataCallback enqueue error", 0); stmt->allocated_callbacks += CALLBACK_ALLOC_ONCE; } stmt->callbacks[stmt->num_callbacks].func = func; diff --git a/statement.h b/statement.h index 441183f..8523ee9 100644 --- a/statement.h +++ b/statement.h @@ -343,11 +343,13 @@ do { \ } while (0) #define SC_REALLOC_return_with_error(t, tp, s, a, m, r) \ do { \ - if (t = (tp *) realloc(t, s), NULL == t) \ + tp *tmp; \ + if (tmp = (tp *) realloc(t, s), NULL == tmp) \ { \ SC_set_error(a, STMT_NO_MEMORY_ERROR, m, "SC_REALLOC"); \ return r; \ } \ + t = tmp; \ } while (0) /* options for SC_free_params() */ @@ -9,9 +9,9 @@ #ifndef __VERSION_H__ #define __VERSION_H__ -#define POSTGRESDRIVERVERSION "08.02.0401" -#define POSTGRES_RESOURCE_VERSION "08.02.0401\0" -#define PG_DRVFILE_VERSION 8,2,04,01 -#define PG_BUILD_VERSION "200704290001" +#define POSTGRESDRIVERVERSION "08.02.0402" +#define POSTGRES_RESOURCE_VERSION "08.02.0402\0" +#define PG_DRVFILE_VERSION 8,2,04,02 +#define PG_BUILD_VERSION "200706020001" #endif @@ -191,7 +191,7 @@ CPP=cl.exe !IF "$(CFG)" == "Release" CPP_PROJ=/nologo /$(LINKMT) /O2 /D "NDEBUG" !ELSEIF "$(CFG)" == "Debug" -CPP_PROJ=/nologo /$(LINKMT)d /Gm /ZI /Od /GZ /D "_DEBUG" +CPP_PROJ=/nologo /$(LINKMT)d /Gm /ZI /Od /RTC1 /D "_DEBUG" !ENDIF CPP_PROJ=$(CPP_PROJ) /W3 $(VC_FLAGS) /I "$(PG_INC)" /I "$(SSL_INC)" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "_CRT_SECURE_NO_DEPRECATE" /D "PSQLODBC_EXPORTS" /D "WIN_MULTITHREAD_SUPPORT" $(ADD_DEFINES) /Fp"$(INTDIR)\psqlodbc.pch" /Fo"$(INTDIR)"\ /Fd"$(INTDIR)"\ /FD @@ -242,7 +242,10 @@ BSC32_SBRS= \ LINK32=link.exe LIB32=lib.exe -LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib $(OUTDIR)\$(DTCLIB).lib winmm.lib /nologo /dll /machine:I386 /def:"$(DEF_FILE)" +!IF "$(MSDTC)" != "no" +LINK32_FLAGS=$(OUTDIR)\$(DTCLIB).lib +!ENDIF +LINK32_FLAGS=$(LINK32_FLAGS) kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib winmm.lib /nologo /dll /machine:I386 /def:"$(DEF_FILE)" !IF "$(ANSI_VERSION)" == "yes" DEF_FILE= "psqlodbca.def" !ELSE |
