static BOOL theResultIsEmpty(const StatementClass *stmt) { QResultClass *res = SC_get_Result(stmt); if (NULL == res) return FALSE; return (0 == QR_get_num_total_tuples(res)); }
RETCODE SQL_API SQLTables(HSTMT StatementHandle, SQLCHAR *CatalogName, SQLSMALLINT NameLength1, SQLCHAR *SchemaName, SQLSMALLINT NameLength2, SQLCHAR *TableName, SQLSMALLINT NameLength3, SQLCHAR *TableType, SQLSMALLINT NameLength4) { CSTR func = "SQLTables"; RETCODE ret; StatementClass *stmt = (StatementClass *) StatementHandle; SQLCHAR *ctName = CatalogName, *scName = SchemaName, *tbName = TableName; UWORD flag = 0; mylog("[%s]", func); ENTER_STMT_CS(stmt); SC_clear_error(stmt); StartRollbackState(stmt); #if (ODBCVER >= 0x0300) if (stmt->options.metadata_id) flag |= PODBC_NOT_SEARCH_PATTERN; #endif if (SC_opencheck(stmt, func)) ret = SQL_ERROR; else ret = PGAPI_Tables(StatementHandle, ctName, NameLength1, scName, NameLength2, tbName, NameLength3, TableType, NameLength4, flag); if (SQL_SUCCESS == ret && 0 == QR_get_num_total_tuples(SC_get_Result(stmt))) { BOOL ifallupper = TRUE, reexec = FALSE; char *newCt =NULL, *newSc = NULL, *newTb = NULL; ConnectionClass *conn = SC_get_conn(stmt); if (SC_is_lower_case(stmt, conn)) /* case-insensitive identifier */ ifallupper = FALSE; if (newCt = make_lstring_ifneeded(conn, CatalogName, NameLength1, ifallupper), NULL != newCt) { ctName = newCt; reexec = TRUE; } if (newSc = make_lstring_ifneeded(conn, SchemaName, NameLength2, ifallupper), NULL != newSc) { scName = newSc; reexec = TRUE; } if (newTb = make_lstring_ifneeded(conn, TableName, NameLength3, ifallupper), NULL != newTb) { tbName = newTb; reexec = TRUE; } if (reexec) { ret = PGAPI_Tables(StatementHandle, ctName, NameLength1, scName, NameLength2, tbName, NameLength3, TableType, NameLength4, flag); if (newCt) free(newCt); if (newSc) free(newSc); if (newTb) free(newTb); } } ret = DiscardStatementSvp(stmt, ret, FALSE); LEAVE_STMT_CS(stmt); return ret; }
RETCODE SQL_API SQLSpecialColumns(HSTMT StatementHandle, SQLUSMALLINT IdentifierType, SQLCHAR *CatalogName, SQLSMALLINT NameLength1, SQLCHAR *SchemaName, SQLSMALLINT NameLength2, SQLCHAR *TableName, SQLSMALLINT NameLength3, SQLUSMALLINT Scope, SQLUSMALLINT Nullable) { CSTR func = "SQLSpecialColumns"; RETCODE ret; StatementClass *stmt = (StatementClass *) StatementHandle; SQLCHAR *ctName = CatalogName, *scName = SchemaName, *tbName = TableName; mylog("[%s]", func); ENTER_STMT_CS(stmt); SC_clear_error(stmt); StartRollbackState(stmt); if (SC_opencheck(stmt, func)) ret = SQL_ERROR; else ret = PGAPI_SpecialColumns(StatementHandle, IdentifierType, ctName, NameLength1, scName, NameLength2, tbName, NameLength3, Scope, Nullable); if (SQL_SUCCESS == ret && 0 == QR_get_num_total_tuples(SC_get_Result(stmt))) { BOOL ifallupper = TRUE, reexec = FALSE; char *newCt =NULL, *newSc = NULL, *newTb = NULL; ConnectionClass *conn = SC_get_conn(stmt); if (SC_is_lower_case(stmt, conn)) /* case-insensitive identifier */ ifallupper = FALSE; if (newCt = make_lstring_ifneeded(conn, CatalogName, NameLength1, ifallupper), NULL != newCt) { ctName = newCt; reexec = TRUE; } if (newSc = make_lstring_ifneeded(conn, SchemaName, NameLength2, ifallupper), NULL != newSc) { scName = newSc; reexec = TRUE; } if (newTb = make_lstring_ifneeded(conn, TableName, NameLength3, ifallupper), NULL != newTb) { tbName = newTb; reexec = TRUE; } if (reexec) { ret = PGAPI_SpecialColumns(StatementHandle, IdentifierType, ctName, NameLength1, scName, NameLength2, tbName, NameLength3, Scope, Nullable); if (newCt) free(newCt); if (newSc) free(newSc); if (newTb) free(newTb); } } ret = DiscardStatementSvp(stmt, ret, FALSE); LEAVE_STMT_CS(stmt); return ret; }
RETCODE SQL_API SQLProcedures( HSTMT hstmt, SQLCHAR *szCatalogName, SQLSMALLINT cbCatalogName, SQLCHAR *szSchemaName, SQLSMALLINT cbSchemaName, SQLCHAR *szProcName, SQLSMALLINT cbProcName) { CSTR func = "SQLProcedures"; RETCODE ret; StatementClass *stmt = (StatementClass *) hstmt; SQLCHAR *ctName = szCatalogName, *scName = szSchemaName, *prName = szProcName; UWORD flag = 0; mylog("[%s]", func); ENTER_STMT_CS(stmt); SC_clear_error(stmt); StartRollbackState(stmt); #if (ODBCVER >= 0x0300) if (stmt->options.metadata_id) flag |= PODBC_NOT_SEARCH_PATTERN; #endif if (SC_opencheck(stmt, func)) ret = SQL_ERROR; else ret = PGAPI_Procedures(hstmt, ctName, cbCatalogName, scName, cbSchemaName, prName, cbProcName, flag); if (SQL_SUCCESS == ret && 0 == QR_get_num_total_tuples(SC_get_Result(stmt))) { BOOL ifallupper = TRUE, reexec = FALSE; char *newCt = NULL, *newSc = NULL, *newPr = NULL; ConnectionClass *conn = SC_get_conn(stmt); if (SC_is_lower_case(stmt, conn)) /* case-insensitive identifier */ ifallupper = FALSE; if (newCt = make_lstring_ifneeded(conn, szCatalogName, cbCatalogName, ifallupper), NULL != newCt) { ctName = newCt; reexec = TRUE; } if (newSc = make_lstring_ifneeded(conn, szSchemaName, cbSchemaName, ifallupper), NULL != newSc) { scName = newSc; reexec = TRUE; } if (newPr = make_lstring_ifneeded(conn, szProcName, cbProcName, ifallupper), NULL != newPr) { prName = newPr; reexec = TRUE; } if (reexec) { ret = PGAPI_Procedures(hstmt, ctName, cbCatalogName, scName, cbSchemaName, prName, cbProcName, flag); if (newCt) free(newCt); if (newSc) free(newSc); if (newPr) free(newPr); } } ret = DiscardStatementSvp(stmt, ret, FALSE); LEAVE_STMT_CS(stmt); return ret; }
RETCODE SQL_API SQLPrimaryKeys( HSTMT hstmt, SQLCHAR *szCatalogName, SQLSMALLINT cbCatalogName, SQLCHAR *szSchemaName, SQLSMALLINT cbSchemaName, SQLCHAR *szTableName, SQLSMALLINT cbTableName) { CSTR func = "SQLPrimaryKeys"; RETCODE ret; StatementClass *stmt = (StatementClass *) hstmt; SQLCHAR *ctName = szCatalogName, *scName = szSchemaName, *tbName = szTableName; mylog("[%s]", func); ENTER_STMT_CS(stmt); SC_clear_error(stmt); StartRollbackState(stmt); if (SC_opencheck(stmt, func)) ret = SQL_ERROR; else ret = PGAPI_PrimaryKeys(hstmt, ctName, cbCatalogName, scName, cbSchemaName, tbName, cbTableName, 0); if (SQL_SUCCESS == ret && 0 == QR_get_num_total_tuples(SC_get_Result(stmt))) { BOOL ifallupper = TRUE, reexec = FALSE; char *newCt = NULL, *newSc = NULL, *newTb = NULL; ConnectionClass *conn = SC_get_conn(stmt); if (SC_is_lower_case(stmt, conn)) /* case-insensitive identifier */ ifallupper = FALSE; if (newCt = make_lstring_ifneeded(conn, szCatalogName, cbCatalogName, ifallupper), NULL != newCt) { ctName = newCt; reexec = TRUE; } if (newSc = make_lstring_ifneeded(conn, szSchemaName, cbSchemaName, ifallupper), NULL != newSc) { scName = newSc; reexec = TRUE; } if (newTb = make_lstring_ifneeded(conn, szTableName, cbTableName, ifallupper), NULL != newTb) { tbName = newTb; reexec = TRUE; } if (reexec) { ret = PGAPI_PrimaryKeys(hstmt, ctName, cbCatalogName, scName, cbSchemaName, tbName, cbTableName, 0); if (newCt) free(newCt); if (newSc) free(newSc); if (newTb) free(newTb); } } ret = DiscardStatementSvp(stmt, ret, FALSE); LEAVE_STMT_CS(stmt); return ret; }
RETCODE SQL_API SQLForeignKeys( HSTMT hstmt, SQLCHAR *szPkCatalogName, SQLSMALLINT cbPkCatalogName, SQLCHAR *szPkSchemaName, SQLSMALLINT cbPkSchemaName, SQLCHAR *szPkTableName, SQLSMALLINT cbPkTableName, SQLCHAR *szFkCatalogName, SQLSMALLINT cbFkCatalogName, SQLCHAR *szFkSchemaName, SQLSMALLINT cbFkSchemaName, SQLCHAR *szFkTableName, SQLSMALLINT cbFkTableName) { CSTR func = "SQLForeignKeys"; RETCODE ret; StatementClass *stmt = (StatementClass *) hstmt; SQLCHAR *pkctName = szPkCatalogName, *pkscName = szPkSchemaName, *pktbName = szPkTableName, *fkctName = szFkCatalogName, *fkscName = szFkSchemaName, *fktbName = szFkTableName; mylog("[%s]", func); ENTER_STMT_CS(stmt); SC_clear_error(stmt); StartRollbackState(stmt); if (SC_opencheck(stmt, func)) ret = SQL_ERROR; else ret = PGAPI_ForeignKeys(hstmt, pkctName, cbPkCatalogName, pkscName, cbPkSchemaName, pktbName, cbPkTableName, fkctName, cbFkCatalogName, fkscName, cbFkSchemaName, fktbName, cbFkTableName); if (SQL_SUCCESS == ret && 0 == QR_get_num_total_tuples(SC_get_Result(stmt))) { BOOL ifallupper = TRUE, reexec = FALSE; char *newPkct = NULL, *newPksc = NULL, *newPktb = NULL, *newFkct = NULL, *newFksc = NULL, *newFktb = NULL; ConnectionClass *conn = SC_get_conn(stmt); if (SC_is_lower_case(stmt, conn)) /* case-insensitive identifier */ ifallupper = FALSE; if (newPkct = make_lstring_ifneeded(conn, szPkCatalogName, cbPkCatalogName, ifallupper), NULL != newPkct) { pkctName = newPkct; reexec = TRUE; } if (newPksc = make_lstring_ifneeded(conn, szPkSchemaName, cbPkSchemaName, ifallupper), NULL != newPksc) { pkscName = newPksc; reexec = TRUE; } if (newPktb = make_lstring_ifneeded(conn, szPkTableName, cbPkTableName, ifallupper), NULL != newPktb) { pktbName = newPktb; reexec = TRUE; } if (newFkct = make_lstring_ifneeded(conn, szFkCatalogName, cbFkCatalogName, ifallupper), NULL != newFkct) { fkctName = newFkct; reexec = TRUE; } if (newFksc = make_lstring_ifneeded(conn, szFkSchemaName, cbFkSchemaName, ifallupper), NULL != newFksc) { fkscName = newFksc; reexec = TRUE; } if (newFktb = make_lstring_ifneeded(conn, szFkTableName, cbFkTableName, ifallupper), NULL != newFktb) { fktbName = newFktb; reexec = TRUE; } if (reexec) { ret = PGAPI_ForeignKeys(hstmt, pkctName, cbPkCatalogName, pkscName, cbPkSchemaName, pktbName, cbPkTableName, fkctName, cbFkCatalogName, fkscName, cbFkSchemaName, fktbName, cbFkTableName); if (newPkct) free(newPkct); if (newPksc) free(newPksc); if (newPktb) free(newPktb); if (newFkct) free(newFkct); if (newFksc) free(newFksc); if (newFktb) free(newFktb); } } ret = DiscardStatementSvp(stmt, ret, FALSE); LEAVE_STMT_CS(stmt); return ret; }