Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ec6c4d8

Browse files
author
Hiroshi Inoue
committed
Improve declare/fetch mode a little.
Add a new DSN option for PREPARE hadling. Hiroshi Inoue
1 parent fc5ec42 commit ec6c4d8

12 files changed

+72
-35
lines changed

src/interfaces/odbc/connection.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ QResultClass *
938938
CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
939939
{
940940
QResultClass *result_in = NULL, *res = NULL, *retres = NULL;
941-
char swallow;
941+
char swallow, *wq;
942942
int id;
943943
SocketClass *sock = self->sock;
944944
int maxlen, empty_reqs;
@@ -999,7 +999,9 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
999999

10001000
ReadyToReturn = FALSE;
10011001
empty_reqs = 0;
1002-
if (strcmp(query, " ") == 0)
1002+
for (wq = query; isspace(*wq); wq++)
1003+
;
1004+
if (*wq == '\0')
10031005
empty_reqs = 1;
10041006
while (!ReadyToReturn)
10051007
{

src/interfaces/odbc/connection.h

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ typedef struct
159159
char translation_dll[MEDIUM_REGISTRY_LEN];
160160
char translation_option[SMALL_REGISTRY_LEN];
161161
char focus_password;
162+
char disallow_premature;
162163
GLOBAL_VALUES drivers; /* moved from driver's option */
163164
} ConnInfo;
164165

src/interfaces/odbc/convert.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -1001,10 +1001,8 @@ copy_statement_with_parameters(StatementClass *stmt)
10011001
#ifdef DRIVER_CURSOR_IMPLEMENT
10021002
BOOL search_from_pos = FALSE;
10031003
#endif /* DRIVER_CURSOR_IMPLEMENT */
1004-
#ifdef PREPARE_TRIAL
1005-
prepare_dummy_cursor = stmt->pre_executing;
1006-
#endif /* PREPARE_TRIAL */
1007-
1004+
if (ci->disallow_premature)
1005+
prepare_dummy_cursor = stmt->pre_executing;
10081006

10091007
if (!old_statement)
10101008
{
@@ -1704,7 +1702,6 @@ copy_statement_with_parameters(StatementClass *stmt)
17041702
if (search_from_pos)
17051703
stmt->options.scroll_concurrency = SQL_CONCUR_READ_ONLY;
17061704
#endif /* DRIVER_CURSOR_IMPLEMENT */
1707-
#ifdef PREPARE_TRIAL
17081705
if (prepare_dummy_cursor && SC_is_pre_executable(stmt))
17091706
{
17101707
char fetchstr[128];
@@ -1715,7 +1712,6 @@ copy_statement_with_parameters(StatementClass *stmt)
17151712
CVT_APPEND_STR(fetchstr);
17161713
stmt->inaccurate_result = TRUE;
17171714
}
1718-
#endif /* PREPARE_TRIAL */
17191715

17201716
return SQL_SUCCESS;
17211717
}

src/interfaces/odbc/dlg_specific.c

+30-4
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,13 @@ driver_optionsProc(HWND hdlg,
245245
ci = (ConnInfo *) lParam;
246246
if (ci && ci->dsn && ci->dsn[0])
247247
{
248+
SetWindowText(hdlg, "Advanced Options (Common)");
248249
driver_optionsDraw(hdlg, NULL, 0, TRUE);
249250
}
250251
else
251252
{
252253
CheckDlgButton(hdlg, DRV_OR_DSN, 1);
254+
SetWindowText(hdlg, "Advanced Options (Connection)");
253255
ShowWindow(GetDlgItem(hdlg, DRV_OR_DSN), SW_HIDE);
254256
driver_optionsDraw(hdlg, ci, 1, FALSE);
255257
}
@@ -284,10 +286,14 @@ driver_optionsProc(HWND hdlg,
284286
if (IsDlgButtonChecked(hdlg, DRV_OR_DSN))
285287
{
286288
ConnInfo *ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
289+
SetWindowText(hdlg, "Advanced Options (per DSN)");
287290
driver_optionsDraw(hdlg, ci, ci ? 1 : 0, ci == NULL);
288291
}
289292
else
293+
{
294+
SetWindowText(hdlg, "Advanced Options (Common)");
290295
driver_optionsDraw(hdlg, NULL, 0, TRUE);
296+
}
291297
}
292298
break;
293299
}
@@ -337,6 +343,7 @@ ds_optionsProc(HWND hdlg,
337343
CheckDlgButton(hdlg, DS_FAKEOIDINDEX, atoi(ci->fake_oid_index));
338344
CheckDlgButton(hdlg, DS_ROWVERSIONING, atoi(ci->row_versioning));
339345
CheckDlgButton(hdlg, DS_SHOWSYSTEMTABLES, atoi(ci->show_system_tables));
346+
CheckDlgButton(hdlg, DS_DISALLOWPREMATURE, ci->disallow_premature);
340347

341348
EnableWindow(GetDlgItem(hdlg, DS_FAKEOIDINDEX), atoi(ci->show_oid_column));
342349

@@ -371,6 +378,7 @@ ds_optionsProc(HWND hdlg,
371378
sprintf(ci->show_system_tables, "%d", IsDlgButtonChecked(hdlg, DS_SHOWSYSTEMTABLES));
372379

373380
sprintf(ci->row_versioning, "%d", IsDlgButtonChecked(hdlg, DS_ROWVERSIONING));
381+
ci->disallow_premature = IsDlgButtonChecked(hdlg, DS_DISALLOWPREMATURE);
374382

375383
/* OID Options */
376384
sprintf(ci->fake_oid_index, "%d", IsDlgButtonChecked(hdlg, DS_FAKEOIDINDEX));
@@ -620,8 +628,13 @@ copyAttributes(ConnInfo *ci, const char *attribute, const char *value)
620628
decode(value, ci->conn_settings);
621629
/* strcpy(ci->conn_settings, value); */
622630
}
631+
else if (stricmp(attribute, INI_DISALLOWPREMATURE) == 0 || stricmp(attribute, "C3") == 0)
632+
{
633+
ci->disallow_premature = atoi(value);
634+
/* strcpy(ci->conn_settings, value); */
635+
}
623636

624-
mylog("copyAttributes: DSN='%s',server='%s',dbase='%s',user='%s',passwd='%s',port='%s',onlyread='%s',protocol='%s', conn_settings='%s')\n", ci->dsn, ci->server, ci->database, ci->username, ci->password, ci->port, ci->onlyread, ci->protocol, ci->conn_settings);
637+
mylog("copyAttributes: DSN='%s',server='%s',dbase='%s',user='%s',passwd='%s',port='%s',onlyread='%s',protocol='%s',conn_settings='%s',disallow_premature=%d)\n", ci->dsn, ci->server, ci->database, ci->username, ci->password, ci->port, ci->onlyread, ci->protocol, ci->conn_settings, ci->disallow_premature);
625638
}
626639

627640
void
@@ -715,7 +728,8 @@ void
715728
getDSNinfo(ConnInfo *ci, char overwrite)
716729
{
717730
char *DSN = ci->dsn;
718-
char encoded_conn_settings[LARGE_REGISTRY_LEN];
731+
char encoded_conn_settings[LARGE_REGISTRY_LEN],
732+
temp[SMALL_REGISTRY_LEN];
719733

720734
/*
721735
* If a driver keyword was present, then dont use a DSN and return.
@@ -784,8 +798,13 @@ getDSNinfo(ConnInfo *ci, char overwrite)
784798
if (ci->translation_option[0] == '\0' || overwrite)
785799
SQLGetPrivateProfileString(DSN, INI_TRANSLATIONOPTION, "", ci->translation_option, sizeof(ci->translation_option), ODBC_INI);
786800

801+
if (ci->disallow_premature == 0 || overwrite)
802+
{
803+
SQLGetPrivateProfileString(DSN, INI_DISALLOWPREMATURE, "", temp, sizeof(temp), ODBC_INI);
804+
ci->disallow_premature = atoi(temp);
805+
}
806+
787807
/* Allow override of odbcinst.ini parameters here */
788-
/* getGlobalDefaults(DSN, ODBC_INI, TRUE); */
789808
getCommonDefaults(DSN, ODBC_INI, ci);
790809

791810
qlog("DSN info: DSN='%s',server='%s',port='%s',dbase='%s',user='%s',passwd='%s'\n",
@@ -823,7 +842,8 @@ void
823842
writeDSNinfo(const ConnInfo *ci)
824843
{
825844
const char *DSN = ci->dsn;
826-
char encoded_conn_settings[LARGE_REGISTRY_LEN];
845+
char encoded_conn_settings[LARGE_REGISTRY_LEN],
846+
temp[SMALL_REGISTRY_LEN];
827847

828848
encode(ci->conn_settings, encoded_conn_settings);
829849

@@ -891,6 +911,12 @@ writeDSNinfo(const ConnInfo *ci)
891911
INI_CONNSETTINGS,
892912
encoded_conn_settings,
893913
ODBC_INI);
914+
915+
sprintf(temp, "%d", ci->disallow_premature);
916+
SQLWritePrivateProfileString(DSN,
917+
INI_DISALLOWPREMATURE,
918+
temp,
919+
ODBC_INI);
894920
}
895921

896922

src/interfaces/odbc/dlg_specific.h

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
#define INI_TRANSLATIONNAME "TranslationName"
9696
#define INI_TRANSLATIONDLL "TranslationDLL"
9797
#define INI_TRANSLATIONOPTION "TranslationOption"
98+
#define INI_DISALLOWPREMATURE "DisallowPremature"
9899

99100

100101
/* Connection Defaults */

src/interfaces/odbc/execute.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,12 @@ PGAPI_Execute(
340340
return retval;
341341

342342
mylog(" stmt_with_params = '%s'\n", stmt->stmt_with_params);
343-
#ifdef PREPARE_TRIAL
344-
if (stmt->inaccurate_result)
343+
/*
344+
* Get the field info for the prepared
345+
* query using dummy backward fetch.
346+
*/
347+
if (stmt->inaccurate_result && conn->connInfo.disallow_premature)
348+
{
345349
if (SC_is_pre_executable(stmt))
346350
{
347351
BOOL in_trans = CC_is_in_trans(conn);
@@ -365,7 +369,8 @@ PGAPI_Execute(
365369
}
366370
else
367371
return SQL_SUCCESS;
368-
#endif /* PREPARE_TRIAL */
372+
}
373+
369374
return SC_execute(stmt);
370375
}
371376

src/interfaces/odbc/psqlodbc.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Comments: See "notice.txt" for copyright and license information.
77
*
8-
* $Id: psqlodbc.h,v 1.47 2001/09/07 06:02:22 inoue Exp $
8+
* $Id: psqlodbc.h,v 1.48 2001/09/08 16:20:16 inoue Exp $
99
*
1010
*/
1111

@@ -42,7 +42,7 @@ typedef UInt4 Oid;
4242
#define DRIVERNAME "PostgreSQL ODBC"
4343
#define DBMS_NAME "PostgreSQL"
4444

45-
#define POSTGRESDRIVERVERSION "07.01.0006"
45+
#define POSTGRESDRIVERVERSION "07.01.0007"
4646

4747
#ifdef WIN32
4848
#define DRIVER_FILE_NAME "PSQLODBC.DLL"

src/interfaces/odbc/psqlodbc.rc

+8-4
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ BEGIN
149149
BS_AUTOCHECKBOX | WS_TABSTOP,149,13,72,10
150150
CONTROL "Show System &Tables",DS_SHOWSYSTEMTABLES,"Button",
151151
BS_AUTOCHECKBOX | WS_TABSTOP,45,28,88,10
152+
CONTROL "Disallow &Premature",DS_DISALLOWPREMATURE,"Button",
153+
BS_AUTOCHECKBOX | WS_TABSTOP,149,28,72,10
152154
GROUPBOX "Protocol",IDC_STATIC,43,44,180,25
153155
CONTROL "7.X,6.4+",DS_PG64,"Button",BS_AUTORADIOBUTTON |
154156
WS_GROUP,53,54,47,10
@@ -264,6 +266,8 @@ BEGIN
264266
BS_AUTOCHECKBOX | WS_TABSTOP,130,10,85,10
265267
CONTROL "Show System &Tables",DS_SHOWSYSTEMTABLES,"Button",
266268
BS_AUTOCHECKBOX | WS_TABSTOP,25,25,85,10
269+
CONTROL "Disallow &Premature",DS_DISALLOWPREMATURE,"Button",
270+
BS_AUTOCHECKBOX | WS_TABSTOP,130,25,85,10
267271
GROUPBOX "Protocol",IDC_STATIC,15,40,180,25
268272
CONTROL "7.X,6.4+",DS_PG64,"Button",BS_AUTORADIOBUTTON | WS_GROUP,25,
269273
50,35,10
@@ -350,8 +354,8 @@ END
350354
//
351355

352356
VS_VERSION_INFO VERSIONINFO
353-
FILEVERSION 7,1,0,6
354-
PRODUCTVERSION 7,1,0,6
357+
FILEVERSION 7,1,0,7
358+
PRODUCTVERSION 7,1,0,7
355359
FILEFLAGSMASK 0x3L
356360
#ifdef _DEBUG
357361
FILEFLAGS 0x1L
@@ -373,14 +377,14 @@ BEGIN
373377
VALUE "CompanyName", "Insight Distribution Systems\0"
374378
#endif
375379
VALUE "FileDescription", "PostgreSQL Driver\0"
376-
VALUE "FileVersion", " 07.01.0006\0"
380+
VALUE "FileVersion", " 07.01.0007\0"
377381
VALUE "InternalName", "psqlodbc\0"
378382
VALUE "LegalCopyright", "\0"
379383
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"
380384
VALUE "OriginalFilename", "psqlodbc.dll\0"
381385
VALUE "PrivateBuild", "\0"
382386
VALUE "ProductName", "Microsoft Open Database Connectivity\0"
383-
VALUE "ProductVersion", " 07.01.0006\0"
387+
VALUE "ProductVersion", " 07.01.0007\0"
384388
VALUE "SpecialBuild", "\0"
385389
END
386390
END

src/interfaces/odbc/qresult.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,15 @@ QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, char *cursor)
238238
if (conn != NULL)
239239
{
240240
ConnInfo *ci = &(conn->connInfo);
241+
BOOL fetch_cursor = (ci->drivers.use_declarefetch && cursor && cursor[0]);
241242
self->conn = conn;
242243

243244
mylog("QR_fetch_tuples: cursor = '%s', self->cursor=%u\n", (cursor == NULL) ? "" : cursor, self->cursor);
244245

245246
if (self->cursor)
246247
free(self->cursor);
247248

248-
if (ci->drivers.use_declarefetch)
249+
if (fetch_cursor)
249250
{
250251
if (!cursor || cursor[0] == '\0')
251252
{
@@ -275,7 +276,7 @@ QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, char *cursor)
275276

276277
mylog("QR_fetch_tuples: past CI_read_fields: num_fields = %d\n", self->num_fields);
277278

278-
if (ci->drivers.use_declarefetch)
279+
if (fetch_cursor)
279280
tuple_size = self->cache_size;
280281
else
281282
tuple_size = TUPLE_MALLOC_INC;
@@ -432,7 +433,7 @@ QR_next_tuple(QResultClass *self)
432433
if (!self->inTuples)
433434
{
434435
ci = &(self->conn->connInfo);
435-
if (!ci->drivers.use_declarefetch)
436+
if (!self->cursor || !ci->drivers.use_declarefetch)
436437
{
437438
mylog("next_tuple: ALL_ROWS: done, fcount = %d, fetch_count = %d\n", fcount, fetch_count);
438439
self->tupleField = NULL;
@@ -535,7 +536,7 @@ QR_next_tuple(QResultClass *self)
535536
case 'B': /* Tuples in binary format */
536537
case 'D': /* Tuples in ASCII format */
537538

538-
if (!ci->drivers.use_declarefetch && self->fcount >= self->count_allocated)
539+
if ((!self->cursor || !ci->drivers.use_declarefetch) && self->fcount >= self->count_allocated)
539540
{
540541
int tuple_size = self->count_allocated;
541542

src/interfaces/odbc/resource.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@
5151
#define DS_PG63 1058
5252
#define DRV_OR_DSN 1059
5353
#define DRV_DEBUG 1060
54+
#define DS_DISALLOWPREMATURE 1061
5455

5556
// Next default values for new objects
5657
//
5758
#ifdef APSTUDIO_INVOKED
5859
#ifndef APSTUDIO_READONLY_SYMBOLS
5960
#define _APS_NEXT_RESOURCE_VALUE 105
6061
#define _APS_NEXT_COMMAND_VALUE 40001
61-
#define _APS_NEXT_CONTROL_VALUE 1061
62+
#define _APS_NEXT_CONTROL_VALUE 1062
6263
#define _APS_NEXT_SYMED_VALUE 101
6364
#endif
6465
#endif

src/interfaces/odbc/results.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ PGAPI_RowCount(
7373

7474
if (res && pcrow)
7575
{
76-
*pcrow = ci->drivers.use_declarefetch ? -1 : QR_get_num_tuples(res);
76+
*pcrow = SC_is_fetchcursor(stmt) ? -1 : QR_get_num_tuples(res);
7777
return SQL_SUCCESS;
7878
}
7979
}
@@ -728,7 +728,7 @@ PGAPI_GetData(
728728
}
729729
}
730730

731-
if (stmt->manual_result || !ci->drivers.use_declarefetch)
731+
if (stmt->manual_result || !SC_is_fetchcursor(stmt))
732732
{
733733
/* make sure we're positioned on a valid row */
734734
num_rows = QR_get_num_tuples(res);
@@ -929,7 +929,7 @@ PGAPI_ExtendedFetch(
929929
}
930930
ci = &(SC_get_conn(stmt)->connInfo);
931931

932-
if (ci->drivers.use_declarefetch && !stmt->manual_result)
932+
if (SC_is_fetchcursor(stmt) && !stmt->manual_result)
933933
{
934934
if (fFetchType != SQL_FETCH_NEXT)
935935
{
@@ -1108,7 +1108,7 @@ PGAPI_ExtendedFetch(
11081108
* Handle Declare Fetch style specially because the end is not really
11091109
* the end...
11101110
*/
1111-
if (ci->drivers.use_declarefetch && !stmt->manual_result)
1111+
if (SC_is_fetchcursor(stmt) && !stmt->manual_result)
11121112
{
11131113
if (QR_end_tuples(res))
11141114
return SQL_NO_DATA_FOUND;
@@ -1190,7 +1190,7 @@ PGAPI_ExtendedFetch(
11901190
stmt->currTuple = stmt->rowset_start;
11911191

11921192
/* For declare/fetch, need to reset cursor to beginning of rowset */
1193-
if (ci->drivers.use_declarefetch && !stmt->manual_result)
1193+
if (SC_is_fetchcursor(stmt) && !stmt->manual_result)
11941194
QR_set_position(res, 0);
11951195

11961196
/* Set the number of rows retrieved */

0 commit comments

Comments
 (0)