SQLColumnPrivileges

decompiled_code:
__int64 __fastcall SQLColumnPrivileges(__int64 a1)
{
if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLColumnPrivileges.c", "SQLColumnPrivileges.c", 33LL, 1LL, 1LL, a1 + 136);
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLColumnPrivileges.c",
"SQLColumnPrivileges.c",
38LL,
1LL,
1LL,
"SQL_ERROR This function not supported");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLColumnPrivileges.c", "SQLColumnPrivileges.c", 33LL, 1LL, 1LL, a1 + 136);
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLColumnPrivileges.c",
"SQLColumnPrivileges.c",
38LL,
1LL,
1LL,
"SQL_ERROR This function not supported");
return 0xFFFFFFFFLL;
}

original_code:
RETCODE SQLColumnPrivileges(
                                    HSTMT hstmt,
                                    UCHAR * szTableQualifier,
                                    SWORD cbTableQualifier,
                                    UCHAR * szTableOwner,
                                    SWORD cbTableOwner,
                                    UCHAR * szTableName,
                                    SWORD cbTableName,
                                    UCHAR * szColumnName,
                                    SWORD cbColumnName)
{
static char* const func="SQLColumnPrivileges";
 mylog("%s: entering...\n", func);
 SC_log_error(func, "Function not implemented", (StatementClass *) hstmt);
    return (-1);
}

canonical_original_code:
short SQLColumnPrivileges(void *hstmt, unsigned char *szTableQualifier, short cbTableQualifier, unsigned char *szTableOwner, short cbTableOwner, unsigned char *szTableName, short cbTableName, unsigned char *szColumnName, short cbColumnName)
{
static char *func = "SQLColumnPrivileges";
 mylog("%s: entering...\n", func);
 SC_log_error(func, "Function not implemented", (struct StatementClass_ *) hstmt);
    return (-1);
}

variable_types:
szTableQualifier
unsigned char *

variable_types: cbTableQualifier short

variable_types:
szTableOwner
unsigned char *

variable_types: cbTableOwner short

variable_types:
szTableName
unsigned char *

variable_types: cbTableName short

variable_types:
szColumnName
unsigned char *

variable_types: cbColumnName short

variable_types:
func
char *

user_defined_types: enum STMT_Status { STMT_ALLOCATED=0, STMT_READY=1, STMT_PREMATURE=2, STMT_FINISHED=3, STMT_EXECUTING=4 }

user_defined_types: struct BindInfoClass_ { int buflen; int data_left; char *buffer; long *used; short returntype; }

user_defined_types: struct ParameterInfoClass_ { int buflen; char *buffer; long *used; short paramType; short CType; short SQLType; unsigned int precision; short scale; unsigned int lobj_oid; int *EXEC_used; char *EXEC_buffer; char data_at_exec; }

user_defined_types: struct StatementOptions_ { int maxRows; int maxLength; int rowset_size; int keyset_size; int cursor_type; int scroll_concurrency; int retrieve_data; int bind_size; int use_bookmarks; }

user_defined_types: enum CONN_Status { CONN_NOT_CONNECTED=0, CONN_CONNECTED=1, CONN_DOWN=2, CONN_EXECUTING=3 }

user_defined_types: struct ConnInfo { char dsn[256]; char desc[256]; char driver[256]; char server[256]; char database[256]; char username[256]; char password[256]; char conn_settings[4096]; char protocol[10]; char port[10]; char uds[4096]; char onlyread[10]; char fake_oid_index[10]; char show_oid_column[10]; char row_versioning[10]; char show_system_tables[10]; char translation_dll[256]; char translation_option[10]; char focus_password; }

user_defined_types: struct TABLE_INFO { struct col_info *col_info; char name[-1]; char alias[-1]; }

user_defined_types: struct FIELD_INFO { struct TABLE_INFO *ti; int precision; int display_size; int length; int type; char nullable; char func; char expr; char quote; char dquote; char numeric; char dot[-1]; char name[-1]; char alias[-1]; }

user_defined_types: struct SocketClass_ { int buffer_filled_in; int buffer_filled_out; int buffer_read_in; unsigned char *buffer_in; unsigned char *buffer_out; int socket; char *errormsg; int errornumber; char reverse; }

user_defined_types: struct col_info { struct QResultClass_ *result; char name[-1]; }

user_defined_types: struct QResultClass_ { struct ColumnInfoClass_ *fields; struct TupleListClass_ *manual_tuples; struct ConnectionClass_ *conn; int fetch_count; int fcount; int currTuple; int base; int num_fields; int cache_size; int rowset_size; enum QueryResultCode_ status; char *message; char *cursor; char *command; char *notice; struct TupleField_ *backend_tuples; struct TupleField_ *tupleField; char inTuples; char aborted; }

user_defined_types: enum QueryResultCode_ { PGRES_EMPTY_QUERY=0, PGRES_COMMAND_OK=1, PGRES_TUPLES_OK=2, PGRES_COPY_OUT=3, PGRES_COPY_IN=4, PGRES_BAD_RESPONSE=5, PGRES_NONFATAL_ERROR=6, PGRES_FATAL_ERROR=7, PGRES_FIELDS_OK=8, PGRES_END_TUPLES=9, PGRES_INTERNAL_ERROR=10 }

user_defined_types: struct ColumnInfoClass_ { short num_fields; char **name; unsigned int *adtid; short *adtsize; short *display_size; int *atttypmod; }

user_defined_types: struct TupleListClass_ { int num_fields; int num_tuples; struct TupleNode_ *list_start; int last_indexed; }

user_defined_types: struct TupleNode_ { struct TupleNode_ *prev; struct TupleField_ tuple[1]; }

user_defined_types: struct TupleField_ { int len; void *value; }


SQLRemoveTranslatorW

repo: xiaotmiaomiao/unixODBC-SPEC

decompiled_code:
// attributes: thunk
__int64 SQLRemoveTranslatorW()
{
return SQLRemoveTranslator_localalias();
}

canonical_decompiled_code:
__int64 func1()
{
return func0();
}

original_code:
int SQLRemoveTranslatorW(LPCWSTR lpszTranslator,
                                 LPDWORD lpdwUsageCount)
{
    inst_logClear();
 return 0;
}

canonical_original_code:
int SQLRemoveTranslatorW(unsigned short *lpszTranslator, unsigned long *lpdwUsageCount)
{
    inst_logClear();
 return 0;
}

variable_types:
lpszTranslator
unsigned short *

variable_types:
lpdwUsageCount
unsigned long *

return_type: int


decompiled_code:
int *__fastcall odbcinst_system_file_path(void *src)
{
int *result; // rax
char *v2; // rsi
char *v3; // rax

if ( saved_3 )
return &save_path_2;
v2 = getenv("ODBCSYSINI");
if ( v2 )
{
v3 = stpcpy((char *)src, v2);
memcpy(&save_path_2, src, v3 - (_BYTE *)src + 1);
result = (int *)src;
}
else
{
strcpy((char *)&save_path_2, "/etc");
result = (int *)"/etc";
}
saved_3 = 1;
return result;
}

canonical_decompiled_code:
int *__fastcall func0(void *src)
{
int *result; // rax
char *v2; // rsi
char *v3; // rax

if ( saved_3 )
return &save_path_2;
v2 = getenv("ODBCSYSINI");
if ( v2 )
{
v3 = stpcpy((char *)src, v2);
memcpy(&save_path_2, src, v3 - (_BYTE *)src + 1);
result = (int *)src;
}
else
{
strcpy((char *)&save_path_2, "/etc");
result = (int *)"/etc";
}
saved_3 = 1;
return result;
}

original_code:
char *odbcinst_system_file_path( char *buffer )
{
    char *path;
    static char save_path[ 512 ];
    static int saved = 0;
    if ( saved ) {
     return save_path;
    }
    if (( path = getenv( "ODBCSYSINI" ))) {
  strcpy( buffer, path );
 strcpy( save_path, buffer );
 saved = 1;
        return buffer;
 }
    else {
 strcpy( save_path, "/etc" );
 saved = 1;
        return "/etc";
 }
}

canonical_original_code:
char *odbcinst_system_file_path(char *buffer)
{
    char *path;
    static char save_path[512];
    static int saved = 0;
    if ( saved ) {
     return save_path;
    }
    if (( path = getenv( "ODBCSYSINI" ))) {
  strcpy( buffer, path );
 strcpy( save_path, buffer );
 saved = 1;
        return buffer;
 }
    else {
 strcpy( save_path, "/etc" );
 saved = 1;
        return "/etc";
 }
}

variable_types:
buffer
char *

variable_types:
path
char *

variable_types: saved int

return_type: char *


decompiled_code:
const char *odbcinst_user_file_name()
{
return ".odbcinst.ini";
}

canonical_decompiled_code:
const char *func1()
{
return ".odbcinst.ini";
}

original_code:
char *odbcinst_user_file_name( char *buffer )
{
 return ".odbcinst.ini";
}

canonical_original_code:
char *odbcinst_user_file_name(char *buffer)
{
 return ".odbcinst.ini";
}


