SQLSpecialColumns

decompiled_code:
__int64 __fastcall SQLSpecialColumns(__int64 a1)
{
__int64 result; // rax

result = 4294967294LL;
if ( a1 )
{
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLSpecialColumns.c", "SQLSpecialColumns.c", 46LL, 1LL, 1LL, a1 + 136);
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLSpecialColumns.c",
"SQLSpecialColumns.c",
52LL,
1LL,
1LL,
"SQL_ERROR This function not supported");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax

result = 4294967294LL;
if ( a1 )
{
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLSpecialColumns.c", "SQLSpecialColumns.c", 46LL, 1LL, 1LL, a1 + 136);
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLSpecialColumns.c",
"SQLSpecialColumns.c",
52LL,
1LL,
1LL,
"SQL_ERROR This function not supported");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
RETCODE SQLSpecialColumns(
                                  HSTMT hstmt,
                                  UWORD fColType,
                                  UCHAR * szTableQualifier,
                                  SWORD cbTableQualifier,
                                  UCHAR * szTableOwner,
                                  SWORD cbTableOwner,
                                  UCHAR * szTableName,
                                  SWORD cbTableName,
                                  UWORD fScope,
                                  UWORD fNullable)
{
static char* const func = "SQLSpecialColumns";
TupleNode *row;
StatementClass *stmt = (StatementClass *) hstmt;
ConnInfo *ci;
HSTMT hcol_stmt;
StatementClass *col_stmt;
char columns_query[65536];
RETCODE result;
char relhasrules[128];
mylog("%s: entering...stmt=%u\n", func, stmt);
    if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
        return (-2);
    }
 ci = &stmt->hdbc->connInfo;
 stmt->manual_result = (int)1;
 sprintf(columns_query, "select c.relhasrules "
  "from pg_user u, pg_class c where "
  "u.usesysid = c.relowner");
 my_strcat(columns_query, " and c.relname like '%.*s'", (char*)szTableName, cbTableName);
 my_strcat(columns_query, " and u.usename like '%.*s'", (char*)szTableOwner, cbTableOwner);
    result = PG_SQLAllocStmt( stmt->hdbc, &hcol_stmt);
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, 4, "Couldn't allocate statement for SQLSpecialColumns result.");
  SC_log_error(func, "", stmt);
        return (-1);
    }
 col_stmt = (StatementClass *) hcol_stmt;
 mylog("SQLSpecialColumns: hcol_stmt = %u, col_stmt = %u\n", hcol_stmt, col_stmt);
    result = PG_SQLExecDirect(hcol_stmt, columns_query,
                           strlen(columns_query));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (col_stmt->__error_number), SC_create_errormsg((StatementClass *)hcol_stmt));
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(hcol_stmt, 1);
        return (-1);
    }
    result = PG_SQLBindCol(hcol_stmt, 1, 1,
                        relhasrules, 128, ((void *)0));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (col_stmt->__error_number), (col_stmt->__error_message));
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(hcol_stmt, 1);
        return (-1);
    }
 result = PG_SQLFetch(hcol_stmt);
 PG_SQLFreeStmt(hcol_stmt, 1);
    stmt->result = QR_Constructor();
    extend_bindings(stmt, 8);
    QR_set_num_fields(stmt->result, 8);
    (CI_set_field_info(stmt->result->fields, 0, "SCOPE", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 1, "COLUMN_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 2, "DATA_TYPE", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 3, "TYPE_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 4, "PRECISION", 23, 4, -1));
    (CI_set_field_info(stmt->result->fields, 5, "LENGTH", 23, 4, -1));
    (CI_set_field_info(stmt->result->fields, 6, "SCALE", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 7, "PSEUDO_COLUMN", 21, 2, -1));
    if ( relhasrules[0] != '1' ) {
  if(fColType == 1) {
   row = (TupleNode *)malloc(sizeof(TupleNode) + (8 - 1) * sizeof(TupleField));
   set_tuplefield_int2(&row->tuple[0], 2);
   set_tuplefield_string(&row->tuple[1], "oid");
   set_tuplefield_int2(&row->tuple[2], pgtype_to_sqltype(stmt, 26));
   set_tuplefield_string(&row->tuple[3], "OID");
   set_tuplefield_int4(&row->tuple[4], pgtype_precision(stmt, 26, -1, -1));
   set_tuplefield_int4(&row->tuple[5], pgtype_length(stmt, 26, -1, -1));
   set_tuplefield_int2(&row->tuple[6], pgtype_scale(stmt, 26, -1));
   set_tuplefield_int2(&row->tuple[7], 2);
   (TL_add_tuple(stmt->result->manual_tuples, row));
  } else if(fColType == 2) {
   short the_type = 23;
   if (atoi(ci->row_versioning)) {
    row = (TupleNode *)malloc(sizeof(TupleNode) + (8 - 1) * sizeof(TupleField));
    set_tuplefield_null(&row->tuple[0]);
    set_tuplefield_string(&row->tuple[1], "xmin");
    set_tuplefield_int2(&row->tuple[2], pgtype_to_sqltype(stmt, the_type));
    set_tuplefield_string(&row->tuple[3], pgtype_to_name(stmt, the_type));
    set_tuplefield_int4(&row->tuple[4], pgtype_precision(stmt, the_type, -1, -1));
    set_tuplefield_int4(&row->tuple[5], pgtype_length(stmt, the_type, -1, -1));
    set_tuplefield_int2(&row->tuple[6], pgtype_scale(stmt, the_type, -1));
    set_tuplefield_int2(&row->tuple[7], 2);
    (TL_add_tuple(stmt->result->manual_tuples, row));
   }
  }
 }
    stmt->status = STMT_FINISHED;
    stmt->currTuple = -1;
 stmt->rowset_start = -1;
 stmt->current_col = -1;
 mylog("SQLSpecialColumns(): EXIT,  stmt=%u\n", stmt);
    return 0;
}

