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

Commit fc3726b

Browse files
author
Hiroshi Inoue
committed
Improve the handling of ODBC escape(a request from Marcelo Aceto).
Change SQLGetFunctions() to reply not yet implemented ODBC 3.0 functions precisely.
1 parent 21f9a65 commit fc3726b

File tree

3 files changed

+46
-23
lines changed

3 files changed

+46
-23
lines changed

src/interfaces/odbc/convert.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,8 @@ copy_statement_with_parameters(StatementClass *stmt)
14021402
}
14031403
opos = end - old_statement; /* positioned at the last } */
14041404
new_statement = stmt->stmt_with_params;
1405+
if (isalnum(end[1]))
1406+
CVT_APPEND_CHAR(' ');
14051407
continue;
14061408
}
14071409
/* End of a procedure call */
@@ -2015,7 +2017,7 @@ int inner_convert_escape(const ConnectionClass *conn, const char *value,
20152017
char valnts[1024], params[1024];
20162018
char key[33], *end;
20172019
const char *valptr;
2018-
UInt4 vlen, prtlen, input_consumed, param_consumed;
2020+
UInt4 vlen, prtlen, input_consumed, param_consumed, extra_len;
20192021
Int4 param_pos[16][2];
20202022

20212023
valptr = value;
@@ -2042,6 +2044,20 @@ int inner_convert_escape(const ConnectionClass *conn, const char *value,
20422044
*input_resume = valptr + vlen; /* resume from the last } */
20432045
mylog("%s: key='%s', val='%s'\n", func, key, valnts);
20442046

2047+
extra_len = 0;
2048+
if (isalnum(result[-1])) /* Avoid the concatenation of the function name with the previous word. Aceto */
2049+
{
2050+
if (1 >= maxLen)
2051+
{
2052+
mylog("%s %d bytes buffer overflow\n", func, maxLen);
2053+
return CONVERT_ESCAPE_OVERFLOW;
2054+
}
2055+
*result = ' ';
2056+
result++;
2057+
*result = '\0';
2058+
maxLen--;
2059+
extra_len++;
2060+
}
20452061
if (strcmp(key, "d") == 0)
20462062
{
20472063
/* Literal; return the escape part adding type cast */
@@ -2185,7 +2201,7 @@ int inner_convert_escape(const ConnectionClass *conn, const char *value,
21852201
}
21862202

21872203
if (count)
2188-
*count = prtlen;
2204+
*count = prtlen + extra_len;
21892205
if (prtlen < 0 || prtlen >= maxLen) /* buffer overflow */
21902206
{
21912207
mylog("%s %d bytes buffer overflow\n", func, maxLen);

src/interfaces/odbc/info.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* API functions: SQLGetInfo, SQLGetTypeInfo, SQLGetFunctions,
1010
* SQLTables, SQLColumns, SQLStatistics, SQLSpecialColumns,
1111
* SQLPrimaryKeys, SQLForeignKeys,
12-
* SQLProcedureColumns(NI), SQLProcedures(NI),
12+
* SQLProcedureColumns(NI), SQLProcedures,
1313
* SQLTablePrivileges(NI), SQLColumnPrivileges(NI)
1414
*
1515
* Comments: See "notice.txt" for copyright and license information.
@@ -3783,6 +3783,8 @@ PGAPI_TablePrivileges(
37833783
extend_bindings(stmt, result_cols);
37843784

37853785
/* set the field names */
3786+
stmt->manual_result = TRUE;
3787+
stmt->result = QR_Constructor();
37863788
QR_set_num_fields(stmt->result, result_cols);
37873789
QR_set_field_info(stmt->result, 0, "TABLE_CAT", PG_TYPE_TEXT, MAX_INFO_STRING);
37883790
QR_set_field_info(stmt->result, 1, "TABLE_SCHEM", PG_TYPE_TEXT, MAX_INFO_STRING);

src/interfaces/odbc/odbcapi30.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,9 @@ SQLSetStmtAttr(HSTMT StatementHandle,
704704
RETCODE SQL_API
705705
PGAPI_GetFunctions30(HDBC hdbc, UWORD fFunction, UWORD FAR * pfExists)
706706
{
707+
ConnectionClass *conn = (ConnectionClass *) hdbc;
708+
ConnInfo *ci = &(conn->connInfo);
709+
707710
if (fFunction != SQL_API_ODBC3_ALL_FUNCTIONS)
708711
return SQL_ERROR;
709712
memset(pfExists, 0, sizeof(UWORD) * SQL_API_ODBC3_ALL_FUNCTIONS_SIZE);
@@ -761,7 +764,8 @@ PGAPI_GetFunctions30(HDBC hdbc, UWORD fFunction, UWORD FAR * pfExists)
761764
SQL_FUNC_ESET(pfExists, SQL_API_SQLSTATISTICS); /* 53 */
762765
SQL_FUNC_ESET(pfExists, SQL_API_SQLTABLES); /* 54 */
763766
SQL_FUNC_ESET(pfExists, SQL_API_SQLBROWSECONNECT); /* 55 */
764-
SQL_FUNC_ESET(pfExists, SQL_API_SQLCOLUMNPRIVILEGES); /* 56 */
767+
if (ci->drivers.lie)
768+
SQL_FUNC_ESET(pfExists, SQL_API_SQLCOLUMNPRIVILEGES); /* 56 not implmented yet */
765769
SQL_FUNC_ESET(pfExists, SQL_API_SQLDATASOURCES); /* 57 */
766770
SQL_FUNC_ESET(pfExists, SQL_API_SQLDESCRIBEPARAM); /* 58 */
767771
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLEXTENDEDFETCH); 59 deprecated */
@@ -776,41 +780,42 @@ PGAPI_GetFunctions30(HDBC hdbc, UWORD fFunction, UWORD FAR * pfExists)
776780
SQL_FUNC_ESET(pfExists, SQL_API_SQLNUMPARAMS); /* 63 */
777781
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLPARAMOPTIONS); 64 deprecated */
778782
SQL_FUNC_ESET(pfExists, SQL_API_SQLPRIMARYKEYS); /* 65 */
779-
SQL_FUNC_ESET(pfExists, SQL_API_SQLPROCEDURECOLUMNS); /* 66 */
783+
if (ci->drivers.lie)
784+
SQL_FUNC_ESET(pfExists, SQL_API_SQLPROCEDURECOLUMNS); /* 66 not implmented yet */
780785
SQL_FUNC_ESET(pfExists, SQL_API_SQLPROCEDURES); /* 67 */
781-
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETPOS); /* 68 */
786+
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETPOS); /* 68 */
782787
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETSCROLLOPTIONS); /* 69 deprecated */
783-
SQL_FUNC_ESET(pfExists, SQL_API_SQLTABLEPRIVILEGES); /* 70 */
788+
if (ci->drivers.lie)
789+
SQL_FUNC_ESET(pfExists, SQL_API_SQLTABLEPRIVILEGES); /* 70 not implemented yet */
784790
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLDRIVERS); */ /* 71 */
785791
SQL_FUNC_ESET(pfExists, SQL_API_SQLBINDPARAMETER); /* 72 */
786792

787793
SQL_FUNC_ESET(pfExists, SQL_API_SQLALLOCHANDLE); /* 1001 */
788794
SQL_FUNC_ESET(pfExists, SQL_API_SQLBINDPARAM); /* 1002 */
789795
SQL_FUNC_ESET(pfExists, SQL_API_SQLCLOSECURSOR); /* 1003 */
790-
SQL_FUNC_ESET(pfExists, SQL_API_SQLCOPYDESC); /* 1004 not implemented
791-
* yet */
796+
if (ci->drivers.lie)
797+
SQL_FUNC_ESET(pfExists, SQL_API_SQLCOPYDESC); /* 1004 not implemented yet */
792798
SQL_FUNC_ESET(pfExists, SQL_API_SQLENDTRAN); /* 1005 */
793799
SQL_FUNC_ESET(pfExists, SQL_API_SQLFREEHANDLE); /* 1006 */
794-
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETCONNECTATTR); /* 1007 */
795-
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDESCFIELD); /* 1008 not implemented
796-
* yet */
797-
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDESCREC); /* 1009 not implemented
798-
* yet */
799-
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDIAGFIELD); /* 1010 not implemented
800-
* yet */
800+
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETCONNECTATTR); /* 1007 */
801+
if (ci->drivers.lie)
802+
{
803+
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDESCFIELD); /* 1008 not implemented yet */
804+
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDESCREC); /* 1009 not implemented yet */
805+
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDIAGFIELD); /* 1010 not implemented yet */
806+
}
801807
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDIAGREC); /* 1011 */
802808
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETENVATTR); /* 1012 */
803809
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETSTMTATTR); /* 1014 */
804-
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETCONNECTATTR); /* 1016 */
805-
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETDESCFIELD); /* 1017 not implemeted
806-
* yet */
807-
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETDESCREC); /* 1018 not implemented
808-
* yet */
810+
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETCONNECTATTR); /* 1016 */
811+
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETDESCFIELD); /* 1017 */
812+
if (ci->drivers.lie)
813+
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETDESCREC); /* 1018 not implemented yet */
809814
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETENVATTR); /* 1019 */
810815
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETSTMTATTR); /* 1020 */
811816
SQL_FUNC_ESET(pfExists, SQL_API_SQLFETCHSCROLL); /* 1021 */
812-
SQL_FUNC_ESET(pfExists, SQL_API_SQLBULKOPERATIONS); /* 24 not implemented
813-
* yet */
817+
if (ci->drivers.lie)
818+
SQL_FUNC_ESET(pfExists, SQL_API_SQLBULKOPERATIONS); /* 24 not implemented yet */
814819

815820
return SQL_SUCCESS;
816821
}

0 commit comments

Comments
 (0)