decompiled_code:
const char *__fastcall odbcinst_user_file_path(void *src)
{
const char *result; // rax
char *v2; // rsi
char *v3; // rax

result = (const char *)&save_path_0;
if ( !saved_1 )
{
v2 = getenv("HOME");
result = "/home";
if ( v2 )
{
v3 = stpcpy((char *)src, v2);
memcpy(&save_path_0, src, v3 - (_BYTE *)src + 1);
result = (const char *)src;
saved_1 = 1;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(void *src)
{
const char *result; // rax
char *v2; // rsi
char *v3; // rax

result = (const char *)&save_path_0;
if ( !saved_1 )
{
v2 = getenv("HOME");
result = "/home";
if ( v2 )
{
v3 = stpcpy((char *)src, v2);
memcpy(&save_path_0, src, v3 - (_BYTE *)src + 1);
result = (const char *)src;
saved_1 = 1;
}
}
return result;
}

original_code:
char *odbcinst_user_file_path( char *buffer )
{
    char *path;
    static char save_path[ 512 ];
    static int saved = 0;
    if ( saved ) {
     return save_path;
    }
    if (( path = getenv( "HOME" ))) {
  strcpy( buffer, path );
  strcpy( save_path, buffer );
  saved = 1;
        return buffer;
 }
 else {
        return "/home";
 }
}

canonical_original_code:
char *odbcinst_user_file_path(char *buffer)
{
    char *path;
    static char save_path[512];
    static int saved = 0;
    if ( saved ) {
     return save_path;
    }
    if (( path = getenv( "HOME" ))) {
  strcpy( buffer, path );
  strcpy( save_path, buffer );
  saved = 1;
        return buffer;
 }
 else {
        return "/home";
 }
}


SQLForeignKeys

decompiled_code:
__int64 __fastcall SQLForeignKeys(__int64 a1)
{
if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLForeignKeys.c", "SQLForeignKeys.c", 37LL, 1LL, 1LL, a1 + 136);
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLForeignKeys.c",
"SQLForeignKeys.c",
42LL,
1LL,
1LL,
"SQL_ERROR This function not supported");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLForeignKeys.c", "SQLForeignKeys.c", 37LL, 1LL, 1LL, a1 + 136);
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLForeignKeys.c",
"SQLForeignKeys.c",
42LL,
1LL,
1LL,
"SQL_ERROR This function not supported");
return 0xFFFFFFFFLL;
}

original_code:
RETCODE SQLForeignKeys(
                               HSTMT hstmt,
                               UCHAR * szPkTableQualifier,
                               SWORD cbPkTableQualifier,
                               UCHAR * szPkTableOwner,
                               SWORD cbPkTableOwner,
                               UCHAR * szPkTableName,
                               SWORD cbPkTableName,
                               UCHAR * szFkTableQualifier,
                               SWORD cbFkTableQualifier,
                               UCHAR * szFkTableOwner,
                               SWORD cbFkTableOwner,
                               UCHAR * szFkTableName,
                               SWORD cbFkTableName)
{
static char* const func = "SQLForeignKeys";
StatementClass *stmt = (StatementClass *) hstmt;
TupleNode *row;
HSTMT htbl_stmt, hpkey_stmt;
StatementClass *tbl_stmt;
RETCODE result, keyresult;
char tables_query[65536];
char trig_deferrable[2];
char trig_initdeferred[2];
char trig_args[1024];
char upd_rule[32], del_rule[32];
char pk_table_needed[32 + 1];
char fk_table_needed[32 + 1];
char *pkey_ptr, *fkey_ptr, *pk_table, *fk_table;
int i, j, k, num_keys;
SWORD trig_nargs, upd_rule_type=0, del_rule_type=0;
char pkey[128];
short result_cols;
 mylog("%s: entering...stmt=%u\n", func, stmt);
    if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
        return (-2);
    }
 stmt->manual_result = (int)1;
 stmt->errormsg_created = (int)1;
    stmt->result = QR_Constructor();
    if(!stmt->result) {
 SC_set_error(stmt, 4, "Couldn't allocate memory for SQLForeignKeys result.");
 SC_log_error(func, "", stmt);
        return (-1);
    }
 result_cols = 14;
    extend_bindings(stmt, result_cols);
    QR_set_num_fields(stmt->result, result_cols);
    (CI_set_field_info(stmt->result->fields, 0, "PKTABLE_QUALIFIER", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 1, "PKTABLE_OWNER", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 2, "PKTABLE_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 3, "PKCOLUMN_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 4, "FKTABLE_QUALIFIER", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 5, "FKTABLE_OWNER", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 6, "FKTABLE_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 7, "FKCOLUMN_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 8, "KEY_SEQ", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 9, "UPDATE_RULE", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 10, "DELETE_RULE", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 11, "FK_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 12, "PK_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 13, "TRIGGER_NAME", 25, 128, -1));
    stmt->status = STMT_FINISHED;
    stmt->currTuple = -1;
 stmt->rowset_start = -1;
 stmt->current_col = -1;
    result = PG_SQLAllocStmt( stmt->hdbc, &htbl_stmt);
    if((result != 0) && (result != 1)) {
 SC_set_error(stmt, 4, "Couldn't allocate statement for SQLForeignKeys result.");
 SC_log_error(func, "", stmt);
 return (-1);
    }
 tbl_stmt = (StatementClass *) htbl_stmt;
 pk_table_needed[0] = '\0';
 fk_table_needed[0] = '\0';
 make_string((char*)szPkTableName, cbPkTableName, pk_table_needed);
 make_string((char*)szFkTableName, cbFkTableName, fk_table_needed);
 if (fk_table_needed[0] != '\0') {
  mylog("%s: entering Foreign Key Case #2", func);
  sprintf(tables_query, "SELECT	pt.tgargs, "
        "		pt.tgnargs, "
        "		pt.tgdeferrable, "
        "		pt.tginitdeferred, "
        "		pg_proc.proname, "
        "		pg_proc_1.proname "
        "FROM	pg_class pc, "
        "		pg_proc pg_proc, "
        "		pg_proc pg_proc_1, "
        "		pg_trigger pg_trigger, "
        "		pg_trigger pg_trigger_1, "
        "		pg_proc pp, "
        "		pg_trigger pt "
        "WHERE	pt.tgrelid = pc.oid "
        "AND pp.oid = pt.tgfoid "
        "AND pg_trigger.tgconstrrelid = pc.oid "
        "AND pg_proc.oid = pg_trigger.tgfoid "
        "AND pg_trigger_1.tgfoid = pg_proc_1.oid "
        "AND pg_trigger_1.tgconstrrelid = pc.oid "
        "AND ((pc.relname='%s') "
        "AND (pp.proname LIKE '%%ins') "
        "AND (pg_proc.proname LIKE '%%upd') "
        "AND (pg_proc_1.proname LIKE '%%del') "
        "AND (pg_trigger.tgrelid=pt.tgconstrrelid) "
        "AND (pg_trigger.tgconstrname=pt.tgconstrname) "
        "AND (pg_trigger_1.tgrelid=pt.tgconstrrelid) "
        "AND (pg_trigger_1.tgconstrname=pt.tgconstrname))",
    fk_table_needed);
  result = PG_SQLExecDirect(htbl_stmt, tables_query, strlen(tables_query));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), SC_create_errormsg((StatementClass *)htbl_stmt));
   SC_log_error(func, "", stmt);
      PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 1, (-2),
       trig_args, sizeof(trig_args), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 2, 5,
       &trig_nargs, 0, ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 3, 1,
       trig_deferrable, sizeof(trig_deferrable), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 4, 1,
       trig_initdeferred, sizeof(trig_initdeferred), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 5, 1,
       upd_rule, sizeof(upd_rule), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 6, 1,
       del_rule, sizeof(del_rule), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLFetch(htbl_stmt);
  if (result == 100)
   return 0;
  if(result != 0) {
   SC_set_error(stmt, (tbl_stmt->__error_number), SC_create_errormsg((StatementClass *)htbl_stmt));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  keyresult = PG_SQLAllocStmt( stmt->hdbc, &hpkey_stmt);
  if((keyresult != 0) && (keyresult != 1)) {
   SC_set_error(stmt, 4, "Couldn't allocate statement for SQLForeignKeys (pkeys) result.");
   SC_log_error(func, "", stmt);
   return (-1);
  }
  keyresult = PG_SQLBindCol(hpkey_stmt, 4, 1,
        pkey, sizeof(pkey), ((void *)0));
  if (keyresult != 0) {
   SC_set_error(stmt, 4, "Couldn't bindcol for primary keys for SQLForeignKeys result.");
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(hpkey_stmt, 1);
   return (-1);
  }
  while (result == 0) {
   num_keys = (trig_nargs - 4) / 2;
   mylog("Foreign Key Case#2: trig_nargs = %d, num_keys = %d\n", trig_nargs, num_keys);
   pk_table = trig_args;
   for (k = 0; k < 2; k++)
    pk_table += strlen(pk_table) + 1;
   if (pk_table_needed[0] != '\0') {
    if ( strcmp(pk_table, pk_table_needed)) {
     result = PG_SQLFetch(htbl_stmt);
     continue;
    }
   }
   keyresult = PG_SQLPrimaryKeys(hpkey_stmt, ((void *)0), 0, ((void *)0), 0, (SQLCHAR*)pk_table, (-3));
   if (keyresult != 0) {
    SC_set_error(stmt, 4, "Couldn't get primary keys for SQLForeignKeys result.");
    SC_log_error(func, "", stmt);
    PG_SQLFreeStmt(hpkey_stmt, 1);
    return (-1);
   }
   keyresult = PG_SQLFetch(hpkey_stmt);
   pkey_ptr = trig_args;
   for (i = 0; i < 5; i++)
    pkey_ptr += strlen(pkey_ptr) + 1;
   for (k = 0; k < num_keys; k++) {
    mylog("%s: pkey_ptr='%s', pkey='%s'\n", func, pkey_ptr, pkey);
    if ( keyresult != 0 || strcmp(pkey_ptr, pkey)) {
     num_keys = 0;
     break;
    }
    for (k = 0; k < 2; k++)
     pkey_ptr += strlen(pkey_ptr) + 1;
    keyresult = PG_SQLFetch(hpkey_stmt);
   }
   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 = 0;
   } else if (!strcmp(upd_rule, "RI_FKey_noaction_upd")) {
    upd_rule_type = 3;
   } else if (!strcmp(upd_rule, "RI_FKey_restrict_upd")) {
    upd_rule_type = 3;
   } else if (!strcmp(upd_rule, "RI_FKey_setdefault_upd")) {
    upd_rule_type = 4;
   } else if (!strcmp(upd_rule, "RI_FKey_setnull_upd")) {
    upd_rule_type = 2;
   }
   if (!strcmp(upd_rule, "RI_FKey_cascade_del")) {
    del_rule_type = 0;
   } else if (!strcmp(upd_rule, "RI_FKey_noaction_del")) {
    del_rule_type = 3;
   } else if (!strcmp(upd_rule, "RI_FKey_restrict_del")) {
    del_rule_type = 3;
   } else if (!strcmp(upd_rule, "RI_FKey_setdefault_del")) {
    del_rule_type = 4;
   } else if (!strcmp(upd_rule, "RI_FKey_setnull_del")) {
    del_rule_type = 2;
   }
   pkey_ptr = trig_args;
   for (i = 0; i < 5; i++)
    pkey_ptr += strlen(pkey_ptr) + 1;
   for (k = 0; k < num_keys; k++) {
    row = (TupleNode *)malloc(sizeof(TupleNode) + (result_cols - 1) * sizeof(TupleField));
    mylog("%s: pk_table = '%s', pkey_ptr = '%s'\n", func, pk_table, pkey_ptr);
    set_tuplefield_null(&row->tuple[0]);
    set_tuplefield_string(&row->tuple[1], "");
    set_tuplefield_string(&row->tuple[2], pk_table);
    set_tuplefield_string(&row->tuple[3], pkey_ptr);
    mylog("%s: fk_table_needed = '%s', fkey_ptr = '%s'\n", func, fk_table_needed, fkey_ptr);
    set_tuplefield_null(&row->tuple[4]);
    set_tuplefield_string(&row->tuple[5], "");
    set_tuplefield_string(&row->tuple[6], fk_table_needed);
    set_tuplefield_string(&row->tuple[7], fkey_ptr);
    mylog("%s: upd_rule_type = '%i', del_rule_type = '%i'\n, trig_name = '%s'", func, upd_rule_type, del_rule_type, trig_args);
    set_tuplefield_int2(&row->tuple[8], (short) (k + 1));
    set_tuplefield_int2(&row->tuple[9], (short) upd_rule_type);
    set_tuplefield_int2(&row->tuple[10], (short) del_rule_type);
    set_tuplefield_null(&row->tuple[11]);
    set_tuplefield_null(&row->tuple[12]);
    set_tuplefield_string(&row->tuple[13], trig_args);
    (TL_add_tuple(stmt->result->manual_tuples, row));
    for (i = 0; i < 2; i++) {
     fkey_ptr += strlen(fkey_ptr) + 1;
     pkey_ptr += strlen(pkey_ptr) + 1;
    }
   }
   result = PG_SQLFetch(htbl_stmt);
  }
  PG_SQLFreeStmt(hpkey_stmt, 1);
 }
    else if (pk_table_needed[0] != '\0') {
  sprintf(tables_query, "SELECT	pg_trigger.tgargs, "
        "		pg_trigger.tgnargs, "
        "		pg_trigger.tgdeferrable, "
        "		pg_trigger.tginitdeferred, "
        "		pg_proc.proname, "
        "		pg_proc_1.proname "
        "FROM	pg_class pg_class, "
        "		pg_class pg_class_1, "
        "		pg_class pg_class_2, "
        "		pg_proc pg_proc, "
        "		pg_proc pg_proc_1, "
        "		pg_trigger pg_trigger, "
        "		pg_trigger pg_trigger_1, "
        "		pg_trigger pg_trigger_2 "
        "WHERE	pg_trigger.tgconstrrelid = pg_class.oid "
        "	AND pg_trigger.tgrelid = pg_class_1.oid "
        "	AND pg_trigger_1.tgfoid = pg_proc_1.oid "
        "	AND pg_trigger_1.tgconstrrelid = pg_class_1.oid "
        "	AND pg_trigger_2.tgconstrrelid = pg_class_2.oid "
        "	AND pg_trigger_2.tgfoid = pg_proc.oid "
        "	AND pg_class_2.oid = pg_trigger.tgrelid "
        "	AND ("
        "		 (pg_class.relname='%s') "
        "	AND  (pg_proc.proname Like '%%upd') "
        "	AND  (pg_proc_1.proname Like '%%del')"
        "	AND	 (pg_trigger_1.tgrelid = pg_trigger.tgconstrrelid) "
        "	AND	 (pg_trigger_2.tgrelid = pg_trigger.tgconstrrelid) "
        "		)",
    pk_table_needed);
  result = PG_SQLExecDirect(htbl_stmt, tables_query, strlen(tables_query));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), SC_create_errormsg((StatementClass *)htbl_stmt));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 1, (-2),
       trig_args, sizeof(trig_args), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 2, 5,
       &trig_nargs, 0, ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 3, 1,
       trig_deferrable, sizeof(trig_deferrable), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 4, 1,
       trig_initdeferred, sizeof(trig_initdeferred), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 5, 1,
       upd_rule, sizeof(upd_rule), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 6, 1,
       del_rule, sizeof(del_rule), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLFetch(htbl_stmt);
  if (result == 100)
   return 0;
  if(result != 0) {
   SC_set_error(stmt, (tbl_stmt->__error_number), SC_create_errormsg((StatementClass *)htbl_stmt));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  while (result == 0) {
   num_keys = (trig_nargs - 4) / 2;;
   if (!strcmp(upd_rule, "RI_FKey_cascade_upd")) {
    upd_rule_type = 0;
   } else if (!strcmp(upd_rule, "RI_FKey_noaction_upd")) {
    upd_rule_type = 3;
   } else if (!strcmp(upd_rule, "RI_FKey_restrict_upd")) {
    upd_rule_type = 3;
   } else if (!strcmp(upd_rule, "RI_FKey_setdefault_upd")) {
    upd_rule_type = 4;
   } else if (!strcmp(upd_rule, "RI_FKey_setnull_upd")) {
    upd_rule_type = 2;
   }
   if (!strcmp(upd_rule, "RI_FKey_cascade_del")) {
    del_rule_type = 0;
   } else if (!strcmp(upd_rule, "RI_FKey_noaction_del")) {
    del_rule_type = 3;
   } else if (!strcmp(upd_rule, "RI_FKey_restrict_del")) {
    del_rule_type = 3;
   } else if (!strcmp(upd_rule, "RI_FKey_setdefault_del")) {
    del_rule_type = 4;
   } else if (!strcmp(upd_rule, "RI_FKey_setnull_del")) {
    del_rule_type = 2;
   }
   mylog("Foreign Key Case#1: trig_nargs = %d, num_keys = %d\n", trig_nargs, num_keys);
   pkey_ptr = trig_args;
   for (i = 0; i < 5; i++)
    pkey_ptr += strlen(pkey_ptr) + 1;
   fk_table = trig_args;
   fk_table += strlen(fk_table) + 1;
   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);
     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);
    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_int2(&row->tuple[8], (short) (k + 1));
    mylog("upd_rule = %d, del_rule= %d", upd_rule_type, del_rule_type);
    (((short) upd_rule_type) != -1 ? set_tuplefield_int2(&row->tuple[9], ((short) upd_rule_type)) : set_tuplefield_null(&row->tuple[9]));
    (((short) del_rule_type) != -1 ? set_tuplefield_int2(&row->tuple[10], ((short) del_rule_type)) : set_tuplefield_null(&row->tuple[10]));
     set_tuplefield_null(&row->tuple[11]);
     set_tuplefield_null(&row->tuple[12]);
    set_tuplefield_string(&row->tuple[13], trig_args);
    (TL_add_tuple(stmt->result->manual_tuples, row));
    for (j = 0; j < 2; j++) {
     pkey_ptr += strlen(pkey_ptr) + 1;
     fkey_ptr += strlen(fkey_ptr) + 1;
    }
   }
   result = PG_SQLFetch(htbl_stmt);
  }
    }
 else {
  SC_set_error(stmt, 8, "No tables specified to SQLForeignKeys.");
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(htbl_stmt, 1);
  return (-1);
 }
 PG_SQLFreeStmt(htbl_stmt, 1);
 mylog("SQLForeignKeys(): EXIT, stmt=%u\n", stmt);
    return 0;
}

