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

Commit 4ad1b5b

Browse files
author
Hiroshi Inoue
committed
Resolve compile errors on unix.
Rename psqlodbc.def -> psqlodbc_win32.def. Improve internal *declare cursor* handling a little. Hiroshi Inoue
1 parent 02b1a7f commit 4ad1b5b

File tree

9 files changed

+121
-56
lines changed

9 files changed

+121
-56
lines changed

src/interfaces/odbc/convert.c

+95-28
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <string.h>
2222
#include <ctype.h>
2323

24+
#include "psqlodbc.h"
2425
#ifdef MULTIBYTE
2526
#include "multibyte.h"
2627
#endif
@@ -938,6 +939,26 @@ into_table_from(const char *stmt)
938939
return isspace((unsigned char) stmt[4]);
939940
}
940941

942+
/*----------
943+
* Check if the statement is
944+
* SELECT ... FOR UPDATE .....
945+
* This isn't really a strict check but ...
946+
*----------
947+
*/
948+
static BOOL
949+
table_for_update(const char *stmt, int *endpos)
950+
{
951+
const char *wstmt = stmt;
952+
while (isspace((unsigned char) *(++wstmt)));
953+
if (! *wstmt)
954+
return FALSE;
955+
if (strnicmp(wstmt, "update", 6))
956+
return FALSE;
957+
wstmt += 6;
958+
*endpos = wstmt - stmt;
959+
return !wstmt[0] || isspace((unsigned char) wstmt[0]);
960+
}
961+
941962
/*
942963
* This function inserts parameters into an SQL statements.
943964
* It will also modify a SELECT statement for use with declare/fetch cursors.
@@ -968,14 +989,17 @@ copy_statement_with_parameters(StatementClass *stmt)
968989
Oid lobj_oid;
969990
int lobj_fd,
970991
retval;
971-
BOOL check_select_into = FALSE; /* select into check */
992+
BOOL check_cursor_ok = FALSE; /* check cursor restriction */
972993
BOOL proc_no_param = TRUE;
973-
unsigned int declare_pos;
994+
unsigned int declare_pos = 0;
974995
ConnectionClass *conn = SC_get_conn(stmt);
975996
ConnInfo *ci = &(conn->connInfo);
976-
BOOL prepare_dummy_cursor = FALSE;
997+
BOOL prepare_dummy_cursor = FALSE;
998+
char token_save[32];
999+
int token_len;
1000+
BOOL prev_token_end;
9771001
#ifdef DRIVER_CURSOR_IMPLEMENT
978-
BOOL ins_ctrl = FALSE;
1002+
BOOL search_from_pos = FALSE;
9791003
#endif /* DRIVER_CURSOR_IMPLEMENT */
9801004
#ifdef PREPARE_TRIAL
9811005
prepare_dummy_cursor = stmt->pre_executing;
@@ -1012,7 +1036,7 @@ copy_statement_with_parameters(StatementClass *stmt)
10121036
stmt->options.scroll_concurrency = SQL_CONCUR_READ_ONLY;
10131037
else if (!stmt->ti || stmt->ntab != 1)
10141038
stmt->options.scroll_concurrency = SQL_CONCUR_READ_ONLY;
1015-
else ins_ctrl = TRUE;
1039+
else search_from_pos = TRUE;
10161040
}
10171041
#endif /* DRIVER_CURSOR_IMPLEMENT */
10181042

