Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -3042,25 +3043,32 @@ 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))
{
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);
Expand Down Expand Up @@ -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;
Expand All @@ -3112,7 +3121,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
Expand Down Expand Up @@ -3181,21 +3190,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)
{
Expand Down
18 changes: 9 additions & 9 deletions test/expected/catalogfunctions.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down