mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-18 18:44:06 +08:00
Fix ODBC compile, prevent ODBCVER warning, though the version numbers go
not match.
This commit is contained in:
parent
0cbfde72fe
commit
01b5efa5e3
@ -2255,12 +2255,15 @@ char tables_query[MAX_STATEMENT_LEN];
|
||||
char trig_deferrable[2];
|
||||
char trig_initdeferred[2];
|
||||
char trig_args[1024];
|
||||
char upd_rule[MAX_NAME_LEN], del_rule[MAX_NAME_LEN];
|
||||
char upd_rule[MAX_TABLE_LEN], del_rule[MAX_TABLE_LEN];
|
||||
char pk_table_needed[MAX_TABLE_LEN + 1];
|
||||
char fk_table_needed[MAX_TABLE_LEN + 1];
|
||||
char *pkey_ptr, *fkey_ptr, *pk_table, *fk_table;
|
||||
int i, j, k, num_keys;
|
||||
SWORD trig_nargs, upd_rule_type, del_rule_type, defer_type;
|
||||
SWORD trig_nargs, upd_rule_type=0, del_rule_type=0;
|
||||
#if (ODBCVER >= 0x0300)
|
||||
SWORD defer_type;
|
||||
#endif
|
||||
char pkey[MAX_INFO_STRING];
|
||||
Int2 result_cols;
|
||||
|
||||
@ -2694,136 +2697,136 @@ Int2 result_cols;
|
||||
return SQL_ERROR;
|
||||
}
|
||||
|
||||
result = SQLBindCol(htbl_stmt, 5, SQL_C_CHAR,
|
||||
upd_rule, sizeof(upd_rule), NULL);
|
||||
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
stmt->errormsg = tbl_stmt->errormsg;
|
||||
result = SQLBindCol(htbl_stmt, 5, SQL_C_CHAR,
|
||||
upd_rule, sizeof(upd_rule), NULL);
|
||||
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
stmt->errormsg = tbl_stmt->errormsg;
|
||||
stmt->errornumber = tbl_stmt->errornumber;
|
||||
SC_log_error(func, "", stmt);
|
||||
SQLFreeStmt(htbl_stmt, SQL_DROP);
|
||||
return SQL_ERROR;
|
||||
}
|
||||
|
||||
result = SQLBindCol(htbl_stmt, 6, SQL_C_CHAR,
|
||||
del_rule, sizeof(del_rule), NULL);
|
||||
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
stmt->errormsg = tbl_stmt->errormsg;
|
||||
stmt->errornumber = tbl_stmt->errornumber;
|
||||
result = SQLBindCol(htbl_stmt, 6, SQL_C_CHAR,
|
||||
del_rule, sizeof(del_rule), NULL);
|
||||
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
stmt->errormsg = tbl_stmt->errormsg;
|
||||
stmt->errornumber = tbl_stmt->errornumber;
|
||||
SC_log_error(func, "", stmt);
|
||||
SQLFreeStmt(htbl_stmt, SQL_DROP);
|
||||
SQLFreeStmt(htbl_stmt, SQL_DROP);
|
||||
return SQL_ERROR;
|
||||
}
|
||||
|
||||
result = SQLFetch(htbl_stmt);
|
||||
if (result == SQL_NO_DATA_FOUND)
|
||||
return SQL_SUCCESS;
|
||||
result = SQLFetch(htbl_stmt);
|
||||
if (result == SQL_NO_DATA_FOUND)
|
||||
return SQL_SUCCESS;
|
||||
|
||||
if(result != SQL_SUCCESS) {
|
||||
stmt->errormsg = SC_create_errormsg(htbl_stmt);
|
||||
stmt->errornumber = tbl_stmt->errornumber;
|
||||
if(result != SQL_SUCCESS) {
|
||||
stmt->errormsg = SC_create_errormsg(htbl_stmt);
|
||||
stmt->errornumber = tbl_stmt->errornumber;
|
||||
SC_log_error(func, "", stmt);
|
||||
SQLFreeStmt(htbl_stmt, SQL_DROP);
|
||||
SQLFreeStmt(htbl_stmt, SQL_DROP);
|
||||
return SQL_ERROR;
|
||||
}
|
||||
|
||||
while (result == SQL_SUCCESS) {
|
||||
|
||||
/* Calculate the number of key parts */
|
||||
num_keys = (trig_nargs - 4) / 2;;
|
||||
num_keys = (trig_nargs - 4) / 2;;
|
||||
|
||||
/* Handle action (i.e., 'cascade', 'restrict', 'setnull') */
|
||||
if (!strcmp(upd_rule, "RI_FKey_cascade_upd")) {
|
||||
upd_rule_type = SQL_CASCADE;
|
||||
} else if (!strcmp(upd_rule, "RI_FKey_noaction_upd")) {
|
||||
upd_rule_type = SQL_NO_ACTION;
|
||||
} else if (!strcmp(upd_rule, "RI_FKey_restrict_upd")) {
|
||||
upd_rule_type = SQL_NO_ACTION;
|
||||
} else if (!strcmp(upd_rule, "RI_FKey_setdefault_upd")) {
|
||||
upd_rule_type = SQL_SET_DEFAULT;
|
||||
} else if (!strcmp(upd_rule, "RI_FKey_setnull_upd")) {
|
||||
upd_rule_type = SQL_SET_NULL;
|
||||
}
|
||||
|
||||
if (!strcmp(upd_rule, "RI_FKey_cascade_del")) {
|
||||
del_rule_type = SQL_CASCADE;
|
||||
} else if (!strcmp(upd_rule, "RI_FKey_noaction_del")) {
|
||||
del_rule_type = SQL_NO_ACTION;
|
||||
} else if (!strcmp(upd_rule, "RI_FKey_restrict_del")) {
|
||||
del_rule_type = SQL_NO_ACTION;
|
||||
} else if (!strcmp(upd_rule, "RI_FKey_setdefault_del")) {
|
||||
del_rule_type = SQL_SET_DEFAULT;
|
||||
} else if (!strcmp(upd_rule, "RI_FKey_setnull_del")) {
|
||||
del_rule_type = SQL_SET_NULL;
|
||||
}
|
||||
|
||||
#if (ODBCVER >= 0x0300)
|
||||
/* Set deferrability type */
|
||||
if (!strcmp(trig_initdeferred, "y")) {
|
||||
defer_type = SQL_INITIALLY_DEFERRED;
|
||||
} else if (!strcmp(trig_deferrable, "y")) {
|
||||
defer_type = SQL_INITIALLY_IMMEDIATE;
|
||||
} else {
|
||||
defer_type = SQL_NOT_DEFERRABLE;
|
||||
}
|
||||
#endif /* ODBCVER >= 0x0300 */
|
||||
|
||||
mylog("Foreign Key Case#1: trig_nargs = %d, num_keys = %d\n", trig_nargs, num_keys);
|
||||
|
||||
/* Get to first primary key */
|
||||
pkey_ptr = trig_args;
|
||||
for (i = 0; i < 5; i++)
|
||||
pkey_ptr += strlen(pkey_ptr) + 1;
|
||||
|
||||
|
||||
/* Get to first foreign table */
|
||||
fk_table = trig_args;
|
||||
fk_table += strlen(fk_table) + 1;
|
||||
|
||||
/* Get to first foreign key */
|
||||
fkey_ptr = trig_args;
|
||||
for (k = 0; k < 4; k++)
|
||||
fkey_ptr += strlen(fkey_ptr) + 1;
|
||||
if (!strcmp(upd_rule, "RI_FKey_cascade_upd")) {
|
||||
upd_rule_type = SQL_CASCADE;
|
||||
} else if (!strcmp(upd_rule, "RI_FKey_noaction_upd")) {
|
||||
upd_rule_type = SQL_NO_ACTION;
|
||||
} else if (!strcmp(upd_rule, "RI_FKey_restrict_upd")) {
|
||||
upd_rule_type = SQL_NO_ACTION;
|
||||
} else if (!strcmp(upd_rule, "RI_FKey_setdefault_upd")) {
|
||||
upd_rule_type = SQL_SET_DEFAULT;
|
||||
} else if (!strcmp(upd_rule, "RI_FKey_setnull_upd")) {
|
||||
upd_rule_type = SQL_SET_NULL;
|
||||
}
|
||||
|
||||
if (!strcmp(upd_rule, "RI_FKey_cascade_del")) {
|
||||
del_rule_type = SQL_CASCADE;
|
||||
} else if (!strcmp(upd_rule, "RI_FKey_noaction_del")) {
|
||||
del_rule_type = SQL_NO_ACTION;
|
||||
} else if (!strcmp(upd_rule, "RI_FKey_restrict_del")) {
|
||||
del_rule_type = SQL_NO_ACTION;
|
||||
} else if (!strcmp(upd_rule, "RI_FKey_setdefault_del")) {
|
||||
del_rule_type = SQL_SET_DEFAULT;
|
||||
} else if (!strcmp(upd_rule, "RI_FKey_setnull_del")) {
|
||||
del_rule_type = SQL_SET_NULL;
|
||||
}
|
||||
|
||||
for (k = 0; k < num_keys; k++) {
|
||||
#if (ODBCVER >= 0x0300)
|
||||
/* Set deferrability type */
|
||||
if (!strcmp(trig_initdeferred, "y")) {
|
||||
defer_type = SQL_INITIALLY_DEFERRED;
|
||||
} else if (!strcmp(trig_deferrable, "y")) {
|
||||
defer_type = SQL_INITIALLY_IMMEDIATE;
|
||||
} else {
|
||||
defer_type = SQL_NOT_DEFERRABLE;
|
||||
}
|
||||
#endif /* ODBCVER >= 0x0300 */
|
||||
|
||||
mylog("pkey_ptr = '%s', fk_table = '%s', fkey_ptr = '%s'\n", pkey_ptr, fk_table, fkey_ptr);
|
||||
mylog("Foreign Key Case#1: trig_nargs = %d, num_keys = %d\n", trig_nargs, num_keys);
|
||||
|
||||
/* Get to first primary key */
|
||||
pkey_ptr = trig_args;
|
||||
for (i = 0; i < 5; i++)
|
||||
pkey_ptr += strlen(pkey_ptr) + 1;
|
||||
|
||||
|
||||
/* Get to first foreign table */
|
||||
fk_table = trig_args;
|
||||
fk_table += strlen(fk_table) + 1;
|
||||
|
||||
/* Get to first foreign key */
|
||||
fkey_ptr = trig_args;
|
||||
for (k = 0; k < 4; k++)
|
||||
fkey_ptr += strlen(fkey_ptr) + 1;
|
||||
|
||||
for (k = 0; k < num_keys; k++) {
|
||||
|
||||
mylog("pkey_ptr = '%s', fk_table = '%s', fkey_ptr = '%s'\n", pkey_ptr, fk_table, fkey_ptr);
|
||||
|
||||
row = (TupleNode *)malloc(sizeof(TupleNode) + (result_cols - 1) * sizeof(TupleField));
|
||||
|
||||
mylog("pk_table_needed = '%s', pkey_ptr = '%s'\n", pk_table_needed, pkey_ptr);
|
||||
mylog("pk_table_needed = '%s', pkey_ptr = '%s'\n", pk_table_needed, pkey_ptr);
|
||||
set_tuplefield_null(&row->tuple[0]);
|
||||
set_tuplefield_string(&row->tuple[1], "");
|
||||
set_tuplefield_string(&row->tuple[2], pk_table_needed);
|
||||
set_tuplefield_string(&row->tuple[3], pkey_ptr);
|
||||
set_tuplefield_string(&row->tuple[2], pk_table_needed);
|
||||
set_tuplefield_string(&row->tuple[3], pkey_ptr);
|
||||
|
||||
mylog("fk_table = '%s', fkey_ptr = '%s'\n", fk_table, fkey_ptr);
|
||||
mylog("fk_table = '%s', fkey_ptr = '%s'\n", fk_table, fkey_ptr);
|
||||
set_tuplefield_null(&row->tuple[4]);
|
||||
set_tuplefield_string(&row->tuple[5], "");
|
||||
set_tuplefield_string(&row->tuple[6], fk_table);
|
||||
set_tuplefield_string(&row->tuple[7], fkey_ptr);
|
||||
set_tuplefield_string(&row->tuple[7], fkey_ptr);
|
||||
|
||||
set_tuplefield_int2(&row->tuple[8], (Int2) (k + 1));
|
||||
set_tuplefield_int2(&row->tuple[8], (Int2) (k + 1));
|
||||
|
||||
mylog("upd_rule = %d, del_rule= %d", upd_rule_type, del_rule_type);
|
||||
set_nullfield_int2(&row->tuple[9], (Int2) upd_rule_type);
|
||||
set_nullfield_int2(&row->tuple[10], (Int2) del_rule_type);
|
||||
mylog("upd_rule = %d, del_rule= %d", upd_rule_type, del_rule_type);
|
||||
set_nullfield_int2(&row->tuple[9], (Int2) upd_rule_type);
|
||||
set_nullfield_int2(&row->tuple[10], (Int2) del_rule_type);
|
||||
|
||||
set_tuplefield_null(&row->tuple[11]);
|
||||
set_tuplefield_null(&row->tuple[12]);
|
||||
|
||||
set_tuplefield_string(&row->tuple[13], trig_args);
|
||||
set_tuplefield_string(&row->tuple[13], trig_args);
|
||||
|
||||
#if (ODBCVER >= 0x0300)
|
||||
mylog("defer_type = '%s', defer_type);
|
||||
set_tuplefield_int2(&row->tuple[14], defer_type);
|
||||
#endif /* ODBCVER >= 0x0300 */
|
||||
#if (ODBCVER >= 0x0300)
|
||||
mylog("defer_type = '%s'", defer_type);
|
||||
set_tuplefield_int2(&row->tuple[14], defer_type);
|
||||
#endif /* ODBCVER >= 0x0300 */
|
||||
|
||||
QR_add_tuple(stmt->result, row);
|
||||
|
||||
/* next primary/foreign key */
|
||||
for (j = 0; j < 2; j++) {
|
||||
pkey_ptr += strlen(pkey_ptr) + 1;
|
||||
fkey_ptr += strlen(fkey_ptr) + 1;
|
||||
for (j = 0; j < 2; j++) {
|
||||
pkey_ptr += strlen(pkey_ptr) + 1;
|
||||
fkey_ptr += strlen(fkey_ptr) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,9 @@ typedef signed short RETCODE;
|
||||
# define SQL_API EXPORT CALLBACK
|
||||
# endif
|
||||
|
||||
#ifndef ODBCVER
|
||||
# define ODBCVER 0x0200
|
||||
#endif
|
||||
|
||||
# define SQL_MAX_MESSAGE_LENGTH 512
|
||||
# define SQL_MAX_DSN_LENGTH 32
|
||||
|
@ -34,7 +34,9 @@ typedef double SDOUBLE;
|
||||
typedef UInt4 Oid;
|
||||
|
||||
/* Driver stuff */
|
||||
#ifndef ODBCVER
|
||||
#define ODBCVER 0x0250
|
||||
#endif
|
||||
#define DRIVER_ODBC_VER "02.50"
|
||||
|
||||
#define DRIVERNAME "PostgreSQL ODBC"
|
||||
|
Loading…
Reference in New Issue
Block a user