@@ -1021,7 +1045,10 @@ copy_statement_with_parameters(StatementClass *stmt)
10211045
sprintf(stmt->cursor_name, "SQL_CUR%p", stmt);
10221046
oldstmtlen = strlen(old_statement);
10231047
CVT_INIT(oldstmtlen);
1048+
10241049
stmt->miscinfo = 0;
1050+
token_len = 0;
1051+
prev_token_end = TRUE;
10251052
/* For selects, prepend a declare cursor to the statement */
10261053
if (stmt->statement_type == STMT_TYPE_SELECT)
10271054
{
@@ -1035,10 +1062,10 @@ copy_statement_with_parameters(StatementClass *stmt)
10351062
}
10361063
else if (ci->drivers.use_declarefetch)
10371064
SC_set_fetchcursor(stmt);
1038-
sprintf(new_statement, "%s declare %s cursor for ",
1065+
sprintf(new_statement, "%sdeclare %s cursor for ",
10391066
new_statement, stmt->cursor_name);
10401067
npos = strlen(new_statement);
1041-
check_select_into = TRUE;
1068+
check_cursor_ok = TRUE;
10421069
declare_pos = npos;
10431070
}
10441071
}
@@ -1176,28 +1203,68 @@ copy_statement_with_parameters(StatementClass *stmt)
11761203
in_escape = TRUE;
11771204
else if (oldchar == '\"')
11781205
in_dquote = TRUE;
1179-
else if (check_select_into && /* select into check */
1180-
opos > 0 &&
1181-
isspace((unsigned char) old_statement[opos - 1]) &&
1182-
into_table_from(&old_statement[opos]))
1206+
else
11831207
{
1184-
stmt->statement_type = STMT_TYPE_CREATE;
1185-
SC_no_pre_executable(stmt);
1186-
SC_no_fetchcursor(stmt);
1187-
stmt->options.scroll_concurrency = SQL_CONCUR_READ_ONLY;
1188-
memmove(new_statement, new_statement + declare_pos, npos - declare_pos);
1189-
npos -= declare_pos;
1190-
}
1208+
if (isspace(oldchar))
1209+
{
1210+
if (!prev_token_end)
1211+
{
1212+
prev_token_end = TRUE;
1213+
token_save[token_len] = '\0';
1214+
if (token_len == 4)
1215+
{
1216+
if (check_cursor_ok &&
1217+
into_table_from(&old_statement[opos - token_len]))
1218+
{
1219+
stmt->statement_type = STMT_TYPE_CREATE;
1220+
SC_no_pre_executable(stmt);
1221+
SC_no_fetchcursor(stmt);
1222+
stmt->options.scroll_concurrency = SQL_CONCUR_READ_ONLY;
1223+
memmove(new_statement, new_statement + declare_pos, npos - declare_pos);
1224+
npos -= declare_pos;
1225+
}
11911226
#ifdef DRIVER_CURSOR_IMPLEMENT
1192-
else if (ins_ctrl && /* select into check */
1193-
opos > 0 &&
1194-
isspace((unsigned char) old_statement[opos - 1]) &&
1195-
strnicmp(&old_statement[opos], "from", 4) == 0)
1196-
{
1197-
ins_ctrl = FALSE;
1198-
CVT_APPEND_STR(", CTID, OID ");
1199-
}
1227+
else if (search_from_pos && /* where's from clause */
1228+
strnicmp(token_save, "from", 4) == 0)
1229+
{
1230+
search_from_pos = FALSE;
1231+
npos -= 5;
1232+
CVT_APPEND_STR(", CTID, OID from");
1233+
}
12001234
#endif /* DRIVER_CURSOR_IMPLEMENT */
1235+
}
1236+
if (token_len == 3)
1237+
{
1238+
int endpos;
1239+
if (check_cursor_ok &&
1240+
strnicmp(token_save, "for", 3) == 0 &&
1241+
table_for_update(&old_statement[opos], &endpos))
1242+
{
1243+
SC_no_fetchcursor(stmt);
1244+
stmt->options.scroll_concurrency = SQL_CONCUR_READ_ONLY;
1245+
if (prepare_dummy_cursor)
1246+
{
1247+
npos -= 4;
1248+
opos += endpos;
1249+
}
1250+
else
1251+
{
1252+
memmove(new_statement, new_statement + declare_pos, npos - declare_pos);
1253+
npos -= declare_pos;
1254+
}
1255+
}
1256+
}
1257+
}
1258+
}
1259+
else if (prev_token_end)
1260+
{
1261+
prev_token_end = FALSE;
1262+
token_save[0] = oldchar;
1263+
token_len = 1;
1264+
}
1265+
else
1266+
token_save[token_len++] = oldchar;
1267+
}
12011268
CVT_APPEND_CHAR(oldchar);
12021269
continue;
12031270
}
@@ -1634,7 +1701,7 @@ copy_statement_with_parameters(StatementClass *stmt)
16341701
}
16351702