canonical_original_code:
short SQLSpecialColumns(void *hstmt, unsigned short fColType, unsigned char *szTableQualifier, short cbTableQualifier, unsigned char *szTableOwner, short cbTableOwner, unsigned char *szTableName, short cbTableName, unsigned short fScope, unsigned short fNullable)
{
static char *func = "SQLSpecialColumns";
struct TupleNode_ *row;
struct StatementClass_ *stmt = (StatementClass *) hstmt;
struct ConnInfo *ci;
void *hcol_stmt;
struct StatementClass_ *col_stmt;
char columns_query[65536];
short result;
char relhasrules[128];
mylog("%s: entering...stmt=%u\n", func, stmt);
    if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
        return (-2);
    }
 ci = &stmt->hdbc->connInfo;
 stmt->manual_result = (int)1;
 sprintf(columns_query, "select c.relhasrules "
  "from pg_user u, pg_class c where "
  "u.usesysid = c.relowner");
 my_strcat(columns_query, " and c.relname like '%.*s'", (char *)szTableName, cbTableName);
 my_strcat(columns_query, " and u.usename like '%.*s'", (char *)szTableOwner, cbTableOwner);
    result = PG_SQLAllocStmt( stmt->hdbc, &hcol_stmt);
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, 4, "Couldn't allocate statement for SQLSpecialColumns result.");
  SC_log_error(func, "", stmt);
        return (-1);
    }
 col_stmt = (struct StatementClass_ *) hcol_stmt;
 mylog("SQLSpecialColumns: hcol_stmt = %u, col_stmt = %u\n", hcol_stmt, col_stmt);
    result = PG_SQLExecDirect(hcol_stmt, columns_query,
                           strlen(columns_query));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (col_stmt->__error_number), SC_create_errormsg((struct StatementClass_ *)hcol_stmt));
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(hcol_stmt, 1);
        return (-1);
    }
    result = PG_SQLBindCol(hcol_stmt, 1, 1,
                        relhasrules, 128, ((void *)0));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (col_stmt->__error_number), (col_stmt->__error_message));
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(hcol_stmt, 1);
        return (-1);
    }
 result = PG_SQLFetch(hcol_stmt);
 PG_SQLFreeStmt(hcol_stmt, 1);
    stmt->result = QR_Constructor();
    extend_bindings(stmt, 8);
    QR_set_num_fields(stmt->result, 8);
    (CI_set_field_info(stmt->result->fields, 0, "SCOPE", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 1, "COLUMN_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 2, "DATA_TYPE", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 3, "TYPE_NAME", 25, 128, -1));
    (CI_set_field_info(stmt->result->fields, 4, "PRECISION", 23, 4, -1));
    (CI_set_field_info(stmt->result->fields, 5, "LENGTH", 23, 4, -1));
    (CI_set_field_info(stmt->result->fields, 6, "SCALE", 21, 2, -1));
    (CI_set_field_info(stmt->result->fields, 7, "PSEUDO_COLUMN", 21, 2, -1));
    if ( relhasrules[0] != '1' ) {
  if(fColType == 1) {
   row = (struct TupleNode_ *)malloc(sizeof(TupleNode) + (8 - 1) * sizeof(TupleField));
   set_tuplefield_int2(&row->tuple[0], 2);
   set_tuplefield_string(&row->tuple[1], "oid");
   set_tuplefield_int2(&row->tuple[2], pgtype_to_sqltype(stmt, 26));
   set_tuplefield_string(&row->tuple[3], "OID");
   set_tuplefield_int4(&row->tuple[4], pgtype_precision(stmt, 26, -1, -1));
   set_tuplefield_int4(&row->tuple[5], pgtype_length(stmt, 26, -1, -1));
   set_tuplefield_int2(&row->tuple[6], pgtype_scale(stmt, 26, -1));
   set_tuplefield_int2(&row->tuple[7], 2);
   (TL_add_tuple(stmt->result->manual_tuples, row));
  } else if(fColType == 2) {
   short the_type = 23;
   if (atoi(ci->row_versioning)) {
    row = (struct TupleNode_ *)malloc(sizeof(TupleNode) + (8 - 1) * sizeof(TupleField));
    set_tuplefield_null(&row->tuple[0]);
    set_tuplefield_string(&row->tuple[1], "xmin");
    set_tuplefield_int2(&row->tuple[2], pgtype_to_sqltype(stmt, the_type));
    set_tuplefield_string(&row->tuple[3], pgtype_to_name(stmt, the_type));
    set_tuplefield_int4(&row->tuple[4], pgtype_precision(stmt, the_type, -1, -1));
    set_tuplefield_int4(&row->tuple[5], pgtype_length(stmt, the_type, -1, -1));
    set_tuplefield_int2(&row->tuple[6], pgtype_scale(stmt, the_type, -1));
    set_tuplefield_int2(&row->tuple[7], 2);
    (TL_add_tuple(stmt->result->manual_tuples, row));
   }
  }
 }
    stmt->status = STMT_FINISHED;
    stmt->currTuple = -1;
 stmt->rowset_start = -1;
 stmt->current_col = -1;
 mylog("SQLSpecialColumns(): EXIT,  stmt=%u\n", stmt);
    return 0;
}

variable_types:
hstmt
void *

variable_types:
fColType
unsigned short

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:
fScope
unsigned short

variable_types:
fNullable
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: 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: result short

variable_types:
relhasrules
char [128]


repo: xiaotmiaomiao/unixODBC-SPEC

decompiled_code:
__int64 __fastcall nnsql_getcolidxbyname(__int64 a1)
{
char **v1; // rbx
int v2; // ebp

if ( nncol_info_tab[0] == 21 )
return 0xFFFFFFFFLL;
v1 = &off_248;
v2 = 0;
while ( !(unsigned int)upper_strneq(a1, *v1, 16LL) )
{
++v2;
v1 += 4;
if ( *((_DWORD *)v1 - 2) == 21 )
return 0xFFFFFFFFLL;
}
return (unsigned int)nncol_info_tab[8 * v2];
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char **v1; // rbx
int v2; // ebp

if ( nncol_info_tab[0] == 21 )
return 0xFFFFFFFFLL;
v1 = &off_248;
v2 = 0;
while ( !(unsigned int)upper_strneq(a1, *v1, 16LL) )
{
++v2;
v1 += 4;
if ( *((_DWORD *)v1 - 2) == 21 )
return 0xFFFFFFFFLL;
}
return (unsigned int)nncol_info_tab[8 * v2];
}

original_code:
int nnsql_getcolidxbyname( char* col_name )
{
 int i;
 for( i= 0; nncol_info_tab[i].idx != en_sql_count; i++ )
 {
  if(upper_strneq( col_name, nncol_info_tab[i].name, 16))
   return nncol_info_tab[i].idx;
 }
 return -1;
}

canonical_original_code:
int nnsql_getcolidxbyname(char *col_name)
{
 int i;
 for( i= 0; nncol_info_tab[i].idx != en_sql_count; i++ )
 {
  if(upper_strneq( col_name, nncol_info_tab[i].name, 16))
   return nncol_info_tab[i].idx;
 }
 return -1;
}

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall nnsql_getcolnamebyidx(int a1)
{
int v1; // eax
int *v2; // rdx
int v3; // ecx

if ( nncol_info_tab[8 * a1] == a1 )
return *(_QWORD *)&nncol_info_tab[8 * a1 + 2];
v1 = nncol_info_tab[0];
v2 = &nncol_info_tab[8];
v3 = 0;
if ( nncol_info_tab[0] == 21 )
return 0LL;
while ( a1 != v1 )
{
++v3;
v2 += 8;
v1 = *(v2 - 8);
if ( v1 == 21 )
return 0LL;
}
return *(_QWORD *)&nncol_info_tab[8 * v3 + 2];
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // eax
int *v2; // rdx
int v3; // ecx

if ( nncol_info_tab[8 * a1] == a1 )
return *(_QWORD *)&nncol_info_tab[8 * a1 + 2];
v1 = nncol_info_tab[0];
v2 = &nncol_info_tab[8];
v3 = 0;
if ( nncol_info_tab[0] == 21 )
return 0LL;
while ( a1 != v1 )
{
++v3;
v2 += 8;
v1 = *(v2 - 8);
if ( v1 == 21 )
return 0LL;
}
return *(_QWORD *)&nncol_info_tab[8 * v3 + 2];
}

original_code:
char* nnsql_getcolnamebyidx( int idx )
{
 int i;
 if( nncol_info_tab[idx].idx == idx )
  return nncol_info_tab[idx].name;
 for(i=0; nncol_info_tab[i].idx != en_sql_count;i++)
 {
  if( nncol_info_tab[i].idx == idx )
   return nncol_info_tab[i].name;
 }
 return 0;
}

canonical_original_code:
char *nnsql_getcolnamebyidx(int idx)
{
 int i;
 if( nncol_info_tab[idx].idx == idx )
  return nncol_info_tab[idx].name;
 for(i=0; nncol_info_tab[i].idx != en_sql_count;i++)
 {
  if( nncol_info_tab[i].idx == idx )
   return nncol_info_tab[i].name;
 }
 return 0;
}

variable_types: idx int

return_type: char *


decompiled_code:
int *__fastcall nnsql_getcoldescbyidx(int a1)
{
__int64 v1; // rcx
int *v2; // rdx
int v3; // eax

v1 = 8LL * a1;
v2 = nncol_info_tab;
v3 = 0;
if ( nncol_info_tab[v1] == a1 )
return &nncol_info_tab[v1];
while ( *v2 != a1 )
{
++v3;
v2 += 8;
if ( v3 == 31 )
return 0LL;
}
return &nncol_info_tab[8 * v3];
}

canonical_decompiled_code:
int *__fastcall func2(int a1)
{
__int64 v1; // rcx
int *v2; // rdx
int v3; // eax

v1 = 8LL * a1;
v2 = nncol_info_tab;
v3 = 0;
if ( nncol_info_tab[v1] == a1 )
return &nncol_info_tab[v1];
while ( *v2 != a1 )
{
++v3;
v2 += 8;
if ( v3 == 31 )
return 0LL;
}
return &nncol_info_tab[8 * v3];
}

original_code:
void* nnsql_getcoldescbyidx( int idx )
{
 int i;
 if( nncol_info_tab[idx].idx == idx )
  return &(nncol_info_tab[idx]);
 for(i=0; i<sizeof(nncol_info_tab)/sizeof(nncol_info_tab[0]); i++)
 {
  if( nncol_info_tab[i].idx == idx )
   return &(nncol_info_tab[i]);
 }
 return 0;
}

canonical_original_code:
void *nnsql_getcoldescbyidx(int idx)
{
 int i;
 if( nncol_info_tab[idx].idx == idx )
  return &(nncol_info_tab[idx]);
 for(i=0; i<sizeof(nncol_info_tab)/sizeof(nncol_info_tab[0]); i++)
 {
  if( nncol_info_tab[i].idx == idx )
   return &(nncol_info_tab[i]);
 }
 return 0;
}

return_type: void *


decompiled_code:
__int64 __fastcall nnsql_getcolnamebydesc(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
char* nnsql_getcolnamebydesc( void* hdesc )
{
 col_desc_t* desc = hdesc;
 return desc->name;
}

canonical_original_code:
char *nnsql_getcolnamebydesc(void *hdesc)
{
 struct col_desc_t *desc = hdesc;
 return desc->name;
}

variable_types:
hdesc
void *

variable_types: struct col_desc_t { int idx; char *name; int datatype; int nullable; int writable; } *


decompiled_code:
__int64 __fastcall nnsql_getcoldatatypebydesc(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int nnsql_getcoldatatypebydesc( void* hdesc )
{
 col_desc_t* desc = hdesc;
 return desc->datatype;
}

canonical_original_code:
int nnsql_getcoldatatypebydesc(void *hdesc)
{
 struct col_desc_t *desc = hdesc;
 return desc->datatype;
}

user_defined_types: struct col_desc_t { int idx; char *name; int datatype; int nullable; int writable; }


decompiled_code:
__int64 __fastcall nnsql_getcolnullablebydesc(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

original_code:
int nnsql_getcolnullablebydesc( void* hdesc )
{
 col_desc_t* desc = hdesc;
 return desc->nullable;
}

canonical_original_code:
int nnsql_getcolnullablebydesc(void *hdesc)
{
 struct col_desc_t *desc = hdesc;
 return desc->nullable;
}


decompiled_code:
__int64 __fastcall set_statement_option(__int64 a1, __int64 a2, unsigned __int16 a3, __int64 a4)
{
unsigned int v5; // ebx
char v7[104]; // [rsp+0h] [rbp-68h] BYREF

v5 = a3;
if ( a2 )
{
SC_set_error(a2, 10LL, "Unknown statement option (Set)");
sprintf(v7, "fOption=%d, vParam=%ld", v5, a4);
SC_log_error("set_statement_option", v7, a2);
}
if ( a1 )
{
CC_set_error(a1, 10LL, "Unknown statement option (Set)");
sprintf(v7, "fOption=%d, vParam=%ld", v5, a4);
CC_log_error("set_statement_option", v7, a1);
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned __int16 a3, __int64 a4)
{
unsigned int v5; // ebx
char v7[104]; // [rsp+0h] [rbp-68h] BYREF

v5 = a3;
if ( a2 )
{
SC_set_error(a2, 10LL, "Unknown statement option (Set)");
sprintf(v7, "fOption=%d, vParam=%ld", v5, a4);
SC_log_error("set_statement_option", v7, a2);
}
if ( a1 )
{
CC_set_error(a1, 10LL, "Unknown statement option (Set)");
sprintf(v7, "fOption=%d, vParam=%ld", v5, a4);
CC_log_error("set_statement_option", v7, a1);
}
return 0xFFFFFFFFLL;
}

original_code:
RETCODE set_statement_option(ConnectionClass *conn,
        StatementClass *stmt,
        UWORD fOption,
        UDWORD vParam)
{
static char* const func="set_statement_option";
char changed = (int)0;
 switch(fOption) {
 case 4:
  break;
 case 5:
  if (conn) conn->stmtOptions.bind_size = vParam;
  if (stmt) stmt->options.bind_size = vParam;
  break;
 case 7:
  if (conn) conn->stmtOptions.scroll_concurrency = vParam;
  if (stmt) stmt->options.scroll_concurrency = vParam;
  break;
 case 6:
  mylog("SetStmtOption(): SQL_CURSOR_TYPE = %d\n", vParam);
  if (globals.lie) {
   if (conn) conn->stmtOptions.cursor_type = vParam;
   if (stmt) stmt->options.cursor_type = vParam;
  }
  else {
   if (globals.use_declarefetch) {
    if (conn) conn->stmtOptions.cursor_type = 0UL;
    if (stmt) stmt->options.cursor_type = 0UL;
    if (vParam != 0UL)
     changed = (int)1;
   }
   else {
    if (vParam == 0UL || vParam == 3UL) {
     if (conn) conn->stmtOptions.cursor_type = vParam;
     if (stmt) stmt->options.cursor_type = vParam;
    }
    else {
     if (conn) conn->stmtOptions.cursor_type = 3UL;
     if (stmt) stmt->options.cursor_type = 3UL;
     changed = (int)1;
    }
   }
  }
  break;
 case 8:
  mylog("SetStmtOption(): SQL_KEYSET_SIZE, vParam = %d\n", vParam);
  if (conn) conn->stmtOptions.keyset_size = vParam;
  if (stmt) stmt->options.keyset_size = vParam;
  break;
 case 3:
  mylog("SetStmtOption(): SQL_MAX_LENGTH, vParam = %d\n", vParam);
  if (conn) conn->stmtOptions.maxLength = vParam;
  if (stmt) stmt->options.maxLength = vParam;
  break;
 case 1:
  mylog("SetStmtOption(): SQL_MAX_ROWS, vParam = %d\n", vParam);
  if (conn) conn->stmtOptions.maxRows = vParam;
  if (stmt) stmt->options.maxRows = vParam;
  break;
 case 2:
  mylog("SetStmtOption: SQL_NOSCAN, vParam = %d\n", vParam);
  break;
 case 0:
  mylog("SetStmtOption: SQL_QUERY_TIMEOUT, vParam = %d\n", vParam);
  break;
 case 11:
  mylog("SetStmtOption(): SQL_RETRIEVE_DATA, vParam = %d\n", vParam);
  if (conn) conn->stmtOptions.retrieve_data = vParam;
  if (stmt) stmt->options.retrieve_data = vParam;
  break;
 case 9:
  mylog("SetStmtOption(): SQL_ROWSET_SIZE, vParam = %d\n", vParam);
  if (stmt && stmt->save_rowset_size <= 0 && stmt->last_fetch_count > 0 )
   stmt->save_rowset_size = stmt->options.rowset_size;
  if (vParam < 1) {
   vParam = 1;
   changed = (int)1;
  }
  if (conn) conn->stmtOptions.rowset_size = vParam;
  if (stmt) stmt->options.rowset_size = vParam;
  break;
 case 10:
  if (stmt) {
   SC_set_error(stmt, 10, "Simulated positioned update/delete not supported.  Use the cursor library.");
   SC_log_error(func, "", stmt);
  }
  if (conn) {
   CC_set_error(conn, 10, "Simulated positioned update/delete not supported.  Use the cursor library.");
   CC_log_error(func, "", conn);
  }
  return (-1);
 case 12:
  if (stmt) stmt->options.use_bookmarks = vParam;
  if (conn) conn->stmtOptions.use_bookmarks = vParam;
  break;
    case 65534:
        break;
    default:
  {
  char option[64];
  if (stmt) {
   SC_set_error(stmt, 10, "Unknown statement option (Set)");
   sprintf(option, "fOption=%d, vParam=%ld", fOption, (long)vParam);
   SC_log_error(func, option, stmt);
  }
  if (conn) {
   CC_set_error(conn, 10, "Unknown statement option (Set)");
   sprintf(option, "fOption=%d, vParam=%ld", fOption, (long)vParam);
   CC_log_error(func, option, conn);
  }
        return (-1);
  }
    }
 if (changed) {
  if (stmt) {
   SC_set_error(stmt, 16, "Requested value changed.");
  }
  if (conn) {
   CC_set_error(conn, 16, "Requested value changed.");
  }
  return 1;
 }
 else
  return 0;
}

canonical_original_code:
short set_statement_option(struct ConnectionClass_ *conn, struct StatementClass_ *stmt, unsigned short fOption, unsigned long vParam)
{
static char *func = "set_statement_option";
char changed = (int)0;
 switch(fOption) {
 case 4:
  break;
 case 5:
  if (conn) conn->stmtOptions.bind_size = vParam;
  if (stmt) stmt->options.bind_size = vParam;
  break;
 case 7:
  if (conn) conn->stmtOptions.scroll_concurrency = vParam;
  if (stmt) stmt->options.scroll_concurrency = vParam;
  break;
 case 6:
  mylog("SetStmtOption(): SQL_CURSOR_TYPE = %d\n", vParam);
  if (globals.lie) {
   if (conn) conn->stmtOptions.cursor_type = vParam;
   if (stmt) stmt->options.cursor_type = vParam;
  }
  else {
   if (globals.use_declarefetch) {
    if (conn) conn->stmtOptions.cursor_type = 0UL;
    if (stmt) stmt->options.cursor_type = 0UL;
    if (vParam != 0UL)
     changed = (int)1;
   }
   else {
    if (vParam == 0UL || vParam == 3UL) {
     if (conn) conn->stmtOptions.cursor_type = vParam;
     if (stmt) stmt->options.cursor_type = vParam;
    }
    else {
     if (conn) conn->stmtOptions.cursor_type = 3UL;
     if (stmt) stmt->options.cursor_type = 3UL;
     changed = (int)1;
    }
   }
  }
  break;
 case 8:
  mylog("SetStmtOption(): SQL_KEYSET_SIZE, vParam = %d\n", vParam);
  if (conn) conn->stmtOptions.keyset_size = vParam;
  if (stmt) stmt->options.keyset_size = vParam;
  break;
 case 3:
  mylog("SetStmtOption(): SQL_MAX_LENGTH, vParam = %d\n", vParam);
  if (conn) conn->stmtOptions.maxLength = vParam;
  if (stmt) stmt->options.maxLength = vParam;
  break;
 case 1:
  mylog("SetStmtOption(): SQL_MAX_ROWS, vParam = %d\n", vParam);
  if (conn) conn->stmtOptions.maxRows = vParam;
  if (stmt) stmt->options.maxRows = vParam;
  break;
 case 2:
  mylog("SetStmtOption: SQL_NOSCAN, vParam = %d\n", vParam);
  break;
 case 0:
  mylog("SetStmtOption: SQL_QUERY_TIMEOUT, vParam = %d\n", vParam);
  break;
 case 11:
  mylog("SetStmtOption(): SQL_RETRIEVE_DATA, vParam = %d\n", vParam);
  if (conn) conn->stmtOptions.retrieve_data = vParam;
  if (stmt) stmt->options.retrieve_data = vParam;
  break;
 case 9:
  mylog("SetStmtOption(): SQL_ROWSET_SIZE, vParam = %d\n", vParam);
  if (stmt && stmt->save_rowset_size <= 0 && stmt->last_fetch_count > 0 )
   stmt->save_rowset_size = stmt->options.rowset_size;
  if (vParam < 1) {
   vParam = 1;
   changed = (int)1;
  }
  if (conn) conn->stmtOptions.rowset_size = vParam;
  if (stmt) stmt->options.rowset_size = vParam;
  break;
 case 10:
  if (stmt) {
   SC_set_error(stmt, 10, "Simulated positioned update/delete not supported.  Use the cursor library.");
   SC_log_error(func, "", stmt);
  }
  if (conn) {
   CC_set_error(conn, 10, "Simulated positioned update/delete not supported.  Use the cursor library.");
   CC_log_error(func, "", conn);
  }
  return (-1);
 case 12:
  if (stmt) stmt->options.use_bookmarks = vParam;
  if (conn) conn->stmtOptions.use_bookmarks = vParam;
  break;
    case 65534:
        break;
    default:
  {
  char option[64];
  if (stmt) {
   SC_set_error(stmt, 10, "Unknown statement option (Set)");
   sprintf(option, "fOption=%d, vParam=%ld", fOption, (long)vParam);
   SC_log_error(func, option, stmt);
  }
  if (conn) {
   CC_set_error(conn, 10, "Unknown statement option (Set)");
   sprintf(option, "fOption=%d, vParam=%ld", fOption, (long)vParam);
   CC_log_error(func, option, conn);
  }
        return (-1);
  }
    }
 if (changed) {
  if (stmt) {
   SC_set_error(stmt, 16, "Requested value changed.");
  }
  if (conn) {
   CC_set_error(conn, 16, "Requested value changed.");
  }
  return 1;
 }
 else
  return 0;
}

variable_types: 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_ { struct ConnectionClass_ *hdbc; 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; 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 { struct QResultClass_ *result; char name[-1]; } *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; } **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 **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; } *

variable_types:
stmt
struct StatementClass_ *

variable_types:
fOption
unsigned short

variable_types:
vParam
unsigned long

variable_types: changed char

variable_types:
option
char [64]

return_type: short

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; }

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 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: struct TABLE_INFO { struct col_info *col_info; char name[-1]; char alias[-1]; }

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]; }


SQLSetConnectOption

decompiled_code:
__int64 __fastcall SQLSetConnectOption(__int64 a1, unsigned __int16 a2, __int64 a3)
{
unsigned int v5; // ebx
__int64 v6; // rbx
__int64 v7; // rsi
unsigned int v8; // eax
char v9; // al
char v11[104]; // [rsp+0h] [rbp-68h] BYREF

mylog("%s: entering...\n", "SQLSetConnectOption");
if ( a1 )
{
if ( a2 <= 0xCu )
{
if ( *(int *)(a1 + 10400) > 0 )
{
v6 = 0LL;
do
{
v7 = *(_QWORD *)(*(_QWORD *)(a1 + 10392) + 8 * v6);
if ( v7 )
set_statement_option(0LL, v7, a2, a3);
++v6;
}
while ( *(_DWORD *)(a1 + 10400) > (int)v6 );
}
v8 = set_statement_option(a1, 0LL, a2, a3);
v5 = v8;
if ( (_WORD)v8 == 1 )
CC_set_error(a1, 213LL, "Requested value changed.");
else
v5 = -((_WORD)v8 == 0xFFFF);
}
else if ( (unsigned __int16)(a2 - 101) > 0xBu )
{
LABEL_21:
CC_set_error(a1, 205LL, "Unknown connect option (Set)");
sprintf(v11, "fOption=%d, vParam=%ld", a2, a3);
CC_log_error("SQLSetConnectOption", v11, a1);
v5 = -1;
}
else
{
switch ( a2 )
{
case 'e':
case 'g':
case 'l':
case 'm':
case 'o':
case 'p':
v5 = 0;
break;
case 'f':
v9 = *(_BYTE *)(a1 + 10466);
if ( (v9 & 2) != 0 )
{
CC_set_error(a1, 207LL, "Cannot switch commit mode while a transaction is in progress");
CC_log_error("SQLSetConnectOption", &LC9, a1);
v5 = -1;
}
else
{
mylog("SQLSetConnectOption: AUTOCOMMIT: transact_status=%d, vparam=%d\n", (unsigned int)v9, a3);
if ( a3 )
{
if ( a3 == 1 )
{
*(_BYTE *)(a1 + 10466) |= 1u;
v5 = 0;
}
else
{
CC_set_error(a1, 206LL, "Illegal parameter value for SQL_AUTOCOMMIT");
CC_log_error("SQLSetConnectOption", &LC9, a1);
v5 = -1;
}
}
else
{
*(_BYTE *)(a1 + 10466) &= 0xFEu;
v5 = 0;
}
}
break;
case 'h':
case 'i':
case 'j':
case 'k':
case 'n':
CC_log_error("SQLSetConnectOption", "This connect option (Set) is only used by the Driver Manager", a1);
v5 = 0;
break;
default:
goto LABEL_21;
}
}
}
else
{
CC_log_error("SQLSetConnectOption", &LC9, 0LL);
v5 = -2;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int16 a2, __int64 a3)
{
unsigned int v5; // ebx
__int64 v6; // rbx
__int64 v7; // rsi
unsigned int v8; // eax
char v9; // al
char v11[104]; // [rsp+0h] [rbp-68h] BYREF

mylog("%s: entering...\n", "SQLSetConnectOption");
if ( a1 )
{
if ( a2 <= 0xCu )
{
if ( *(int *)(a1 + 10400) > 0 )
{
v6 = 0LL;
do
{
v7 = *(_QWORD *)(*(_QWORD *)(a1 + 10392) + 8 * v6);
if ( v7 )
func0(0LL, v7, a2, a3);
++v6;
}
while ( *(_DWORD *)(a1 + 10400) > (int)v6 );
}
v8 = func0(a1, 0LL, a2, a3);
v5 = v8;
if ( (_WORD)v8 == 1 )
CC_set_error(a1, 213LL, "Requested value changed.");
else
v5 = -((_WORD)v8 == 0xFFFF);
}
else if ( (unsigned __int16)(a2 - 101) > 0xBu )
{
LABEL_21:
CC_set_error(a1, 205LL, "Unknown connect option (Set)");
sprintf(v11, "fOption=%d, vParam=%ld", a2, a3);
CC_log_error("SQLSetConnectOption", v11, a1);
v5 = -1;
}
else
{
switch ( a2 )
{
case 'e':
case 'g':
case 'l':
case 'm':
case 'o':
case 'p':
v5 = 0;
break;
case 'f':
v9 = *(_BYTE *)(a1 + 10466);
if ( (v9 & 2) != 0 )
{
CC_set_error(a1, 207LL, "Cannot switch commit mode while a transaction is in progress");
CC_log_error("SQLSetConnectOption", &LC9, a1);
v5 = -1;
}
else
{
mylog("SQLSetConnectOption: AUTOCOMMIT: transact_status=%d, vparam=%d\n", (unsigned int)v9, a3);
if ( a3 )
{
if ( a3 == 1 )
{
*(_BYTE *)(a1 + 10466) |= 1u;
v5 = 0;
}
else
{
CC_set_error(a1, 206LL, "Illegal parameter value for SQL_AUTOCOMMIT");
CC_log_error("SQLSetConnectOption", &LC9, a1);
v5 = -1;
}
}
else
{
*(_BYTE *)(a1 + 10466) &= 0xFEu;
v5 = 0;
}
}
break;
case 'h':
case 'i':
case 'j':
case 'k':
case 'n':
CC_log_error("SQLSetConnectOption", "This connect option (Set) is only used by the Driver Manager", a1);
v5 = 0;
break;
default:
goto LABEL_21;
}
}
}
else
{
CC_log_error("SQLSetConnectOption", &LC9, 0LL);
v5 = -2;
}
return v5;
}

original_code:
RETCODE SQLSetConnectOption(
        HDBC hdbc,
        UWORD fOption,
        SQLUINTEGER vParam)
{
static char* const func="SQLSetConnectOption";
ConnectionClass *conn = (ConnectionClass *) hdbc;
char changed = (int)0;
RETCODE retval;
int i;
 mylog("%s: entering...\n", func);
 if ( ! conn) {
  CC_log_error(func, "", ((void *)0));
  return (-2);
 }
 switch (fOption) {
 case 4:
 case 5:
 case 7:
 case 6:
 case 8:
 case 3:
 case 1:
 case 2:
 case 0:
 case 11:
 case 9:
 case 10:
 case 12:
  for (i = 0; i < conn->num_stmts; i++) {
   if ( conn->stmts[i]) {
    set_statement_option(((void *)0), conn->stmts[i], fOption, vParam);
   }
  }
  retval = set_statement_option(conn, ((void *)0), fOption, vParam);
  if (retval == 1)
   changed = (int)1;
  else if (retval == (-1))
   return (-1);
  break;
 case 101:
  break;
 case 102:
  if ((conn->transact_status & 0x02)) {
   CC_set_error(conn, 207, "Cannot switch commit mode while a transaction is in progress");
   CC_log_error(func, "", conn);
   return (-1);
  }
  mylog("SQLSetConnectOption: AUTOCOMMIT: transact_status=%d, vparam=%d\n", conn->transact_status, vParam);
  switch(vParam) {
  case 0UL:
   (conn->transact_status &= ~0x01);
   break;
  case 1UL:
   (conn->transact_status |= 0x01);
   break;
  default:
   CC_set_error(conn, 206, "Illegal parameter value for SQL_AUTOCOMMIT");
   CC_log_error(func, "", conn);
   return (-1);
  }
  break;
 case 109:
  break;
 case 103:
  break;
 case 112:
  break;
 case 111:
  break;
 case 108:
  break;
 case 110:
 case 104:
 case 105:
 case 106:
 case 107:
  CC_log_error(func, "This connect option (Set) is only used by the Driver Manager", conn);
  break;
 default:
  {
  char option[64];
  CC_set_error(conn, 205, "Unknown connect option (Set)");
  sprintf(option, "fOption=%d, vParam=%ld", fOption, vParam);
  CC_log_error(func, option, conn);
  return (-1);
  }
 }
 if (changed) {
  CC_set_error(conn, 213, "Requested value changed.");
  return 1;
 }
 else
  return 0;
}

canonical_original_code:
short SQLSetConnectOption(void *hdbc, unsigned short fOption, unsigned long vParam)
{
static char *func = "SQLSetConnectOption";
struct ConnectionClass_ *conn = (ConnectionClass *) hdbc;
char changed = (int)0;
short retval;
int i;
 mylog("%s: entering...\n", func);
 if ( ! conn) {
  CC_log_error(func, "", ((void *)0));
  return (-2);
 }
 switch (fOption) {
 case 4:
 case 5:
 case 7:
 case 6:
 case 8:
 case 3:
 case 1:
 case 2:
 case 0:
 case 11:
 case 9:
 case 10:
 case 12:
  for (i = 0; i < conn->num_stmts; i++) {
   if ( conn->stmts[i]) {
    set_statement_option(((void *)0), conn->stmts[i], fOption, vParam);
   }
  }
  retval = set_statement_option(conn, ((void *)0), fOption, vParam);
  if (retval == 1)
   changed = (int)1;
  else if (retval == (-1))
   return (-1);
  break;
 case 101:
  break;
 case 102:
  if ((conn->transact_status & 0x02)) {
   CC_set_error(conn, 207, "Cannot switch commit mode while a transaction is in progress");
   CC_log_error(func, "", conn);
   return (-1);
  }
  mylog("SQLSetConnectOption: AUTOCOMMIT: transact_status=%d, vparam=%d\n", conn->transact_status, vParam);
  switch(vParam) {
  case 0UL:
   (conn->transact_status &= ~0x01);
   break;
  case 1UL:
   (conn->transact_status |= 0x01);
   break;
  default:
   CC_set_error(conn, 206, "Illegal parameter value for SQL_AUTOCOMMIT");
   CC_log_error(func, "", conn);
   return (-1);
  }
  break;
 case 109:
  break;
 case 103:
  break;
 case 112:
  break;
 case 111:
  break;
 case 108:
  break;
 case 110:
 case 104:
 case 105:
 case 106:
 case 107:
  CC_log_error(func, "This connect option (Set) is only used by the Driver Manager", conn);
  break;
 default:
  {
  char option[64];
  CC_set_error(conn, 205, "Unknown connect option (Set)");
  sprintf(option, "fOption=%d, vParam=%ld", fOption, vParam);
  CC_log_error(func, option, conn);
  return (-1);
  }
 }
 if (changed) {
  CC_set_error(conn, 213, "Requested value changed.");
  return 1;
 }
 else
  return 0;
}

variable_types:
hdbc
void *

variable_types: retval short

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 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: 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: 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 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 ColumnInfoClass_ { short num_fields; char **name; unsigned int *adtid; short *adtsize; short *display_size; int *atttypmod; }

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

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


SQLGetConnectOption

decompiled_code:
__int64 __fastcall SQLGetConnectOption(__int64 a1, unsigned __int16 a2, _QWORD *a3)
{
__int64 result; // rax
char v5[88]; // [rsp+0h] [rbp-58h] BYREF

mylog("%s: entering...\n", "SQLGetConnectOption");
if ( a1 )
{
switch ( a2 )
{
case 'e':
*a3 = 0LL;
result = 0LL;
break;
case 'f':
*a3 = *(_BYTE *)(a1 + 10466) & 1;
result = 0LL;
break;
case 'g':
*a3 = 0LL;
result = 0LL;
break;
case 'h':
case 'i':
case 'j':
case 'k':
case 'n':
CC_log_error("SQLGetConnectOption", "This connect option (Get) is only used by the Driver Manager", a1);
result = 0LL;
break;
case 'l':
*a3 = 8LL;
result = 0LL;
break;
case 'm':
result = 0LL;
if ( a3 )
*(_BYTE *)a3 = 0;
break;
case 'o':
*a3 = 0LL;
result = 0LL;
break;
case 'p':
*a3 = *((int *)&globals + 1);
result = 0LL;
break;
default:
CC_set_error(a1, 205LL, "Unknown connect option (Get)");
sprintf(v5, "fOption=%d", a2);
CC_log_error("SQLGetConnectOption", v5, a1);
result = 0xFFFFFFFFLL;
break;
}
}
else
{
CC_log_error("SQLGetConnectOption", &LC9, 0LL);
result = 4294967294LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int16 a2, _QWORD *a3)
{
__int64 result; // rax
char v5[88]; // [rsp+0h] [rbp-58h] BYREF

mylog("%s: entering...\n", "SQLGetConnectOption");
if ( a1 )
{
switch ( a2 )
{
case 'e':
*a3 = 0LL;
result = 0LL;
break;
case 'f':
*a3 = *(_BYTE *)(a1 + 10466) & 1;
result = 0LL;
break;
case 'g':
*a3 = 0LL;
result = 0LL;
break;
case 'h':
case 'i':
case 'j':
case 'k':
case 'n':
CC_log_error("SQLGetConnectOption", "This connect option (Get) is only used by the Driver Manager", a1);
result = 0LL;
break;
case 'l':
*a3 = 8LL;
result = 0LL;
break;
case 'm':
result = 0LL;
if ( a3 )
*(_BYTE *)a3 = 0;
break;
case 'o':
*a3 = 0LL;
result = 0LL;
break;
case 'p':
*a3 = *((int *)&globals + 1);
result = 0LL;
break;
default:
CC_set_error(a1, 205LL, "Unknown connect option (Get)");
sprintf(v5, "fOption=%d", a2);
CC_log_error("SQLGetConnectOption", v5, a1);
result = 0xFFFFFFFFLL;
break;
}
}
else
{
CC_log_error("SQLGetConnectOption", &LC9, 0LL);
result = 4294967294LL;
}
return result;
}

original_code:
RETCODE SQLGetConnectOption(
        HDBC hdbc,
        UWORD fOption,
        PTR pvParam)
{
static char* const func="SQLGetConnectOption";
ConnectionClass *conn = (ConnectionClass *) hdbc;
 mylog("%s: entering...\n", func);
 if (! conn) {
  CC_log_error(func, "", ((void *)0));
  return (-2);
 }
 switch (fOption) {
 case 101:
  *((UDWORD *) pvParam) = 0UL;
  break;
 case 102:
  *((UDWORD *)pvParam) = (UDWORD)( (conn->transact_status & 0x01) ?
      1UL : 0UL);
  break;
 case 109:
  if(pvParam) {
   ((char*)pvParam)[0]='\0';
  }
  break;
 case 103:
  *((UDWORD *) pvParam) = 0;
  break;
 case 112:
  *((UDWORD *) pvParam) = globals.socket_buffersize;
  break;
 case 111:
  *((UDWORD *) pvParam) = (UDWORD) ((void *)0);
  break;
 case 108:
  *((UDWORD *) pvParam) = 0x00000008L;
  break;
 case 110:
 case 104:
 case 105:
 case 106:
 case 107:
  CC_log_error(func, "This connect option (Get) is only used by the Driver Manager", conn);
  break;
 default:
  {
  char option[64];
  CC_set_error(conn, 205, "Unknown connect option (Get)");
  sprintf(option, "fOption=%d", fOption);
  CC_log_error(func, option, conn);
  return (-1);
  break;
  }
 }
 return 0;
}

canonical_original_code:
short SQLGetConnectOption(void *hdbc, unsigned short fOption, void *pvParam)
{
static char *func = "SQLGetConnectOption";
struct ConnectionClass_ *conn = (ConnectionClass *) hdbc;
 mylog("%s: entering...\n", func);
 if (! conn) {
  CC_log_error(func, "", ((void *)0));
  return (-2);
 }
 switch (fOption) {
 case 101:
  *((unsigned long *) pvParam) = 0UL;
  break;
 case 102:
  *((unsigned long *)pvParam) = (UDWORD)( (conn->transact_status & 0x01) ?
      1UL : 0UL);
  break;
 case 109:
  if(pvParam) {
   ((char *)pvParam)[0]='\0';
  }
  break;
 case 103:
  *((unsigned long *) pvParam) = 0;
  break;
 case 112:
  *((unsigned long *) pvParam) = globals.socket_buffersize;
  break;
 case 111:
  *((unsigned long *) pvParam) = (UDWORD) ((void *)0);
  break;
 case 108:
  *((unsigned long *) pvParam) = 0x00000008L;
  break;
 case 110:
 case 104:
 case 105:
 case 106:
 case 107:
  CC_log_error(func, "This connect option (Get) is only used by the Driver Manager", conn);
  break;
 default:
  {
  char option[64];
  CC_set_error(conn, 205, "Unknown connect option (Get)");
  sprintf(option, "fOption=%d", fOption);
  CC_log_error(func, option, conn);
  return (-1);
  break;
  }
 }
 return 0;
}

variable_types:
pvParam
void *

variable_types:
func
char *

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; }

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; }


SQLSetStmtOption

decompiled_code:
__int64 __fastcall SQLSetStmtOption(__int64 a1, unsigned __int16 a2, __int64 a3)
{
mylog("%s: entering...\n", "SQLSetStmtOption");
if ( a1 )
return set_statement_option(0LL, a1, a2, a3);
SC_log_error("SQLSetStmtOption", &LC9, 0LL);
return 4294967294LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int16 a2, __int64 a3)
{
mylog("%s: entering...\n", "SQLSetStmtOption");
if ( a1 )
return func0(0LL, a1, a2, a3);
SC_log_error("SQLSetStmtOption", &LC9, 0LL);
return 4294967294LL;
}

original_code:
RETCODE SQLSetStmtOption(
        HSTMT hstmt,
        UWORD fOption,
        SQLUINTEGER vParam)
{
static char* const func="SQLSetStmtOption";
StatementClass *stmt = (StatementClass *) hstmt;
 mylog("%s: entering...\n", func);
 if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 return set_statement_option(((void *)0), stmt, fOption, vParam);
}

canonical_original_code:
short SQLSetStmtOption(void *hstmt, unsigned short fOption, unsigned long vParam)
{
static char *func = "SQLSetStmtOption";
struct StatementClass_ *stmt = (StatementClass *) hstmt;
 mylog("%s: entering...\n", func);
 if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 return set_statement_option(((void *)0), stmt, fOption, vParam);
}

variable_types:
hstmt
void *

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; } *

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; }


