From 8a86e36af23b77a889c420c7259c5f99a952a55a Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Thu, 30 Oct 2014 22:43:56 +0200 Subject: [PATCH] Fix max identifier length stuff. CC_get_max_idlen function didn't work correctly. It sent the "show identifier_length" query to the backend, but assumed that the value comes back in the command tag. It doesnt; the command tag is always "SHOW". We fell back to the compiled in NAMEDATALEN_V73 default. But that's off-by-one; the actual max identifier length is NAMEDATALEN - 1. --- connection.c | 2 +- info.c | 12 ++++++------ psqlodbc.h | 8 ++++++-- test/expected/catalogfunctions.out | 24 ++++++++++++------------ 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/connection.c b/connection.c index d2fb593..f623a5f 100644 --- a/connection.c +++ b/connection.c @@ -2242,7 +2242,7 @@ int CC_get_max_idlen(ConnectionClass *self) res = CC_send_query(self, "show max_identifier_length", NULL, ROLLBACK_ON_ERROR | IGNORE_ABORT_ON_CONN, NULL); if (QR_command_maybe_successful(res)) - len = self->max_identifier_length = atoi(res->command); + len = self->max_identifier_length = QR_get_value_backend_int(res, 0, 0, FALSE); QR_Destructor(res); } mylog("max_identifier_length=%d\n", len); diff --git a/info.c b/info.c index 8a7fd22..951ee49 100644 --- a/info.c +++ b/info.c @@ -335,7 +335,7 @@ mylog("CONVERT_FUNCTIONS=" FORMAT_ULEN "\n", value); len = 2; value = CC_get_max_idlen(conn); if (0 == value) - value = NAMEDATALEN_V73; + value = NAMEDATALEN_V73 - 1; break; case SQL_MAX_COLUMNS_IN_GROUP_BY: /* ODBC 2.0 */ @@ -383,7 +383,7 @@ mylog("CONVERT_FUNCTIONS=" FORMAT_ULEN "\n", value); value = MAX_SCHEMA_LEN; #endif /* MAX_SCHEMA_LEN */ if (0 == value) - value = NAMEDATALEN_V73; + value = NAMEDATALEN_V73 - 1; break; case SQL_MAX_PROCEDURE_NAME_LEN: /* ODBC 1.0 */ @@ -416,7 +416,7 @@ mylog("CONVERT_FUNCTIONS=" FORMAT_ULEN "\n", value); value = MAX_TABLE_LEN; #endif /* MAX_TABLE_LEN */ if (0 == value) - value = NAMEDATALEN_V73; + value = NAMEDATALEN_V73 - 1; break; case SQL_MAX_TABLES_IN_SELECT: /* ODBC 2.0 */ @@ -924,9 +924,9 @@ mylog("CONVERT_FUNCTIONS=" FORMAT_ULEN "\n", value); break; case SQL_MAX_IDENTIFIER_LEN: len = 2; - /* FIXME: This is the default, but the server might be compiled - * with a different NAMEDATALEN value */ - value = 64; + value = CC_get_max_idlen(conn); + if (0 == value) + value = NAMEDATALEN_V73 - 1; break; case SQL_MAX_ROW_SIZE_INCLUDES_LONG: len = 0; diff --git a/psqlodbc.h b/psqlodbc.h index 90b0ae5..2eaf375 100644 --- a/psqlodbc.h +++ b/psqlodbc.h @@ -73,11 +73,15 @@ void debug_memory_check(void); /* Must come before sql.h */ #define ODBCVER 0x0351 -#define NAMEDATALEN_V72 32 +/* + * Default NAMEDATALEN value in the server. The server can be compiled with + * a different value, but this will do. + */ #define NAMEDATALEN_V73 64 + #ifndef NAMESTORAGELEN #define NAMESTORAGELEN 64 -#endif /* NAMEDATALEN */ +#endif /* NAMESTORAGELEN */ #ifndef WIN32 diff --git a/test/expected/catalogfunctions.out b/test/expected/catalogfunctions.out index e51c5a9..c5c28f9 100644 --- a/test/expected/catalogfunctions.out +++ b/test/expected/catalogfunctions.out @@ -118,27 +118,27 @@ Result set: contrib_regression public testtab1 id 1 testtab1_pkey Check for SQLForeignKeys Result set metadata: -pktable_cat: VARCHAR(64) digits: 0, nullable -pktable_schem: VARCHAR(64) digits: 0, not nullable -pktable_name: VARCHAR(64) digits: 0, not nullable -pkcolumn_name: VARCHAR(64) digits: 0, not nullable -fktable_cat: VARCHAR(64) digits: 0, nullable -fktable_schem: VARCHAR(64) digits: 0, not nullable -fktable_name: VARCHAR(64) digits: 0, not nullable -fkcolumn_name: VARCHAR(64) digits: 0, not nullable +pktable_cat: VARCHAR(63) digits: 0, nullable +pktable_schem: VARCHAR(63) digits: 0, not nullable +pktable_name: VARCHAR(63) digits: 0, not nullable +pkcolumn_name: VARCHAR(63) digits: 0, not nullable +fktable_cat: VARCHAR(63) digits: 0, nullable +fktable_schem: VARCHAR(63) digits: 0, not nullable +fktable_name: VARCHAR(63) digits: 0, not nullable +fkcolumn_name: VARCHAR(63) digits: 0, not nullable key_seq: SMALLINT(5) digits: 0, nullable update_rule: SMALLINT(5) digits: 0, nullable delete_rule: SMALLINT(5) digits: 0, nullable -fk_name: VARCHAR(64) digits: 0, not nullable -pk_name: VARCHAR(64) digits: 0, not nullable +fk_name: VARCHAR(63) digits: 0, not nullable +pk_name: VARCHAR(63) digits: 0, not nullable deferrablity: SMALLINT(5) digits: 0, nullable Result set: contrib_regression public testtab1 id contrib_regression public testtab_fk id 1 3 3 testtab_fk_id_fkey testtab1_pkey 7 Check for SQLProcedures Result set metadata: procedure_cat: VARCHAR(255) digits: 0, nullable -procedure_schem: VARCHAR(64) digits: 0, not nullable -procedure_name: VARCHAR(64) digits: 0, not nullable +procedure_schem: VARCHAR(63) digits: 0, not nullable +procedure_name: VARCHAR(63) digits: 0, not nullable num_input_params: VARCHAR(255) digits: 0, nullable num_output_params: VARCHAR(255) digits: 0, nullable num_result_sets: VARCHAR(255) digits: 0, nullable -- 2.39.5