@@ -832,7 +832,8 @@ PGAPI_GetFunctions(
832
832
UWORD FAR * pfExists )
833
833
{
834
834
static char * func = "PGAPI_GetFunctions" ;
835
- ConnInfo * ci = & (((ConnectionClass * )hdbc )-> connInfo );
835
+ ConnectionClass * conn = (ConnectionClass * )hdbc ;
836
+ ConnInfo * ci = & (conn -> connInfo );
836
837
837
838
mylog ("%s: entering...%u\n" , func , fFunction );
838
839
@@ -915,7 +916,10 @@ PGAPI_GetFunctions(
915
916
pfExists [SQL_API_SQLPARAMOPTIONS ] = FALSE;
916
917
pfExists [SQL_API_SQLPRIMARYKEYS ] = TRUE;
917
918
pfExists [SQL_API_SQLPROCEDURECOLUMNS ] = FALSE;
918
- pfExists [SQL_API_SQLPROCEDURES ] = FALSE;
919
+ if (PG_VERSION_LT (conn , 6.5 ))
920
+ pfExists [SQL_API_SQLPROCEDURES ] = FALSE;
921
+ else
922
+ pfExists [SQL_API_SQLPROCEDURES ] = TRUE;
919
923
pfExists [SQL_API_SQLSETPOS ] = TRUE;
920
924
pfExists [SQL_API_SQLSETSCROLLOPTIONS ] = TRUE; /* odbc 1.0 */
921
925
pfExists [SQL_API_SQLTABLEPRIVILEGES ] = FALSE;
@@ -1090,7 +1094,10 @@ PGAPI_GetFunctions(
1090
1094
* pfExists = FALSE;
1091
1095
break ;
1092
1096
case SQL_API_SQLPROCEDURES :
1093
- * pfExists = FALSE;
1097
+ if (PG_VERSION_LT (conn , 6.5 ))
1098
+ * pfExists = FALSE;
1099
+ else
1100
+ * pfExists = TRUE;
1094
1101
break ;
1095
1102
case SQL_API_SQLSETPOS :
1096
1103
* pfExists = TRUE;
@@ -3615,30 +3622,53 @@ PGAPI_Procedures(
3615
3622
{
3616
3623
static char * func = "PGAPI_Procedures" ;
3617
3624
StatementClass * stmt = (StatementClass * ) hstmt ;
3618
- Int2 result_cols ;
3625
+ ConnectionClass * conn = SC_get_conn (stmt );
3626
+ char proc_query [INFO_INQUIRY_LEN ];
3627
+ QResultClass * res ;
3619
3628
3620
3629
mylog ("%s: entering...\n" , func );
3630
+
3631
+ if (PG_VERSION_LT (conn , 6.5 ))
3632
+ {
3633
+ stmt -> errornumber = STMT_NOT_IMPLEMENTED_ERROR ;
3634
+ stmt -> errormsg = "Version is too old" ;
3635
+ SC_log_error (func , "Function not implemented" , (StatementClass * ) hstmt );
3636
+ return SQL_ERROR ;
3637
+ }
3638
+ if (!SC_recycle_statement (stmt ))
3639
+ return SQL_ERROR ;
3640
+ /*
3641
+ * The following seems the simplest implementation
3642
+ */
3643
+ strcpy (proc_query , "select '' as " "PROCEDURE_CAT" ", '' as " "PROCEDURE_SCHEM" ","
3644
+ " proname as " "PROCEDURE_NAME" ", '' as " "NUM_INPUT_PARAMS" ","
3645
+ " '' as " "NUM_OUTPUT_PARAMS" ", '' as " "NUM_RESULT_SETS" ","
3646
+ " '' as " "REMARKS" ","
3647
+ " case when prorettype =0 then 1::int2 else 2::int2 end as " "PROCEDURE_TYPE" " from pg_proc" );
3648
+ my_strcat (proc_query , " where proname like '%.*s'" , szProcName , cbProcName );
3621
3649
3650
+ res = CC_send_query (conn , proc_query , NULL );
3651
+ if (!res || QR_aborted (res ))
3652
+ {
3653
+ if (res )
3654
+ QR_Destructor (res );
3655
+ stmt -> errornumber = STMT_EXEC_ERROR ;
3656
+ stmt -> errormsg = "PGAPI_Procedures query error" ;
3657
+ return SQL_ERROR ;
3658
+ }
3659
+ stmt -> result = res ;
3622
3660
/*
3623
- * a statement is actually executed, so we'll have to do this
3624
- * ourselves.
3625
- */
3626
- result_cols = 8 ;
3627
- extend_bindings (stmt , result_cols );
3661
+ * also, things need to think that this statement is finished so the
3662
+ * results can be retrieved.
3663
+ */
3664
+ stmt -> status = STMT_FINISHED ;
3665
+ extend_bindings (stmt , 8 );
3666
+ /* set up the current tuple pointer for SQLFetch */
3667
+ stmt -> currTuple = -1 ;
3668
+ stmt -> rowset_start = -1 ;
3669
+ stmt -> current_col = -1 ;
3628
3670
3629
- /* set the field names */
3630
- QR_set_num_fields (stmt -> result , result_cols );
3631
- QR_set_field_info (stmt -> result , 0 , "PROCEDURE_CAT" , PG_TYPE_TEXT , MAX_INFO_STRING );
3632
- QR_set_field_info (stmt -> result , 1 , "PROCEDURE_SCHEM" , PG_TYPE_TEXT , MAX_INFO_STRING );
3633
- QR_set_field_info (stmt -> result , 2 , "PROCEDURE_NAME" , PG_TYPE_TEXT , MAX_INFO_STRING );
3634
- QR_set_field_info (stmt -> result , 3 , "NUM_INPUT_PARAMS" , PG_TYPE_TEXT , MAX_INFO_STRING );
3635
- QR_set_field_info (stmt -> result , 4 , "NUM_OUTPUT_PARAMS" , PG_TYPE_TEXT , MAX_INFO_STRING );
3636
- QR_set_field_info (stmt -> result , 5 , "NUM_RESULT_SET" , PG_TYPE_TEXT , MAX_INFO_STRING );
3637
- QR_set_field_info (stmt -> result , 6 , "REMARKS" , PG_TYPE_TEXT , MAX_INFO_STRING );
3638
- QR_set_field_info (stmt -> result , 7 , "PROCEDURE_TYPE" , PG_TYPE_INT2 , 2 );
3639
-
3640
- SC_log_error (func , "Function not implemented" , (StatementClass * ) hstmt );
3641
- return SQL_ERROR ;
3671
+ return SQL_SUCCESS ;
3642
3672
}
3643
3673
3644
3674
0 commit comments