SQLGetStmtOption

decompiled_code:
__int64 __fastcall SQLGetStmtOption(__int64 a1, unsigned __int16 a2)
{
__int64 result; // rax
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

mylog("%s: entering...\n", "SQLGetStmtOption");
if ( a1 )
{
SC_set_error(a1, 10LL, "Unknown statement option (Get)");
sprintf(v3, "fOption=%d", a2);
SC_log_error("SQLGetStmtOption", v3, a1);
result = 0xFFFFFFFFLL;
}
else
{
SC_log_error("SQLGetStmtOption", &LC9, 0LL);
result = 4294967294LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int16 a2)
{
__int64 result; // rax
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

mylog("%s: entering...\n", "SQLGetStmtOption");
if ( a1 )
{
SC_set_error(a1, 10LL, "Unknown statement option (Get)");
sprintf(v3, "fOption=%d", a2);
SC_log_error("SQLGetStmtOption", v3, a1);
result = 0xFFFFFFFFLL;
}
else
{
SC_log_error("SQLGetStmtOption", &LC9, 0LL);
result = 4294967294LL;
}
return result;
}

original_code:
RETCODE SQLGetStmtOption(
        HSTMT hstmt,
        UWORD fOption,
        PTR pvParam)
{
static char* const func="SQLGetStmtOption";
StatementClass *stmt = (StatementClass *) hstmt;
QResultClass *res;
 mylog("%s: entering...\n", func);
 if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 switch(fOption) {
 case 13:
 case 14:
  res = stmt->result;
  if ( stmt->manual_result || ! globals.use_declarefetch) {
   if((stmt->currTuple < 0) ||
      (stmt->currTuple >= (res->manual_tuples ? (res->manual_tuples->num_tuples) : res->fcount))) {
    SC_set_error(stmt, 15, "Not positioned on a valid row.");
    SC_log_error(func, "", stmt);
    return (-1);
   }
  }
  else {
   if (stmt->currTuple == -1 || ! res || ! res->tupleField) {
    SC_set_error(stmt, 15, "Not positioned on a valid row.");
    SC_log_error(func, "", stmt);
    return (-1);
   }
  }
  if (fOption == 13 && stmt->options.use_bookmarks == 0UL) {
   SC_set_error(stmt, 25, "Operation invalid because use bookmarks not enabled.");
   SC_log_error(func, "", stmt);
   return (-1);
  }
  *((UDWORD *) pvParam) = SC_get_bookmark(stmt);
  break;
 case 4:
  *((SDWORD *) pvParam) = 0UL;
  break;
 case 5:
  *((SDWORD *) pvParam) = stmt->options.bind_size;
  break;
 case 7:
  mylog("GetStmtOption(): SQL_CONCURRENCY\n");
  *((SDWORD *)pvParam) = stmt->options.scroll_concurrency;
  break;
 case 6:
  mylog("GetStmtOption(): SQL_CURSOR_TYPE\n");
  *((SDWORD *)pvParam) = stmt->options.cursor_type;
  break;
 case 8:
  mylog("GetStmtOption(): SQL_KEYSET_SIZE\n");
  *((SDWORD *)pvParam) = stmt->options.keyset_size;
  break;
 case 3:
  *((SDWORD *)pvParam) = stmt->options.maxLength;
  break;
 case 1:
  *((SDWORD *)pvParam) = stmt->options.maxRows;
  mylog("GetSmtOption: MAX_ROWS, returning %d\n", stmt->options.maxRows);
  break;
 case 2:
  *((SDWORD *) pvParam) = 1UL;
  break;
 case 0:
  *((SDWORD *) pvParam) = 0;
  break;
 case 11:
  *((SDWORD *) pvParam) = stmt->options.retrieve_data;
  break;
 case 9:
  *((SDWORD *) pvParam) = stmt->options.rowset_size;
  break;
 case 10:
  *((SDWORD *) pvParam) = 0UL;
  break;
 case 12:
  *((SDWORD *) pvParam) = stmt->options.use_bookmarks;
  break;
    case 65534:
  *((SDWORD *) pvParam) = 0;
        break;
 default:
  {
  char option[64];
  SC_set_error(stmt, 10, "Unknown statement option (Get)");
  sprintf(option, "fOption=%d", fOption);
  SC_log_error(func, option, stmt);
  return (-1);
  }
 }
 return 0;
}

canonical_original_code:
short SQLGetStmtOption(void *hstmt, unsigned short fOption, void *pvParam)
{
static char *func = "SQLGetStmtOption";
struct StatementClass_ *stmt = (StatementClass *) hstmt;
struct QResultClass_ *res;
 mylog("%s: entering...\n", func);
 if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 switch(fOption) {
 case 13:
 case 14:
  res = stmt->result;
  if ( stmt->manual_result || ! globals.use_declarefetch) {
   if((stmt->currTuple < 0) ||
      (stmt->currTuple >= (res->manual_tuples ? (res->manual_tuples->num_tuples) : res->fcount))) {
    SC_set_error(stmt, 15, "Not positioned on a valid row.");
    SC_log_error(func, "", stmt);
    return (-1);
   }
  }
  else {
   if (stmt->currTuple == -1 || ! res || ! res->tupleField) {
    SC_set_error(stmt, 15, "Not positioned on a valid row.");
    SC_log_error(func, "", stmt);
    return (-1);
   }
  }
  if (fOption == 13 && stmt->options.use_bookmarks == 0UL) {
   SC_set_error(stmt, 25, "Operation invalid because use bookmarks not enabled.");
   SC_log_error(func, "", stmt);
   return (-1);
  }
  *((unsigned long *) pvParam) = SC_get_bookmark(stmt);
  break;
 case 4:
  *((long *) pvParam) = 0UL;
  break;
 case 5:
  *((long *) pvParam) = stmt->options.bind_size;
  break;
 case 7:
  mylog("GetStmtOption(): SQL_CONCURRENCY\n");
  *((long *)pvParam) = stmt->options.scroll_concurrency;
  break;
 case 6:
  mylog("GetStmtOption(): SQL_CURSOR_TYPE\n");
  *((long *)pvParam) = stmt->options.cursor_type;
  break;
 case 8:
  mylog("GetStmtOption(): SQL_KEYSET_SIZE\n");
  *((long *)pvParam) = stmt->options.keyset_size;
  break;
 case 3:
  *((long *)pvParam) = stmt->options.maxLength;
  break;
 case 1:
  *((long *)pvParam) = stmt->options.maxRows;
  mylog("GetSmtOption: MAX_ROWS, returning %d\n", stmt->options.maxRows);
  break;
 case 2:
  *((long *) pvParam) = 1UL;
  break;
 case 0:
  *((long *) pvParam) = 0;
  break;
 case 11:
  *((long *) pvParam) = stmt->options.retrieve_data;
  break;
 case 9:
  *((long *) pvParam) = stmt->options.rowset_size;
  break;
 case 10:
  *((long *) pvParam) = 0UL;
  break;
 case 12:
  *((long *) pvParam) = stmt->options.use_bookmarks;
  break;
    case 65534:
  *((long *) pvParam) = 0;
        break;
 default:
  {
  char option[64];
  SC_set_error(stmt, 10, "Unknown statement option (Get)");
  sprintf(option, "fOption=%d", fOption);
  SC_log_error(func, option, stmt);
  return (-1);
  }
 }
 return 0;
}

variable_types: 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_ { 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_ { struct ConnectionClass_ *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 { struct QResultClass_ *result; char name[-1]; } *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; } **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 **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; } *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; } *

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

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