canonical_original_code:
short SQLForeignKeys(void *hstmt, unsigned char *szPkTableQualifier, short cbPkTableQualifier, unsigned char *szPkTableOwner, short cbPkTableOwner, unsigned char *szPkTableName, short cbPkTableName, unsigned char *szFkTableQualifier, short cbFkTableQualifier, unsigned char *szFkTableOwner, short cbFkTableOwner, unsigned char *szFkTableName, short cbFkTableName)
{
static char *func = "SQLForeignKeys";
struct StatementClass_ *stmt = (StatementClass *) hstmt;
struct TupleNode_ *row;
void *htbl_stmt; void *hpkey_stmt;
struct StatementClass_ *tbl_stmt;
short result; short keyresult;
char tables_query[65536];
char trig_deferrable[2];
char trig_initdeferred[2];
char trig_args[1024];
char upd_rule[32]; char del_rule[32];
char pk_table_needed[-1];
char fk_table_needed[-1];
char *pkey_ptr; char *fkey_ptr; char *pk_table; char *fk_table;
int i; int j; int k; int num_keys;
short trig_nargs; short upd_rule_type = 0; short del_rule_type = 0;
char pkey[128];
short result_cols;
 mylog("%s: entering...stmt=%u\n", func, stmt);
    if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
        return (-2);
    }
 stmt->manual_result = (int)1;
 stmt->errormsg_created = (int)1;
    stmt->result = QR_Constructor();
    if(!stmt->result) {
 SC_set_error(stmt, 4, "Couldn't allocate memory for SQLForeignKeys result.");
 SC_log_error(func, "", stmt);
        return (-1);
    }
 result_cols = 14;
    extend_bindings(stmt, result_cols);
    QR_set_num_fields(stmt->result, result_cols);
    (CI_set_field_info(stmt->result->fields, 0, "PKTABLE_QUALIFIER", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 1, "PKTABLE_OWNER", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 2, "PKTABLE_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 3, "PKCOLUMN_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 4, "FKTABLE_QUALIFIER", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 5, "FKTABLE_OWNER", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 6, "FKTABLE_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 7, "FKCOLUMN_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 8, "KEY_SEQ", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 9, "UPDATE_RULE", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 10, "DELETE_RULE", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 11, "FK_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 12, "PK_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 13, "TRIGGER_NAME", 25, 128, -1));
    stmt->status = STMT_FINISHED;
    stmt->currTuple = -1;
 stmt->rowset_start = -1;
 stmt->current_col = -1;
    result = PG_SQLAllocStmt( stmt->hdbc, &htbl_stmt);
    if((result != 0) && (result != 1)) {
 SC_set_error(stmt, 4, "Couldn't allocate statement for SQLForeignKeys result.");
 SC_log_error(func, "", stmt);
 return (-1);
    }
 tbl_stmt = (struct StatementClass_ *) htbl_stmt;
 pk_table_needed[0] = '\0';
 fk_table_needed[0] = '\0';
 make_string((char *)szPkTableName, cbPkTableName, pk_table_needed);
 make_string((char *)szFkTableName, cbFkTableName, fk_table_needed);
 if (fk_table_needed[0] != '\0') {
  mylog("%s: entering Foreign Key Case #2", func);
  sprintf(tables_query, "SELECT	pt.tgargs, "
        "		pt.tgnargs, "
        "		pt.tgdeferrable, "
        "		pt.tginitdeferred, "
        "		pg_proc.proname, "
        "		pg_proc_1.proname "
        "FROM	pg_class pc, "
        "		pg_proc pg_proc, "
        "		pg_proc pg_proc_1, "
        "		pg_trigger pg_trigger, "
        "		pg_trigger pg_trigger_1, "
        "		pg_proc pp, "
        "		pg_trigger pt "
        "WHERE	pt.tgrelid = pc.oid "
        "AND pp.oid = pt.tgfoid "
        "AND pg_trigger.tgconstrrelid = pc.oid "
        "AND pg_proc.oid = pg_trigger.tgfoid "
        "AND pg_trigger_1.tgfoid = pg_proc_1.oid "
        "AND pg_trigger_1.tgconstrrelid = pc.oid "
        "AND ((pc.relname='%s') "
        "AND (pp.proname LIKE '%%ins') "
        "AND (pg_proc.proname LIKE '%%upd') "
        "AND (pg_proc_1.proname LIKE '%%del') "
        "AND (pg_trigger.tgrelid=pt.tgconstrrelid) "
        "AND (pg_trigger.tgconstrname=pt.tgconstrname) "
        "AND (pg_trigger_1.tgrelid=pt.tgconstrrelid) "
        "AND (pg_trigger_1.tgconstrname=pt.tgconstrname))",
    fk_table_needed);
  result = PG_SQLExecDirect(htbl_stmt, tables_query, strlen(tables_query));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), SC_create_errormsg((struct StatementClass_ *)htbl_stmt));
   SC_log_error(func, "", stmt);
      PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 1, (-2),
       trig_args, sizeof(trig_args), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 2, 5,
       &trig_nargs, 0, ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 3, 1,
       trig_deferrable, sizeof(trig_deferrable), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 4, 1,
       trig_initdeferred, sizeof(trig_initdeferred), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 5, 1,
       upd_rule, sizeof(upd_rule), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 6, 1,
       del_rule, sizeof(del_rule), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLFetch(htbl_stmt);
  if (result == 100)
   return 0;
  if(result != 0) {
   SC_set_error(stmt, (tbl_stmt->__error_number), SC_create_errormsg((struct StatementClass_ *)htbl_stmt));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  keyresult = PG_SQLAllocStmt( stmt->hdbc, &hpkey_stmt);
  if((keyresult != 0) && (keyresult != 1)) {
   SC_set_error(stmt, 4, "Couldn't allocate statement for SQLForeignKeys (pkeys) result.");
   SC_log_error(func, "", stmt);
   return (-1);
  }
  keyresult = PG_SQLBindCol(hpkey_stmt, 4, 1,
        pkey, sizeof(pkey), ((void *)0));
  if (keyresult != 0) {
   SC_set_error(stmt, 4, "Couldn't bindcol for primary keys for SQLForeignKeys result.");
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(hpkey_stmt, 1);
   return (-1);
  }
  while (result == 0) {
   num_keys = (trig_nargs - 4) / 2;
   mylog("Foreign Key Case#2: trig_nargs = %d, num_keys = %d\n", trig_nargs, num_keys);
   pk_table = trig_args;
   for (k = 0; k < 2; k++)
    pk_table += strlen(pk_table) + 1;
   if (pk_table_needed[0] != '\0') {
    if ( strcmp(pk_table, pk_table_needed)) {
     result = PG_SQLFetch(htbl_stmt);
     continue;
    }
   }
   keyresult = PG_SQLPrimaryKeys(hpkey_stmt, ((void *)0), 0, ((void *)0), 0, (unsigned char *)pk_table, (-3));
   if (keyresult != 0) {
    SC_set_error(stmt, 4, "Couldn't get primary keys for SQLForeignKeys result.");
    SC_log_error(func, "", stmt);
    PG_SQLFreeStmt(hpkey_stmt, 1);
    return (-1);
   }
   keyresult = PG_SQLFetch(hpkey_stmt);
   pkey_ptr = trig_args;
   for (i = 0; i < 5; i++)
    pkey_ptr += strlen(pkey_ptr) + 1;
   for (k = 0; k < num_keys; k++) {
    mylog("%s: pkey_ptr='%s', pkey='%s'\n", func, pkey_ptr, pkey);
    if ( keyresult != 0 || strcmp(pkey_ptr, pkey)) {
     num_keys = 0;
     break;
    }
    for (k = 0; k < 2; k++)
     pkey_ptr += strlen(pkey_ptr) + 1;
    keyresult = PG_SQLFetch(hpkey_stmt);
   }
   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 = 0;
   } else if (!strcmp(upd_rule, "RI_FKey_noaction_upd")) {
    upd_rule_type = 3;
   } else if (!strcmp(upd_rule, "RI_FKey_restrict_upd")) {
    upd_rule_type = 3;
   } else if (!strcmp(upd_rule, "RI_FKey_setdefault_upd")) {
    upd_rule_type = 4;
   } else if (!strcmp(upd_rule, "RI_FKey_setnull_upd")) {
    upd_rule_type = 2;
   }
   if (!strcmp(upd_rule, "RI_FKey_cascade_del")) {
    del_rule_type = 0;
   } else if (!strcmp(upd_rule, "RI_FKey_noaction_del")) {
    del_rule_type = 3;
   } else if (!strcmp(upd_rule, "RI_FKey_restrict_del")) {
    del_rule_type = 3;
   } else if (!strcmp(upd_rule, "RI_FKey_setdefault_del")) {
    del_rule_type = 4;
   } else if (!strcmp(upd_rule, "RI_FKey_setnull_del")) {
    del_rule_type = 2;
   }
   pkey_ptr = trig_args;
   for (i = 0; i < 5; i++)
    pkey_ptr += strlen(pkey_ptr) + 1;
   for (k = 0; k < num_keys; k++) {
    row = (struct TupleNode_ *)malloc(sizeof(TupleNode) + (result_cols - 1) * sizeof(TupleField));
    mylog("%s: pk_table = '%s', pkey_ptr = '%s'\n", func, pk_table, pkey_ptr);
    set_tuplefield_null(&row->tuple[0]);
    set_tuplefield_string(&row->tuple[1], "");
    set_tuplefield_string(&row->tuple[2], pk_table);
    set_tuplefield_string(&row->tuple[3], pkey_ptr);
    mylog("%s: fk_table_needed = '%s', fkey_ptr = '%s'\n", func, fk_table_needed, fkey_ptr);
    set_tuplefield_null(&row->tuple[4]);
    set_tuplefield_string(&row->tuple[5], "");
    set_tuplefield_string(&row->tuple[6], fk_table_needed);
    set_tuplefield_string(&row->tuple[7], fkey_ptr);
    mylog("%s: upd_rule_type = '%i', del_rule_type = '%i'\n, trig_name = '%s'", func, upd_rule_type, del_rule_type, trig_args);
    set_tuplefield_int2(&row->tuple[8], (short) (k + 1));
    set_tuplefield_int2(&row->tuple[9], (short) upd_rule_type);
    set_tuplefield_int2(&row->tuple[10], (short) del_rule_type);
    set_tuplefield_null(&row->tuple[11]);
    set_tuplefield_null(&row->tuple[12]);
    set_tuplefield_string(&row->tuple[13], trig_args);
    (TL_add_tuple(stmt->result->manual_tuples, row));
    for (i = 0; i < 2; i++) {
     fkey_ptr += strlen(fkey_ptr) + 1;
     pkey_ptr += strlen(pkey_ptr) + 1;
    }
   }
   result = PG_SQLFetch(htbl_stmt);
  }
  PG_SQLFreeStmt(hpkey_stmt, 1);
 }
    else if (pk_table_needed[0] != '\0') {
  sprintf(tables_query, "SELECT	pg_trigger.tgargs, "
        "		pg_trigger.tgnargs, "
        "		pg_trigger.tgdeferrable, "
        "		pg_trigger.tginitdeferred, "
        "		pg_proc.proname, "
        "		pg_proc_1.proname "
        "FROM	pg_class pg_class, "
        "		pg_class pg_class_1, "
        "		pg_class pg_class_2, "
        "		pg_proc pg_proc, "
        "		pg_proc pg_proc_1, "
        "		pg_trigger pg_trigger, "
        "		pg_trigger pg_trigger_1, "
        "		pg_trigger pg_trigger_2 "
        "WHERE	pg_trigger.tgconstrrelid = pg_class.oid "
        "	AND pg_trigger.tgrelid = pg_class_1.oid "
        "	AND pg_trigger_1.tgfoid = pg_proc_1.oid "
        "	AND pg_trigger_1.tgconstrrelid = pg_class_1.oid "
        "	AND pg_trigger_2.tgconstrrelid = pg_class_2.oid "
        "	AND pg_trigger_2.tgfoid = pg_proc.oid "
        "	AND pg_class_2.oid = pg_trigger.tgrelid "
        "	AND ("
        "		 (pg_class.relname='%s') "
        "	AND  (pg_proc.proname Like '%%upd') "
        "	AND  (pg_proc_1.proname Like '%%del')"
        "	AND	 (pg_trigger_1.tgrelid = pg_trigger.tgconstrrelid) "
        "	AND	 (pg_trigger_2.tgrelid = pg_trigger.tgconstrrelid) "
        "		)",
    pk_table_needed);
  result = PG_SQLExecDirect(htbl_stmt, tables_query, strlen(tables_query));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), SC_create_errormsg((struct StatementClass_ *)htbl_stmt));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 1, (-2),
       trig_args, sizeof(trig_args), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 2, 5,
       &trig_nargs, 0, ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 3, 1,
       trig_deferrable, sizeof(trig_deferrable), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 4, 1,
       trig_initdeferred, sizeof(trig_initdeferred), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 5, 1,
       upd_rule, sizeof(upd_rule), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLBindCol(htbl_stmt, 6, 1,
       del_rule, sizeof(del_rule), ((void *)0));
  if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  result = PG_SQLFetch(htbl_stmt);
  if (result == 100)
   return 0;
  if(result != 0) {
   SC_set_error(stmt, (tbl_stmt->__error_number), SC_create_errormsg((struct StatementClass_ *)htbl_stmt));
   SC_log_error(func, "", stmt);
   PG_SQLFreeStmt(htbl_stmt, 1);
   return (-1);
  }
  while (result == 0) {
   num_keys = (trig_nargs - 4) / 2;;
   if (!strcmp(upd_rule, "RI_FKey_cascade_upd")) {
    upd_rule_type = 0;
   } else if (!strcmp(upd_rule, "RI_FKey_noaction_upd")) {
    upd_rule_type = 3;
   } else if (!strcmp(upd_rule, "RI_FKey_restrict_upd")) {
    upd_rule_type = 3;
   } else if (!strcmp(upd_rule, "RI_FKey_setdefault_upd")) {
    upd_rule_type = 4;
   } else if (!strcmp(upd_rule, "RI_FKey_setnull_upd")) {
    upd_rule_type = 2;
   }
   if (!strcmp(upd_rule, "RI_FKey_cascade_del")) {
    del_rule_type = 0;
   } else if (!strcmp(upd_rule, "RI_FKey_noaction_del")) {
    del_rule_type = 3;
   } else if (!strcmp(upd_rule, "RI_FKey_restrict_del")) {
    del_rule_type = 3;
   } else if (!strcmp(upd_rule, "RI_FKey_setdefault_del")) {
    del_rule_type = 4;
   } else if (!strcmp(upd_rule, "RI_FKey_setnull_del")) {
    del_rule_type = 2;
   }
   mylog("Foreign Key Case#1: trig_nargs = %d, num_keys = %d\n", trig_nargs, num_keys);
   pkey_ptr = trig_args;
   for (i = 0; i < 5; i++)
    pkey_ptr += strlen(pkey_ptr) + 1;
   fk_table = trig_args;
   fk_table += strlen(fk_table) + 1;
   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 = (struct TupleNode_ *)malloc(sizeof(TupleNode) + (result_cols - 1) * sizeof(TupleField));
    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);
    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_int2(&row->tuple[8], (short) (k + 1));
    mylog("upd_rule = %d, del_rule= %d", upd_rule_type, del_rule_type);
    (((short) upd_rule_type) != -1 ? set_tuplefield_int2(&row->tuple[9], ((short) upd_rule_type)) : set_tuplefield_null(&row->tuple[9]));
    (((short) del_rule_type) != -1 ? set_tuplefield_int2(&row->tuple[10], ((short) del_rule_type)) : set_tuplefield_null(&row->tuple[10]));
     set_tuplefield_null(&row->tuple[11]);
     set_tuplefield_null(&row->tuple[12]);
    set_tuplefield_string(&row->tuple[13], trig_args);
    (TL_add_tuple(stmt->result->manual_tuples, row));
    for (j = 0; j < 2; j++) {
     pkey_ptr += strlen(pkey_ptr) + 1;
     fkey_ptr += strlen(fkey_ptr) + 1;
    }
   }
   result = PG_SQLFetch(htbl_stmt);
  }
    }
 else {
  SC_set_error(stmt, 8, "No tables specified to SQLForeignKeys.");
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(htbl_stmt, 1);
  return (-1);
 }
 PG_SQLFreeStmt(htbl_stmt, 1);
 mylog("SQLForeignKeys(): EXIT, stmt=%u\n", stmt);
    return 0;
}

