From 11873ade60248604e5865b23118dfbdba31143e5 Mon Sep 17 00:00:00 2001 From: Dave Cramer Date: Thu, 23 Jan 2025 11:10:35 -0500 Subject: [PATCH 1/4] test with just unique keys --- test/sampletables.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/sampletables.sql b/test/sampletables.sql index 9eddeffc..94ae96b8 100644 --- a/test/sampletables.sql +++ b/test/sampletables.sql @@ -32,7 +32,8 @@ INSERT INTO booltab VALUES (3, 'true', true); INSERT INTO booltab VALUES (4, 'false', false); INSERT INTO booltab VALUES (5, 'not', false); -CREATE TABLE test_special( id integer primary key, ival integer); +CREATE TABLE test_special( id integer, ival integer); +CREATE UNIQUE index test_special_id on public.test_special(id); CREATE UNIQUE index test_special_ui on public.test_special(ival); -- View From 541a2fbbc338d94310a72235c708da27dfb83469 Mon Sep 17 00:00:00 2001 From: Dave Cramer Date: Tue, 11 Mar 2025 16:15:41 -0400 Subject: [PATCH 2/4] Send query directly and set result for best rowid --- info.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/info.c b/info.c index cbb67173..23d809c7 100644 --- a/info.c +++ b/info.c @@ -3112,7 +3112,7 @@ PGAPI_SpecialColumns(HSTMT hstmt, set_tuplefield_int4(&tuple[SPECOLS_BUFFER_LENGTH], PGTYPE_ATTR_BUFFER_LENGTH(conn, the_type, atttypmod)); set_tuplefield_int2(&tuple[SPECOLS_DECIMAL_DIGITS], PGTYPE_ATTR_DECIMAL_DIGITS(conn, the_type, atttypmod)); set_tuplefield_int2(&tuple[SPECOLS_PSEUDO_COLUMN], SQL_PC_NOT_PSEUDO); -MYLOG(DETAIL_LOG_LEVEL, "Add ctid\n"); + MYLOG(DETAIL_LOG_LEVEL, "Add ctid\n"); } } else @@ -3181,21 +3181,15 @@ WHERE a.attnum > 0 and c.relname like 'testuktab'; if (szTableQualifier != NULL) - appendPQExpBuffer(&columns_query, " and c.relnamespace = %s" , szSchemaName); + appendPQExpBuffer(&columns_query, " and c.relnamespace = %s" , szSchemaName); - result = PGAPI_ExecDirect(stmt, (SQLCHAR *) columns_query.data, SQL_NTS, PODBC_RDONLY); - if (!SQL_SUCCEEDED(result)) + if (res = CC_send_query(conn, columns_query.data, NULL, READ_ONLY_QUERY, stmt), !QR_command_maybe_successful(res)) { - /* - * "Couldn't execute index query (w/SQLExecDirect) in - * SpecialColumns"; - */ - SC_full_error_copy(stmt, stmt, FALSE); + SC_set_error(stmt, STMT_EXEC_ERROR, "PGAPI_Special query error", func); goto cleanup; } - res = SC_get_Result(stmt); + SC_set_Result(stmt, res); } - } else if (fColType == SQL_ROWVER) { From 1a1eec0dbbaf427a12863f01cc993ce51ff6cc68 Mon Sep 17 00:00:00 2001 From: Dave Cramer Date: Wed, 12 Mar 2025 09:40:56 -0400 Subject: [PATCH 3/4] revert sql file and fix expected file for catalogfunctions --- test/expected/catalogfunctions.out | 18 +++++++++--------- test/sampletables.sql | 3 +-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/test/expected/catalogfunctions.out b/test/expected/catalogfunctions.out index a69686b0..71ede25a 100644 --- a/test/expected/catalogfunctions.out +++ b/test/expected/catalogfunctions.out @@ -107,7 +107,7 @@ contrib_regression public testtab1 id UPDATE YES contrib_regression public testtab1 id SELECT YES contrib_regression public testtab1 id REFERENCES YES contrib_regression public testtab1 id INSERT YES -Check for SQLSpecialColumns +Check for SQLSpecialColumns ROWVER Result set metadata: SCOPE: SMALLINT(5) digits: 0, nullable COLUMN_NAME: VARCHAR(128) digits: 0, nullable @@ -119,16 +119,16 @@ DECIMAL_DIGITS: SMALLINT(5) digits: 0, nullable PSEUDO_COLUMN: SMALLINT(5) digits: 0, nullable Result set: NULL xmin 4 xid 10 4 0 2 -Check for SQLSpecialColumns +Check for SQLSpecialColumns ROWID Result set metadata: SCOPE: LONGVARCHAR(8190) digits: 0, nullable -SCHEMA_NAME: VARCHAR(63) digits: 0, nullable -TABLE_NAME: VARCHAR(63) digits: 0, nullable -COLUMN_NAME: VARCHAR(63) digits: 0, nullable -DATA_TYPE: VARCHAR(63) digits: 0, nullable -TYPE_NAME: VARCHAR(63) digits: 0, nullable -COLUMN_SIZE: SMALLINT(5) digits: 0, nullable -BUFFER_LENGTH: SMALLINT(5) digits: 0, nullable +SCHEMA_NAME: VARCHAR(63) digits: 0, not nullable +TABLE_NAME: VARCHAR(63) digits: 0, not nullable +COLUMN_NAME: VARCHAR(63) digits: 0, not nullable +DATA_TYPE: VARCHAR(63) digits: 0, not nullable +TYPE_NAME: VARCHAR(63) digits: 0, not nullable +COLUMN_SIZE: SMALLINT(5) digits: 0, not nullable +BUFFER_LENGTH: SMALLINT(5) digits: 0, not nullable DECIMAL_DIGITS: INTEGER(10) digits: 0, nullable PSEUDO_COLUMN: INTEGER(10) digits: 0, nullable Result set: diff --git a/test/sampletables.sql b/test/sampletables.sql index 94ae96b8..9eddeffc 100644 --- a/test/sampletables.sql +++ b/test/sampletables.sql @@ -32,8 +32,7 @@ INSERT INTO booltab VALUES (3, 'true', true); INSERT INTO booltab VALUES (4, 'false', false); INSERT INTO booltab VALUES (5, 'not', false); -CREATE TABLE test_special( id integer, ival integer); -CREATE UNIQUE index test_special_id on public.test_special(id); +CREATE TABLE test_special( id integer primary key, ival integer); CREATE UNIQUE index test_special_ui on public.test_special(ival); -- View From 65e9911b02e17a39dc23d464b206c42882df19ef Mon Sep 17 00:00:00 2001 From: Dave Cramer Date: Wed, 12 Mar 2025 09:51:33 -0400 Subject: [PATCH 4/4] comments --- info.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/info.c b/info.c index 23d809c7..1fc3f122 100644 --- a/info.c +++ b/info.c @@ -2993,6 +2993,7 @@ PGAPI_SpecialColumns(HSTMT hstmt, appendPQExpBufferStr(&columns_query, ", c.relhasoids"); else appendPQExpBufferStr(&columns_query, ", 0 as relhasoids"); + appendPQExpBufferStr(&columns_query, " from pg_catalog.pg_namespace u," " pg_catalog.pg_class c where " "u.oid = c.relnamespace"); @@ -3042,6 +3043,7 @@ PGAPI_SpecialColumns(HSTMT hstmt, goto cleanup; } + // check to see if the relation has rules result = PGAPI_BindCol(col_stmt, 1, internal_asis_type, relhasrules, sizeof(relhasrules), NULL); if (!SQL_SUCCEEDED(result)) @@ -3049,18 +3051,24 @@ PGAPI_SpecialColumns(HSTMT hstmt, goto cleanup; } + // bind to relkind to check if a view or not result = PGAPI_BindCol(col_stmt, 2, internal_asis_type, relkind, sizeof(relkind), NULL); if (!SQL_SUCCEEDED(result)) { goto cleanup; } - relhasoids[0] = '1'; - result = PGAPI_BindCol(col_stmt, 3, internal_asis_type, - relhasoids, sizeof(relhasoids), NULL); - if (!SQL_SUCCEEDED(result)) + + // check to see if the relation has oids, this is only done for versions less than 12 + if (PG_VERSION_LT(conn, 12.0)) { - goto cleanup; + relhasoids[0] = '1'; + result = PGAPI_BindCol(col_stmt, 3, internal_asis_type, + relhasoids, sizeof(relhasoids), NULL); + if (!SQL_SUCCEEDED(result)) + { + goto cleanup; + } } result = PGAPI_Fetch(col_stmt); @@ -3092,6 +3100,7 @@ PGAPI_SpecialColumns(HSTMT hstmt, if (relisaview) { /* there's no oid for views */ + // TODO: this may still work for views since we don't really have to rely on oid for best rowid if (fColType == SQL_BEST_ROWID) { ret = SQL_SUCCESS;