16361703
#ifdef DRIVER_CURSOR_IMPLEMENT
1637-
if (ins_ctrl)
1704+
if (search_from_pos)
16381705
stmt->options.scroll_concurrency = SQL_CONCUR_READ_ONLY;
16391706
#endif /* DRIVER_CURSOR_IMPLEMENT */
16401707
#ifdef PREPARE_TRIAL
@@ -2142,7 +2209,7 @@ decode(const char *in, char *out)
21422209
*-------
21432210
*/
21442211
int
2145-
convert_lo(StatementClass *stmt, void *value, Int2 fCType, PTR rgbValue,
2212+
convert_lo(StatementClass *stmt, const void *value, Int2 fCType, PTR rgbValue,
21462213
SDWORD cbValueMax, SDWORD *pcbValue)
21472214
{
21482215
Oid oid;

src/interfaces/odbc/convert.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ typedef struct
2929
int ss;
3030
} SIMPLE_TIME;
3131

32-
int copy_and_convert_field_bindinfo(StatementClass *stmt, Int4 field_type, const void *value, int col);
33-
int copy_and_convert_field(StatementClass *stmt, Int4 field_type, const void *value, Int2 fCType,
32+
int copy_and_convert_field_bindinfo(StatementClass *stmt, Int4 field_type, void *value, int col);
33+
int copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2 fCType,
3434
PTR rgbValue, SDWORD cbValueMax, SDWORD *pcbValue);
3535

3636
int copy_statement_with_parameters(StatementClass *stmt);

src/interfaces/odbc/execute.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,11 @@ PGAPI_Cancel(
458458
static char *func = "PGAPI_Cancel";
459459
StatementClass *stmt = (StatementClass *) hstmt;
460460
RETCODE result;
461+
ConnInfo *ci;
461462

462463
#ifdef WIN32
463464
HMODULE hmodule;
464465
FARPROC addr;
465-
ConnInfo *ci;
466466

467467
#endif
468468

src/interfaces/odbc/gpps.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@
5151
* ODBCINST_INI
5252
*/
5353
DWORD
54-
GetPrivateProfileString(char *theSection, /* section name */
55-
char *theKey, /* search key name */
56-
char *theDefault, /* default value if not
54+
GetPrivateProfileString(const char *theSection, /* section name */
55+
const char *theKey, /* search key name */
56+
const char *theDefault, /* default value if not
5757
* found */
5858
char *theReturnBuffer, /* return value stored
5959
* here */
6060
size_t theReturnBufferLength, /* byte length of return
6161
* buffer */
62-
char *theIniFileName) /* pathname of ini file to
62+
const char *theIniFileName) /* pathname of ini file to
6363
* search */
6464
{
6565
char buf[MAXPGPATH];
@@ -273,10 +273,10 @@ GetPrivateProfileString(char *theSection, /* section name */
273273

274274

275275
DWORD
276-
WritePrivateProfileString(char *theSection, /* section name */
277-
char *theKey, /* write key name */
278-
char *theBuffer, /* input buffer */
279-
char *theIniFileName) /* pathname of ini file to
276+
WritePrivateProfileString(const char *theSection, /* section name */
277+
const char *theKey, /* write key name */
278+
const char *theBuffer, /* input buffer */
279+
const char *theIniFileName) /* pathname of ini file to
280280
* write */
281281
{
282282
return 0;

src/interfaces/odbc/gpps.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ extern "C"
1717
#endif
1818

1919
DWORD
20-
GetPrivateProfileString(char *theSection, /* section name */
21-
char *theKey, /* search key name */
22-
char *theDefault, /* default value if not
20+
GetPrivateProfileString(const char *theSection, /* section name */
21+
const char *theKey, /* search key name */
22+
const char *theDefault, /* default value if not
2323
* found */
2424
char *theReturnBuffer, /* return valuse stored
2525
* here */
2626
size_t theBufferLength, /* byte length of return
2727
* buffer */
28-
char *theIniFileName); /* pathname of ini file
28+
const char *theIniFileName); /* pathname of ini file
2929
* to search */
3030

3131
DWORD
32-
WritePrivateProfileString(char *theSection, /* section name */
33-
char *theKey, /* write key name */
34-
char *theBuffer, /* input buffer */
35-
char *theIniFileName); /* pathname of ini file
32+
WritePrivateProfileString(const char *theSection, /* section name */
33+
const char *theKey, /* write key name */
34+
const char *theBuffer, /* input buffer */
35+
const char *theIniFileName); /* pathname of ini file
3636
* to write */
3737

3838
#ifdef __cplusplus

src/interfaces/odbc/qresult.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
#define FALSE (BOOL)0
3333
#endif
3434

35-
extern GLOBAL_VALUES globals;
36-
3735

3836
/*
3937
* Used for building a Manual Result only
@@ -119,7 +117,7 @@ QR_Constructor()
119117
rv->cursor = NULL;
120118
rv->aborted = FALSE;
121119

122-
rv->cache_size = globals.fetch_max;
120+
rv->cache_size = 0;
123121
rv->rowset_size = 1;
124122
}
125123

src/interfaces/odbc/statement.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ struct StatementClass_
232232
/* misc info */
233233
#define SC_set_pre_executable(a) (a->miscinfo |= 1L)
234234
#define SC_no_pre_executable(a) (a->miscinfo &= ~1L)
235-
#define SC_is_pre_executable(a) (a->miscinfo & 1L != 0)
235+
#define SC_is_pre_executable(a) ((a->miscinfo & 1L) != 0)
236236
#define SC_set_fetchcursor(a) (a->miscinfo |= 2L)
237237
#define SC_no_fetchcursor(a) (a->miscinfo &= ~2L)
238-
#define SC_is_fetchcursor(a) (a->miscinfo & 2L != 0)
238+
#define SC_is_fetchcursor(a) ((a->miscinfo & 2L) != 0)
239239

240240
/* Statement prototypes */
241241
StatementClass *SC_Constructor(void);

src/interfaces/odbc/win32.mak

+4-4
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ BSC32_FLAGS=/nologo /o"$(OUTDIR)\psqlodbc.bsc"
139139
BSC32_SBRS= \
140140

141141
LINK32=link.exe
142-
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 /nologo /dll /incremental:no /pdb:"$(OUTDIR)\psqlodbc.pdb" /machine:I386 /def:"psqlodbc.def" /out:"$(OUTDIR)\psqlodbc.dll" /implib:"$(OUTDIR)\psqlodbc.lib"
143-
DEF_FILE= "psqlodbc.def"
142+
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 /nologo /dll /incremental:no /pdb:"$(OUTDIR)\psqlodbc.pdb" /machine:I386 /def:"psqlodbc_win32.def" /out:"$(OUTDIR)\psqlodbc.dll" /implib:"$(OUTDIR)\psqlodbc.lib"
143+
DEF_FILE= "psqlodbc_win32.def"
144144
LINK32_OBJS= \
145145
"$(INTDIR)\bind.obj" \
146146
"$(INTDIR)\columninfo.obj" \
@@ -277,8 +277,8 @@ BSC32_FLAGS=/nologo /o"$(OUTDIR)\psqlodbc.bsc"
277277
BSC32_SBRS= \
278278

279279
LINK32=link.exe
280-
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 /nologo /dll /incremental:yes /pdb:"$(OUTDIR)\psqlodbc.pdb" /debug /machine:I386 /def:"psqlodbc.def" /out:"$(OUTDIR)\psqlodbc.dll" /implib:"$(OUTDIR)\psqlodbc.lib" /pdbtype:sept
281-
DEF_FILE= "psqlodbc.def"
280+
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 /nologo /dll /incremental:yes /pdb:"$(OUTDIR)\psqlodbc.pdb" /debug /machine:I386 /def:"psqlodbc_win32.def" /out:"$(OUTDIR)\psqlodbc.dll" /implib:"$(OUTDIR)\psqlodbc.lib" /pdbtype:sept
281+
DEF_FILE= "psqlodbc_win32.def"
282282
LINK32_OBJS= \
283283
"$(INTDIR)\bind.obj" \
284284
"$(INTDIR)\columninfo.obj" \

0 commit comments

Comments
 (0)