variable_types:
hstmt
void *

variable_types:
szPkTableQualifier
unsigned char *

variable_types: cbPkTableQualifier short

variable_types:
szPkTableOwner
unsigned char *

variable_types: cbPkTableOwner short

variable_types:
szPkTableName
unsigned char *

variable_types: cbPkTableName short

variable_types:
szFkTableQualifier
unsigned char *

variable_types: cbFkTableQualifier short

variable_types:
szFkTableOwner
unsigned char *

variable_types: cbFkTableOwner short

variable_types:
szFkTableName
unsigned char *

variable_types: cbFkTableName short

variable_types: struct StatementClass_ { struct ConnectionClass_ { void *henv; struct StatementOptions_ { int maxRows; int maxLength; int rowset_size; int keyset_size; int cursor_type; int scroll_concurrency; int retrieve_data; int bind_size; int use_bookmarks; } stmtOptions; char *__error_message; int __error_number; enum CONN_Status { CONN_NOT_CONNECTED=0, CONN_CONNECTED=1, CONN_DOWN=2, CONN_EXECUTING=3 } status; struct ConnInfo { char dsn[256]; char desc[256]; char driver[256]; char server[256]; char database[256]; char username[256]; char password[256]; char conn_settings[4096]; char protocol[10]; char port[10]; char uds[4096]; char onlyread[10]; char fake_oid_index[10]; char show_oid_column[10]; char row_versioning[10]; char show_system_tables[10]; char translation_dll[256]; char translation_option[10]; char focus_password; } connInfo; struct StatementClass_ **stmts; int num_stmts; struct SocketClass_ { int buffer_filled_in; int buffer_filled_out; int buffer_read_in; unsigned char *buffer_in; unsigned char *buffer_out; int socket; char *errormsg; int errornumber; char reverse; } *sock; int lobj_type; int ntables; struct col_info { struct QResultClass_ { struct ColumnInfoClass_ { short num_fields; char **name; unsigned int *adtid; short *adtsize; short *display_size; int *atttypmod; } *fields; struct TupleListClass_ { int num_fields; int num_tuples; struct TupleNode_ { struct TupleNode_ *prev; struct TupleField_ { int len; void *value; } tuple[1]; } *list_start; int last_indexed; } *manual_tuples; struct ConnectionClass_ *conn; int fetch_count; int fcount; int currTuple; int base; int num_fields; int cache_size; int rowset_size; enum QueryResultCode_ { PGRES_EMPTY_QUERY=0, PGRES_COMMAND_OK=1, PGRES_TUPLES_OK=2, PGRES_COPY_OUT=3, PGRES_COPY_IN=4, PGRES_BAD_RESPONSE=5, PGRES_NONFATAL_ERROR=6, PGRES_FATAL_ERROR=7, PGRES_FIELDS_OK=8, PGRES_END_TUPLES=9, PGRES_INTERNAL_ERROR=10 } status; char *message; char *cursor; char *command; char *notice; struct TupleField_ *backend_tuples; struct TupleField_ *tupleField; char inTuples; char aborted; } *result; char name[-1]; } **col_info; long translation_option; void *translation_handle; int (*DataSourceToDriver)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); int (*DriverToDataSource)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); short driver_version; char transact_status; char errormsg_created; char pg_version[128]; float pg_version_number; short pg_version_major; short pg_version_minor; char ms_jet; char unicode; char result_uncommitted; char schema_support; char *client_encoding; char *server_encoding; int ccsc; int be_pid; int be_key; unsigned int isolation; char *current_schema; int num_discardp; char **discardp; } *hdbc; struct QResultClass_ *result; void **phstmt; struct StatementOptions_ options; enum STMT_Status { STMT_ALLOCATED=0, STMT_READY=1, STMT_PREMATURE=2, STMT_FINISHED=3, STMT_EXECUTING=4 } status; char *__error_message; int __error_number; struct BindInfoClass_ { int buflen; int data_left; char *buffer; long *used; short returntype; } *bindings; struct BindInfoClass_ bookmark; int bindings_allocated; int parameters_allocated; struct ParameterInfoClass_ { int buflen; char *buffer; long *used; short paramType; short CType; short SQLType; unsigned int precision; short scale; unsigned int lobj_oid; int *EXEC_used; char *EXEC_buffer; char data_at_exec; } *parameters; int currTuple; int save_rowset_size; int rowset_start; int bind_row; int last_fetch_count; int current_col; int lobj_fd; char *statement; struct TABLE_INFO { struct col_info *col_info; char name[-1]; char alias[-1]; } **ti; struct FIELD_INFO { struct TABLE_INFO *ti; int precision; int display_size; int length; int type; char nullable; char func; char expr; char quote; char dquote; char numeric; char dot[-1]; char name[-1]; char alias[-1]; } **fi; int nfld; int ntab; int parse_status; int statement_type; int data_at_exec; int current_exec_param; char put_data; char errormsg_created; char manual_result; char prepare; char internal; char cursor_name[-1]; char stmt_with_params[65536]; int reexecute; } *

variable_types: result short

variable_types: keyresult short

variable_types: i int

variable_types: j int

variable_types: k int

variable_types:
pkey
char [128]

return_type: short

user_defined_types: struct StatementClass_ { struct ConnectionClass_ *hdbc; struct QResultClass_ *result; void **phstmt; struct StatementOptions_ options; enum STMT_Status status; char *__error_message; int __error_number; struct BindInfoClass_ *bindings; struct BindInfoClass_ bookmark; int bindings_allocated; int parameters_allocated; struct ParameterInfoClass_ *parameters; int currTuple; int save_rowset_size; int rowset_start; int bind_row; int last_fetch_count; int current_col; int lobj_fd; char *statement; struct TABLE_INFO **ti; struct FIELD_INFO **fi; int nfld; int ntab; int parse_status; int statement_type; int data_at_exec; int current_exec_param; char put_data; char errormsg_created; char manual_result; char prepare; char internal; char cursor_name[-1]; char stmt_with_params[65536]; int reexecute; }

user_defined_types: struct ConnectionClass_ { void *henv; struct StatementOptions_ stmtOptions; char *__error_message; int __error_number; enum CONN_Status status; struct ConnInfo connInfo; struct StatementClass_ **stmts; int num_stmts; struct SocketClass_ *sock; int lobj_type; int ntables; struct col_info **col_info; long translation_option; void *translation_handle; int (*DataSourceToDriver)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); int (*DriverToDataSource)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); short driver_version; char transact_status; char errormsg_created; char pg_version[128]; float pg_version_number; short pg_version_major; short pg_version_minor; char ms_jet; char unicode; char result_uncommitted; char schema_support; char *client_encoding; char *server_encoding; int ccsc; int be_pid; int be_key; unsigned int isolation; char *current_schema; int num_discardp; char **discardp; }


SQLGetCursorName

