decompiled_code:
__int64 __fastcall nnodbc_getstmterrstack(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
void* nnodbc_getstmterrstack(void* hstmt)
{
 return ((stmt_t*)hstmt)->herr;
}

canonical_original_code:
void *nnodbc_getstmterrstack(void *hstmt)
{
 return ((struct stmt_t *)hstmt)->herr;
}

return_type: void *

user_defined_types: struct stmt_t { void *herr; void *hdbc; struct column_t *pcol; struct param_t *ppar; int ndelay; void *yystmt; int refetch; int putipar; }

user_defined_types: struct column_t { short ctype; char *userbuf; long userbufsize; long *pdatalen; long offset; }

user_defined_types: struct param_t { int bind; short type; unsigned long coldef; short scale; char *userbuf; long userbufsize; long *pdatalen; int ctype; int sqltype; char *(*cvt)(); char *putdtbuf; int putdtlen; int need; }


repo: xiaotmiaomiao/unixODBC-SPEC

decompiled_code:
__int64 __fastcall nnodbc_sqlfreestmt(void *ptr, int a2)
{
void *v3; // rdi
void *v4; // rdi
__int64 result; // rax
int v6; // eax
int v7; // er13
__int64 v8; // r12
int v9; // ebp
int v10; // esi
__int64 v11; // rax
__int64 v12; // rcx
int v13; // edx

if ( a2 == 2 )
{
v10 = nnsql_max_column();
v11 = *((_QWORD *)ptr + 2);
if ( v10 >= 0 && v11 )
{
v12 = 0LL;
v13 = 0;
do
{
*(_QWORD *)(v11 + v12 + 8) = 0LL;
++v13;
v11 = *((_QWORD *)ptr + 2);
v12 += 40LL;
}
while ( v10 >= v13 && v11 );
result = 0LL;
}
else
{
result = 0LL;
}
}
else if ( a2 > 2 )
{
result = 0xFFFFFFFFLL;
if ( a2 == 3 )
{
v6 = nnsql_max_param();
v7 = v6;
if ( *((_QWORD *)ptr + 3) && v6 > 0 )
{
v8 = 0LL;
v9 = 1;
do
{
nnsql_yyunbindpar(*((_QWORD *)ptr + 5), (unsigned int)v9);
*(_DWORD *)(*((_QWORD *)ptr + 3) + v8) = 0;
++v9;
v8 += 80LL;
}
while ( *((_QWORD *)ptr + 3) && v7 >= v9 );
result = 0LL;
}
else
{
result = 0LL;
}
}
}
else if ( a2 )
{
if ( a2 == 1 )
{
nnodbc_detach_stmt(*((_QWORD *)ptr + 1), ptr);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 3);
if ( v4 )
free(v4);
nnodbc_clearerr(*(_QWORD *)ptr);
free(ptr);
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
nnsql_close_cursor();
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr, int a2)
{
void *v3; // rdi
void *v4; // rdi
__int64 result; // rax
int v6; // eax
int v7; // er13
__int64 v8; // r12
int v9; // ebp
int v10; // esi
__int64 v11; // rax
__int64 v12; // rcx
int v13; // edx

if ( a2 == 2 )
{
v10 = nnsql_max_column();
v11 = *((_QWORD *)ptr + 2);
if ( v10 >= 0 && v11 )
{
v12 = 0LL;
v13 = 0;
do
{
*(_QWORD *)(v11 + v12 + 8) = 0LL;
++v13;
v11 = *((_QWORD *)ptr + 2);
v12 += 40LL;
}
while ( v10 >= v13 && v11 );
result = 0LL;
}
else
{
result = 0LL;
}
}
else if ( a2 > 2 )
{
result = 0xFFFFFFFFLL;
if ( a2 == 3 )
{
v6 = nnsql_max_param();
v7 = v6;
if ( *((_QWORD *)ptr + 3) && v6 > 0 )
{
v8 = 0LL;
v9 = 1;
do
{
nnsql_yyunbindpar(*((_QWORD *)ptr + 5), (unsigned int)v9);
*(_DWORD *)(*((_QWORD *)ptr + 3) + v8) = 0;
++v9;
v8 += 80LL;
}
while ( *((_QWORD *)ptr + 3) && v7 >= v9 );
result = 0LL;
}
else
{
result = 0LL;
}
}
}
else if ( a2 )
{
if ( a2 == 1 )
{
nnodbc_detach_stmt(*((_QWORD *)ptr + 1), ptr);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 3);
if ( v4 )
free(v4);
nnodbc_clearerr(*(_QWORD *)ptr);
free(ptr);
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
else
{
nnsql_close_cursor();
result = 0LL;
}
return result;
}

original_code:
int nnodbc_sqlfreestmt(
  void* hstmt,
  int fOption)
{
 stmt_t* pstmt = hstmt;
 int i, max;
 switch( fOption )
 {
  case 1:
   nnodbc_detach_stmt(pstmt->hdbc, hstmt);
   {if(pstmt->pcol) free(pstmt->pcol);};
   {if(pstmt->ppar) free(pstmt->ppar);};
   pstmt->herr = nnodbc_clearerr(pstmt->herr);
   {if(hstmt) free(hstmt);};
   break;
  case 0:
   nnsql_close_cursor(hstmt);
   break;
  case 2:
   max = nnsql_max_column();
   for(i=0; pstmt->pcol && i < max + 1; i++ )
    (pstmt->pcol)[i].userbuf = 0;
   break;
  case 3:
   max = nnsql_max_param();
   for(i=1;pstmt->ppar && i < max + 1; i++ )
   {
    nnsql_yyunbindpar( pstmt->yystmt, i);
    (pstmt->ppar)[i-1].bind = 0;
   }
   break;
  default:
   return (-1);
 }
 return 0;
}

canonical_original_code:
int nnodbc_sqlfreestmt(void *hstmt, int fOption)
{
 struct stmt_t *pstmt = hstmt;
 int i; int max;
 switch( fOption )
 {
  case 1:
   nnodbc_detach_stmt(pstmt->hdbc, hstmt);
   {if(pstmt->pcol) free(pstmt->pcol);};
   {if(pstmt->ppar) free(pstmt->ppar);};
   pstmt->herr = nnodbc_clearerr(pstmt->herr);
   {if(hstmt) free(hstmt);};
   break;
  case 0:
   nnsql_close_cursor(hstmt);
   break;
  case 2:
   max = nnsql_max_column();
   for(i=0; pstmt->pcol && i < max + 1; i++ )
    (pstmt->pcol)[i].userbuf = 0;
   break;
  case 3:
   max = nnsql_max_param();
   for(i=1;pstmt->ppar && i < max + 1; i++ )
   {
    nnsql_yyunbindpar( pstmt->yystmt, i);
    (pstmt->ppar)[i-1].bind = 0;
   }
   break;
  default:
   return (-1);
 }
 return 0;
}

variable_types:
hstmt
void *

variable_types: fOption int

variable_types: struct stmt_t { void *herr; void *hdbc; struct column_t { short ctype; char *userbuf; long userbufsize; long *pdatalen; long offset; } *pcol; struct param_t { int bind; short type; unsigned long coldef; short scale; char *userbuf; long userbufsize; long *pdatalen; int ctype; int sqltype; char *(*cvt)(); char *putdtbuf; int putdtlen; int need; } *ppar; int ndelay; void *yystmt; int refetch; int putipar; } *

variable_types: i int

variable_types: max int

return_type: int


decompiled_code:
__int64 __fastcall nnodbc_sqlprepare(_QWORD *a1, const char *a2, int a3)
{
__int64 result; // rax
unsigned int v4; // ebp
__int64 v5; // rax

if ( a3 == -3 && a2 )
strlen(a2);
result = nnsql_prepare(a1[5], a2);
if ( (_DWORD)result )
{
v4 = nnsql_errcode(a1[5]);
if ( v4 == -1 )
v4 = *_errno_location();
v5 = nnsql_errmsg(a1[5]);
*a1 = nnodbc_pusherr(*a1, v4, v5);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, const char *a2, int a3)
{
__int64 result; // rax
unsigned int v4; // ebp
__int64 v5; // rax

if ( a3 == -3 && a2 )
strlen(a2);
result = nnsql_prepare(a1[5], a2);
if ( (_DWORD)result )
{
v4 = nnsql_errcode(a1[5]);
if ( v4 == -1 )
v4 = *_errno_location();
v5 = nnsql_errmsg(a1[5]);
*a1 = nnodbc_pusherr(*a1, v4, v5);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int nnodbc_sqlprepare (
        void* hstmt,
        char* szSqlStr,
        int cbSqlStr )
{
 stmt_t* pstmt = hstmt;
 int len;
 len = (cbSqlStr == (-3) )? ((szSqlStr)? strlen((char*)(szSqlStr)):0):cbSqlStr;
 if ( nnsql_prepare(pstmt->yystmt, szSqlStr, len ) )
 {
  int code;
  code = nnsql_errcode(pstmt->yystmt);
  if ( code == -1 )
   code = (*__errno_location ());
  pstmt->herr = nnodbc_pusherr(pstmt->herr, code, nnsql_errmsg(pstmt->yystmt));
  return (-1);
 }
 return 0;
}

canonical_original_code:
int nnodbc_sqlprepare(void *hstmt, char *szSqlStr, int cbSqlStr)
{
 struct stmt_t *pstmt = hstmt;
 int len;
 len = (cbSqlStr == (-3) )? ((szSqlStr)? strlen((char *)(szSqlStr)):0):cbSqlStr;
 if ( nnsql_prepare(pstmt->yystmt, szSqlStr, len ) )
 {
  int code;
  code = nnsql_errcode(pstmt->yystmt);
  if ( code == -1 )
   code = (*__errno_location ());
  pstmt->herr = nnodbc_pusherr(pstmt->herr, code, nnsql_errmsg(pstmt->yystmt));
  return (-1);
 }
 return 0;
}

variable_types:
szSqlStr
char *

variable_types: cbSqlStr int

variable_types: len int

variable_types: code int


getleaftype

decompiled_code:
__int64 __fastcall getleaftype(__int64 a1, unsigned int *a2)
{
__int64 result; // rax

result = *a2;
if ( (_DWORD)result == 6 )
{
result = *(unsigned int *)(*(_QWORD *)(a1 + 40) + 24LL * (int)a2[2] - 24);
if ( (int)result <= 5 )
{
if ( (int)result <= 2 )
result = 0xFFFFFFFFLL;
}
else if ( (_DWORD)result != 7 )
{
result = 0xFFFFFFFFLL;
}
}
else if ( (int)result > 6 )
{
if ( (_DWORD)result != 7 )
result = 0xFFFFFFFFLL;
}
else if ( (_DWORD)result == 2 )
{
switch ( a2[2] )
{
case 0u:
case 0x13u:
case 0x15u:
case 0x17u:
result = 4LL;
break;
case 0x10u:
case 0x18u:
result = 5LL;
break;
default:
result = 3LL;
break;
}
}
else if ( (unsigned int)(result - 3) >= 3 )
{
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int *a2)
{
__int64 result; // rax

result = *a2;
if ( (_DWORD)result == 6 )
{
result = *(unsigned int *)(*(_QWORD *)(a1 + 40) + 24LL * (int)a2[2] - 24);
if ( (int)result <= 5 )
{
if ( (int)result <= 2 )
result = 0xFFFFFFFFLL;
}
else if ( (_DWORD)result != 7 )
{
result = 0xFFFFFFFFLL;
}
}
else if ( (int)result > 6 )
{
if ( (_DWORD)result != 7 )
result = 0xFFFFFFFFLL;
}
else if ( (_DWORD)result == 2 )
{
switch ( a2[2] )
{
case 0u:
case 0x13u:
case 0x15u:
case 0x17u:
result = 4LL;
break;
case 0x10u:
case 0x18u:
result = 5LL;
break;
default:
result = 3LL;
break;
}
}
else if ( (unsigned int)(result - 3) >= 3 )
{
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int getleaftype(yystmt_t* yystmt, node_t* nd)
{
 yypar_t* par;
 yyattr_t* attr;
 switch( nd->type )
 {
  case en_nt_attr:
   attr = yystmt->pattr + (nd->value).iattr;
   switch((nd->value).iattr)
   {
    case en_lines:
    case en_article_num:
    case en_sql_num:
    case en_sql_count:
     return en_nt_num;
    case en_date:
    case en_sql_date:
     return en_nt_date;
    default:
     break;
   }
   return en_nt_qstr;
  case en_nt_param:
   par = yystmt->ppar + (nd->value).ipar - 1;
   switch(par->type)
   {
    case en_nt_null:
    case en_nt_num:
    case en_nt_qstr:
    case en_nt_date:
     break;
    default:
     return -1;
   }
   return par->type;
  case en_nt_num:
  case en_nt_qstr:
  case en_nt_date:
  case en_nt_null:
   return nd->type;
  default:
   return -1;
 }
}

canonical_original_code:
static int getleaftype(struct yystmt_t *yystmt, struct tnode *nd)
{
 struct yypar_t *par;
 struct yyattr_t *attr;
 switch( nd->type )
 {
  case en_nt_attr:
   attr = yystmt->pattr + (nd->value).iattr;
   switch((nd->value).iattr)
   {
    case en_lines:
    case en_article_num:
    case en_sql_num:
    case en_sql_count:
     return en_nt_num;
    case en_date:
    case en_sql_date:
     return en_nt_date;
    default:
     break;
   }
   return en_nt_qstr;
  case en_nt_param:
   par = yystmt->ppar + (nd->value).ipar - 1;
   switch(par->type)
   {
    case en_nt_null:
    case en_nt_num:
    case en_nt_qstr:
    case en_nt_date:
     break;
    default:
     return -1;
   }
   return par->type;
  case en_nt_num:
  case en_nt_qstr:
  case en_nt_date:
  case en_nt_null:
   return nd->type;
  default:
   return -1;
 }
}

variable_types: struct yystmt_t { void *hcndes; int type; int errcode; int errpos; struct yycol_t { int iattr; char *table; union { long num; char *qstr; struct date_t { int year; int month; int day; } date; } value; } *pcol; struct yyattr_t { int stat; int wstat; int article; union { char *location; long number; struct date_t date; } value; void *nntp_hand; } *pattr; struct yypar_t { int type; union { char *location; long number; struct date_t date; } value; } *ppar; char *table; int ncol; int npar; int count; char *sqlexpr; char *texts_buf; char msgbuf[64]; struct tnode { int type; union { int cmpop; int logop; int iattr; int ipar; char *qstr; long num; struct date_t date; char esc; } value; struct tnode *left; struct tnode *right; } *srchtree; struct tnode *node_buf; int srchtreesize; int srchtreenum; char **ins_heads; struct tnode *ins_values; long artnum_min; long artnum_max; } *

variable_types:
nd
struct tnode *

variable_types: struct yypar_t { int type; union { char *location; long number; struct date_t { int year; int month; int day; } date; } value; } *

variable_types: struct yyattr_t { int stat; int wstat; int article; union { char *location; long number; struct date_t { int year; int month; int day; } date; } value; void *nntp_hand; } *

user_defined_types: struct yystmt_t { void *hcndes; int type; int errcode; int errpos; struct yycol_t *pcol; struct yyattr_t *pattr; struct yypar_t *ppar; char *table; int ncol; int npar; int count; char *sqlexpr; char *texts_buf; char msgbuf[64]; struct tnode *srchtree; struct tnode *node_buf; int srchtreesize; int srchtreenum; char **ins_heads; struct tnode *ins_values; long artnum_min; long artnum_max; }

user_defined_types: struct yycol_t { int iattr; char *table; union { long num; char *qstr; struct date_t date; } value; }


decompiled_code:
__int64 __fastcall cmp_tchk(__int64 a1, unsigned int *a2, unsigned int *a3)
{
int v4; // ebx
int v5; // eax
unsigned int v6; // edx

v4 = getleaftype(a1, a2);
v5 = getleaftype(a1, a3);
if ( v4 == -1 || v5 == -1 )
return (unsigned int)-1;
if ( v4 != 5 || (v6 = 0, v5 != 3) )
v6 = -(v4 != v5 && v4 != 7 && v5 != 7);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int *a2, unsigned int *a3)
{
int v4; // ebx
int v5; // eax
unsigned int v6; // edx

v4 = func0(a1, a2);
v5 = func0(a1, a3);
if ( v4 == -1 || v5 == -1 )
return (unsigned int)-1;
if ( v4 != 5 || (v6 = 0, v5 != 3) )
v6 = -(v4 != v5 && v4 != 7 && v5 != 7);
return v6;
}

original_code:
static int cmp_tchk(yystmt_t* yystmt, node_t* a, node_t* b)
{
 int ta, tb;
 ta = getleaftype( yystmt, a );
 tb = getleaftype( yystmt, b );
 if( ta == -1 || tb == -1 )
  return -1;
 if( ta == en_nt_date && tb == en_nt_qstr )
  return 0;
 if( ta != tb && ta != en_nt_null && tb != en_nt_null )
  return -1;
 return 0;
}

canonical_original_code:
static int cmp_tchk(struct yystmt_t *yystmt, struct tnode *a, struct tnode *b)
{
 int ta; int tb;
 ta = getleaftype( yystmt, a );
 tb = getleaftype( yystmt, b );
 if( ta == -1 || tb == -1 )
  return -1;
 if( ta == en_nt_date && tb == en_nt_qstr )
  return 0;
 if( ta != tb && ta != en_nt_null && tb != en_nt_null )
  return -1;
 return 0;
}

variable_types:
a
struct tnode *

variable_types:
b
struct tnode *

variable_types: ta int

variable_types: tb int

user_defined_types: struct yyattr_t { int stat; int wstat; int article; union { char *location; long number; struct date_t date; } value; void *nntp_hand; }

user_defined_types: struct yypar_t { int type; union { char *location; long number; struct date_t date; } value; }

user_defined_types: struct tnode { int type; union { int cmpop; int logop; int iattr; int ipar; char *qstr; long num; struct date_t date; char esc; } value; struct tnode *left; struct tnode *right; }

user_defined_types: struct date_t { int year; int month; int day; }


decompiled_code:
__int64 __fastcall evl_like_tchk(__int64 a1, unsigned int *a2, unsigned int *a3)
{
int v4; // er12
int v5; // edx
__int64 result; // rax

v4 = getleaftype(a1, a2);
v5 = getleaftype(a1, a3);
result = 0LL;
if ( v5 != 7 )
result = (unsigned int)-(v5 != 3 || v4 != 3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2, unsigned int *a3)
{
int v4; // er12
int v5; // edx
__int64 result; // rax

v4 = func0(a1, a2);
v5 = func0(a1, a3);
result = 0LL;
if ( v5 != 7 )
result = (unsigned int)-(v5 != 3 || v4 != 3);
return result;
}

original_code:
static int evl_like_tchk(yystmt_t* yystmt, node_t* a, node_t* b)
{
 int ta, tb;
 ta = getleaftype(yystmt, a);
 tb = getleaftype(yystmt, b);
 if( tb == en_nt_null
  || tb == en_nt_null )
  return 0;
 if( ta != en_nt_qstr
  || tb != en_nt_qstr )
  return -1;
 return 0;
}

canonical_original_code:
static int evl_like_tchk(struct yystmt_t *yystmt, struct tnode *a, struct tnode *b)
{
 int ta; int tb;
 ta = getleaftype(yystmt, a);
 tb = getleaftype(yystmt, b);
 if( tb == en_nt_null
  || tb == en_nt_null )
  return 0;
 if( ta != en_nt_qstr
  || tb != en_nt_qstr )
  return -1;
 return 0;
}


decompiled_code:
__int64 __fastcall srchtree_tchk(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // eax
int v4; // er12
__int64 v5; // r13
unsigned int *v6; // r12
int v7; // ebx
__int64 v8; // r12
unsigned int *v9; // rbx

if ( !a2 )
return 0LL;
switch ( *(_DWORD *)a2 )
{
case 0:
return cmp_tchk(a1, *(unsigned int **)(a2 + 24), *(unsigned int **)(a2 + 32));
case 1:
v3 = *(_DWORD *)(a2 + 8);
if ( v3 > 7 )
{
if ( v3 != 8 )
LABEL_7:
abort();
result = srchtree_tchk(a1, *(_QWORD *)(a2 + 32));
}
else
{
if ( v3 <= 5 )
goto LABEL_7;
v4 = srchtree_tchk(a1, *(_QWORD *)(a2 + 24));
result = (unsigned int)-((unsigned int)srchtree_tchk(a1, *(_QWORD *)(a2 + 32)) == -1 || v4 == -1);
}
break;
case 8:
case 0xB:
return evl_like_tchk(a1, *(unsigned int **)(a2 + 24), *(unsigned int **)(a2 + 32));
case 9:
v5 = *(_QWORD *)(a2 + 32);
v6 = *(unsigned int **)(a2 + 24);
v7 = cmp_tchk(a1, v6, *(unsigned int **)(v5 + 24));
return (unsigned int)-((unsigned int)cmp_tchk(a1, v6, *(unsigned int **)(v5 + 32)) == -1 || v7 == -1);
case 0xA:
v8 = *(_QWORD *)(a2 + 32);
if ( !v8 )
return 0LL;
v9 = *(unsigned int **)(a2 + 24);
do
{
result = cmp_tchk(a1, v9, (unsigned int *)v8);
if ( (_DWORD)result == -1 )
return result;
v8 = *(_QWORD *)(v8 + 32);
}
while ( v8 );
return 0LL;
case 0xC:
return 0LL;
default:
abort();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // eax
int v4; // er12
__int64 v5; // r13
unsigned int *v6; // r12
int v7; // ebx
__int64 v8; // r12
unsigned int *v9; // rbx

if ( !a2 )
return 0LL;
switch ( *(_DWORD *)a2 )
{
case 0:
return func1(a1, *(unsigned int **)(a2 + 24), *(unsigned int **)(a2 + 32));
case 1:
v3 = *(_DWORD *)(a2 + 8);
if ( v3 > 7 )
{
if ( v3 != 8 )
LABEL_7:
abort();
result = func3(a1, *(_QWORD *)(a2 + 32));
}
else
{
if ( v3 <= 5 )
goto LABEL_7;
v4 = func3(a1, *(_QWORD *)(a2 + 24));
result = (unsigned int)-((unsigned int)func3(a1, *(_QWORD *)(a2 + 32)) == -1 || v4 == -1);
}
break;
case 8:
case 0xB:
return func2(a1, *(unsigned int **)(a2 + 24), *(unsigned int **)(a2 + 32));
case 9:
v5 = *(_QWORD *)(a2 + 32);
v6 = *(unsigned int **)(a2 + 24);
v7 = func1(a1, v6, *(unsigned int **)(v5 + 24));
return (unsigned int)-((unsigned int)func1(a1, v6, *(unsigned int **)(v5 + 32)) == -1 || v7 == -1);
case 0xA:
v8 = *(_QWORD *)(a2 + 32);
if ( !v8 )
return 0LL;
v9 = *(unsigned int **)(a2 + 24);
do
{
result = func1(a1, v9, (unsigned int *)v8);
if ( (_DWORD)result == -1 )
return result;
v8 = *(_QWORD *)(v8 + 32);
}
while ( v8 );
return 0LL;
case 0xC:
return 0LL;
default:
abort();
}
return result;
}

original_code:
static int srchtree_tchk(yystmt_t* yystmt, node_t* node)
{
 int r, s, flag = 0;
 node_t* ptr;
 if( ! node )
  return 0;
 switch( node->type )
 {
  case en_nt_cmpop:
   return cmp_tchk(yystmt, node->left, node->right);
  case en_nt_logop:
   switch( (node->value).logop )
   {
    case en_logop_not:
     return srchtree_tchk(yystmt, node->right);
    case en_logop_and:
    case en_logop_or:
     r = srchtree_tchk(yystmt, node->left);
     s = srchtree_tchk(yystmt, node->right);
     if( r == -1 || s == -1 )
      return -1;
     return 0;
    default:
     abort();
     break;
   }
   break;
  case en_nt_isnull:
   return 0;
  case en_nt_between:
   r = cmp_tchk(yystmt, node->left, node->right->left);
   s = cmp_tchk(yystmt, node->left, node->right->right);
   if( r == -1 || s == -1 )
    return -1;
   return 0;
  case en_nt_in:
   for(ptr=node->right; ptr; ptr=ptr->right)
   {
    r = cmp_tchk(yystmt, node->left, ptr);
    if( r == -1 )
     return -1;
   }
   return 0;
  case en_nt_caselike:
  case en_nt_like:
   return evl_like_tchk( yystmt, node->left, node->right);
  default:
   abort();
   break;
 }
 return -1;
}

canonical_original_code:
static int srchtree_tchk(struct yystmt_t *yystmt, struct tnode *node)
{
 int r; int s; int flag = 0;
 struct tnode *ptr;
 if( ! node )
  return 0;
 switch( node->type )
 {
  case en_nt_cmpop:
   return cmp_tchk(yystmt, node->left, node->right);
  case en_nt_logop:
   switch( (node->value).logop )
   {
    case en_logop_not:
     return srchtree_tchk(yystmt, node->right);
    case en_logop_and:
    case en_logop_or:
     r = srchtree_tchk(yystmt, node->left);
     s = srchtree_tchk(yystmt, node->right);
     if( r == -1 || s == -1 )
      return -1;
     return 0;
    default:
     abort();
     break;
   }
   break;
  case en_nt_isnull:
   return 0;
  case en_nt_between:
   r = cmp_tchk(yystmt, node->left, node->right->left);
   s = cmp_tchk(yystmt, node->left, node->right->right);
   if( r == -1 || s == -1 )
    return -1;
   return 0;
  case en_nt_in:
   for(ptr=node->right; ptr; ptr=ptr->right)
   {
    r = cmp_tchk(yystmt, node->left, ptr);
    if( r == -1 )
     return -1;
   }
   return 0;
  case en_nt_caselike:
  case en_nt_like:
   return evl_like_tchk( yystmt, node->left, node->right);
  default:
   abort();
   break;
 }
 return -1;
}

variable_types:
node
struct tnode *

variable_types: r int

variable_types: s int

variable_types: flag int

variable_types: struct tnode { int type; union { int cmpop; int logop; int iattr; int ipar; char *qstr; long num; struct date_t { int year; int month; int day; } date; char esc; } value; struct tnode *left; struct tnode *right; } *


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

result = srchtree_tchk(a1, *(_QWORD *)(a1 + 152));
if ( (_DWORD)result )
*(_DWORD *)(a1 + 12) = 222;
return result;
}

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

result = func3(a1, *(_QWORD *)(a1 + 152));
if ( (_DWORD)result )
*(_DWORD *)(a1 + 12) = 222;
return result;
}

original_code:
int nnsql_srchtree_tchk(void* hstmt)
{
 yystmt_t* yystmt = hstmt;
 int r;
 r = srchtree_tchk(yystmt, yystmt->srchtree);
 if( r )
  yystmt->errcode = 222;
 return r;
}

canonical_original_code:
int nnsql_srchtree_tchk(void *hstmt)
{
 struct yystmt_t *yystmt = hstmt;
 int r;
 r = srchtree_tchk(yystmt, yystmt->srchtree);
 if( r )
  yystmt->errcode = 222;
 return r;
}

variable_types:
hstmt
void *


SQLColumnPrivileges

decompiled_code:
__int64 __fastcall SQLColumnPrivileges(__int64 a1, __int64 a2, __int16 a3, __int64 a4, __int16 a5, __int64 a6, __int16 a7, __int64 a8, __int16 a9)
{
const char *v12; // rax
int v13; // eax
int v14; // edx
__int64 v15; // rdx
void *v16; // r15
__int16 v17; // bp
__int64 (__fastcall *v18)(_QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD); // r10
const char *v19; // rax
void *v21; // [rsp+0h] [rbp-428h]
void *v22; // [rsp+8h] [rbp-420h]
const char *ptra; // [rsp+18h] [rbp-410h]
void *ptr; // [rsp+18h] [rbp-410h]
const char *v26; // [rsp+20h] [rbp-408h]
const char *v27; // [rsp+28h] [rbp-400h]
char v28[240]; // [rsp+30h] [rbp-3F8h] BYREF
char v29[240]; // [rsp+120h] [rbp-308h] BYREF
char v30[240]; // [rsp+210h] [rbp-218h] BYREF
char v31[296]; // [rsp+300h] [rbp-128h] BYREF

if ( !(unsigned int)_validate_stmt() )
{
dm_log_write("SQLColumnPrivileges.c", 175LL, 0LL, 0LL, "Error: SQL_INVALID_HANDLE");
return 4294967294LL;
}
function_entry(a1);
if ( log_info[4] )
{
ptra = (const char *)_string_with_length(v28, a8, a9);
v26 = (const char *)_string_with_length(v29, a6, a7);
v27 = (const char *)_string_with_length(v30, a4, a5);
v12 = (const char *)_string_with_length(v31, a2, a3);
sprintf(
(char *)(a1 + 16),
"\n"
"\t\tEntry:\n"
"\t\t\tStatement = %p\n"
"\t\t\tCatalog Name = %s\n"
"\t\t\tSchema Name = %s\n"
"\t\t\tTable Name = %s\n"
"\t\t\tColumn Name = %s",
(const void *)a1,
v12,
v27,
v26,
ptra);
dm_log_write("SQLColumnPrivileges.c", 200LL, 0LL, 0LL, a1 + 16);
}
thread_protect(3LL, a1);
if ( a3 < 0 && a3 != -3 || a5 < 0 && a5 != -3 || a7 < 0 && a7 != -3 || a9 < 0 && a9 != -3 )
{
dm_log_write("SQLColumnPrivileges.c", 214LL, 0LL, 0LL, "Error: HY090");
_post_internal_error(a1 + 1088, 29LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v13 = *(_DWORD *)(a1 + 1040);
if ( v13 == 6 )
{
v14 = 6;
if ( *(_DWORD *)(a1 + 1664) )
goto LABEL_17;
LABEL_30:
dm_log_write("SQLColumnPrivileges.c", 240LL, 0LL, 0LL, "Error: 24000");
_post_internal_error(a1 + 1088, 8LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( v13 == 7 )
goto LABEL_30;
v14 = *(_DWORD *)(a1 + 1040);
if ( (unsigned int)(v13 - 8) <= 2 )
{
dm_log_write("SQLColumnPrivileges.c", 256LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
LABEL_17:
if ( (unsigned int)(v14 - 11) <= 1 && *(_DWORD *)(a1 + 1072) != 56 )
{
dm_log_write("SQLColumnPrivileges.c", 274LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( !a6 )
{
dm_log_write("SQLColumnPrivileges.c", 290LL, 0LL, 0LL, "Error: HY009");
_post_internal_error(a1 + 1088, 22LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v15 = *(_QWORD *)(a1 + 1048);
if ( *(_DWORD *)(v15 + 1456) )
{
if ( !*(_QWORD *)(*(_QWORD *)(v15 + 1320) + 936LL) )
{
dm_log_write("SQLColumnPrivileges.c", 313LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
ptr = (void *)ansi_to_unicode_alloc(a2, a3);
v22 = (void *)ansi_to_unicode_alloc(a4, a5);
v21 = (void *)ansi_to_unicode_alloc(a6, a7);
v16 = (void *)ansi_to_unicode_alloc(a8, a9);
v17 = (*(__int64 (__fastcall **)(_QWORD, void *, _QWORD, void *, _QWORD, void *, _QWORD, void *, _QWORD))(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1320LL) + 936LL))(
*(_QWORD *)(a1 + 1056),
ptr,
(unsigned int)a3,
v22,
(unsigned int)a5,
v21,
(unsigned int)a7,
v16,
(unsigned int)a9);
if ( ptr )
free(ptr);
if ( v22 )
free(v22);
if ( v21 )
free(v21);
if ( v16 )
free(v16);
}
else
{
v18 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD))(*(_QWORD *)(v15 + 1320) + 928LL);
if ( !v18 )
{
dm_log_write("SQLColumnPrivileges.c", 355LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v17 = v18(
*(_QWORD *)(a1 + 1056),
a2,
(unsigned int)a3,
a4,
(unsigned int)a5,
a6,
(unsigned int)a7,
a8,
(unsigned int)a9);
}
if ( (v17 & 0xFFFE) != 0 )
{
if ( v17 == 2 )
{
*(_DWORD *)(a1 + 1072) = 56;
if ( (unsigned int)(*(_DWORD *)(a1 + 1040) - 11) > 1 )
*(_DWORD *)(a1 + 1040) = 11;
}
else
{
*(_DWORD *)(a1 + 1040) = 1;
}
}
else
{
*(_DWORD *)(a1 + 1040) = 5;
*(_DWORD *)(a1 + 1068) = 0;
}
if ( log_info[4] )
{
v19 = (const char *)_get_return_status((unsigned int)v17, v31);
sprintf((char *)(a1 + 16), "\n\t\tExit:[%s]", v19);
dm_log_write("SQLColumnPrivileges.c", 403LL, 0LL, 0LL, a1 + 16);
}
return function_return_ex(3LL, a1, (unsigned int)v17, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int16 a3, __int64 a4, __int16 a5, __int64 a6, __int16 a7, __int64 a8, __int16 a9)
{
const char *v12; // rax
int v13; // eax
int v14; // edx
__int64 v15; // rdx
void *v16; // r15
__int16 v17; // bp
__int64 (__fastcall *v18)(_QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD); // r10
const char *v19; // rax
void *v21; // [rsp+0h] [rbp-428h]
void *v22; // [rsp+8h] [rbp-420h]
const char *ptra; // [rsp+18h] [rbp-410h]
void *ptr; // [rsp+18h] [rbp-410h]
const char *v26; // [rsp+20h] [rbp-408h]
const char *v27; // [rsp+28h] [rbp-400h]
char v28[240]; // [rsp+30h] [rbp-3F8h] BYREF
char v29[240]; // [rsp+120h] [rbp-308h] BYREF
char v30[240]; // [rsp+210h] [rbp-218h] BYREF
char v31[296]; // [rsp+300h] [rbp-128h] BYREF

if ( !(unsigned int)_validate_stmt() )
{
dm_log_write("SQLColumnPrivileges.c", 175LL, 0LL, 0LL, "Error: SQL_INVALID_HANDLE");
return 4294967294LL;
}
function_entry(a1);
if ( log_info[4] )
{
ptra = (const char *)_string_with_length(v28, a8, a9);
v26 = (const char *)_string_with_length(v29, a6, a7);
v27 = (const char *)_string_with_length(v30, a4, a5);
v12 = (const char *)_string_with_length(v31, a2, a3);
sprintf(
(char *)(a1 + 16),
"\n"
"\t\tEntry:\n"
"\t\t\tStatement = %p\n"
"\t\t\tCatalog Name = %s\n"
"\t\t\tSchema Name = %s\n"
"\t\t\tTable Name = %s\n"
"\t\t\tColumn Name = %s",
(const void *)a1,
v12,
v27,
v26,
ptra);
dm_log_write("SQLColumnPrivileges.c", 200LL, 0LL, 0LL, a1 + 16);
}
thread_protect(3LL, a1);
if ( a3 < 0 && a3 != -3 || a5 < 0 && a5 != -3 || a7 < 0 && a7 != -3 || a9 < 0 && a9 != -3 )
{
dm_log_write("SQLColumnPrivileges.c", 214LL, 0LL, 0LL, "Error: HY090");
_post_internal_error(a1 + 1088, 29LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v13 = *(_DWORD *)(a1 + 1040);
if ( v13 == 6 )
{
v14 = 6;
if ( *(_DWORD *)(a1 + 1664) )
goto LABEL_17;
LABEL_30:
dm_log_write("SQLColumnPrivileges.c", 240LL, 0LL, 0LL, "Error: 24000");
_post_internal_error(a1 + 1088, 8LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( v13 == 7 )
goto LABEL_30;
v14 = *(_DWORD *)(a1 + 1040);
if ( (unsigned int)(v13 - 8) <= 2 )
{
dm_log_write("SQLColumnPrivileges.c", 256LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
LABEL_17:
if ( (unsigned int)(v14 - 11) <= 1 && *(_DWORD *)(a1 + 1072) != 56 )
{
dm_log_write("SQLColumnPrivileges.c", 274LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( !a6 )
{
dm_log_write("SQLColumnPrivileges.c", 290LL, 0LL, 0LL, "Error: HY009");
_post_internal_error(a1 + 1088, 22LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v15 = *(_QWORD *)(a1 + 1048);
if ( *(_DWORD *)(v15 + 1456) )
{
if ( !*(_QWORD *)(*(_QWORD *)(v15 + 1320) + 936LL) )
{
dm_log_write("SQLColumnPrivileges.c", 313LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
ptr = (void *)ansi_to_unicode_alloc(a2, a3);
v22 = (void *)ansi_to_unicode_alloc(a4, a5);
v21 = (void *)ansi_to_unicode_alloc(a6, a7);
v16 = (void *)ansi_to_unicode_alloc(a8, a9);
v17 = (*(__int64 (__fastcall **)(_QWORD, void *, _QWORD, void *, _QWORD, void *, _QWORD, void *, _QWORD))(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1320LL) + 936LL))(
*(_QWORD *)(a1 + 1056),
ptr,
(unsigned int)a3,
v22,
(unsigned int)a5,
v21,
(unsigned int)a7,
v16,
(unsigned int)a9);
if ( ptr )
free(ptr);
if ( v22 )
free(v22);
if ( v21 )
free(v21);
if ( v16 )
free(v16);
}
else
{
v18 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD))(*(_QWORD *)(v15 + 1320) + 928LL);
if ( !v18 )
{
dm_log_write("SQLColumnPrivileges.c", 355LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v17 = v18(
*(_QWORD *)(a1 + 1056),
a2,
(unsigned int)a3,
a4,
(unsigned int)a5,
a6,
(unsigned int)a7,
a8,
(unsigned int)a9);
}
if ( (v17 & 0xFFFE) != 0 )
{
if ( v17 == 2 )
{
*(_DWORD *)(a1 + 1072) = 56;
if ( (unsigned int)(*(_DWORD *)(a1 + 1040) - 11) > 1 )
*(_DWORD *)(a1 + 1040) = 11;
}
else
{
*(_DWORD *)(a1 + 1040) = 1;
}
}
else
{
*(_DWORD *)(a1 + 1040) = 5;
*(_DWORD *)(a1 + 1068) = 0;
}
if ( log_info[4] )
{
v19 = (const char *)_get_return_status((unsigned int)v17, v31);
sprintf((char *)(a1 + 16), "\n\t\tExit:[%s]", v19);
dm_log_write("SQLColumnPrivileges.c", 403LL, 0LL, 0LL, a1 + 16);
}
return function_return_ex(3LL, a1, (unsigned int)v17, 0LL);
}

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 *

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: enum STMT_Status { STMT_ALLOCATED=0, STMT_READY=1, STMT_PREMATURE=2, STMT_FINISHED=3, STMT_EXECUTING=4 }

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

decompiled_code:
__int64 SQLRemoveTranslatorW()
{
inst_logClear();
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
inst_logClear();
return 0LL;
}

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 *


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

result = save_path_2;
if ( !saved_3 )
{
v2 = getenv("ODBCSYSINI");
if ( v2 )
{
strcpy(src, v2);
strcpy(save_path_2, src);
saved_3 = 1;
result = src;
}
else
{
strcpy(save_path_2, "/etc");
saved_3 = 1;
result = "/etc";
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
char *result; // rax
char *v2; // rsi

result = save_path_2;
if ( !saved_3 )
{
v2 = getenv("ODBCSYSINI");
if ( v2 )
{
strcpy(src, v2);
strcpy(save_path_2, src);
saved_3 = 1;
result = src;
}
else
{
strcpy(save_path_2, "/etc");
saved_3 = 1;
result = "/etc";
}
}
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 *func2()
{
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:
char *__fastcall odbcinst_user_file_path(char *src)
{
char *result; // rax
char *v2; // rsi

result = save_path_0;
if ( !saved_1 )
{
v2 = getenv("HOME");
result = "/home";
if ( v2 )
{
strcpy(src, v2);
strcpy(save_path_0, src);
saved_1 = 1;
result = src;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(char *src)
{
char *result; // rax
char *v2; // rsi

result = save_path_0;
if ( !saved_1 )
{
v2 = getenv("HOME");
result = "/home";
if ( v2 )
{
strcpy(src, v2);
strcpy(save_path_0, src);
saved_1 = 1;
result = src;
}
}
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, __int64 a2, __int16 a3, __int64 a4, __int16 a5, __int64 a6, __int16 a7, __int64 a8, __int16 a9, __int64 a10, __int16 a11, __int64 a12, __int16 a13)
{
const char *v16; // rax
int v17; // eax
int v18; // edx
__int64 v19; // rdx
__int16 v20; // bp
__int64 (__fastcall *v21)(_QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD); // r10
const char *v22; // rax
void *v23; // [rsp+10h] [rbp-618h]
void *v25; // [rsp+18h] [rbp-610h]
void *v27; // [rsp+20h] [rbp-608h]
const char *v28; // [rsp+28h] [rbp-600h]
void *v29; // [rsp+28h] [rbp-600h]
const char *ptra; // [rsp+30h] [rbp-5F8h]
void *ptr; // [rsp+30h] [rbp-5F8h]
const char *v32; // [rsp+38h] [rbp-5F0h]
void *v33; // [rsp+38h] [rbp-5F0h]
const char *v34; // [rsp+40h] [rbp-5E8h]
const char *v35; // [rsp+48h] [rbp-5E0h]
char v36[240]; // [rsp+50h] [rbp-5D8h] BYREF
char v37[240]; // [rsp+140h] [rbp-4E8h] BYREF
char v38[240]; // [rsp+230h] [rbp-3F8h] BYREF
char v39[240]; // [rsp+320h] [rbp-308h] BYREF
char v40[240]; // [rsp+410h] [rbp-218h] BYREF
char v41[296]; // [rsp+500h] [rbp-128h] BYREF

if ( !(unsigned int)_validate_stmt() )
{
dm_log_write("SQLForeignKeys.c", 197LL, 0LL, 0LL, "Error: SQL_INVALID_HANDLE");
return 4294967294LL;
}
function_entry(a1);
if ( log_info[4] )
{
v28 = (const char *)_string_with_length(v36, a12, a13);
ptra = (const char *)_string_with_length(v37, a10, a11);
v32 = (const char *)_string_with_length(v38, a8, a9);
v34 = (const char *)_string_with_length(v39, a6, a7);
v35 = (const char *)_string_with_length(v40, a4, a5);
v16 = (const char *)_string_with_length(v41, a2, a3);
sprintf(
(char *)(a1 + 16),
"\n"
"\t\tEntry:\n"
"\t\t\tStatement = %p\n"
"\t\t\tPK Catalog Name = %s\n"
"\t\t\tPK Schema Name = %s\n"
"\t\t\tPK Table Name = %s\n"
"\t\t\tFK Catalog Name = %s\n"
"\t\t\tFK Schema Name = %s\n"
"\t\t\tFK Table Name = %s",
(const void *)a1,
v16,
v35,
v34,
v32,
ptra,
v28);
dm_log_write("SQLForeignKeys.c", 226LL, 0LL, 0LL, a1 + 16);
}
thread_protect(3LL, a1);
if ( a3 < 0 && a3 != -3
|| a5 < 0 && a5 != -3
|| a7 < 0 && a7 != -3
|| a9 < 0 && a9 != -3
|| a11 < 0 && a11 != -3
|| a13 < 0 && a13 != -3 )
{
_post_internal_error(a1 + 1088, 29LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v17 = *(_DWORD *)(a1 + 1040);
if ( v17 == 6 )
{
v18 = 6;
if ( *(_DWORD *)(a1 + 1664) )
goto LABEL_21;
LABEL_37:
dm_log_write("SQLForeignKeys.c", 262LL, 0LL, 0LL, "Error: 24000");
_post_internal_error(a1 + 1088, 8LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( v17 == 7 )
goto LABEL_37;
v18 = *(_DWORD *)(a1 + 1040);
if ( (unsigned int)(v17 - 8) <= 2 )
{
dm_log_write("SQLForeignKeys.c", 278LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
LABEL_21:
if ( (unsigned int)(v18 - 11) <= 1 && *(_DWORD *)(a1 + 1072) != 60 )
{
dm_log_write("SQLForeignKeys.c", 296LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v19 = *(_QWORD *)(a1 + 1048);
if ( *(_DWORD *)(v19 + 1456) )
{
if ( !*(_QWORD *)(*(_QWORD *)(v19 + 1320) + 2024LL) )
{
dm_log_write("SQLForeignKeys.c", 320LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
ptr = (void *)ansi_to_unicode_alloc(a2, a3);
v23 = (void *)ansi_to_unicode_alloc(a4, a5);
v25 = (void *)ansi_to_unicode_alloc(a6, a7);
v27 = (void *)ansi_to_unicode_alloc(a8, a9);
v29 = (void *)ansi_to_unicode_alloc(a10, a11);
v33 = (void *)ansi_to_unicode_alloc(a12, a13);
v20 = (*(__int64 (__fastcall **)(_QWORD, void *, _QWORD, void *, _QWORD, void *, _QWORD, void *, _QWORD, void *, _QWORD, void *, _QWORD))(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1320LL) + 2024LL))(
*(_QWORD *)(a1 + 1056),
ptr,
(unsigned int)a3,
v23,
(unsigned int)a5,
v25,
(unsigned int)a7,
v27,
(unsigned int)a9,
v29,
(unsigned int)a11,
v33,
(unsigned int)a13);
if ( ptr )
free(ptr);
if ( v23 )
free(v23);
if ( v25 )
free(v25);
if ( v27 )
free(v27);
if ( v29 )
free(v29);
if ( v33 )
free(v33);
}
else
{
v21 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD))(*(_QWORD *)(v19 + 1320) + 2016LL);
if ( !v21 )
{
dm_log_write("SQLForeignKeys.c", 372LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v20 = v21(
*(_QWORD *)(a1 + 1056),
a2,
(unsigned int)a3,
a4,
(unsigned int)a5,
a6,
(unsigned int)a7,
a8,
(unsigned int)a9,
a10,
(unsigned int)a11,
a12,
(unsigned int)a13);
}
if ( (v20 & 0xFFFE) != 0 )
{
if ( v20 == 2 )
{
*(_DWORD *)(a1 + 1072) = 60;
if ( (unsigned int)(*(_DWORD *)(a1 + 1040) - 11) > 1 )
*(_DWORD *)(a1 + 1040) = 11;
}
else
{
*(_DWORD *)(a1 + 1040) = 1;
}
}
else
{
*(_WORD *)(a1 + 1064) = 1;
*(_DWORD *)(a1 + 1040) = 5;
*(_DWORD *)(a1 + 1068) = 0;
}
if ( log_info[4] )
{
v22 = (const char *)_get_return_status((unsigned int)v20, v41);
sprintf((char *)(a1 + 16), "\n\t\tExit:[%s]", v22);
dm_log_write("SQLForeignKeys.c", 444LL, 0LL, 0LL, a1 + 16);
}
return function_return_ex(3LL, a1, (unsigned int)v20, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int16 a3, __int64 a4, __int16 a5, __int64 a6, __int16 a7, __int64 a8, __int16 a9, __int64 a10, __int16 a11, __int64 a12, __int16 a13)
{
const char *v16; // rax
int v17; // eax
int v18; // edx
__int64 v19; // rdx
__int16 v20; // bp
__int64 (__fastcall *v21)(_QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD); // r10
const char *v22; // rax
void *v23; // [rsp+10h] [rbp-618h]
void *v25; // [rsp+18h] [rbp-610h]
void *v27; // [rsp+20h] [rbp-608h]
const char *v28; // [rsp+28h] [rbp-600h]
void *v29; // [rsp+28h] [rbp-600h]
const char *ptra; // [rsp+30h] [rbp-5F8h]
void *ptr; // [rsp+30h] [rbp-5F8h]
const char *v32; // [rsp+38h] [rbp-5F0h]
void *v33; // [rsp+38h] [rbp-5F0h]
const char *v34; // [rsp+40h] [rbp-5E8h]
const char *v35; // [rsp+48h] [rbp-5E0h]
char v36[240]; // [rsp+50h] [rbp-5D8h] BYREF
char v37[240]; // [rsp+140h] [rbp-4E8h] BYREF
char v38[240]; // [rsp+230h] [rbp-3F8h] BYREF
char v39[240]; // [rsp+320h] [rbp-308h] BYREF
char v40[240]; // [rsp+410h] [rbp-218h] BYREF
char v41[296]; // [rsp+500h] [rbp-128h] BYREF

if ( !(unsigned int)_validate_stmt() )
{
dm_log_write("SQLForeignKeys.c", 197LL, 0LL, 0LL, "Error: SQL_INVALID_HANDLE");
return 4294967294LL;
}
function_entry(a1);
if ( log_info[4] )
{
v28 = (const char *)_string_with_length(v36, a12, a13);
ptra = (const char *)_string_with_length(v37, a10, a11);
v32 = (const char *)_string_with_length(v38, a8, a9);
v34 = (const char *)_string_with_length(v39, a6, a7);
v35 = (const char *)_string_with_length(v40, a4, a5);
v16 = (const char *)_string_with_length(v41, a2, a3);
sprintf(
(char *)(a1 + 16),
"\n"
"\t\tEntry:\n"
"\t\t\tStatement = %p\n"
"\t\t\tPK Catalog Name = %s\n"
"\t\t\tPK Schema Name = %s\n"
"\t\t\tPK Table Name = %s\n"
"\t\t\tFK Catalog Name = %s\n"
"\t\t\tFK Schema Name = %s\n"
"\t\t\tFK Table Name = %s",
(const void *)a1,
v16,
v35,
v34,
v32,
ptra,
v28);
dm_log_write("SQLForeignKeys.c", 226LL, 0LL, 0LL, a1 + 16);
}
thread_protect(3LL, a1);
if ( a3 < 0 && a3 != -3
|| a5 < 0 && a5 != -3
|| a7 < 0 && a7 != -3
|| a9 < 0 && a9 != -3
|| a11 < 0 && a11 != -3
|| a13 < 0 && a13 != -3 )
{
_post_internal_error(a1 + 1088, 29LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v17 = *(_DWORD *)(a1 + 1040);
if ( v17 == 6 )
{
v18 = 6;
if ( *(_DWORD *)(a1 + 1664) )
goto LABEL_21;
LABEL_37:
dm_log_write("SQLForeignKeys.c", 262LL, 0LL, 0LL, "Error: 24000");
_post_internal_error(a1 + 1088, 8LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
if ( v17 == 7 )
goto LABEL_37;
v18 = *(_DWORD *)(a1 + 1040);
if ( (unsigned int)(v17 - 8) <= 2 )
{
dm_log_write("SQLForeignKeys.c", 278LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
LABEL_21:
if ( (unsigned int)(v18 - 11) <= 1 && *(_DWORD *)(a1 + 1072) != 60 )
{
dm_log_write("SQLForeignKeys.c", 296LL, 0LL, 0LL, "Error: HY010");
_post_internal_error(a1 + 1088, 23LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v19 = *(_QWORD *)(a1 + 1048);
if ( *(_DWORD *)(v19 + 1456) )
{
if ( !*(_QWORD *)(*(_QWORD *)(v19 + 1320) + 2024LL) )
{
dm_log_write("SQLForeignKeys.c", 320LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
ptr = (void *)ansi_to_unicode_alloc(a2, a3);
v23 = (void *)ansi_to_unicode_alloc(a4, a5);
v25 = (void *)ansi_to_unicode_alloc(a6, a7);
v27 = (void *)ansi_to_unicode_alloc(a8, a9);
v29 = (void *)ansi_to_unicode_alloc(a10, a11);
v33 = (void *)ansi_to_unicode_alloc(a12, a13);
v20 = (*(__int64 (__fastcall **)(_QWORD, void *, _QWORD, void *, _QWORD, void *, _QWORD, void *, _QWORD, void *, _QWORD, void *, _QWORD))(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1320LL) + 2024LL))(
*(_QWORD *)(a1 + 1056),
ptr,
(unsigned int)a3,
v23,
(unsigned int)a5,
v25,
(unsigned int)a7,
v27,
(unsigned int)a9,
v29,
(unsigned int)a11,
v33,
(unsigned int)a13);
if ( ptr )
free(ptr);
if ( v23 )
free(v23);
if ( v25 )
free(v25);
if ( v27 )
free(v27);
if ( v29 )
free(v29);
if ( v33 )
free(v33);
}
else
{
v21 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD, __int64, _QWORD))(*(_QWORD *)(v19 + 1320) + 2016LL);
if ( !v21 )
{
dm_log_write("SQLForeignKeys.c", 372LL, 0LL, 0LL, "Error: IM001");
_post_internal_error(a1 + 1088, 42LL, 0LL, *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 1048) + 1048LL) + 1048LL));
return function_return_ex(3LL, a1, 0xFFFFFFFFLL, 0LL);
}
v20 = v21(
*(_QWORD *)(a1 + 1056),
a2,
(unsigned int)a3,
a4,
(unsigned int)a5,
a6,
(unsigned int)a7,
a8,
(unsigned int)a9,
a10,
(unsigned int)a11,
a12,
(unsigned int)a13);
}
if ( (v20 & 0xFFFE) != 0 )
{
if ( v20 == 2 )
{
*(_DWORD *)(a1 + 1072) = 60;
if ( (unsigned int)(*(_DWORD *)(a1 + 1040) - 11) > 1 )
*(_DWORD *)(a1 + 1040) = 11;
}
else
{
*(_DWORD *)(a1 + 1040) = 1;
}
}
else
{
*(_WORD *)(a1 + 1064) = 1;
*(_DWORD *)(a1 + 1040) = 5;
*(_DWORD *)(a1 + 1068) = 0;
}
if ( log_info[4] )
{
v22 = (const char *)_get_return_status((unsigned int)v20, v41);
sprintf((char *)(a1 + 16), "\n\t\tExit:[%s]", v22);
dm_log_write("SQLForeignKeys.c", 444LL, 0LL, 0LL, a1 + 16);
}
return function_return_ex(3LL, a1, (unsigned int)v20, 0LL);
}

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:
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]

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