Merge commit 'origin/master'
[versaplex.git] / vxodbc / odbcapi.cc
blobc4b4b71c410402068d1b1151ba88bb0c9df7fdbe
1 /*
2 * Description: This module contains routines related to
3 * preparing and executing an SQL statement.
4 */
5 #include "psqlodbc.h"
6 #include <stdio.h>
7 #include <string.h>
9 #include "pgapifunc.h"
10 #include "environ.h"
11 #include "connection.h"
12 #include "statement.h"
13 #include "qresult.h"
15 RETCODE SQL_API
16 SQLBindCol(HSTMT StatementHandle,
17 SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType,
18 PTR TargetValue, SQLLEN BufferLength, SQLLEN * StrLen_or_Ind)
20 RETCODE ret;
21 StatementClass *stmt = (StatementClass *) StatementHandle;
22 mylog("Start\n");
24 ENTER_STMT_CS(stmt);
25 SC_clear_error(stmt);
26 StartRollbackState(stmt);
27 ret = PGAPI_BindCol(StatementHandle, ColumnNumber,
28 TargetType, TargetValue, BufferLength,
29 StrLen_or_Ind);
30 ret = DiscardStatementSvp(stmt, ret, FALSE);
31 LEAVE_STMT_CS(stmt);
32 return ret;
35 RETCODE SQL_API SQLCancel(HSTMT StatementHandle)
37 RETCODE ret;
38 StatementClass *stmt = (StatementClass *) StatementHandle;
39 mylog("Start\n");
41 /* Not that neither ENTER_STMT_CS nor StartRollbackState is called */
42 /* SC_clear_error((StatementClass *) StatementHandle); maybe this neither */
43 ret = PGAPI_Cancel(StatementHandle);
44 return DiscardStatementSvp(stmt, ret, FALSE);
47 RETCODE SQL_API
48 SQLColumns(HSTMT StatementHandle,
49 SQLCHAR * CatalogName, SQLSMALLINT NameLength1,
50 SQLCHAR * SchemaName, SQLSMALLINT NameLength2,
51 SQLCHAR * TableName, SQLSMALLINT NameLength3,
52 SQLCHAR * ColumnName, SQLSMALLINT NameLength4)
54 CSTR func = "SQLColumns";
55 RETCODE ret;
56 StatementClass *stmt = (StatementClass *) StatementHandle;
57 SQLCHAR *ctName = CatalogName, *scName = SchemaName,
58 *tbName = TableName, *clName = ColumnName;
59 UWORD flag = PODBC_SEARCH_PUBLIC_SCHEMA;
60 mylog("Start\n");
62 ENTER_STMT_CS(stmt);
63 SC_clear_error(stmt);
64 StartRollbackState(stmt);
65 if (stmt->options.metadata_id)
66 flag |= PODBC_NOT_SEARCH_PATTERN;
67 if (SC_opencheck(stmt, func))
68 ret = SQL_ERROR;
69 else
70 ret = PGAPI_Columns(StatementHandle, ctName, NameLength1,
71 scName, NameLength2, tbName, NameLength3,
72 clName, NameLength4, flag, 0, 0);
73 if (SQL_SUCCESS == ret
74 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt)))
76 BOOL ifallupper = TRUE, reexec = FALSE;
77 char *newCt = NULL, *newSc = NULL, *newTb = NULL, *newCl = NULL;
78 ConnectionClass *conn = SC_get_conn(stmt);
80 if (SC_is_lower_case(stmt, conn)) /* case-insensitive identifier */
81 ifallupper = FALSE;
82 if (newCt =
83 make_lstring_ifneeded(conn, CatalogName, NameLength1,
84 ifallupper), NULL != newCt)
86 ctName = (UCHAR *)newCt;
87 reexec = TRUE;
89 if (newSc =
90 make_lstring_ifneeded(conn, SchemaName, NameLength2,
91 ifallupper), NULL != newSc)
93 scName = (UCHAR *)newSc;
94 reexec = TRUE;
96 if (newTb =
97 make_lstring_ifneeded(conn, TableName, NameLength3,
98 ifallupper), NULL != newTb)
100 tbName = (UCHAR *)newTb;
101 reexec = TRUE;
103 if (newCl =
104 make_lstring_ifneeded(conn, ColumnName, NameLength4,
105 ifallupper), NULL != newCl)
107 clName = (UCHAR *)newCl;
108 reexec = TRUE;
110 if (reexec)
112 ret = PGAPI_Columns(StatementHandle, ctName, NameLength1,
113 scName, NameLength2, tbName,
114 NameLength3, clName, NameLength4, flag,
115 0, 0);
116 if (newCt)
117 free(newCt);
118 if (newSc)
119 free(newSc);
120 if (newTb)
121 free(newTb);
122 if (newCl)
123 free(newCl);
126 ret = DiscardStatementSvp(stmt, ret, FALSE);
127 LEAVE_STMT_CS(stmt);
128 return ret;
132 RETCODE SQL_API
133 SQLConnect(HDBC ConnectionHandle,
134 SQLCHAR * ServerName, SQLSMALLINT NameLength1,
135 SQLCHAR * UserName, SQLSMALLINT NameLength2,
136 SQLCHAR * Authentication, SQLSMALLINT NameLength3)
138 RETCODE ret;
139 ConnectionClass *conn = (ConnectionClass *) ConnectionHandle;
140 mylog("Start\n");
142 ENTER_CONN_CS(conn);
143 CC_clear_error(conn);
144 ret = PGAPI_Connect(ConnectionHandle, ServerName, NameLength1,
145 UserName, NameLength2, Authentication,
146 NameLength3);
147 LEAVE_CONN_CS(conn);
148 return ret;
151 RETCODE SQL_API
152 SQLDriverConnect(HDBC hdbc,
153 HWND hwnd,
154 SQLCHAR FAR * szConnStrIn,
155 SQLSMALLINT cbConnStrIn,
156 SQLCHAR FAR * szConnStrOut,
157 SQLSMALLINT cbConnStrOutMax,
158 SQLSMALLINT FAR * pcbConnStrOut,
159 SQLUSMALLINT fDriverCompletion)
161 RETCODE ret;
162 ConnectionClass *conn = (ConnectionClass *) hdbc;
163 mylog("Start\n");
165 ENTER_CONN_CS(conn);
166 CC_clear_error(conn);
167 ret = PGAPI_DriverConnect(hdbc, hwnd, szConnStrIn, cbConnStrIn,
168 szConnStrOut, cbConnStrOutMax,
169 pcbConnStrOut, fDriverCompletion);
170 LEAVE_CONN_CS(conn);
171 return ret;
174 RETCODE SQL_API
175 SQLBrowseConnect(HDBC hdbc,
176 SQLCHAR * szConnStrIn,
177 SQLSMALLINT cbConnStrIn,
178 SQLCHAR * szConnStrOut,
179 SQLSMALLINT cbConnStrOutMax,
180 SQLSMALLINT * pcbConnStrOut)
182 RETCODE ret;
183 ConnectionClass *conn = (ConnectionClass *) hdbc;
184 mylog("Start\n");
186 ENTER_CONN_CS(conn);
187 CC_clear_error(conn);
188 ret = PGAPI_BrowseConnect(hdbc, szConnStrIn, cbConnStrIn,
189 szConnStrOut, cbConnStrOutMax,
190 pcbConnStrOut);
191 LEAVE_CONN_CS(conn);
192 return ret;
195 RETCODE SQL_API
196 SQLDataSources(HENV EnvironmentHandle,
197 SQLUSMALLINT Direction, SQLCHAR * ServerName,
198 SQLSMALLINT BufferLength1, SQLSMALLINT * NameLength1,
199 SQLCHAR * Description, SQLSMALLINT BufferLength2,
200 SQLSMALLINT * NameLength2)
202 mylog("Start\n");
203 mylog("Not implemented!\n");
206 * return PGAPI_DataSources(EnvironmentHandle, Direction, ServerName,
207 * BufferLength1, NameLength1, Description, BufferLength2,
208 * NameLength2);
210 return SQL_ERROR;
213 RETCODE SQL_API
214 SQLDescribeCol(HSTMT StatementHandle,
215 SQLUSMALLINT ColumnNumber, SQLCHAR * ColumnName,
216 SQLSMALLINT BufferLength, SQLSMALLINT * NameLength,
217 SQLSMALLINT * DataType, SQLULEN * ColumnSize,
218 SQLSMALLINT * DecimalDigits, SQLSMALLINT * Nullable)
220 RETCODE ret;
221 StatementClass *stmt = (StatementClass *) StatementHandle;
222 mylog("Start\n");
224 ENTER_STMT_CS(stmt);
225 SC_clear_error(stmt);
226 StartRollbackState(stmt);
227 ret = PGAPI_DescribeCol(StatementHandle, ColumnNumber,
228 ColumnName, BufferLength, NameLength,
229 DataType, ColumnSize, DecimalDigits,
230 Nullable);
231 ret = DiscardStatementSvp(stmt, ret, FALSE);
232 LEAVE_STMT_CS(stmt);
233 return ret;
236 RETCODE SQL_API SQLDisconnect(HDBC ConnectionHandle)
238 RETCODE ret;
239 ConnectionClass *conn = (ConnectionClass *) ConnectionHandle;
240 mylog("Start\n");
242 #ifdef _HANDLE_ENLIST_IN_DTC_
243 CALL_DtcOnDisconnect(conn); /* must be called without holding the connection lock */
244 #endif /* _HANDLE_ENLIST_IN_DTC_ */
245 ENTER_CONN_CS(conn);
246 CC_clear_error(conn);
247 ret = PGAPI_Disconnect(ConnectionHandle);
248 LEAVE_CONN_CS(conn);
249 return ret;
253 RETCODE SQL_API
254 SQLExecDirect(HSTMT StatementHandle,
255 SQLCHAR * StatementText, SQLINTEGER TextLength)
257 CSTR func = "SQLExecDirect";
258 RETCODE ret;
259 StatementClass *stmt = (StatementClass *) StatementHandle;
260 UWORD flag = 0;
261 mylog("Start\n");
263 ENTER_STMT_CS(stmt);
264 SC_clear_error(stmt);
265 if (PG_VERSION_GE(SC_get_conn(stmt), 7.4))
266 flag |= PODBC_WITH_HOLD;
267 if (SC_opencheck(stmt, func))
268 ret = SQL_ERROR;
269 else
271 StartRollbackState(stmt);
272 ret =
273 PGAPI_ExecDirect_Vx(StatementHandle, StatementText, TextLength,
274 flag);
275 ret = DiscardStatementSvp(stmt, ret, FALSE);
277 LEAVE_STMT_CS(stmt);
278 return ret;
281 RETCODE SQL_API SQLExecute(HSTMT StatementHandle)
283 CSTR func = "SQLExecute";
284 RETCODE ret;
285 StatementClass *stmt = (StatementClass *) StatementHandle;
286 UWORD flag = 0;
287 mylog("Start\n");
289 ENTER_STMT_CS(stmt);
290 SC_clear_error(stmt);
291 if (PG_VERSION_GE(SC_get_conn(stmt), 7.4))
292 flag |= PODBC_WITH_HOLD;
293 if (SC_opencheck(stmt, func))
294 ret = SQL_ERROR;
295 else
297 StartRollbackState(stmt);
298 ret = PGAPI_Execute_Vx(StatementHandle, flag);
299 ret = DiscardStatementSvp(stmt, ret, FALSE);
301 LEAVE_STMT_CS(stmt);
302 return ret;
305 RETCODE SQL_API SQLFetch(HSTMT StatementHandle)
307 RETCODE ret;
308 StatementClass *stmt = (StatementClass *) StatementHandle;
309 mylog("Start\n");
311 ENTER_STMT_CS(stmt);
312 SC_clear_error(stmt);
313 StartRollbackState(stmt);
314 if (SC_get_conn(stmt)->driver_version >= 0x0300)
316 IRDFields *irdopts = SC_get_IRDF(stmt);
317 ARDFields *ardopts = SC_get_ARDF(stmt);
318 SQLUSMALLINT *rowStatusArray = irdopts->rowStatusArray;
319 SQLUINTEGER *pcRow = irdopts->rowsFetched;
321 ret = PGAPI_ExtendedFetch(StatementHandle, SQL_FETCH_NEXT, 0,
322 pcRow, rowStatusArray, 0,
323 ardopts->size_of_rowset);
324 stmt->transition_status = 6;
326 else
327 ret = PGAPI_Fetch(StatementHandle);
328 ret = DiscardStatementSvp(stmt, ret, FALSE);
329 LEAVE_STMT_CS(stmt);
330 return ret;
334 RETCODE SQL_API SQLFreeStmt(HSTMT StatementHandle, SQLUSMALLINT Option)
336 RETCODE ret;
337 mylog("Start\n");
339 ret = PGAPI_FreeStmt(StatementHandle, Option);
340 return ret;
344 RETCODE SQL_API
345 SQLGetCursorName(HSTMT StatementHandle,
346 SQLCHAR * CursorName, SQLSMALLINT BufferLength,
347 SQLSMALLINT * NameLength)
349 RETCODE ret;
350 StatementClass *stmt = (StatementClass *) StatementHandle;
351 mylog("Start\n");
353 ENTER_STMT_CS(stmt);
354 SC_clear_error(stmt);
355 StartRollbackState(stmt);
356 ret = PGAPI_GetCursorName(StatementHandle, CursorName, BufferLength,
357 NameLength);
358 ret = DiscardStatementSvp(stmt, ret, FALSE);
359 LEAVE_STMT_CS(stmt);
360 return ret;
363 RETCODE SQL_API
364 SQLGetData(HSTMT StatementHandle,
365 SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType,
366 PTR TargetValue, SQLLEN BufferLength, SQLLEN * StrLen_or_Ind)
368 RETCODE ret;
369 StatementClass *stmt = (StatementClass *) StatementHandle;
370 mylog("Start\n");
372 ENTER_STMT_CS(stmt);
373 SC_clear_error(stmt);
374 StartRollbackState(stmt);
375 ret = PGAPI_GetData(StatementHandle, ColumnNumber, TargetType,
376 TargetValue, BufferLength, StrLen_or_Ind);
377 ret = DiscardStatementSvp(stmt, ret, FALSE);
378 LEAVE_STMT_CS(stmt);
379 return ret;
382 RETCODE SQL_API
383 SQLGetFunctions(HDBC ConnectionHandle,
384 SQLUSMALLINT FunctionId, SQLUSMALLINT * Supported)
386 RETCODE ret;
387 ConnectionClass *conn = (ConnectionClass *) ConnectionHandle;
388 mylog("Start\n");
390 ENTER_CONN_CS(conn);
391 CC_clear_error(conn);
392 if (FunctionId == SQL_API_ODBC3_ALL_FUNCTIONS)
393 ret =
394 PGAPI_GetFunctions30(ConnectionHandle, FunctionId,
395 Supported);
396 else
398 ret =
399 PGAPI_GetFunctions(ConnectionHandle, FunctionId, Supported);
401 LEAVE_CONN_CS(conn);
402 return ret;
405 RETCODE SQL_API
406 SQLGetInfo(HDBC ConnectionHandle,
407 SQLUSMALLINT InfoType, PTR InfoValue,
408 SQLSMALLINT BufferLength, SQLSMALLINT * StringLength)
410 RETCODE ret;
411 ConnectionClass *conn = (ConnectionClass *) ConnectionHandle;
412 mylog("Start\n");
414 ENTER_CONN_CS(conn);
415 CC_clear_error(conn);
416 if ((ret = PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue,
417 BufferLength, StringLength)) == SQL_ERROR)
419 if (conn->driver_version >= 0x0300)
421 CC_clear_error(conn);
422 ret = PGAPI_GetInfo30(ConnectionHandle, InfoType, InfoValue,
423 BufferLength, StringLength);
424 goto cleanup;
427 if (SQL_ERROR == ret)
428 CC_log_error("SQLGetInfo(30)", "", conn);
429 cleanup:
430 LEAVE_CONN_CS(conn);
431 return ret;
435 RETCODE SQL_API
436 SQLGetTypeInfo(HSTMT StatementHandle, SQLSMALLINT DataType)
438 CSTR func = "SQLGetTypeInfo";
439 RETCODE ret;
440 StatementClass *stmt = (StatementClass *) StatementHandle;
441 mylog("Start\n");
443 ENTER_STMT_CS(stmt);
444 SC_clear_error(stmt);
445 if (SC_opencheck(stmt, func))
446 ret = SQL_ERROR;
447 else
449 StartRollbackState(stmt);
450 ret = PGAPI_GetTypeInfo(StatementHandle, DataType);
451 ret = DiscardStatementSvp(stmt, ret, FALSE);
453 LEAVE_STMT_CS(stmt);
454 return ret;
457 RETCODE SQL_API
458 SQLNumResultCols(HSTMT StatementHandle, SQLSMALLINT * ColumnCount)
460 RETCODE ret;
461 StatementClass *stmt = (StatementClass *) StatementHandle;
462 mylog("Start\n");
464 ENTER_STMT_CS(stmt);
465 SC_clear_error(stmt);
466 StartRollbackState(stmt);
467 ret = PGAPI_NumResultCols(StatementHandle, ColumnCount);
468 ret = DiscardStatementSvp(stmt, ret, FALSE);
469 LEAVE_STMT_CS(stmt);
470 return ret;
473 RETCODE SQL_API SQLParamData(HSTMT StatementHandle, PTR * Value)
475 RETCODE ret;
476 StatementClass *stmt = (StatementClass *) StatementHandle;
477 mylog("Start\n");
479 ENTER_STMT_CS(stmt);
480 SC_clear_error(stmt);
481 ret = PGAPI_ParamData(StatementHandle, Value);
482 ret = DiscardStatementSvp(stmt, ret, FALSE);
483 LEAVE_STMT_CS(stmt);
484 return ret;
487 RETCODE SQL_API
488 SQLPrepare(HSTMT StatementHandle,
489 SQLCHAR * StatementText, SQLINTEGER TextLength)
491 RETCODE ret;
492 StatementClass *stmt = (StatementClass *) StatementHandle;
493 mylog("Start\n");
495 ENTER_STMT_CS(stmt);
496 SC_clear_error(stmt);
497 StartRollbackState(stmt);
498 ret = PGAPI_Prepare(StatementHandle, StatementText, TextLength);
499 ret = DiscardStatementSvp(stmt, ret, FALSE);
500 LEAVE_STMT_CS(stmt);
501 return ret;
504 RETCODE SQL_API
505 SQLPutData(HSTMT StatementHandle, PTR Data, SQLLEN StrLen_or_Ind)
507 RETCODE ret;
508 StatementClass *stmt = (StatementClass *) StatementHandle;
509 mylog("Start\n");
511 ENTER_STMT_CS(stmt);
512 SC_clear_error(stmt);
513 ret = PGAPI_PutData(StatementHandle, Data, StrLen_or_Ind);
514 ret = DiscardStatementSvp(stmt, ret, TRUE);
515 LEAVE_STMT_CS(stmt);
516 return ret;
519 RETCODE SQL_API SQLRowCount(HSTMT StatementHandle, SQLLEN * RowCount)
521 RETCODE ret;
522 StatementClass *stmt = (StatementClass *) StatementHandle;
523 mylog("Start\n");
525 ENTER_STMT_CS(stmt);
526 SC_clear_error(stmt);
527 StartRollbackState(stmt);
528 ret = PGAPI_RowCount(StatementHandle, RowCount);
529 ret = DiscardStatementSvp(stmt, ret, FALSE);
530 LEAVE_STMT_CS(stmt);
531 return ret;
535 RETCODE SQL_API
536 SQLSetCursorName(HSTMT StatementHandle,
537 SQLCHAR * CursorName, SQLSMALLINT NameLength)
539 RETCODE ret;
540 StatementClass *stmt = (StatementClass *) StatementHandle;
541 mylog("Start\n");
543 ENTER_STMT_CS(stmt);
544 SC_clear_error(stmt);
545 StartRollbackState(stmt);
546 ret = PGAPI_SetCursorName(StatementHandle, CursorName, NameLength);
547 ret = DiscardStatementSvp(stmt, ret, FALSE);
548 LEAVE_STMT_CS(stmt);
549 return ret;
552 RETCODE SQL_API
553 SQLSetParam(HSTMT StatementHandle,
554 SQLUSMALLINT ParameterNumber, SQLSMALLINT ValueType,
555 SQLSMALLINT ParameterType, SQLULEN LengthPrecision,
556 SQLSMALLINT ParameterScale, PTR ParameterValue,
557 SQLLEN * StrLen_or_Ind)
559 mylog("Start\n");
560 SC_clear_error((StatementClass *) StatementHandle);
563 * return PGAPI_SetParam(StatementHandle, ParameterNumber, ValueType,
564 * ParameterType, LengthPrecision, ParameterScale, ParameterValue,
565 * StrLen_or_Ind);
567 return SQL_ERROR;
571 RETCODE SQL_API
572 SQLSpecialColumns(HSTMT StatementHandle,
573 SQLUSMALLINT IdentifierType, SQLCHAR * CatalogName,
574 SQLSMALLINT NameLength1, SQLCHAR * SchemaName,
575 SQLSMALLINT NameLength2, SQLCHAR * TableName,
576 SQLSMALLINT NameLength3, SQLUSMALLINT Scope,
577 SQLUSMALLINT Nullable)
579 CSTR func = "SQLSpecialColumns";
580 RETCODE ret;
581 StatementClass *stmt = (StatementClass *) StatementHandle;
582 SQLCHAR *ctName = CatalogName, *scName = SchemaName, *tbName =
583 TableName;
584 mylog("Start\n");
586 ENTER_STMT_CS(stmt);
587 SC_clear_error(stmt);
588 StartRollbackState(stmt);
589 if (SC_opencheck(stmt, func))
590 ret = SQL_ERROR;
591 else
592 ret =
593 PGAPI_SpecialColumns(StatementHandle, IdentifierType,
594 ctName, NameLength1, scName,
595 NameLength2, tbName, NameLength3,
596 Scope, Nullable);
597 if (SQL_SUCCESS == ret
598 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt)))
600 BOOL ifallupper = TRUE, reexec = FALSE;
601 char *newCt = NULL, *newSc = NULL, *newTb = NULL;
602 ConnectionClass *conn = SC_get_conn(stmt);
604 if (SC_is_lower_case(stmt, conn)) /* case-insensitive identifier */
605 ifallupper = FALSE;
606 if (newCt =
607 make_lstring_ifneeded(conn, CatalogName, NameLength1,
608 ifallupper), NULL != newCt)
610 ctName = (UCHAR *)newCt;
611 reexec = TRUE;
613 if (newSc =
614 make_lstring_ifneeded(conn, SchemaName, NameLength2,
615 ifallupper), NULL != newSc)
617 scName = (UCHAR *)newSc;
618 reexec = TRUE;
620 if (newTb =
621 make_lstring_ifneeded(conn, TableName, NameLength3,
622 ifallupper), NULL != newTb)
624 tbName = (UCHAR *)newTb;
625 reexec = TRUE;
627 if (reexec)
629 ret =
630 PGAPI_SpecialColumns(StatementHandle, IdentifierType,
631 ctName, NameLength1, scName,
632 NameLength2, tbName, NameLength3,
633 Scope, Nullable);
634 if (newCt)
635 free(newCt);
636 if (newSc)
637 free(newSc);
638 if (newTb)
639 free(newTb);
642 ret = DiscardStatementSvp(stmt, ret, FALSE);
643 LEAVE_STMT_CS(stmt);
644 return ret;
647 RETCODE SQL_API
648 SQLStatistics(HSTMT StatementHandle,
649 SQLCHAR * CatalogName, SQLSMALLINT NameLength1,
650 SQLCHAR * SchemaName, SQLSMALLINT NameLength2,
651 SQLCHAR * TableName, SQLSMALLINT NameLength3,
652 SQLUSMALLINT Unique, SQLUSMALLINT Reserved)
654 CSTR func = "SQLStatistics";
655 RETCODE ret;
656 StatementClass *stmt = (StatementClass *) StatementHandle;
657 SQLCHAR *ctName = CatalogName, *scName = SchemaName, *tbName =
658 TableName;
659 mylog("Start\n");
661 ENTER_STMT_CS(stmt);
662 SC_clear_error(stmt);
663 StartRollbackState(stmt);
664 if (SC_opencheck(stmt, func))
665 ret = SQL_ERROR;
666 else
667 ret = PGAPI_Statistics(StatementHandle, ctName, NameLength1,
668 scName, NameLength2, tbName, NameLength3,
669 Unique, Reserved);
670 if (SQL_SUCCESS == ret
671 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt)))
673 BOOL ifallupper = TRUE, reexec = FALSE;
674 char *newCt = NULL, *newSc = NULL, *newTb = NULL;
675 ConnectionClass *conn = SC_get_conn(stmt);
677 if (SC_is_lower_case(stmt, conn)) /* case-insensitive identifier */
678 ifallupper = FALSE;
679 if (newCt =
680 make_lstring_ifneeded(conn, CatalogName, NameLength1,
681 ifallupper), NULL != newCt)
683 ctName = (UCHAR *)newCt;
684 reexec = TRUE;
686 if (newSc =
687 make_lstring_ifneeded(conn, SchemaName, NameLength2,
688 ifallupper), NULL != newSc)
690 scName = (UCHAR *)newSc;
691 reexec = TRUE;
693 if (newTb =
694 make_lstring_ifneeded(conn, TableName, NameLength3,
695 ifallupper), NULL != newTb)
697 tbName = (UCHAR *)newTb;
698 reexec = TRUE;
700 if (reexec)
702 ret = PGAPI_Statistics(StatementHandle, ctName, NameLength1,
703 scName, NameLength2, tbName,
704 NameLength3, Unique, Reserved);
705 if (newCt)
706 free(newCt);
707 if (newSc)
708 free(newSc);
709 if (newTb)
710 free(newTb);
713 ret = DiscardStatementSvp(stmt, ret, FALSE);
714 LEAVE_STMT_CS(stmt);
715 return ret;
718 RETCODE SQL_API
719 SQLTables(HSTMT StatementHandle,
720 SQLCHAR * CatalogName, SQLSMALLINT NameLength1,
721 SQLCHAR * SchemaName, SQLSMALLINT NameLength2,
722 SQLCHAR * TableName, SQLSMALLINT NameLength3,
723 SQLCHAR * TableType, SQLSMALLINT NameLength4)
725 CSTR func = "SQLTables";
726 RETCODE ret;
727 StatementClass *stmt = (StatementClass *) StatementHandle;
728 SQLCHAR *ctName = CatalogName, *scName = SchemaName, *tbName =
729 TableName;
730 UWORD flag = 0;
731 mylog("Start\n");
733 ENTER_STMT_CS(stmt);
734 SC_clear_error(stmt);
735 StartRollbackState(stmt);
736 if (stmt->options.metadata_id)
737 flag |= PODBC_NOT_SEARCH_PATTERN;
738 if (SC_opencheck(stmt, func))
739 ret = SQL_ERROR;
740 else
741 ret = PGAPI_Tables(StatementHandle, ctName, NameLength1,
742 scName, NameLength2, tbName, NameLength3,
743 TableType, NameLength4, flag);
744 if (SQL_SUCCESS == ret
745 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt)))
747 BOOL ifallupper = TRUE, reexec = FALSE;
748 char *newCt = NULL, *newSc = NULL, *newTb = NULL;
749 ConnectionClass *conn = SC_get_conn(stmt);
751 if (SC_is_lower_case(stmt, conn)) /* case-insensitive identifier */
752 ifallupper = FALSE;
753 if (newCt =
754 make_lstring_ifneeded(conn, CatalogName, NameLength1,
755 ifallupper), NULL != newCt)
757 ctName = (UCHAR *)newCt;
758 reexec = TRUE;
760 if (newSc =
761 make_lstring_ifneeded(conn, SchemaName, NameLength2,
762 ifallupper), NULL != newSc)
764 scName = (UCHAR *)newSc;
765 reexec = TRUE;
767 if (newTb =
768 make_lstring_ifneeded(conn, TableName, NameLength3,
769 ifallupper), NULL != newTb)
771 tbName = (UCHAR *)newTb;
772 reexec = TRUE;
774 if (reexec)
776 ret = PGAPI_Tables(StatementHandle, ctName, NameLength1,
777 scName, NameLength2, tbName, NameLength3,
778 TableType, NameLength4, flag);
779 if (newCt)
780 free(newCt);
781 if (newSc)
782 free(newSc);
783 if (newTb)
784 free(newTb);
787 ret = DiscardStatementSvp(stmt, ret, FALSE);
788 LEAVE_STMT_CS(stmt);
789 return ret;
793 RETCODE SQL_API
794 SQLColumnPrivileges(HSTMT hstmt,
795 SQLCHAR * szCatalogName,
796 SQLSMALLINT cbCatalogName,
797 SQLCHAR * szSchemaName,
798 SQLSMALLINT cbSchemaName,
799 SQLCHAR * szTableName,
800 SQLSMALLINT cbTableName,
801 SQLCHAR * szColumnName, SQLSMALLINT cbColumnName)
803 CSTR func = "SQLColumnPrivileges";
804 RETCODE ret;
805 StatementClass *stmt = (StatementClass *) hstmt;
806 SQLCHAR *ctName = szCatalogName, *scName = szSchemaName,
807 *tbName = szTableName, *clName = szColumnName;
808 UWORD flag = 0;
809 mylog("Start\n");
811 ENTER_STMT_CS(stmt);
812 SC_clear_error(stmt);
813 StartRollbackState(stmt);
814 if (stmt->options.metadata_id)
815 flag |= PODBC_NOT_SEARCH_PATTERN;
816 if (SC_opencheck(stmt, func))
817 ret = SQL_ERROR;
818 else
819 ret = PGAPI_ColumnPrivileges(hstmt, ctName, cbCatalogName,
820 scName, cbSchemaName, tbName,
821 cbTableName, clName, cbColumnName,
822 flag);
823 if (SQL_SUCCESS == ret
824 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt)))
826 BOOL ifallupper = TRUE, reexec = FALSE;
827 char *newCt = NULL, *newSc = NULL, *newTb = NULL, *newCl = NULL;
828 ConnectionClass *conn = SC_get_conn(stmt);
830 if (SC_is_lower_case(stmt, conn)) /* case-insensitive identifier */
831 ifallupper = FALSE;
832 if (newCt =
833 make_lstring_ifneeded(conn, szCatalogName, cbCatalogName,
834 ifallupper), NULL != newCt)
836 ctName = (UCHAR *)newCt;
837 reexec = TRUE;
839 if (newSc =
840 make_lstring_ifneeded(conn, szSchemaName, cbSchemaName,
841 ifallupper), NULL != newSc)
843 scName = (UCHAR *)newSc;
844 reexec = TRUE;
846 if (newTb =
847 make_lstring_ifneeded(conn, szTableName, cbTableName,
848 ifallupper), NULL != newTb)
850 tbName = (UCHAR *)newTb;
851 reexec = TRUE;
853 if (newCl =
854 make_lstring_ifneeded(conn, szColumnName, cbColumnName,
855 ifallupper), NULL != newCl)
857 clName = (UCHAR *)newCl;
858 reexec = TRUE;
860 if (reexec)
862 ret = PGAPI_ColumnPrivileges(hstmt, ctName, cbCatalogName,
863 scName, cbSchemaName, tbName,
864 cbTableName, clName,
865 cbColumnName, flag);
866 if (newCt)
867 free(newCt);
868 if (newSc)
869 free(newSc);
870 if (newTb)
871 free(newTb);
872 if (newCl)
873 free(newCl);
876 ret = DiscardStatementSvp(stmt, ret, FALSE);
877 LEAVE_STMT_CS(stmt);
878 return ret;
881 RETCODE SQL_API
882 SQLDescribeParam(HSTMT hstmt,
883 SQLUSMALLINT ipar,
884 SQLSMALLINT * pfSqlType,
885 SQLULEN * pcbParamDef,
886 SQLSMALLINT * pibScale, SQLSMALLINT * pfNullable)
888 RETCODE ret;
889 StatementClass *stmt = (StatementClass *) hstmt;
890 mylog("Start\n");
892 ENTER_STMT_CS(stmt);
893 SC_clear_error(stmt);
894 StartRollbackState(stmt);
895 ret = PGAPI_DescribeParam(hstmt, ipar, pfSqlType, pcbParamDef,
896 pibScale, pfNullable);
897 ret = DiscardStatementSvp(stmt, ret, FALSE);
898 LEAVE_STMT_CS(stmt);
899 return ret;
902 RETCODE SQL_API
903 SQLExtendedFetch(HSTMT hstmt, SQLUSMALLINT fFetchType, SQLLEN irow,
904 #ifdef WITH_UNIXODBC
905 SQLROWSETSIZE * pcrow,
906 #else
907 SQLULEN * pcrow,
908 #endif /* WITH_UNIXODBC */
909 SQLUSMALLINT * rgfRowStatus)
911 RETCODE ret;
912 StatementClass *stmt = (StatementClass *) hstmt;
913 mylog("Start\n");
915 ENTER_STMT_CS(stmt);
916 SC_clear_error(stmt);
917 StartRollbackState(stmt);
918 #ifdef WITH_UNIXODBC
920 SQLULEN retrieved;
922 ret =
923 PGAPI_ExtendedFetch(hstmt, fFetchType, irow, &retrieved,
924 rgfRowStatus, 0,
925 SC_get_ARDF(stmt)->
926 size_of_rowset_odbc2);
927 if (pcrow)
928 *pcrow = retrieved;
930 #else
931 ret =
932 PGAPI_ExtendedFetch(hstmt, fFetchType, irow, pcrow,
933 rgfRowStatus, 0,
934 SC_get_ARDF(stmt)->size_of_rowset_odbc2);
935 #endif /* WITH_UNIXODBC */
936 stmt->transition_status = 7;
937 ret = DiscardStatementSvp(stmt, ret, FALSE);
938 LEAVE_STMT_CS(stmt);
939 return ret;
942 RETCODE SQL_API
943 SQLForeignKeys(HSTMT hstmt,
944 SQLCHAR * szPkCatalogName,
945 SQLSMALLINT cbPkCatalogName,
946 SQLCHAR * szPkSchemaName,
947 SQLSMALLINT cbPkSchemaName,
948 SQLCHAR * szPkTableName,
949 SQLSMALLINT cbPkTableName,
950 SQLCHAR * szFkCatalogName,
951 SQLSMALLINT cbFkCatalogName,
952 SQLCHAR * szFkSchemaName,
953 SQLSMALLINT cbFkSchemaName,
954 SQLCHAR * szFkTableName, SQLSMALLINT cbFkTableName)
956 CSTR func = "SQLForeignKeys";
957 RETCODE ret;
958 StatementClass *stmt = (StatementClass *) hstmt;
959 SQLCHAR *pkctName = szPkCatalogName, *pkscName = szPkSchemaName,
960 *pktbName = szPkTableName, *fkctName = szFkCatalogName,
961 *fkscName = szFkSchemaName, *fktbName = szFkTableName;
962 mylog("Start\n");
964 ENTER_STMT_CS(stmt);
965 SC_clear_error(stmt);
966 StartRollbackState(stmt);
967 if (SC_opencheck(stmt, func))
968 ret = SQL_ERROR;
969 else
970 ret = PGAPI_ForeignKeys(hstmt, pkctName, cbPkCatalogName,
971 pkscName, cbPkSchemaName, pktbName,
972 cbPkTableName, fkctName,
973 cbFkCatalogName, fkscName,
974 cbFkSchemaName, fktbName,
975 cbFkTableName);
976 if (SQL_SUCCESS == ret
977 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt)))
979 BOOL ifallupper = TRUE, reexec = FALSE;
980 char *newPkct = NULL, *newPksc = NULL, *newPktb = NULL,
981 *newFkct = NULL, *newFksc = NULL, *newFktb = NULL;
982 ConnectionClass *conn = SC_get_conn(stmt);
984 if (SC_is_lower_case(stmt, conn)) /* case-insensitive identifier */
985 ifallupper = FALSE;
986 if (newPkct =
987 make_lstring_ifneeded(conn, szPkCatalogName,
988 cbPkCatalogName, ifallupper),
989 NULL != newPkct)
991 pkctName = (UCHAR *)newPkct;
992 reexec = TRUE;
994 if (newPksc =
995 make_lstring_ifneeded(conn, szPkSchemaName, cbPkSchemaName,
996 ifallupper), NULL != newPksc)
998 pkscName = (UCHAR *)newPksc;
999 reexec = TRUE;
1001 if (newPktb =
1002 make_lstring_ifneeded(conn, szPkTableName, cbPkTableName,
1003 ifallupper), NULL != newPktb)
1005 pktbName = (UCHAR *)newPktb;
1006 reexec = TRUE;
1008 if (newFkct =
1009 make_lstring_ifneeded(conn, szFkCatalogName,
1010 cbFkCatalogName, ifallupper),
1011 NULL != newFkct)
1013 fkctName = (UCHAR *)newFkct;
1014 reexec = TRUE;
1016 if (newFksc =
1017 make_lstring_ifneeded(conn, szFkSchemaName, cbFkSchemaName,
1018 ifallupper), NULL != newFksc)
1020 fkscName = (UCHAR *)newFksc;
1021 reexec = TRUE;
1023 if (newFktb =
1024 make_lstring_ifneeded(conn, szFkTableName, cbFkTableName,
1025 ifallupper), NULL != newFktb)
1027 fktbName = (UCHAR *)newFktb;
1028 reexec = TRUE;
1030 if (reexec)
1032 ret = PGAPI_ForeignKeys(hstmt, pkctName, cbPkCatalogName,
1033 pkscName, cbPkSchemaName, pktbName,
1034 cbPkTableName, fkctName,
1035 cbFkCatalogName, fkscName,
1036 cbFkSchemaName, fktbName,
1037 cbFkTableName);
1038 if (newPkct)
1039 free(newPkct);
1040 if (newPksc)
1041 free(newPksc);
1042 if (newPktb)
1043 free(newPktb);
1044 if (newFkct)
1045 free(newFkct);
1046 if (newFksc)
1047 free(newFksc);
1048 if (newFktb)
1049 free(newFktb);
1052 ret = DiscardStatementSvp(stmt, ret, FALSE);
1053 LEAVE_STMT_CS(stmt);
1054 return ret;
1057 RETCODE SQL_API SQLMoreResults(HSTMT hstmt)
1059 RETCODE ret;
1060 StatementClass *stmt = (StatementClass *) hstmt;
1061 mylog("Start\n");
1063 ENTER_STMT_CS(stmt);
1064 SC_clear_error(stmt);
1065 StartRollbackState(stmt);
1066 ret = PGAPI_MoreResults(hstmt);
1067 ret = DiscardStatementSvp(stmt, ret, FALSE);
1068 LEAVE_STMT_CS(stmt);
1069 return ret;
1072 RETCODE SQL_API
1073 SQLNativeSql(HDBC hdbc,
1074 SQLCHAR * szSqlStrIn,
1075 SQLINTEGER cbSqlStrIn,
1076 SQLCHAR * szSqlStr,
1077 SQLINTEGER cbSqlStrMax, SQLINTEGER * pcbSqlStr)
1079 RETCODE ret;
1080 ConnectionClass *conn = (ConnectionClass *) hdbc;
1081 mylog("Start\n");
1083 ENTER_CONN_CS(conn);
1084 CC_clear_error(conn);
1085 ret = PGAPI_NativeSql(hdbc, szSqlStrIn, cbSqlStrIn, szSqlStr,
1086 cbSqlStrMax, pcbSqlStr);
1087 LEAVE_CONN_CS(conn);
1088 return ret;
1091 RETCODE SQL_API SQLNumParams(HSTMT hstmt, SQLSMALLINT * pcpar)
1093 RETCODE ret;
1094 StatementClass *stmt = (StatementClass *) hstmt;
1095 mylog("Start\n");
1097 ENTER_STMT_CS(stmt);
1098 SC_clear_error(stmt);
1099 StartRollbackState(stmt);
1100 ret = PGAPI_NumParams(hstmt, pcpar);
1101 ret = DiscardStatementSvp(stmt, ret, FALSE);
1102 LEAVE_STMT_CS(stmt);
1103 return ret;
1107 RETCODE SQL_API
1108 SQLPrimaryKeys(HSTMT hstmt,
1109 SQLCHAR * szCatalogName,
1110 SQLSMALLINT cbCatalogName,
1111 SQLCHAR * szSchemaName,
1112 SQLSMALLINT cbSchemaName,
1113 SQLCHAR * szTableName, SQLSMALLINT cbTableName)
1115 CSTR func = "SQLPrimaryKeys";
1116 RETCODE ret;
1117 StatementClass *stmt = (StatementClass *) hstmt;
1118 SQLCHAR *ctName = szCatalogName, *scName = szSchemaName,
1119 *tbName = szTableName;
1120 mylog("Start\n");
1122 ENTER_STMT_CS(stmt);
1123 SC_clear_error(stmt);
1124 StartRollbackState(stmt);
1125 if (SC_opencheck(stmt, func))
1126 ret = SQL_ERROR;
1127 else
1128 ret = PGAPI_PrimaryKeys(hstmt, ctName, cbCatalogName,
1129 scName, cbSchemaName, tbName,
1130 cbTableName);
1131 if (SQL_SUCCESS == ret
1132 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt)))
1134 BOOL ifallupper = TRUE, reexec = FALSE;
1135 char *newCt = NULL, *newSc = NULL, *newTb = NULL;
1136 ConnectionClass *conn = SC_get_conn(stmt);
1138 if (SC_is_lower_case(stmt, conn)) /* case-insensitive identifier */
1139 ifallupper = FALSE;
1140 if (newCt =
1141 make_lstring_ifneeded(conn, szCatalogName, cbCatalogName,
1142 ifallupper), NULL != newCt)
1144 ctName = (UCHAR *)newCt;
1145 reexec = TRUE;
1147 if (newSc =
1148 make_lstring_ifneeded(conn, szSchemaName, cbSchemaName,
1149 ifallupper), NULL != newSc)
1151 scName = (UCHAR *)newSc;
1152 reexec = TRUE;
1154 if (newTb =
1155 make_lstring_ifneeded(conn, szTableName, cbTableName,
1156 ifallupper), NULL != newTb)
1158 tbName = (UCHAR *)newTb;
1159 reexec = TRUE;
1161 if (reexec)
1163 ret = PGAPI_PrimaryKeys(hstmt, ctName, cbCatalogName,
1164 scName, cbSchemaName, tbName,
1165 cbTableName);
1166 if (newCt)
1167 free(newCt);
1168 if (newSc)
1169 free(newSc);
1170 if (newTb)
1171 free(newTb);
1174 ret = DiscardStatementSvp(stmt, ret, FALSE);
1175 LEAVE_STMT_CS(stmt);
1176 return ret;
1179 RETCODE SQL_API
1180 SQLProcedureColumns(HSTMT hstmt,
1181 SQLCHAR * szCatalogName,
1182 SQLSMALLINT cbCatalogName,
1183 SQLCHAR * szSchemaName,
1184 SQLSMALLINT cbSchemaName,
1185 SQLCHAR * szProcName,
1186 SQLSMALLINT cbProcName,
1187 SQLCHAR * szColumnName, SQLSMALLINT cbColumnName)
1189 CSTR func = "SQLProcedureColumns";
1190 RETCODE ret;
1191 StatementClass *stmt = (StatementClass *) hstmt;
1192 SQLCHAR *ctName = szCatalogName, *scName = szSchemaName,
1193 *prName = szProcName, *clName = szColumnName;
1194 UWORD flag = 0;
1195 mylog("Start\n");
1197 ENTER_STMT_CS(stmt);
1198 SC_clear_error(stmt);
1199 StartRollbackState(stmt);
1200 if (stmt->options.metadata_id)
1201 flag |= PODBC_NOT_SEARCH_PATTERN;
1202 if (SC_opencheck(stmt, func))
1203 ret = SQL_ERROR;
1204 else
1205 ret = PGAPI_ProcedureColumns(hstmt, ctName, cbCatalogName,
1206 scName, cbSchemaName, prName,
1207 cbProcName, clName, cbColumnName,
1208 flag);
1209 if (SQL_SUCCESS == ret
1210 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt)))
1212 BOOL ifallupper = TRUE, reexec = FALSE;
1213 char *newCt = NULL, *newSc = NULL, *newPr = NULL, *newCl = NULL;
1214 ConnectionClass *conn = SC_get_conn(stmt);
1216 if (SC_is_lower_case(stmt, conn)) /* case-insensitive identifier */
1217 ifallupper = FALSE;
1218 if (newCt =
1219 make_lstring_ifneeded(conn, szCatalogName, cbCatalogName,
1220 ifallupper), NULL != newCt)
1222 ctName = (UCHAR *)newCt;
1223 reexec = TRUE;
1225 if (newSc =
1226 make_lstring_ifneeded(conn, szSchemaName, cbSchemaName,
1227 ifallupper), NULL != newSc)
1229 scName = (UCHAR *)newSc;
1230 reexec = TRUE;
1232 if (newPr =
1233 make_lstring_ifneeded(conn, szProcName, cbProcName,
1234 ifallupper), NULL != newPr)
1236 prName = (UCHAR *)newPr;
1237 reexec = TRUE;
1239 if (newCl =
1240 make_lstring_ifneeded(conn, szColumnName, cbColumnName,
1241 ifallupper), NULL != newCl)
1243 clName = (UCHAR *)newCl;
1244 reexec = TRUE;
1246 if (reexec)
1248 ret = PGAPI_ProcedureColumns(hstmt, ctName, cbCatalogName,
1249 scName, cbSchemaName, prName,
1250 cbProcName, clName,
1251 cbColumnName, flag);
1252 if (newCt)
1253 free(newCt);
1254 if (newSc)
1255 free(newSc);
1256 if (newPr)
1257 free(newPr);
1258 if (newCl)
1259 free(newCl);
1262 ret = DiscardStatementSvp(stmt, ret, FALSE);
1263 LEAVE_STMT_CS(stmt);
1264 return ret;
1267 RETCODE SQL_API
1268 SQLProcedures(HSTMT hstmt,
1269 SQLCHAR * szCatalogName,
1270 SQLSMALLINT cbCatalogName,
1271 SQLCHAR * szSchemaName,
1272 SQLSMALLINT cbSchemaName,
1273 SQLCHAR * szProcName, SQLSMALLINT cbProcName)
1275 CSTR func = "SQLProcedures";
1276 RETCODE ret;
1277 StatementClass *stmt = (StatementClass *) hstmt;
1278 SQLCHAR *ctName = szCatalogName, *scName = szSchemaName,
1279 *prName = szProcName;
1280 UWORD flag = 0;
1281 mylog("Start\n");
1283 ENTER_STMT_CS(stmt);
1284 SC_clear_error(stmt);
1285 StartRollbackState(stmt);
1286 if (stmt->options.metadata_id)
1287 flag |= PODBC_NOT_SEARCH_PATTERN;
1288 if (SC_opencheck(stmt, func))
1289 ret = SQL_ERROR;
1290 else
1291 ret = PGAPI_Procedures(hstmt, ctName, cbCatalogName,
1292 scName, cbSchemaName, prName,
1293 cbProcName, flag);
1294 if (SQL_SUCCESS == ret
1295 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt)))
1297 BOOL ifallupper = TRUE, reexec = FALSE;
1298 char *newCt = NULL, *newSc = NULL, *newPr = NULL;
1299 ConnectionClass *conn = SC_get_conn(stmt);
1301 if (SC_is_lower_case(stmt, conn)) /* case-insensitive identifier */
1302 ifallupper = FALSE;
1303 if (newCt =
1304 make_lstring_ifneeded(conn, szCatalogName, cbCatalogName,
1305 ifallupper), NULL != newCt)
1307 ctName = (UCHAR *)newCt;
1308 reexec = TRUE;
1310 if (newSc =
1311 make_lstring_ifneeded(conn, szSchemaName, cbSchemaName,
1312 ifallupper), NULL != newSc)
1314 scName = (UCHAR *)newSc;
1315 reexec = TRUE;
1317 if (newPr =
1318 make_lstring_ifneeded(conn, szProcName, cbProcName,
1319 ifallupper), NULL != newPr)
1321 prName = (UCHAR *)newPr;
1322 reexec = TRUE;
1324 if (reexec)
1326 ret = PGAPI_Procedures(hstmt, ctName, cbCatalogName,
1327 scName, cbSchemaName, prName,
1328 cbProcName, flag);
1329 if (newCt)
1330 free(newCt);
1331 if (newSc)
1332 free(newSc);
1333 if (newPr)
1334 free(newPr);
1337 ret = DiscardStatementSvp(stmt, ret, FALSE);
1338 LEAVE_STMT_CS(stmt);
1339 return ret;
1342 RETCODE SQL_API
1343 SQLSetPos(HSTMT hstmt,
1344 SQLSETPOSIROW irow, SQLUSMALLINT fOption, SQLUSMALLINT fLock)
1346 RETCODE ret;
1347 StatementClass *stmt = (StatementClass *) hstmt;
1348 mylog("Start\n");
1350 ENTER_STMT_CS(stmt);
1351 SC_clear_error(stmt);
1352 StartRollbackState(stmt);
1353 ret = PGAPI_SetPos(hstmt, irow, fOption, fLock);
1354 ret = DiscardStatementSvp(stmt, ret, FALSE);
1355 LEAVE_STMT_CS(stmt);
1356 return ret;
1359 RETCODE SQL_API
1360 SQLTablePrivileges(HSTMT hstmt,
1361 SQLCHAR * szCatalogName,
1362 SQLSMALLINT cbCatalogName,
1363 SQLCHAR * szSchemaName,
1364 SQLSMALLINT cbSchemaName,
1365 SQLCHAR * szTableName, SQLSMALLINT cbTableName)
1367 CSTR func = "SQLTablePrivileges";
1368 RETCODE ret;
1369 StatementClass *stmt = (StatementClass *) hstmt;
1370 SQLCHAR *ctName = szCatalogName, *scName = szSchemaName,
1371 *tbName = szTableName;
1372 UWORD flag = 0;
1373 mylog("Start\n");
1375 ENTER_STMT_CS(stmt);
1376 SC_clear_error(stmt);
1377 StartRollbackState(stmt);
1378 if (stmt->options.metadata_id)
1379 flag |= PODBC_NOT_SEARCH_PATTERN;
1380 if (SC_opencheck(stmt, func))
1381 ret = SQL_ERROR;
1382 else
1383 ret = PGAPI_TablePrivileges(hstmt, ctName, cbCatalogName,
1384 scName, cbSchemaName, tbName,
1385 cbTableName, flag);
1386 if (SQL_SUCCESS == ret
1387 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt)))
1389 BOOL ifallupper = TRUE, reexec = FALSE;
1390 char *newCt = NULL, *newSc = NULL, *newTb = NULL;
1391 ConnectionClass *conn = SC_get_conn(stmt);
1393 if (SC_is_lower_case(stmt, conn)) /* case-insensitive identifier */
1394 ifallupper = FALSE;
1395 if (newCt =
1396 make_lstring_ifneeded(conn, szCatalogName, cbCatalogName,
1397 ifallupper), NULL != newCt)
1399 ctName = (UCHAR *)newCt;
1400 reexec = TRUE;
1402 if (newSc =
1403 make_lstring_ifneeded(conn, szSchemaName, cbSchemaName,
1404 ifallupper), NULL != newSc)
1406 scName = (UCHAR *)newSc;
1407 reexec = TRUE;
1409 if (newTb =
1410 make_lstring_ifneeded(conn, szTableName, cbTableName,
1411 ifallupper), NULL != newTb)
1413 tbName = (UCHAR *)newTb;
1414 reexec = TRUE;
1416 if (reexec)
1418 ret = PGAPI_TablePrivileges(hstmt, ctName, cbCatalogName,
1419 scName, cbSchemaName, tbName,
1420 cbTableName, 0);
1421 if (newCt)
1422 free(newCt);
1423 if (newSc)
1424 free(newSc);
1425 if (newTb)
1426 free(newTb);
1429 ret = DiscardStatementSvp(stmt, ret, FALSE);
1430 LEAVE_STMT_CS(stmt);
1431 return ret;
1434 RETCODE SQL_API
1435 SQLBindParameter(HSTMT hstmt,
1436 SQLUSMALLINT ipar,
1437 SQLSMALLINT fParamType,
1438 SQLSMALLINT fCType,
1439 SQLSMALLINT fSqlType,
1440 SQLULEN cbColDef,
1441 SQLSMALLINT ibScale,
1442 PTR rgbValue, SQLLEN cbValueMax, SQLLEN * pcbValue)
1444 RETCODE ret;
1445 StatementClass *stmt = (StatementClass *) hstmt;
1446 mylog("Start\n");
1448 ENTER_STMT_CS(stmt);
1449 SC_clear_error(stmt);
1450 StartRollbackState(stmt);
1451 ret = PGAPI_BindParameter(hstmt, ipar, fParamType, fCType,
1452 fSqlType, cbColDef, ibScale, rgbValue,
1453 cbValueMax, pcbValue);
1454 ret = DiscardStatementSvp(stmt, ret, FALSE);
1455 LEAVE_STMT_CS(stmt);
1456 return ret;