decompiled_code:
__int64 __fastcall SQLGetCursorName(__int64 a1, char *a2, __int16 a3)
{
int v4; // eax
__int64 v5; // rdi
__int64 result; // rax

if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLGetCursorName.c", "SQLGetCursorName.c", 30LL, 1LL, 1LL, a1 + 136);
if ( a2 )
{
strncpy(a2, (const char *)(a1 + 24), a3);
v4 = strlen((const char *)(a1 + 24));
v5 = *(_QWORD *)(a1 + 1160);
if ( a3 < v4 )
{
logPushMsg(
v5,
"SQLGetCursorName.c",
"SQLGetCursorName.c",
53LL,
1LL,
1LL,
"SQL_SUCCESS_WITH_INFO Cursor was truncated");
result = 1LL;
}
else
{
logPushMsg(v5, "SQLGetCursorName.c", "SQLGetCursorName.c", 57LL, 0LL, 0LL, "SQL_SUCCESS");
result = 0LL;
}
}
else
{
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLGetCursorName.c",
"SQLGetCursorName.c",
34LL,
1LL,
1LL,
"SQL_ERROR No cursor name.");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char *a2, __int16 a3)
{
int v4; // eax
__int64 v5; // rdi
__int64 result; // rax

if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLGetCursorName.c", "SQLGetCursorName.c", 30LL, 1LL, 1LL, a1 + 136);
if ( a2 )
{
strncpy(a2, (const char *)(a1 + 24), a3);
v4 = strlen((const char *)(a1 + 24));
v5 = *(_QWORD *)(a1 + 1160);
if ( a3 < v4 )
{
logPushMsg(
v5,
"SQLGetCursorName.c",
"SQLGetCursorName.c",
53LL,
1LL,
1LL,
"SQL_SUCCESS_WITH_INFO Cursor was truncated");
result = 1LL;
}
else
{
logPushMsg(v5, "SQLGetCursorName.c", "SQLGetCursorName.c", 57LL, 0LL, 0LL, "SQL_SUCCESS");
result = 0LL;
}
}
else
{
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLGetCursorName.c",
"SQLGetCursorName.c",
34LL,
1LL,
1LL,
"SQL_ERROR No cursor name.");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
RETCODE SQLGetCursorName(
        HSTMT hstmt,
        UCHAR *szCursor,
        SWORD cbCursorMax,
        SWORD *pcbCursor)
{
static char* const func="SQLGetCursorName";
StatementClass *stmt = (StatementClass *) hstmt;
int len = 0;
RETCODE result;
mylog("SQLGetCursorName: hstmt=%u, szCursor=%u, cbCursorMax=%d, pcbCursor=%u\n", hstmt, szCursor, cbCursorMax, pcbCursor);
 if ( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 if ( stmt->cursor_name[0] == '\0') {
  SC_set_error(stmt, 18, "No Cursor name available");
  SC_log_error(func, "", stmt);
  return (-1);
 }
 result = 0;
 len = strlen(stmt->cursor_name);
 if (szCursor) {
  strncpy_null((char*)szCursor, (char*)stmt->cursor_name, cbCursorMax);
  if (len >= cbCursorMax) {
   result = 1;
   SC_set_error(stmt, -2, "The buffer was too small for the result.");
  }
 }
 if (pcbCursor)
  *pcbCursor = len;
 return result;
}

canonical_original_code:
short SQLGetCursorName(void *hstmt, unsigned char *szCursor, short cbCursorMax, short *pcbCursor)
{
static char *func = "SQLGetCursorName";
struct StatementClass_ *stmt = (StatementClass *) hstmt;
int len = 0;
short result;
mylog("SQLGetCursorName: hstmt=%u, szCursor=%u, cbCursorMax=%d, pcbCursor=%u\n", hstmt, szCursor, cbCursorMax, pcbCursor);
 if ( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 if ( stmt->cursor_name[0] == '\0') {
  SC_set_error(stmt, 18, "No Cursor name available");
  SC_log_error(func, "", stmt);
  return (-1);
 }
 result = 0;
 len = strlen(stmt->cursor_name);
 if (szCursor) {
  strncpy_null((char *)szCursor, (char *)stmt->cursor_name, cbCursorMax);
  if (len >= cbCursorMax) {
   result = 1;
   SC_set_error(stmt, -2, "The buffer was too small for the result.");
  }
 }
 if (pcbCursor)
  *pcbCursor = len;
 return result;
}

variable_types:
hstmt
void *

variable_types:
szCursor
unsigned char *

variable_types: cbCursorMax short

variable_types:
pcbCursor
short *

variable_types:
func
char *

variable_types: len int

user_defined_types: enum STMT_Status { STMT_ALLOCATED=0, STMT_READY=1, STMT_PREMATURE=2, STMT_FINISHED=3, STMT_EXECUTING=4 }

user_defined_types: struct BindInfoClass_ { int buflen; int data_left; char *buffer; long *used; short returntype; }


decompiled_code:
__int64 __fastcall TL_Destructor(void *ptr)
{
void **v1; // r13
void **v2; // rbp
int i; // ebx
void **v4; // rbx

mylog("TupleList: in DESTRUCTOR\n");
v1 = (void **)*((_QWORD *)ptr + 1);
if ( v1 )
{
while ( 1 )
{
v2 = v1 + 3;
for ( i = 0; *(_DWORD *)ptr > i; v2 += 2 )
{
if ( *v2 )
free(*v2);
++i;
}
v4 = (void **)v1[1];
free(v1);
if ( !v4 )
break;
v1 = v4;
}
}
free(ptr);
return mylog("TupleList: exit DESTRUCTOR\n");
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
void **v1; // r13
void **v2; // rbp
int i; // ebx
void **v4; // rbx

mylog("TupleList: in DESTRUCTOR\n");
v1 = (void **)*((_QWORD *)ptr + 1);
if ( v1 )
{
while ( 1 )
{
v2 = v1 + 3;
for ( i = 0; *(_DWORD *)ptr > i; v2 += 2 )
{
if ( *v2 )
free(*v2);
++i;
}
v4 = (void **)v1[1];
free(v1);
if ( !v4 )
break;
v1 = v4;
}
}
free(ptr);
return mylog("TupleList: exit DESTRUCTOR\n");
}

original_code:
void
TL_Destructor(TupleListClass *self)
{
int lf;
TupleNode *node, *tp;
 mylog("TupleList: in DESTRUCTOR\n");
    node = self->list_start;
    while(node != ((void *)0)) {
        for (lf=0; lf < self->num_fields; lf++)
            if (node->tuple[lf].value != ((void *)0)) {
                free(node->tuple[lf].value);
            }
        tp = node->next;
        free(node);
        node = tp;
    }
 free(self);
 mylog("TupleList: exit DESTRUCTOR\n");
}

canonical_original_code:
void TL_Destructor(struct TupleListClass_ *self)
{
int lf;
struct TupleNode_ *node; struct TupleNode_ *tp;
 mylog("TupleList: in DESTRUCTOR\n");
    node = self->list_start;
    while(node != ((void *)0)) {
        for (lf=0; lf < self->num_fields; lf++)
            if (node->tuple[lf].value != ((void *)0)) {
                free(node->tuple[lf].value);
            }
        tp = node->next;
        free(node);
        node = tp;
    }
 free(self);
 mylog("TupleList: exit DESTRUCTOR\n");
}

variable_types: struct TupleListClass_ { int num_fields; int num_tuples; struct TupleNode_ { struct TupleNode_ *prev; struct TupleField_ { int len; void *value; } tuple[1]; } *list_start; int last_indexed; } *

variable_types: lf int

return_type: void


original_code:
void *
TL_get_fieldval(TupleListClass *self, int tupleno, short fieldno)
{
int lf;
int delta, from_end;
char end_is_closer, start_is_closer;
TupleNode *rv;
 if (self->last_indexed == -1)
  return ((void *)0);
 if ((tupleno >= self->num_tuples) || (tupleno < 0))
  return ((void *)0);
 if ((fieldno >= self->num_fields) || (fieldno < 0))
  return ((void *)0);
 if (tupleno == self->last_indexed)
  return self->lastref->tuple[fieldno].value;
 delta = tupleno - self->last_indexed;
 from_end = (self->num_tuples - 1) - tupleno;
 start_is_closer = labs(delta) > tupleno;
 end_is_closer = labs(delta) > from_end;
 if (end_is_closer) {
  rv = self->list_end;
  for (lf=0; lf < from_end; lf++)
   rv = rv->prev;
 } else if (start_is_closer) {
  rv = self->list_start;
  for (lf=0; lf < tupleno; lf++)
   rv = rv->next;
 } else {
  rv = self->lastref;
  if (delta < 0) {
   for(lf=0; lf < (-1)*delta; lf++)
    rv = rv->prev;
  } else {
   for (lf=0; lf < delta; lf++)
   rv = rv->next;
  }
 }
 self->lastref = rv;
 self->last_indexed = tupleno;
 return rv->tuple[fieldno].value;
}

canonical_original_code:
void *TL_get_fieldval(struct TupleListClass_ *self, int tupleno, short fieldno)
{
int lf;
int delta; int from_end;
char end_is_closer; char start_is_closer;
struct TupleNode_ *rv;
 if (self->last_indexed == -1)
  return ((void *)0);
 if ((tupleno >= self->num_tuples) || (tupleno < 0))
  return ((void *)0);
 if ((fieldno >= self->num_fields) || (fieldno < 0))
  return ((void *)0);
 if (tupleno == self->last_indexed)
  return self->lastref->tuple[fieldno].value;
 delta = tupleno - self->last_indexed;
 from_end = (self->num_tuples - 1) - tupleno;
 start_is_closer = labs(delta) > tupleno;
 end_is_closer = labs(delta) > from_end;
 if (end_is_closer) {
  rv = self->list_end;
  for (lf=0; lf < from_end; lf++)
   rv = rv->prev;
 } else if (start_is_closer) {
  rv = self->list_start;
  for (lf=0; lf < tupleno; lf++)
   rv = rv->next;
 } else {
  rv = self->lastref;
  if (delta < 0) {
   for(lf=0; lf < (-1)*delta; lf++)
    rv = rv->prev;
  } else {
   for (lf=0; lf < delta; lf++)
   rv = rv->next;
  }
 }
 self->lastref = rv;
 self->last_indexed = tupleno;
 return rv->tuple[fieldno].value;
}

variable_types: tupleno int

variable_types: fieldno short

variable_types: delta int

variable_types: struct TupleNode_ { struct TupleNode_ *prev; struct TupleField_ { int len; void *value; } tuple[1]; } *

return_type: void *


original_code:
char
TL_add_tuple(TupleListClass *self, TupleNode *new_field)
{
 new_field->prev = ((void *)0);
 new_field->next = ((void *)0);
 if (self->list_start == ((void *)0)) {
  self->list_start = new_field;
  self->list_end = new_field;
  self->lastref = new_field;
  self->last_indexed = 0;
 } else {
  self->list_end->next = new_field;
  new_field->prev = self->list_end;
  self->list_end = new_field;
 }
 self->num_tuples++;
 return 1;
}

canonical_original_code:
char TL_add_tuple(struct TupleListClass_ *self, struct TupleNode_ *new_field)
{
 new_field->prev = ((void *)0);
 new_field->next = ((void *)0);
 if (self->list_start == ((void *)0)) {
  self->list_start = new_field;
  self->list_end = new_field;
  self->lastref = new_field;
  self->last_indexed = 0;
 } else {
  self->list_end->next = new_field;
  new_field->prev = self->list_end;
  self->list_end = new_field;
 }
 self->num_tuples++;
 return 1;
}

return_type: char


decompiled_code:
void __fastcall dconn_get_connect_attributes(char *s, void *a2)
{
char *v2; // r13
char *v3; // rdi
char *v4; // rax
const char *v5; // r14
char *v6; // rax
char *v7; // r12

memset(a2, 0, 0x2851uLL);
v2 = strdup(s);
mylog("our_connect_string = '%s'\n", v2);
v3 = v2;
while ( 1 )
{
v4 = strtok(v3, ";");
v5 = v4;
if ( !v4 )
break;
while ( 1 )
{
v6 = strchr(v4, 61);
v3 = v6;
if ( !v6 )
break;
*v6 = 0;
v7 = v6 + 1;
mylog("attribute = '%s', value = '%s'\n", v5, v6 + 1);
copyAttributes(a2, v5, v7);
v4 = strtok(0LL, ";");
v5 = v4;
if ( !v4 )
goto LABEL_5;
}
}
LABEL_5:
free(v2);
}

canonical_decompiled_code:
void __fastcall func0(char *s, void *a2)
{
char *v2; // r13
char *v3; // rdi
char *v4; // rax
const char *v5; // r14
char *v6; // rax
char *v7; // r12

memset(a2, 0, 0x2851uLL);
v2 = strdup(s);
mylog("our_connect_string = '%s'\n", v2);
v3 = v2;
while ( 1 )
{
v4 = strtok(v3, ";");
v5 = v4;
if ( !v4 )
break;
while ( 1 )
{
v6 = strchr(v4, 61);
v3 = v6;
if ( !v6 )
break;
*v6 = 0;
v7 = v6 + 1;
mylog("attribute = '%s', value = '%s'\n", v5, v6 + 1);
copyAttributes(a2, v5, v7);
v4 = strtok(0LL, ";");
v5 = v4;
if ( !v4 )
goto LABEL_5;
}
}
LABEL_5:
free(v2);
}

original_code:
void dconn_get_connect_attributes(UCHAR *connect_string, ConnInfo *ci)
{
char *our_connect_string;
char *pair, *attribute, *value, *equals;
char *strtok_arg;
 memset(ci, 0, sizeof(ConnInfo));
 our_connect_string = strdup((char*)connect_string);
 strtok_arg = our_connect_string;
 mylog("our_connect_string = '%s'\n", our_connect_string);
 while(1) {
  pair = strtok(strtok_arg, ";");
  if(strtok_arg) {
   strtok_arg = 0;
  }
  if(!pair) {
   break;
  }
  equals = strchr(pair, '=');
  if ( ! equals)
   continue;
  *equals = '\0';
  attribute = pair;
  value = equals + 1;
  mylog("attribute = '%s', value = '%s'\n", attribute, value);
  if( !attribute || !value)
   continue;
  copyAttributes(ci, attribute, value);
 }
 free(our_connect_string);
}

canonical_original_code:
void dconn_get_connect_attributes(unsigned char *connect_string, struct ConnInfo *ci)
{
char *our_connect_string;
char *pair; char *attribute; char *value; char *equals;
char *strtok_arg;
 memset(ci, 0, sizeof(ConnInfo));
 our_connect_string = strdup((char *)connect_string);
 strtok_arg = our_connect_string;
 mylog("our_connect_string = '%s'\n", our_connect_string);
 while(1) {
  pair = strtok(strtok_arg, ";");
  if(strtok_arg) {
   strtok_arg = 0;
  }
  if(!pair) {
   break;
  }
  equals = strchr(pair, '=');
  if ( ! equals)
   continue;
  *equals = '\0';
  attribute = pair;
  value = equals + 1;
  mylog("attribute = '%s', value = '%s'\n", attribute, value);
  if( !attribute || !value)
   continue;
  copyAttributes(ci, attribute, value);
 }
 free(our_connect_string);
}

variable_types: struct ConnInfo { char dsn[256]; char desc[256]; char driver[256]; char server[256]; char database[256]; char username[256]; char password[256]; char conn_settings[4096]; char protocol[10]; char port[10]; char uds[4096]; char onlyread[10]; char fake_oid_index[10]; char show_oid_column[10]; char row_versioning[10]; char show_system_tables[10]; char translation_dll[256]; char translation_option[10]; char focus_password; } *

variable_types:
pair
char *

variable_types:
attribute
char *

variable_types:
value
char *

variable_types:
equals
char *


SQLDriverConnect

decompiled_code:
__int64 __fastcall SQLDriverConnect(_BYTE *a1, __int64 a2, __int64 a3, __int16 a4, const char *a5, __int16 a6, _WORD *a7, unsigned __int16 a8)
{
unsigned int v11; // er12
bool v12; // zf
int v13; // eax
int v14; // ebx
unsigned int v15; // er14
char v18[5]; // [rsp+1Bh] [rbp-203Dh] BYREF
char v19[4096]; // [rsp+20h] [rbp-2038h] BYREF
char s[4152]; // [rsp+1020h] [rbp-1038h] BYREF

mylog("%s: entering...\n", "SQLDriverConnect");
if ( a1 )
{
make_string(a3, (unsigned int)a4, v19);
mylog("**** SQLDriverConnect: fDriverCompletion=%d, connStrIn='%s'\n", a8, v19);
qlog("conn=%u, SQLDriverConnect( in)='%s', fDriverCompletion=%d\n", a1, v19, a8);
v11 = 100;
dconn_get_connect_attributes(v19, a1 + 64);
getDSNinfo(a1 + 64, 0LL);
getDSNdefaults(a1 + 64);
CC_initialize_pg_version(a1);
v12 = a1[1344] == 0;
v18[0] = 0;
a1[10384] = 0;
if ( !v12 && a1[832] && a1[1088] && a1[5962] )
{
v13 = (char)CC_connect(a1, 0LL, v18);
if ( v13 < 0 )
{
v11 = -1;
if ( !a8 )
CC_log_error("SQLDriverConnect", "Need password but Driver_NoPrompt", a1);
}
else if ( v13 )
{
makeConnectString(s, a1 + 64);
v14 = strlen(s);
if ( a5 && (strncpy_null(a5, s, (unsigned int)a6), a6 <= v14) )
{
v15 = 1;
CC_set_error(a1, 215LL, "The buffer was too small for the result.");
v11 = 1;
}
else
{
v15 = 0;
v11 = 0;
}
if ( a7 )
*a7 = v14;
mylog("szConnStrOut = '%s'\n", a5);
qlog("conn=%u, SQLDriverConnect(out)='%s'\n", a1, a5);
mylog("SQLDRiverConnect: returning %d\n", v15);
}
else
{
v11 = -1;
CC_log_error("SQLDriverConnect", "Error from CC_Connect", a1);
}
}
}
else
{
v11 = -2;
CC_log_error("SQLDriverConnect", &LC5, 0LL);
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, __int64 a2, __int64 a3, __int16 a4, const char *a5, __int16 a6, _WORD *a7, unsigned __int16 a8)
{
unsigned int v11; // er12
bool v12; // zf
int v13; // eax
int v14; // ebx
unsigned int v15; // er14
char v18[5]; // [rsp+1Bh] [rbp-203Dh] BYREF
char v19[4096]; // [rsp+20h] [rbp-2038h] BYREF
char s[4152]; // [rsp+1020h] [rbp-1038h] BYREF

mylog("%s: entering...\n", "SQLDriverConnect");
if ( a1 )
{
make_string(a3, (unsigned int)a4, v19);
mylog("**** SQLDriverConnect: fDriverCompletion=%d, connStrIn='%s'\n", a8, v19);
qlog("conn=%u, SQLDriverConnect( in)='%s', fDriverCompletion=%d\n", a1, v19, a8);
v11 = 100;
func0(v19, a1 + 64);
getDSNinfo(a1 + 64, 0LL);
getDSNdefaults(a1 + 64);
CC_initialize_pg_version(a1);
v12 = a1[1344] == 0;
v18[0] = 0;
a1[10384] = 0;
if ( !v12 && a1[832] && a1[1088] && a1[5962] )
{
v13 = (char)CC_connect(a1, 0LL, v18);
if ( v13 < 0 )
{
v11 = -1;
if ( !a8 )
CC_log_error("SQLDriverConnect", "Need password but Driver_NoPrompt", a1);
}
else if ( v13 )
{
makeConnectString(s, a1 + 64);
v14 = strlen(s);
if ( a5 && (strncpy_null(a5, s, (unsigned int)a6), a6 <= v14) )
{
v15 = 1;
CC_set_error(a1, 215LL, "The buffer was too small for the result.");
v11 = 1;
}
else
{
v15 = 0;
v11 = 0;
}
if ( a7 )
*a7 = v14;
mylog("szConnStrOut = '%s'\n", a5);
qlog("conn=%u, SQLDriverConnect(out)='%s'\n", a1, a5);
mylog("SQLDRiverConnect: returning %d\n", v15);
}
else
{
v11 = -1;
CC_log_error("SQLDriverConnect", "Error from CC_Connect", a1);
}
}
}
else
{
v11 = -2;
CC_log_error("SQLDriverConnect", &LC5, 0LL);
}
return v11;
}

original_code:
RETCODE SQLDriverConnect(
            HDBC hdbc,
            HWND hwnd,
            UCHAR* szConnStrIn,
            SWORD cbConnStrIn,
            UCHAR* szConnStrOut,
            SWORD cbConnStrOutMax,
            SWORD* pcbConnStrOut,
            UWORD fDriverCompletion)
{
 dbc_t* pdbc = hdbc;
 char *dsn, *server;
 char buf[64];
 int sqlstat = en_00000;
 nnodbc_errstkunset(pdbc->herr);
 server = getkeyvalinstr((char*)szConnStrIn, cbConnStrIn,
         "Server", buf, sizeof(buf));
 if ( ! server )
 {
  dsn = getkeyvalinstr((char*)szConnStrIn, cbConnStrIn,
         "DSN", buf, sizeof(buf));
  if ( !dsn )
   dsn = "default";
  server = getkeyvalbydsn((char*)dsn, (-3), "Server",
          buf, sizeof(buf));
 }
 if ( ! server )
  buf[0] = 0;
 switch ( fDriverCompletion )
 {
 case 0:
  break;
 case 1:
 case 3:
  if ( ! server )
   break;
 case 2:
  if ( nnodbc_conndialog( hwnd, buf, sizeof(buf)) )
  {
   sqlstat = en_IM008;
   break;
  }
  server = buf;
  break;
 default:
  sqlstat = en_S1110;
  break;
 }
 if ( sqlstat != en_00000 )
 {
  pdbc->herr = nnodbc_pusherr(pdbc->herr, sqlstat, 0);
  return (-1);
 }
 if ( !server )
 {
  pdbc->herr = nnodbc_pusherr(pdbc->herr, en_S1000, "[NetNews ODBC][NNODBC driver]" "server name or address not specified");
  return (-1);
 }
 pdbc->hcndes = nntp_connect(server);
 if ( ! pdbc->hcndes )
 {
  pdbc->herr = nnodbc_pusherr(pdbc->herr, en_08001, 0);
  pdbc->herr = nnodbc_pusherr(pdbc->herr, (*__errno_location ()), nntp_errmsg(0));
  return (-1);
 }
 return 0;
}

canonical_original_code:
short SQLDriverConnect(void *hdbc, void *hwnd, unsigned char *szConnStrIn, short cbConnStrIn, unsigned char *szConnStrOut, short cbConnStrOutMax, short *pcbConnStrOut, unsigned short fDriverCompletion)
{
 struct DBC *pdbc = hdbc;
 char *dsn; char *server;
 char buf[64];
 int sqlstat = en_00000;
 nnodbc_errstkunset(pdbc->herr);
 server = getkeyvalinstr((char *)szConnStrIn, cbConnStrIn,
         "Server", buf, sizeof(buf));
 if ( ! server )
 {
  dsn = getkeyvalinstr((char *)szConnStrIn, cbConnStrIn,
         "DSN", buf, sizeof(buf));
  if ( !dsn )
   dsn = "default";
  server = getkeyvalbydsn((char *)dsn, (-3), "Server",
          buf, sizeof(buf));
 }
 if ( ! server )
  buf[0] = 0;
 switch ( fDriverCompletion )
 {
 case 0:
  break;
 case 1:
 case 3:
  if ( ! server )
   break;
 case 2:
  if ( nnodbc_conndialog( hwnd, buf, sizeof(buf)) )
  {
   sqlstat = en_IM008;
   break;
  }
  server = buf;
  break;
 default:
  sqlstat = en_S1110;
  break;
 }
 if ( sqlstat != en_00000 )
 {
  pdbc->herr = nnodbc_pusherr(pdbc->herr, sqlstat, 0);
  return (-1);
 }
 if ( !server )
 {
  pdbc->herr = nnodbc_pusherr(pdbc->herr, en_S1000, "[NetNews ODBC][NNODBC driver]" "server name or address not specified");
  return (-1);
 }
 pdbc->hcndes = nntp_connect(server);
 if ( ! pdbc->hcndes )
 {
  pdbc->herr = nnodbc_pusherr(pdbc->herr, en_08001, 0);
  pdbc->herr = nnodbc_pusherr(pdbc->herr, (*__errno_location ()), nntp_errmsg(0));
  return (-1);
 }
 return 0;
}

variable_types:
hdbc
void *

variable_types:
hwnd
void *

variable_types:
szConnStrIn
unsigned char *

variable_types: cbConnStrIn short

variable_types:
szConnStrOut
unsigned char *

variable_types: cbConnStrOutMax short

variable_types:
pcbConnStrOut
short *

variable_types:
fDriverCompletion
unsigned short

variable_types: struct DBC { void *hcndes; void *henv; struct GSTMT { void *hdbc; void *hstmt; struct GSTMT *next; } *stmt; void *herr; struct DBC *next; } *

variable_types:
dsn
char *

variable_types:
server
char *

variable_types:
buf
char [64]

variable_types: sqlstat int

user_defined_types: struct DBC { void *hcndes; void *henv; struct GSTMT *stmt; void *herr; struct DBC *next; }


SQLRemoveDSNFromIniW

decompiled_code:
__int64 __fastcall SQLRemoveDSNFromIniW(__int64 a1)
{
_BYTE *v1; // rbp
unsigned int v2; // er12

inst_logClear();
v1 = (_BYTE *)single_string_alloc_and_copy(a1);
v2 = SQLRemoveDSNFromIni(v1);
free(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
_BYTE *v1; // rbp
unsigned int v2; // er12

inst_logClear();
v1 = (_BYTE *)single_string_alloc_and_copy(a1);
v2 = func0(v1);
free(v1);
return v2;
}

original_code:
int SQLRemoveDSNFromIniW(LPCWSTR lpszDSN)
{
 char *dsn;
 int ret;
    inst_logClear();
 dsn = _single_string_alloc_and_copy( lpszDSN );
 ret = SQLRemoveDSNFromIni( dsn );
 free( dsn );
 return ret;
}

canonical_original_code:
int SQLRemoveDSNFromIniW(unsigned short *lpszDSN)
{
 char *dsn;
 int ret;
    inst_logClear();
 dsn = _single_string_alloc_and_copy( lpszDSN );
 ret = SQLRemoveDSNFromIni( dsn );
 free( dsn );
 return ret;
}

variable_types:
lpszDSN
unsigned short *

variable_types: ret int


SQLStatistics

decompiled_code:
__int64 __fastcall SQLStatistics(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, _BYTE *a6)
{
__int64 v8; // rdx
__int64 v9; // rcx
_QWORD *v10; // rdi
void *v11; // rdi
__int64 v12; // rdi

if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLStatistics.c", "SQLStatistics.c", 67LL, 1LL, 1LL, a1 + 136);
if ( !a6 )
{
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLStatistics.c", "SQLStatistics.c", 71LL, 1LL, 1LL, "SQL_ERROR No table name");
return 0xFFFFFFFFLL;
}
if ( !*a6 )
{
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLStatistics.c", "SQLStatistics.c", 77LL, 1LL, 1LL, "SQL_ERROR No table name");
return 0xFFFFFFFFLL;
}
v10 = *(_QWORD **)(a1 + 1168);
if ( *v10 )
((void (__fastcall *)(_QWORD *, const char *, __int64, __int64))FreeResults)(v10, "SQLStatistics.c", v8, v9);
v11 = *(void **)(a1 + 128);
if ( v11 )
free(v11);
v12 = *(_QWORD *)(a1 + 1160);
*(_QWORD *)(a1 + 128) = 0LL;
logPushMsg(v12, "SQLStatistics.c", "SQLStatistics.c", 111LL, 0LL, 0LL, "SQL_SUCCESS");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, _BYTE *a6)
{
__int64 v8; // rdx
__int64 v9; // rcx
_QWORD *v10; // rdi
void *v11; // rdi
__int64 v12; // rdi

if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLStatistics.c", "SQLStatistics.c", 67LL, 1LL, 1LL, a1 + 136);
if ( !a6 )
{
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLStatistics.c", "SQLStatistics.c", 71LL, 1LL, 1LL, "SQL_ERROR No table name");
return 0xFFFFFFFFLL;
}
if ( !*a6 )
{
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLStatistics.c", "SQLStatistics.c", 77LL, 1LL, 1LL, "SQL_ERROR No table name");
return 0xFFFFFFFFLL;
}
v10 = *(_QWORD **)(a1 + 1168);
if ( *v10 )
((void (__fastcall *)(_QWORD *, const char *, __int64, __int64))FreeResults)(v10, "SQLStatistics.c", v8, v9);
v11 = *(void **)(a1 + 128);
if ( v11 )
free(v11);
v12 = *(_QWORD *)(a1 + 1160);
*(_QWORD *)(a1 + 128) = 0LL;
logPushMsg(v12, "SQLStatistics.c", "SQLStatistics.c", 111LL, 0LL, 0LL, "SQL_SUCCESS");
return 0LL;
}

original_code:
RETCODE SQLStatistics(
                              HSTMT hstmt,
                              UCHAR * szTableQualifier,
                              SWORD cbTableQualifier,
                              UCHAR * szTableOwner,
                              SWORD cbTableOwner,
                              UCHAR * szTableName,
                              SWORD cbTableName,
                              UWORD fUnique,
                              UWORD fAccuracy)
{
static char* const func="SQLStatistics";
StatementClass *stmt = (StatementClass *) hstmt;
char index_query[65536];
HSTMT hindx_stmt;
RETCODE result;
char *table_name;
char index_name[128];
short fields_vector[8];
char isunique[10], isclustered[10];
SDWORD index_name_len, fields_vector_len;
TupleNode *row;
int i;
HSTMT hcol_stmt;
StatementClass *col_stmt, *indx_stmt;
char column_name[128], relhasrules[128];
char **column_names = 0;
int column_name_len;
int total_columns = 0;
char error = (int)1;
ConnInfo *ci;
char buf[256];
mylog("%s: entering...stmt=%u\n", func, stmt);
    if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
        return (-2);
    }
 stmt->manual_result = (int)1;
 stmt->errormsg_created = (int)1;
 ci = &stmt->hdbc->connInfo;
    stmt->result = QR_Constructor();
    if(!stmt->result) {
 SC_set_error(stmt, 4, "Couldn't allocate memory for SQLStatistics result.");
 SC_log_error(func, "", stmt);
 return (-1);
    }
    extend_bindings(stmt, 13);
    QR_set_num_fields(stmt->result, 13);
    (CI_set_field_info(stmt->result->fields, 0, "TABLE_QUALIFIER", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 1, "TABLE_OWNER", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 2, "TABLE_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 3, "NON_UNIQUE", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 4, "INDEX_QUALIFIER", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 5, "INDEX_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 6, "TYPE", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 7, "SEQ_IN_INDEX", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 8, "COLUMN_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 9, "COLLATION", 18, 1, -1));
    (CI_set_field_info(stmt->result->fields, 10, "CARDINALITY", 23, 4, -1));
    (CI_set_field_info(stmt->result->fields, 11, "PAGES", 23, 4, -1));
    (CI_set_field_info(stmt->result->fields, 12, "FILTER_CONDITION", 25, 128, -1));
 table_name = make_string((char*)szTableName, cbTableName, ((void *)0));
 if ( ! table_name) {
  SC_set_error(stmt, 8, "No table name passed to SQLStatistics.");
  SC_log_error(func, "", stmt);
  return (-1);
 }
 result = PG_SQLAllocStmt( stmt->hdbc, &hcol_stmt);
 if((result != 0) && (result != 1)) {
  SC_set_error(stmt, 4, "SQLAllocStmt failed in SQLStatistics for columns.");
  goto SEEYA;
 }
 col_stmt = (StatementClass *) hcol_stmt;
 col_stmt->internal = (int)1;
 result = PG_SQLColumns(hcol_stmt, (SQLCHAR*)"", 0, (SQLCHAR*)"", 0,
    (SQLCHAR*)table_name, (SWORD) strlen(table_name), (SQLCHAR*)"", 0);
 col_stmt->internal = (int)0;
 if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (col_stmt->__error_number), (col_stmt->__error_message));
   PG_SQLFreeStmt(hcol_stmt, 1);
   goto SEEYA;
 }
 result = PG_SQLBindCol(hcol_stmt, 4, 1,
    column_name, 128, &column_name_len);
 if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (col_stmt->__error_number), (col_stmt->__error_message));
  PG_SQLFreeStmt(hcol_stmt, 1);
  goto SEEYA;
 }
 result = PG_SQLFetch(hcol_stmt);
 while((result == 0) || (result == 1)) {
  total_columns++;
  column_names =
  (char **)realloc(column_names,
     total_columns * sizeof(char *));
  column_names[total_columns-1] =
  (char *)malloc(strlen(column_name)+1);
  strcpy(column_names[total_columns-1], column_name);
  mylog("SQLStatistics: column_name = '%s'\n", column_name);
  result = PG_SQLFetch(hcol_stmt);
 }
 if(result != 100 || total_columns == 0) {
   SC_set_error(stmt, (col_stmt->__error_number), SC_create_errormsg((StatementClass *)hcol_stmt));
   PG_SQLFreeStmt(hcol_stmt, 1);
      goto SEEYA;
 }
 PG_SQLFreeStmt(hcol_stmt, 1);
    result = PG_SQLAllocStmt( stmt->hdbc, &hindx_stmt);
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, 4, "SQLAllocStmt failed in SQLStatistics for indices.");
  goto SEEYA;
    }
 indx_stmt = (StatementClass *) hindx_stmt;
 sprintf(index_query, "select c.relname, i.indkey, i.indisunique"
   ", i.indisclustered, c.relhasrules"
   " from pg_index i, pg_class c, pg_class d"
   " where c.oid = i.indexrelid and d.relname = '%s'"
   " and d.oid = i.indrelid", table_name);
    result = PG_SQLExecDirect(hindx_stmt, index_query, strlen(index_query));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (indx_stmt->__error_number), SC_create_errormsg((StatementClass *)hindx_stmt));
  PG_SQLFreeStmt(hindx_stmt, 1);
    goto SEEYA;
    }
    result = PG_SQLBindCol(hindx_stmt, 1, 1,
                        index_name, 128, &index_name_len);
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (indx_stmt->__error_number), (indx_stmt->__error_message));
  PG_SQLFreeStmt(hindx_stmt, 1);
     goto SEEYA;
    }
    result = PG_SQLBindCol(hindx_stmt, 2, 99,
                        fields_vector, 16, &fields_vector_len);
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (indx_stmt->__error_number), (indx_stmt->__error_message));
  PG_SQLFreeStmt(hindx_stmt, 1);
  goto SEEYA;
    }
    result = PG_SQLBindCol(hindx_stmt, 3, 1,
                        isunique, sizeof(isunique), ((void *)0));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (indx_stmt->__error_number), (indx_stmt->__error_message));
  PG_SQLFreeStmt(hindx_stmt, 1);
  goto SEEYA;
    }
    result = PG_SQLBindCol(hindx_stmt, 4, 1,
                        isclustered, sizeof(isclustered), ((void *)0));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (indx_stmt->__error_number), (indx_stmt->__error_message));
  PG_SQLFreeStmt(hindx_stmt, 1);
  goto SEEYA;
    }
    result = PG_SQLBindCol(hindx_stmt, 5, 1,
                        relhasrules, 128, ((void *)0));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (indx_stmt->__error_number), (indx_stmt->__error_message));
  PG_SQLFreeStmt(hindx_stmt, 1);
        goto SEEYA;
    }
 if ( relhasrules[0] != '1' && atoi(ci->show_oid_column) && atoi(ci->fake_oid_index)) {
  row = (TupleNode *)malloc(sizeof(TupleNode) +
       (13 - 1) * sizeof(TupleField));
  set_tuplefield_string(&row->tuple[0], "");
  set_tuplefield_string(&row->tuple[1], "");
  set_tuplefield_string(&row->tuple[2], table_name);
  set_tuplefield_int2(&row->tuple[3], (short) (globals.unique_index ? (int)0 : (int)1));
  set_tuplefield_string(&row->tuple[4], "");
  sprintf(buf, "%s_idx_fake_oid", table_name);
  set_tuplefield_string(&row->tuple[5], buf);
  set_tuplefield_int2(&row->tuple[6], (short) 3);
  set_tuplefield_int2(&row->tuple[7], (short) 1);
  set_tuplefield_string(&row->tuple[8], "oid");
  set_tuplefield_string(&row->tuple[9], "A");
  set_tuplefield_null(&row->tuple[10]);
  set_tuplefield_null(&row->tuple[11]);
  set_tuplefield_null(&row->tuple[12]);
  (TL_add_tuple(stmt->result->manual_tuples, row));
 }
    result = PG_SQLFetch(hindx_stmt);
    while((result == 0) || (result == 1)) {
  if (fUnique == 1 ||
   (fUnique == 0 && atoi(isunique))) {
   i = 0;
   while(i < 8 && fields_vector[i] != 0) {
    row = (TupleNode *)malloc(sizeof(TupleNode) +
         (13 - 1) * sizeof(TupleField));
    set_tuplefield_string(&row->tuple[0], "");
    set_tuplefield_string(&row->tuple[1], "");
    set_tuplefield_string(&row->tuple[2], table_name);
    if (globals.unique_index)
     set_tuplefield_int2(&row->tuple[3], (short) (atoi(isunique) ? (int)0 : (int)1));
    else
     set_tuplefield_int2(&row->tuple[3], (int)1);
    set_tuplefield_string(&row->tuple[4], "");
    set_tuplefield_string(&row->tuple[5], index_name);
    set_tuplefield_int2(&row->tuple[6], (short) (atoi(isclustered) ? 1 : 3));
    set_tuplefield_int2(&row->tuple[7], (short) (i+1));
    if(fields_vector[i] == -2) {
     set_tuplefield_string(&row->tuple[8], "oid");
     mylog("SQLStatistics: column name = oid\n");
    }
    else if(fields_vector[i] < 0 || fields_vector[i] > total_columns) {
     set_tuplefield_string(&row->tuple[8], "UNKNOWN");
     mylog("SQLStatistics: column name = UNKNOWN\n");
    }
    else {
     set_tuplefield_string(&row->tuple[8], column_names[fields_vector[i]-1]);
     mylog("SQLStatistics: column name = '%s'\n", column_names[fields_vector[i]-1]);
    }
    set_tuplefield_string(&row->tuple[9], "A");
    set_tuplefield_null(&row->tuple[10]);
    set_tuplefield_null(&row->tuple[11]);
    set_tuplefield_null(&row->tuple[12]);
    (TL_add_tuple(stmt->result->manual_tuples, row));
    i++;
   }
  }
        result = PG_SQLFetch(hindx_stmt);
    }
    if(result != 100) {
  SC_set_error(stmt, (indx_stmt->__error_number), SC_create_errormsg((StatementClass *)hindx_stmt));
  PG_SQLFreeStmt(hindx_stmt, 1);
  goto SEEYA;
    }
 PG_SQLFreeStmt(hindx_stmt, 1);
    stmt->status = STMT_FINISHED;
    stmt->currTuple = -1;
 stmt->rowset_start = -1;
 stmt->current_col = -1;
 error = (int)0;
