@@ -2993,6 +2993,7 @@ PGAPI_SpecialColumns(HSTMT hstmt,
2993
2993
appendPQExpBufferStr (& columns_query , ", c.relhasoids" );
2994
2994
else
2995
2995
appendPQExpBufferStr (& columns_query , ", 0 as relhasoids" );
2996
+
2996
2997
appendPQExpBufferStr (& columns_query , " from pg_catalog.pg_namespace u,"
2997
2998
" pg_catalog.pg_class c where "
2998
2999
"u.oid = c.relnamespace" );
@@ -3042,25 +3043,32 @@ PGAPI_SpecialColumns(HSTMT hstmt,
3042
3043
goto cleanup ;
3043
3044
}
3044
3045
3046
+ // check to see if the relation has rules
3045
3047
result = PGAPI_BindCol (col_stmt , 1 , internal_asis_type ,
3046
3048
relhasrules , sizeof (relhasrules ), NULL );
3047
3049
if (!SQL_SUCCEEDED (result ))
3048
3050
{
3049
3051
goto cleanup ;
3050
3052
}
3051
3053
3054
+ // bind to relkind to check if a view or not
3052
3055
result = PGAPI_BindCol (col_stmt , 2 , internal_asis_type ,
3053
3056
relkind , sizeof (relkind ), NULL );
3054
3057
if (!SQL_SUCCEEDED (result ))
3055
3058
{
3056
3059
goto cleanup ;
3057
3060
}
3058
- relhasoids [0 ] = '1' ;
3059
- result = PGAPI_BindCol (col_stmt , 3 , internal_asis_type ,
3060
- relhasoids , sizeof (relhasoids ), NULL );
3061
- if (!SQL_SUCCEEDED (result ))
3061
+
3062
+ // check to see if the relation has oids, this is only done for versions less than 12
3063
+ if (PG_VERSION_LT (conn , 12.0 ))
3062
3064
{
3063
- goto cleanup ;
3065
+ relhasoids [0 ] = '1' ;
3066
+ result = PGAPI_BindCol (col_stmt , 3 , internal_asis_type ,
3067
+ relhasoids , sizeof (relhasoids ), NULL );
3068
+ if (!SQL_SUCCEEDED (result ))
3069
+ {
3070
+ goto cleanup ;
3071
+ }
3064
3072
}
3065
3073
3066
3074
result = PGAPI_Fetch (col_stmt );
@@ -3092,6 +3100,7 @@ PGAPI_SpecialColumns(HSTMT hstmt,
3092
3100
if (relisaview )
3093
3101
{
3094
3102
/* there's no oid for views */
3103
+ // TODO: this may still work for views since we don't really have to rely on oid for best rowid
3095
3104
if (fColType == SQL_BEST_ROWID )
3096
3105
{
3097
3106
ret = SQL_SUCCESS ;
@@ -3112,7 +3121,7 @@ PGAPI_SpecialColumns(HSTMT hstmt,
3112
3121
set_tuplefield_int4 (& tuple [SPECOLS_BUFFER_LENGTH ], PGTYPE_ATTR_BUFFER_LENGTH (conn , the_type , atttypmod ));
3113
3122
set_tuplefield_int2 (& tuple [SPECOLS_DECIMAL_DIGITS ], PGTYPE_ATTR_DECIMAL_DIGITS (conn , the_type , atttypmod ));
3114
3123
set_tuplefield_int2 (& tuple [SPECOLS_PSEUDO_COLUMN ], SQL_PC_NOT_PSEUDO );
3115
- MYLOG (DETAIL_LOG_LEVEL , "Add ctid\n" );
3124
+ MYLOG (DETAIL_LOG_LEVEL , "Add ctid\n" );
3116
3125
}
3117
3126
}
3118
3127
else
@@ -3181,21 +3190,15 @@ WHERE a.attnum > 0 and c.relname like 'testuktab';
3181
3190
3182
3191
3183
3192
if (szTableQualifier != NULL )
3184
- appendPQExpBuffer (& columns_query , " and c.relnamespace = %s" , szSchemaName );
3193
+ appendPQExpBuffer (& columns_query , " and c.relnamespace = %s" , szSchemaName );
3185
3194
3186
- result = PGAPI_ExecDirect (stmt , (SQLCHAR * ) columns_query .data , SQL_NTS , PODBC_RDONLY );
3187
- if (!SQL_SUCCEEDED (result ))
3195
+ if (res = CC_send_query (conn , columns_query .data , NULL , READ_ONLY_QUERY , stmt ), !QR_command_maybe_successful (res ))
3188
3196
{
3189
- /*
3190
- * "Couldn't execute index query (w/SQLExecDirect) in
3191
- * SpecialColumns";
3192
- */
3193
- SC_full_error_copy (stmt , stmt , FALSE);
3197
+ SC_set_error (stmt , STMT_EXEC_ERROR , "PGAPI_Special query error" , func );
3194
3198
goto cleanup ;
3195
3199
}
3196
- res = SC_get_Result (stmt );
3200
+ SC_set_Result (stmt , res );
3197
3201
}
3198
-
3199
3202
}
3200
3203
else if (fColType == SQL_ROWVER )
3201
3204
{
0 commit comments