SQLRemoveDriverW

decompiled_code:
__int64 __fastcall SQLRemoveDriverW(__int64 a1, unsigned int a2, __int64 *a3)
{
_BYTE *v4; // rbx
unsigned int v5; // ebp

v4 = (_BYTE *)single_string_alloc_and_copy();
inst_logClear();
v5 = SQLRemoveDriver(v4, a2, a3);
free(v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, __int64 *a3)
{
_BYTE *v4; // rbx
unsigned int v5; // ebp

v4 = (_BYTE *)single_string_alloc_and_copy();
inst_logClear();
v5 = func0(v4, a2, a3);
free(v4);
return v5;
}

original_code:
int SQLRemoveDriverW(LPCWSTR lpszDriver,
                             int fRemoveDSN,
                             LPDWORD lpdwUsageCount)
{
 int ret;
 char *drv = _single_string_alloc_and_copy( lpszDriver );
    inst_logClear();
 ret = SQLRemoveDriver( drv, fRemoveDSN, lpdwUsageCount );
 free( drv );
 return ret;
}

canonical_original_code:
int SQLRemoveDriverW(unsigned short *lpszDriver, int fRemoveDSN, unsigned long *lpdwUsageCount)
{
 int ret;
 char *drv = _single_string_alloc_and_copy( lpszDriver );
    inst_logClear();
 ret = SQLRemoveDriver( drv, fRemoveDSN, lpdwUsageCount );
 free( drv );
 return ret;
}

variable_types:
lpszDriver
unsigned short *

variable_types: fRemoveDSN int

variable_types:
lpdwUsageCount
unsigned long *

variable_types: ret int

variable_types:
drv
char *