SEEYA:
 free(table_name);
    for(i = 0; i < total_columns; i++) {
  free(column_names[i]);
    }
    free(column_names);
 mylog("SQLStatistics(): EXIT, %s, stmt=%u\n", error ? "error" : "success", stmt);
 if (error) {
  SC_log_error(func, "", stmt);
  return (-1);
 }
 else
  return 0;
}

canonical_original_code:
short SQLStatistics(void *hstmt, unsigned char *szTableQualifier, short cbTableQualifier, unsigned char *szTableOwner, short cbTableOwner, unsigned char *szTableName, short cbTableName, unsigned short fUnique, unsigned short fAccuracy)
{
static char *func = "SQLStatistics";
struct StatementClass_ *stmt = (StatementClass *) hstmt;
char index_query[65536];
void *hindx_stmt;
short result;
char *table_name;
char index_name[128];
short fields_vector[8];
char isunique[10]; char isclustered[10];
long index_name_len; long fields_vector_len;
struct TupleNode_ *row;
int i;
void *hcol_stmt;
struct StatementClass_ *col_stmt; struct StatementClass_ *indx_stmt;
char column_name[128]; char relhasrules[128];
char **column_names = 0;
int column_name_len;
int total_columns = 0;
char error = (int)1;
struct ConnInfo *ci;
char buf[256];
mylog("%s: entering...stmt=%u\n", func, stmt);
    if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
        return (-2);
    }
 stmt->manual_result = (int)1;
 stmt->errormsg_created = (int)1;
 ci = &stmt->hdbc->connInfo;
    stmt->result = QR_Constructor();
    if(!stmt->result) {
 SC_set_error(stmt, 4, "Couldn't allocate memory for SQLStatistics result.");
 SC_log_error(func, "", stmt);
 return (-1);
    }
    extend_bindings(stmt, 13);
    QR_set_num_fields(stmt->result, 13);
    (CI_set_field_info(stmt->result->fields, 0, "TABLE_QUALIFIER", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 1, "TABLE_OWNER", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 2, "TABLE_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 3, "NON_UNIQUE", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 4, "INDEX_QUALIFIER", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 5, "INDEX_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 6, "TYPE", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 7, "SEQ_IN_INDEX", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 8, "COLUMN_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 9, "COLLATION", 18, 1, -1));
    (CI_set_field_info(stmt->result->fields, 10, "CARDINALITY", 23, 4, -1));
    (CI_set_field_info(stmt->result->fields, 11, "PAGES", 23, 4, -1));
    (CI_set_field_info(stmt->result->fields, 12, "FILTER_CONDITION", 25, 128, -1));
 table_name = make_string((char *)szTableName, cbTableName, ((void *)0));
 if ( ! table_name) {
  SC_set_error(stmt, 8, "No table name passed to SQLStatistics.");
  SC_log_error(func, "", stmt);
  return (-1);
 }
 result = PG_SQLAllocStmt( stmt->hdbc, &hcol_stmt);
 if((result != 0) && (result != 1)) {
  SC_set_error(stmt, 4, "SQLAllocStmt failed in SQLStatistics for columns.");
  goto SEEYA;
 }
 col_stmt = (struct StatementClass_ *) hcol_stmt;
 col_stmt->internal = (int)1;
 result = PG_SQLColumns(hcol_stmt, (unsigned char *)"", 0, (unsigned char *)"", 0,
    (unsigned char *)table_name, (short) strlen(table_name), (unsigned char *)"", 0);
 col_stmt->internal = (int)0;
 if((result != 0) && (result != 1)) {
   SC_set_error(stmt, (col_stmt->__error_number), (col_stmt->__error_message));
   PG_SQLFreeStmt(hcol_stmt, 1);
   goto SEEYA;
 }
 result = PG_SQLBindCol(hcol_stmt, 4, 1,
    column_name, 128, &column_name_len);
 if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (col_stmt->__error_number), (col_stmt->__error_message));
  PG_SQLFreeStmt(hcol_stmt, 1);
  goto SEEYA;
 }
 result = PG_SQLFetch(hcol_stmt);
 while((result == 0) || (result == 1)) {
  total_columns++;
  column_names =
  (char **)realloc(column_names,
     total_columns * sizeof(char *));
  column_names[total_columns-1] =
  (char *)malloc(strlen(column_name)+1);
  strcpy(column_names[total_columns-1], column_name);
  mylog("SQLStatistics: column_name = '%s'\n", column_name);
  result = PG_SQLFetch(hcol_stmt);
 }
 if(result != 100 || total_columns == 0) {
   SC_set_error(stmt, (col_stmt->__error_number), SC_create_errormsg((struct StatementClass_ *)hcol_stmt));
   PG_SQLFreeStmt(hcol_stmt, 1);
      goto SEEYA;
 }
 PG_SQLFreeStmt(hcol_stmt, 1);
    result = PG_SQLAllocStmt( stmt->hdbc, &hindx_stmt);
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, 4, "SQLAllocStmt failed in SQLStatistics for indices.");
  goto SEEYA;
    }
 indx_stmt = (struct StatementClass_ *) hindx_stmt;
 sprintf(index_query, "select c.relname, i.indkey, i.indisunique"
   ", i.indisclustered, c.relhasrules"
   " from pg_index i, pg_class c, pg_class d"
   " where c.oid = i.indexrelid and d.relname = '%s'"
   " and d.oid = i.indrelid", table_name);
    result = PG_SQLExecDirect(hindx_stmt, index_query, strlen(index_query));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (indx_stmt->__error_number), SC_create_errormsg((struct StatementClass_ *)hindx_stmt));
  PG_SQLFreeStmt(hindx_stmt, 1);
    goto SEEYA;
    }
    result = PG_SQLBindCol(hindx_stmt, 1, 1,
                        index_name, 128, &index_name_len);
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (indx_stmt->__error_number), (indx_stmt->__error_message));
  PG_SQLFreeStmt(hindx_stmt, 1);
     goto SEEYA;
    }
    result = PG_SQLBindCol(hindx_stmt, 2, 99,
                        fields_vector, 16, &fields_vector_len);
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (indx_stmt->__error_number), (indx_stmt->__error_message));
  PG_SQLFreeStmt(hindx_stmt, 1);
  goto SEEYA;
    }
    result = PG_SQLBindCol(hindx_stmt, 3, 1,
                        isunique, sizeof(isunique), ((void *)0));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (indx_stmt->__error_number), (indx_stmt->__error_message));
  PG_SQLFreeStmt(hindx_stmt, 1);
  goto SEEYA;
    }
    result = PG_SQLBindCol(hindx_stmt, 4, 1,
                        isclustered, sizeof(isclustered), ((void *)0));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (indx_stmt->__error_number), (indx_stmt->__error_message));
  PG_SQLFreeStmt(hindx_stmt, 1);
  goto SEEYA;
    }
    result = PG_SQLBindCol(hindx_stmt, 5, 1,
                        relhasrules, 128, ((void *)0));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (indx_stmt->__error_number), (indx_stmt->__error_message));
  PG_SQLFreeStmt(hindx_stmt, 1);
        goto SEEYA;
    }
 if ( relhasrules[0] != '1' && atoi(ci->show_oid_column) && atoi(ci->fake_oid_index)) {
  row = (struct TupleNode_ *)malloc(sizeof(TupleNode) +
       (13 - 1) * sizeof(TupleField));
  set_tuplefield_string(&row->tuple[0], "");
  set_tuplefield_string(&row->tuple[1], "");
  set_tuplefield_string(&row->tuple[2], table_name);
  set_tuplefield_int2(&row->tuple[3], (short) (globals.unique_index ? (int)0 : (int)1));
  set_tuplefield_string(&row->tuple[4], "");
  sprintf(buf, "%s_idx_fake_oid", table_name);
  set_tuplefield_string(&row->tuple[5], buf);
  set_tuplefield_int2(&row->tuple[6], (short) 3);
  set_tuplefield_int2(&row->tuple[7], (short) 1);
  set_tuplefield_string(&row->tuple[8], "oid");
  set_tuplefield_string(&row->tuple[9], "A");
  set_tuplefield_null(&row->tuple[10]);
  set_tuplefield_null(&row->tuple[11]);
  set_tuplefield_null(&row->tuple[12]);
  (TL_add_tuple(stmt->result->manual_tuples, row));
 }
    result = PG_SQLFetch(hindx_stmt);
    while((result == 0) || (result == 1)) {
  if (fUnique == 1 ||
   (fUnique == 0 && atoi(isunique))) {
   i = 0;
   while(i < 8 && fields_vector[i] != 0) {
    row = (struct TupleNode_ *)malloc(sizeof(TupleNode) +
         (13 - 1) * sizeof(TupleField));
    set_tuplefield_string(&row->tuple[0], "");
    set_tuplefield_string(&row->tuple[1], "");
    set_tuplefield_string(&row->tuple[2], table_name);
    if (globals.unique_index)
     set_tuplefield_int2(&row->tuple[3], (short) (atoi(isunique) ? (int)0 : (int)1));
    else
     set_tuplefield_int2(&row->tuple[3], (int)1);
    set_tuplefield_string(&row->tuple[4], "");
    set_tuplefield_string(&row->tuple[5], index_name);
    set_tuplefield_int2(&row->tuple[6], (short) (atoi(isclustered) ? 1 : 3));
    set_tuplefield_int2(&row->tuple[7], (short) (i+1));
    if(fields_vector[i] == -2) {
     set_tuplefield_string(&row->tuple[8], "oid");
     mylog("SQLStatistics: column name = oid\n");
    }
    else if(fields_vector[i] < 0 || fields_vector[i] > total_columns) {
     set_tuplefield_string(&row->tuple[8], "UNKNOWN");
     mylog("SQLStatistics: column name = UNKNOWN\n");
    }
    else {
     set_tuplefield_string(&row->tuple[8], column_names[fields_vector[i]-1]);
     mylog("SQLStatistics: column name = '%s'\n", column_names[fields_vector[i]-1]);
    }
    set_tuplefield_string(&row->tuple[9], "A");
    set_tuplefield_null(&row->tuple[10]);
    set_tuplefield_null(&row->tuple[11]);
    set_tuplefield_null(&row->tuple[12]);
    (TL_add_tuple(stmt->result->manual_tuples, row));
    i++;
   }
  }
        result = PG_SQLFetch(hindx_stmt);
    }
    if(result != 100) {
  SC_set_error(stmt, (indx_stmt->__error_number), SC_create_errormsg((struct StatementClass_ *)hindx_stmt));
  PG_SQLFreeStmt(hindx_stmt, 1);
  goto SEEYA;
    }
 PG_SQLFreeStmt(hindx_stmt, 1);
    stmt->status = STMT_FINISHED;
    stmt->currTuple = -1;
 stmt->rowset_start = -1;
 stmt->current_col = -1;
 error = (int)0;
SEEYA:
 free(table_name);
    for(i = 0; i < total_columns; i++) {
  free(column_names[i]);
    }
    free(column_names);
 mylog("SQLStatistics(): EXIT, %s, stmt=%u\n", error ? "error" : "success", stmt);
 if (error) {
  SC_log_error(func, "", stmt);
  return (-1);
 }
 else
  return 0;
}

variable_types:
hstmt
void *

variable_types:
szTableQualifier
unsigned char *

variable_types: cbTableQualifier short

variable_types:
szTableOwner
unsigned char *

variable_types: cbTableOwner short

variable_types:
szTableName
unsigned char *

variable_types: cbTableName short

variable_types:
fUnique
unsigned short

variable_types:
fAccuracy
unsigned short

variable_types:
func
char *

variable_types: struct StatementClass_ { struct ConnectionClass_ { void *henv; struct StatementOptions_ { int maxRows; int maxLength; int rowset_size; int keyset_size; int cursor_type; int scroll_concurrency; int retrieve_data; int bind_size; int use_bookmarks; } stmtOptions; char *__error_message; int __error_number; enum CONN_Status { CONN_NOT_CONNECTED=0, CONN_CONNECTED=1, CONN_DOWN=2, CONN_EXECUTING=3 } status; struct ConnInfo { char dsn[256]; char desc[256]; char driver[256]; char server[256]; char database[256]; char username[256]; char password[256]; char conn_settings[4096]; char protocol[10]; char port[10]; char uds[4096]; char onlyread[10]; char fake_oid_index[10]; char show_oid_column[10]; char row_versioning[10]; char show_system_tables[10]; char translation_dll[256]; char translation_option[10]; char focus_password; } connInfo; struct StatementClass_ **stmts; int num_stmts; struct SocketClass_ { int buffer_filled_in; int buffer_filled_out; int buffer_read_in; unsigned char *buffer_in; unsigned char *buffer_out; int socket; char *errormsg; int errornumber; char reverse; } *sock; int lobj_type; int ntables; struct col_info { struct QResultClass_ { struct ColumnInfoClass_ { short num_fields; char **name; unsigned int *adtid; short *adtsize; short *display_size; int *atttypmod; } *fields; struct TupleListClass_ { int num_fields; int num_tuples; struct TupleNode_ { struct TupleNode_ *prev; struct TupleField_ { int len; void *value; } tuple[1]; } *list_start; int last_indexed; } *manual_tuples; struct ConnectionClass_ *conn; int fetch_count; int fcount; int currTuple; int base; int num_fields; int cache_size; int rowset_size; enum QueryResultCode_ { PGRES_EMPTY_QUERY=0, PGRES_COMMAND_OK=1, PGRES_TUPLES_OK=2, PGRES_COPY_OUT=3, PGRES_COPY_IN=4, PGRES_BAD_RESPONSE=5, PGRES_NONFATAL_ERROR=6, PGRES_FATAL_ERROR=7, PGRES_FIELDS_OK=8, PGRES_END_TUPLES=9, PGRES_INTERNAL_ERROR=10 } status; char *message; char *cursor; char *command; char *notice; struct TupleField_ *backend_tuples; struct TupleField_ *tupleField; char inTuples; char aborted; } *result; char name[-1]; } **col_info; long translation_option; void *translation_handle; int (*DataSourceToDriver)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); int (*DriverToDataSource)(unsigned long, short, void *, long, void *, long, long *, unsigned char *, short, short *); short driver_version; char transact_status; char errormsg_created; char pg_version[128]; float pg_version_number; short pg_version_major; short pg_version_minor; char ms_jet; char unicode; char result_uncommitted; char schema_support; char *client_encoding; char *server_encoding; int ccsc; int be_pid; int be_key; unsigned int isolation; char *current_schema; int num_discardp; char **discardp; } *hdbc; struct QResultClass_ *result; void **phstmt; struct StatementOptions_ options; enum STMT_Status { STMT_ALLOCATED=0, STMT_READY=1, STMT_PREMATURE=2, STMT_FINISHED=3, STMT_EXECUTING=4 } status; char *__error_message; int __error_number; struct BindInfoClass_ { int buflen; int data_left; char *buffer; long *used; short returntype; } *bindings; struct BindInfoClass_ bookmark; int bindings_allocated; int parameters_allocated; struct ParameterInfoClass_ { int buflen; char *buffer; long *used; short paramType; short CType; short SQLType; unsigned int precision; short scale; unsigned int lobj_oid; int *EXEC_used; char *EXEC_buffer; char data_at_exec; } *parameters; int currTuple; int save_rowset_size; int rowset_start; int bind_row; int last_fetch_count; int current_col; int lobj_fd; char *statement; struct TABLE_INFO { struct col_info *col_info; char name[-1]; char alias[-1]; } **ti; struct FIELD_INFO { struct TABLE_INFO *ti; int precision; int display_size; int length; int type; char nullable; char func; char expr; char quote; char dquote; char numeric; char dot[-1]; char name[-1]; char alias[-1]; } **fi; int nfld; int ntab; int parse_status; int statement_type; int data_at_exec; int current_exec_param; char put_data; char errormsg_created; char manual_result; char prepare; char internal; char cursor_name[-1]; char stmt_with_params[65536]; int reexecute; } *

variable_types: result short

variable_types:
isunique
char [10]

variable_types:
isclustered
char [10]

variable_types: i int

variable_types:
relhasrules
char [128]

variable_types: error char

variable_types: struct ConnInfo { char dsn[256]; char desc[256]; char driver[256]; char server[256]; char database[256]; char username[256]; char password[256]; char conn_settings[4096]; char protocol[10]; char port[10]; char uds[4096]; char onlyread[10]; char fake_oid_index[10]; char show_oid_column[10]; char row_versioning[10]; char show_system_tables[10]; char translation_dll[256]; char translation_option[10]; char focus_password; } *

variable_types:
buf
char [256]