decompiled_code:
__int64 __fastcall date2char(unsigned int *a1, char *a2, __int64 a3, _QWORD *a4)
{
__int64 result; // rax

*a4 = 11LL;
result = -1LL;
if ( a3 > 10 )
{
sprintf(a2, "%04d-%02d-%02d", *a1, a1[1], a1[2]);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned int *a1, char *a2, __int64 a3, _QWORD *a4)
{
__int64 result; // rax

*a4 = 11LL;
result = -1LL;
if ( a3 > 10 )
{
sprintf(a2, "%04d-%02d-%02d", *a1, a1[1], a1[2]);
result = 0LL;
}
return result;
}

original_code:
static char* date2char(date_t* dt, char* buf, long size, long* psize)
{
 *psize = 11;
 if(size < 11)
  return (char*)(-1);
 sprintf(buf, "%04d-%02d-%02d", dt->year, dt->month, dt->day);
 return 0;
}

canonical_original_code:
static char *date2char(struct date_t *dt, char *buf, long size, long *psize)
{
 *psize = 11;
 if(size < 11)
  return (char *)(-1);
 sprintf(buf, "%04d-%02d-%02d", dt->year, dt->month, dt->day);
 return 0;
}

variable_types:
buf
char *

variable_types: size long

variable_types:
psize
long *


repo: xiaotmiaomiao/unixODBC-SPEC

decompiled_code:
__int64 __fastcall num2char(__int64 a1, char *a2, signed __int64 a3, signed __int64 *a4)
{
signed __int64 v6; // rax
__int64 v7; // rdx
char v9[72]; // [rsp+0h] [rbp-48h] BYREF

sprintf(v9, "%ld", a1);
v6 = 1LL;
if ( a2 )
v6 = strlen(a2) + 1;
*a4 = v6;
v7 = -1LL;
if ( v6 <= a3 )
{
strcpy(a2, v9);
v7 = 0LL;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, char *a2, signed __int64 a3, signed __int64 *a4)
{
signed __int64 v6; // rax
__int64 v7; // rdx
char v9[72]; // [rsp+0h] [rbp-48h] BYREF

sprintf(v9, "%ld", a1);
v6 = 1LL;
if ( a2 )
v6 = strlen(a2) + 1;
*a4 = v6;
v7 = -1LL;
if ( v6 <= a3 )
{
strcpy(a2, v9);
v7 = 0LL;
}
return v7;
}

original_code:
static char* num2char( long x, char* buf, long size, long* psize)
{
 char tbuf[48];
 sprintf(tbuf, "%ld", x);
 *psize = ((buf)? strlen((char*)(buf)):0) + 1;
 if(*psize > size )
  return (char*)(-1);
 (strcpy((char*)(buf), (char*)(tbuf)));
 return 0;
}

canonical_original_code:
static char *num2char(long x, char *buf, long size, long *psize)
{
 char tbuf[48];
 sprintf(tbuf, "%ld", x);
 *psize = ((buf)? strlen((char *)(buf)):0) + 1;
 if(*psize > size )
  return (char *)(-1);
 (strcpy((char *)(buf), (char *)(tbuf)));
 return 0;
}

variable_types: x long

variable_types:
tbuf
char [48]

return_type: char *


decompiled_code:
__int64 __fastcall str2date(__int64 a1, _WORD *a2)
{
int v2; // edx
__int64 result; // rax
int v4; // [rsp+4h] [rbp-14h] BYREF
int v5; // [rsp+8h] [rbp-10h]
int v6; // [rsp+Ch] [rbp-Ch]

v2 = nnsql_nndatestr2date(a1, &v4);
result = -1LL;
if ( !v2 )
{
*a2 = v4;
a2[1] = v5;
a2[2] = v6;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, _WORD *a2)
{
int v2; // edx
__int64 result; // rax
int v4; // [rsp+4h] [rbp-14h] BYREF
int v5; // [rsp+8h] [rbp-10h]
int v6; // [rsp+Ch] [rbp-Ch]

v2 = nnsql_nndatestr2date(a1, &v4);
result = -1LL;
if ( !v2 )
{
*a2 = v4;
a2[1] = v5;
a2[2] = v6;
result = 0LL;
}
return result;
}

original_code:
static char* str2date( char* ptr, odbc_date_t* buf )
{
 date_t dt;
 if( nnsql_nndatestr2date(ptr, &dt) )
  return (char*)(-1);
 buf->year = dt.year;
 buf->month= dt.month;
 buf->day = dt.day;
 return 0;
}

canonical_original_code:
static char *str2date(char *ptr, struct DATE_STRUCT *buf)
{
 struct date_t dt;
 if( nnsql_nndatestr2date(ptr, &dt) )
  return (char *)(-1);
 buf->year = dt.year;
 buf->month= dt.month;
 buf->day = dt.day;
 return 0;
}

variable_types:
ptr
char *

variable_types: struct DATE_STRUCT { short year; unsigned short month; unsigned short day; } *

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


decompiled_code:
__int64 __fastcall str2short(const char *a1, _WORD *a2, __int64 a3, _QWORD *a4)
{
int v5; // eax
__int64 result; // rax

v5 = atoi(a1);
if ( (unsigned __int64)v5 <= 0xFFFF )
{
*a2 = v5;
result = 0LL;
}
else
{
*a4 = v5;
result = -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(const char *a1, _WORD *a2, __int64 a3, _QWORD *a4)
{
int v5; // eax
__int64 result; // rax

v5 = atoi(a1);
if ( (unsigned __int64)v5 <= 0xFFFF )
{
*a2 = v5;
result = 0LL;
}
else
{
*a4 = v5;
result = -1LL;
}
return result;
}

original_code:
static char* str2short( char* ptr, short* buf, long size, long* psize)
{
 unsigned long a, b = (unsigned short)(-1);
 a = atoi(ptr);
 if( a > b )
 {
  *psize = a;
  return (char*)(-1);
 }
 *buf = (short)a;
 return 0;
}

canonical_original_code:
static char *str2short(char *ptr, short *buf, long size, long *psize)
{
 unsigned long a; unsigned long b = (unsigned short)(-1);
 a = atoi(ptr);
 if( a > b )
 {
  *psize = a;
  return (char *)(-1);
 }
 *buf = (short)a;
 return 0;
}

variable_types:
buf
short *

variable_types:
a
unsigned long

variable_types:
b
unsigned long


decompiled_code:
__int64 __fastcall nnodbc_get_c2sql_cvt(int a1, int a2)
{
__int64 v2; // rax
int v3; // edx
int v4; // edi
__int64 v5; // rax
int v6; // edx
int v7; // eax
__int64 result; // rax

v2 = 0LL;
do
v3 = v2++;
while ( dword_6B8[2 * v2] != a1 );
v4 = ctype_idx_tab[2 * v3 + 1];
if ( v4 == -1 )
return 0LL;
v5 = 0LL;
do
v6 = v5++;
while ( sqltype_idx_tab[2 * v5 - 2] != a2 );
v7 = sqltype_idx_tab[2 * v6 + 1];
if ( v7 == -1 )
result = 0LL;
else
result = (__int64)*(&c2sql_cvt_tab[3 * v4] + v7);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func22(int a1, int a2)
{
__int64 v2; // rax
int v3; // edx
int v4; // edi
__int64 v5; // rax
int v6; // edx
int v7; // eax
__int64 result; // rax

v2 = 0LL;
do
v3 = v2++;
while ( dword_6B8[2 * v2] != a1 );
v4 = ctype_idx_tab[2 * v3 + 1];
if ( v4 == -1 )
return 0LL;
v5 = 0LL;
do
v6 = v5++;
while ( sqltype_idx_tab[2 * v5 - 2] != a2 );
v7 = sqltype_idx_tab[2 * v6 + 1];
if ( v7 == -1 )
result = 0LL;
else
result = (__int64)*(&c2sql_cvt_tab[3 * v4] + v7);
return result;
}

original_code:
fptr_t nnodbc_get_c2sql_cvt(int ctype, int sqltype)
{
 int i, cidx = -1, sqlidx = -1;
 for(i=0; i< sizeof(ctype_idx_tab); i++ )
 {
  if( ctype_idx_tab[i].ctype == ctype )
  {
   cidx = ctype_idx_tab[i].idx;
   break;
  }
 }
 if( cidx == -1 )
  return 0;
 for(i=0; i< sizeof(ctype_idx_tab); i++ )
 {
  if( sqltype_idx_tab[i].sqltype == sqltype )
  {
   sqlidx = sqltype_idx_tab[i].idx;
   break;
  }
 }
 if( sqlidx == -1 )
  return 0;
 return c2sql_cvt_tab[cidx][sqlidx];
}

canonical_original_code:
char *(*nnodbc_get_c2sql_cvt(int ctype, int sqltype))()
{
 int i; int cidx = -1; int sqlidx = -1;
 for(i=0; i< sizeof(ctype_idx_tab); i++ )
 {
  if( ctype_idx_tab[i].ctype == ctype )
  {
   cidx = ctype_idx_tab[i].idx;
   break;
  }
 }
 if( cidx == -1 )
  return 0;
 for(i=0; i< sizeof(ctype_idx_tab); i++ )
 {
  if( sqltype_idx_tab[i].sqltype == sqltype )
  {
   sqlidx = sqltype_idx_tab[i].idx;
   break;
  }
 }
 if( sqlidx == -1 )
  return 0;
 return c2sql_cvt_tab[cidx][sqlidx];
}

variable_types: ctype int

variable_types: sqltype int

variable_types: i int

variable_types: cidx int

variable_types: sqlidx int


decompiled_code:
__int64 __fastcall nnodbc_get_sql2c_cvt(int a1, int a2)
{
__int64 v2; // rax
int v3; // edx
int v4; // esi
__int64 v5; // rax
int v6; // edx
int v7; // eax
__int64 result; // rax

v2 = 0LL;
do
v3 = v2++;
while ( dword_6B8[2 * v2] != a2 );
v4 = ctype_idx_tab[2 * v3 + 1];
if ( v4 == -1 )
return 0LL;
v5 = 0LL;
do
v6 = v5++;
while ( sqltype_idx_tab[2 * v5 - 2] != a1 );
v7 = sqltype_idx_tab[2 * v6 + 1];
if ( v7 == -1 )
result = 0LL;
else
result = (__int64)*(&sql2c_cvt_tab + 5 * v7 + v4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(int a1, int a2)
{
__int64 v2; // rax
int v3; // edx
int v4; // esi
__int64 v5; // rax
int v6; // edx
int v7; // eax
__int64 result; // rax

v2 = 0LL;
do
v3 = v2++;
while ( dword_6B8[2 * v2] != a2 );
v4 = ctype_idx_tab[2 * v3 + 1];
if ( v4 == -1 )
return 0LL;
v5 = 0LL;
do
v6 = v5++;
while ( sqltype_idx_tab[2 * v5 - 2] != a1 );
v7 = sqltype_idx_tab[2 * v6 + 1];
if ( v7 == -1 )
result = 0LL;
else
result = (__int64)*(&sql2c_cvt_tab + 5 * v7 + v4);
return result;
}

original_code:
fptr_t nnodbc_get_sql2c_cvt(int sqltype, int ctype)
{
 int i, cidx = -1, sqlidx = -1;
 for(i=0; i< sizeof(ctype_idx_tab); i++ )
 {
  if( ctype_idx_tab[i].ctype == ctype )
  {
   cidx = ctype_idx_tab[i].idx;
   break;
  }
 }
 if( cidx == -1 )
  return 0;
 for(i=0; i< sizeof(ctype_idx_tab); i++ )
 {
  if( sqltype_idx_tab[i].sqltype == sqltype )
  {
   sqlidx = sqltype_idx_tab[i].idx;
   break;
  }
 }
 if( sqlidx == -1 )
  return 0;
 return sql2c_cvt_tab[sqlidx][cidx];
}

canonical_original_code:
char *(*nnodbc_get_sql2c_cvt(int sqltype, int ctype))()
{
 int i; int cidx = -1; int sqlidx = -1;
 for(i=0; i< sizeof(ctype_idx_tab); i++ )
 {
  if( ctype_idx_tab[i].ctype == ctype )
  {
   cidx = ctype_idx_tab[i].idx;
   break;
  }
 }
 if( cidx == -1 )
  return 0;
 for(i=0; i< sizeof(ctype_idx_tab); i++ )
 {
  if( sqltype_idx_tab[i].sqltype == sqltype )
  {
   sqlidx = sqltype_idx_tab[i].idx;
   break;
  }
 }
 if( sqlidx == -1 )
  return 0;
 return sql2c_cvt_tab[sqlidx][cidx];
}


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

if ( a1 )
result = *(_DWORD *)(a1 + 48) == 0;
else
result = 1LL;
return result;
}

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

if ( a1 )
result = *(_DWORD *)(a1 + 48) == 0;
else
result = 1LL;
return result;
}

original_code:
int nnodbc_errstkempty(void* stack)
{
 err_stack_t* err_stack = stack;
 if( ! err_stack
  || ! err_stack->top )
  return 1;
 return 0;
}

canonical_original_code:
int nnodbc_errstkempty(void *stack)
{
 struct err_stack_t *err_stack = stack;
 if( ! err_stack
  || ! err_stack->top )
  return 1;
 return 0;
}

variable_types:
stack
void *

variable_types: struct err_stack_t { struct err_t { int code; char *msg; } stack[3]; int top; } *

return_type: int

user_defined_types: struct err_stack_t { struct err_t stack[3]; int top; }


decompiled_code:
void __fastcall nnodbc_errstkunset(__int64 a1)
{
if ( a1 )
*(_DWORD *)(a1 + 48) = 0;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
if ( a1 )
*(_DWORD *)(a1 + 48) = 0;
}

original_code:
void nnodbc_errstkunset(void* stack)
{
 if( stack )
  ((err_stack_t*)stack)->top = 0;
}

canonical_original_code:
void nnodbc_errstkunset(void *stack)
{
 if( stack )
  ((struct err_stack_t *)stack)->top = 0;
}

return_type: void


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

result = nnodbc_errstkempty(a1);
if ( !result )
--*(_DWORD *)(a1 + 48);
return result;
}

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

result = func1(a1);
if ( !result )
--*(_DWORD *)(a1 + 48);
return result;
}

original_code:
void nnodbc_poperr(void* stack )
{
 err_stack_t* err_stack = stack;
 if( ! nnodbc_errstkempty( err_stack ) )
  err_stack->top --;
 return;
}

canonical_original_code:
void nnodbc_poperr(void *stack)
{
 struct err_stack_t *err_stack = stack;
 if( ! nnodbc_errstkempty( err_stack ) )
  err_stack->top --;
 return;
}


decompiled_code:
__int64 __fastcall nnodbc_getsqlstatcode(__int64 a1)
{
unsigned int *v1; // rbx
__int64 result; // rax

v1 = (unsigned int *)(a1 + 16LL * *(int *)(a1 + 48) - 16);
result = is_sqlerr((__int64)v1);
if ( (_DWORD)result )
result = *v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int *v1; // rbx
__int64 result; // rax

v1 = (unsigned int *)(a1 + 16LL * *(int *)(a1 + 48) - 16);
result = func0((__int64)v1);
if ( (_DWORD)result )
result = *v1;
return result;
}

original_code:
int nnodbc_getsqlstatcode(void* stack)
{
 err_stack_t* err_stack = stack;
 err_t* err;
 err = err_stack->stack + err_stack->top - 1;
 if( ! is_sqlerr(err) )
  return 0;
 return err->code;
}

canonical_original_code:
int nnodbc_getsqlstatcode(void *stack)
{
 struct err_stack_t *err_stack = stack;
 struct err_t *err;
 err = err_stack->stack + err_stack->top - 1;
 if( ! is_sqlerr(err) )
  return 0;
 return err->code;
}

variable_types:
err
struct err_t { int code; char *msg; } *


decompiled_code:
const char *__fastcall nnodbc_getsqlstatstr(__int64 a1)
{
_DWORD *v1; // rbx
char *v2; // rax
const char *v3; // rdx

v1 = (_DWORD *)(a1 + 16LL * *(int *)(a1 + 48) - 16);
if ( !is_sqlerr((__int64)v1) )
return 0LL;
v2 = (char *)&sqlerrmsg_tab;
v3 = "00000";
do
{
if ( *(_DWORD *)v2 == *v1 )
break;
v2 += 24;
v3 = (const char *)*((_QWORD *)v2 + 1);
}
while ( v3 );
return v3;
}

canonical_decompiled_code:
const char *__fastcall func5(__int64 a1)
{
_DWORD *v1; // rbx
char *v2; // rax
const char *v3; // rdx

v1 = (_DWORD *)(a1 + 16LL * *(int *)(a1 + 48) - 16);
if ( !func0((__int64)v1) )
return 0LL;
v2 = (char *)&sqlerrmsg_tab;
v3 = "00000";
do
{
if ( *(_DWORD *)v2 == *v1 )
break;
v2 += 24;
v3 = (const char *)*((_QWORD *)v2 + 1);
}
while ( v3 );
return v3;
}

original_code:
char* nnodbc_getsqlstatstr(void* stack)
{
 err_stack_t* err_stack = stack;
 err_t* err;
 int i;
 err = err_stack->stack + err_stack->top - 1;
 if( ! is_sqlerr(err) )
  return 0;
 for(i=0;sqlerrmsg_tab[i].stat;i++)
 {
  if( sqlerrmsg_tab[i].code == err->code )
   return sqlerrmsg_tab[i].stat;
 }
 return 0;
}

canonical_original_code:
char *nnodbc_getsqlstatstr(void *stack)
{
 struct err_stack_t *err_stack = stack;
 struct err_t *err;
 int i;
 err = err_stack->stack + err_stack->top - 1;
 if( ! is_sqlerr(err) )
  return 0;
 for(i=0;sqlerrmsg_tab[i].stat;i++)
 {
  if( sqlerrmsg_tab[i].code == err->code )
   return sqlerrmsg_tab[i].stat;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall nnodbc_getsqlstatmsg(__int64 a1)
{
_DWORD *v1; // rbx
_QWORD *v2; // rax
int v3; // edx
__int64 v4; // rcx

v1 = (_DWORD *)(a1 + 16LL * *(int *)(a1 + 48) - 16);
if ( !is_sqlerr((__int64)v1) )
return 0LL;
v2 = &sqlerrmsg_tab;
v3 = 0;
while ( *(_DWORD *)v2 != *v1 )
{
++v3;
v2 += 3;
v4 = v2[1];
if ( !v4 )
return v4;
}
return *((_QWORD *)&sqlerrmsg_tab + 3 * v3 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
_DWORD *v1; // rbx
_QWORD *v2; // rax
int v3; // edx
__int64 v4; // rcx

v1 = (_DWORD *)(a1 + 16LL * *(int *)(a1 + 48) - 16);
if ( !func0((__int64)v1) )
return 0LL;
v2 = &sqlerrmsg_tab;
v3 = 0;
while ( *(_DWORD *)v2 != *v1 )
{
++v3;
v2 += 3;
v4 = v2[1];
if ( !v4 )
return v4;
}
return *((_QWORD *)&sqlerrmsg_tab + 3 * v3 + 2);
}

original_code:
char* nnodbc_getsqlstatmsg(void* stack)
{
 err_stack_t* err_stack = stack;
 err_t* err;
 int i;
 err = err_stack->stack + err_stack->top - 1;
 if( ! is_sqlerr(err) )
  return 0;
 for(i=0;sqlerrmsg_tab[i].stat;i++)
 {
  if( sqlerrmsg_tab[i].code == err->code )
   return sqlerrmsg_tab[i].msg;
 }
 return 0;
}

canonical_original_code:
char *nnodbc_getsqlstatmsg(void *stack)
{
 struct err_stack_t *err_stack = stack;
 struct err_t *err;
 int i;
 err = err_stack->stack + err_stack->top - 1;
 if( ! is_sqlerr(err) )
  return 0;
 for(i=0;sqlerrmsg_tab[i].stat;i++)
 {
  if( sqlerrmsg_tab[i].code == err->code )
   return sqlerrmsg_tab[i].msg;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall nnodbc_getnativcode(__int64 a1)
{
unsigned int *v1; // rbx
_BOOL4 v2; // edx
__int64 result; // rax

v1 = (unsigned int *)(a1 + 16LL * *(int *)(a1 + 48) - 16);
v2 = is_sqlerr((__int64)v1);
result = 0LL;
if ( !v2 )
result = *v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
unsigned int *v1; // rbx
_BOOL4 v2; // edx
__int64 result; // rax

v1 = (unsigned int *)(a1 + 16LL * *(int *)(a1 + 48) - 16);
v2 = func0((__int64)v1);
result = 0LL;
if ( !v2 )
result = *v1;
return result;
}

original_code:
int nnodbc_getnativcode(void* stack)
{
 err_stack_t* err_stack = stack;
 err_t* err;
 err = err_stack->stack + err_stack->top - 1;
 if( is_sqlerr(err) )
  return 0;
 return err->code;
}

canonical_original_code:
int nnodbc_getnativcode(void *stack)
{
 struct err_stack_t *err_stack = stack;
 struct err_t *err;
 err = err_stack->stack + err_stack->top - 1;
 if( is_sqlerr(err) )
  return 0;
 return err->code;
}


decompiled_code:
__int64 __fastcall nnodbc_getnativemsg(__int64 a1)
{
return *(_QWORD *)(a1 + 16LL * *(int *)(a1 + 48) - 8);
}

original_code:
char* nnodbc_getnativemsg(void* stack)
{
 err_stack_t* err_stack = stack;
 err_t* err;
 err = err_stack->stack + err_stack->top - 1;
 return err->msg;
}

canonical_original_code:
char *nnodbc_getnativemsg(void *stack)
{
 struct err_stack_t *err_stack = stack;
 struct err_t *err;
 err = err_stack->stack + err_stack->top - 1;
 return err->msg;
}


decompiled_code:
__int64 __fastcall nnodbc_clearerr(void *a1)
{
if ( a1 )
free(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(void *a1)
{
if ( a1 )
free(a1);
return 0LL;
}

original_code:
void* nnodbc_clearerr(void* stack)
{
 {if(stack) free(stack);};
 return 0;
}

canonical_original_code:
void *nnodbc_clearerr(void *stack)
{
 {if(stack) free(stack);};
 return 0;
}

return_type: void *


init

decompiled_code:
__int64 init()
{
getGlobalDefaults("PostgreSQL", "ODBCINST.INI", 0LL);
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
getGlobalDefaults("PostgreSQL", "ODBCINST.INI", 0LL);
return 1LL;
}

original_code:
static int
__attribute__((constructor))
init(void)
{
 getGlobalDefaults("PostgreSQL", "ODBCINST.INI", (int)0);
 return (int)1;
}

canonical_original_code:
static int init()
{
 getGlobalDefaults("PostgreSQL", "ODBCINST.INI", (int)0);
 return (int)1;
}


SQLDummyOrdinal

decompiled_code:
__int64 SQLDummyOrdinal()
{
return 0LL;
}

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

original_code:
RETCODE SQLDummyOrdinal(void)
{
 return 0;
}

canonical_original_code:
short SQLDummyOrdinal()
{
 return 0;
}

return_type: short


sqlputdata

decompiled_code:
__int64 __fastcall sqlputdata(__int64 a1, int a2, __int64 a3)
{
__int64 result; // rax

switch ( *(_DWORD *)(*(_QWORD *)(a1 + 24) + 80LL * a2 - 28) )
{
case 0xFFFFFFFA:
case 4:
case 5:
nnsql_putnum(*(_QWORD *)(a1 + 40));
result = 0LL;
break;
case 0xFFFFFFFB:
case 0xFFFFFFFC:
case 0xFFFFFFFD:
case 0xFFFFFFFE:
case 0:
case 2:
case 3:
case 6:
case 7:
case 8:
case 0xA:
case 0xB:
result = 0xFFFFFFFFLL;
break;
case 0xFFFFFFFF:
case 1:
case 0xC:
if ( a3 )
nnsql_putstr(*(_QWORD *)(a1 + 40));
else
nnsql_putnull(*(_QWORD *)(a1 + 40));
result = 0LL;
break;
case 9:
if ( a3 )
nnsql_putdate(*(_QWORD *)(a1 + 40));
else
nnsql_putnull(*(_QWORD *)(a1 + 40));
result = 0LL;
break;
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

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

switch ( *(_DWORD *)(*(_QWORD *)(a1 + 24) + 80LL * a2 - 28) )
{
case 0xFFFFFFFA:
case 4:
case 5:
nnsql_putnum(*(_QWORD *)(a1 + 40));
result = 0LL;
break;
case 0xFFFFFFFB:
case 0xFFFFFFFC:
case 0xFFFFFFFD:
case 0xFFFFFFFE:
case 0:
case 2:
case 3:
case 6:
case 7:
case 8:
case 0xA:
case 0xB:
result = 0xFFFFFFFFLL;
break;
case 0xFFFFFFFF:
case 1:
case 0xC:
if ( a3 )
nnsql_putstr(*(_QWORD *)(a1 + 40));
else
nnsql_putnull(*(_QWORD *)(a1 + 40));
result = 0LL;
break;
case 9:
if ( a3 )
nnsql_putdate(*(_QWORD *)(a1 + 40));
else
nnsql_putnull(*(_QWORD *)(a1 + 40));
result = 0LL;
break;
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

original_code:
int sqlputdata (
  stmt_t* pstmt,
  int ipar,
  char* data )
{
 param_t* ppar;
 ppar = pstmt->ppar + ipar - 1;
 switch( ppar->sqltype )
 {
  case 1:
  case 12:
  case (-1):
   if( ! data )
    nnsql_putnull(pstmt->yystmt, ipar );
   else
    nnsql_putstr(pstmt->yystmt, ipar, (char*)data);
   break;
  case (-6):
  case 5:
  case 4:
   nnsql_putnum(pstmt->yystmt, ipar, (long)data);
   break;
  case 9:
   if(!data )
    nnsql_putnull(pstmt->yystmt, ipar );
   else
    nnsql_putdate(pstmt->yystmt, ipar, (date_t*)data);
   break;
  default:
   return -1;
 }
 return 0;
}

canonical_original_code:
int sqlputdata(struct stmt_t *pstmt, int ipar, char *data)
{
 struct param_t *ppar;
 ppar = pstmt->ppar + ipar - 1;
 switch( ppar->sqltype )
 {
  case 1:
  case 12:
  case (-1):
   if( ! data )
    nnsql_putnull(pstmt->yystmt, ipar );
   else
    nnsql_putstr(pstmt->yystmt, ipar, (char *)data);
   break;
  case (-6):
  case 5:
  case 4:
   nnsql_putnum(pstmt->yystmt, ipar, (long)data);
   break;
  case 9:
   if(!data )
    nnsql_putnull(pstmt->yystmt, ipar );
   else
    nnsql_putdate(pstmt->yystmt, ipar, (struct date_t *)data);
   break;
  default:
   return -1;
 }
 return 0;
}

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: ipar int

variable_types:
data
char *

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 date_t { int year; int month; int day; }


sqlexecute

original_code:
int sqlexecute (
 stmt_t* pstmt)
{
 param_t* ppar = pstmt->ppar;
 int i, npar, flag = 0;
 long csize;
 pstmt->refetch = 0;
 pstmt->ndelay = 0;
 npar = nnsql_getparnum(pstmt->yystmt);
 for( i = 0; ppar && i< npar; i++ )
 {
  ppar = pstmt->ppar + i;
  if( ! ppar->bind )
  {
   pstmt->herr = nnodbc_pusherr(pstmt->herr, en_07001, 0);
   return (-1);
  }
  if( ( ! ppar->userbuf && ppar->pdatalen )
   || ( ppar->userbuf && ppar->pdatalen
      && *ppar->pdatalen < 0 && *ppar->pdatalen != (-3) ) )
  {
    if( *ppar->pdatalen
     || *ppar->pdatalen == (long)(-1)
     || *ppar->pdatalen == (long)(-2)
     || *ppar->pdatalen <= (long)( (-100) - 0 ) )
    continue;
   pstmt->herr = nnodbc_pusherr(pstmt->herr, en_S1090, 0);
   return (-1);
  }
 }
 for( i = 0; ppar && i< npar; i++ )
 {
  char* (*cvt)();
  date_t date;
  char* data;
  ppar = pstmt->ppar + i;
  if( ! ppar->pdatalen )
   csize = 0;
  else
   csize = *(ppar->pdatalen);
  if( csize == (long)(-1) )
  {
   nnsql_putnull(pstmt->yystmt, i+1);
   continue;
  }
  if( csize == (long)(-2)
   || csize <= (long)( (-100) - 0 ) )
  {
   pstmt->ndelay ++;
   ppar->need = 1;
   continue;
  }
  cvt = ppar->cvt;
  data= cvt(ppar->userbuf, csize, &date );
  if( data == (char*)(-1) )
  {
   pstmt->herr = nnodbc_pusherr(pstmt->herr, en_S1000, 0);
   return (-1);
  }
  sqlputdata(pstmt, i+1, data);
 }
 if( pstmt->ndelay )
  return 99;
 if( nnsql_execute(pstmt->yystmt) )
 {
  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);
 }
 if( ! nnsql_getcolnum(pstmt->yystmt)
  && nnsql_getrowcount(pstmt->yystmt) > 1 )
 {
  pstmt->herr = nnodbc_pusherr(pstmt->herr, en_01S04, 0);
  return 1;
 }
 return 0;
}

canonical_original_code:
int sqlexecute(struct stmt_t *pstmt)
{
 struct param_t *ppar = pstmt->ppar;
 int i; int npar; int flag = 0;
 long csize;
 pstmt->refetch = 0;
 pstmt->ndelay = 0;
 npar = nnsql_getparnum(pstmt->yystmt);
 for( i = 0; ppar && i< npar; i++ )
 {
  ppar = pstmt->ppar + i;
  if( ! ppar->bind )
  {
   pstmt->herr = nnodbc_pusherr(pstmt->herr, en_07001, 0);
   return (-1);
  }
  if( ( ! ppar->userbuf && ppar->pdatalen )
   || ( ppar->userbuf && ppar->pdatalen
      && *ppar->pdatalen < 0 && *ppar->pdatalen != (-3) ) )
  {
    if( *ppar->pdatalen
     || *ppar->pdatalen == (long)(-1)
     || *ppar->pdatalen == (long)(-2)
     || *ppar->pdatalen <= (long)( (-100) - 0 ) )
    continue;
   pstmt->herr = nnodbc_pusherr(pstmt->herr, en_S1090, 0);
   return (-1);
  }
 }
 for( i = 0; ppar && i< npar; i++ )
 {
  char *(*cvt)();
  struct date_t date;
  char *data;
  ppar = pstmt->ppar + i;
  if( ! ppar->pdatalen )
   csize = 0;
  else
   csize = *(ppar->pdatalen);
  if( csize == (long)(-1) )
  {
   nnsql_putnull(pstmt->yystmt, i+1);
   continue;
  }
  if( csize == (long)(-2)
   || csize <= (long)( (-100) - 0 ) )
  {
   pstmt->ndelay ++;
   ppar->need = 1;
   continue;
  }
  cvt = ppar->cvt;
  data= cvt(ppar->userbuf, csize, &date );
  if( data == (char *)(-1) )
  {
   pstmt->herr = nnodbc_pusherr(pstmt->herr, en_S1000, 0);
   return (-1);
  }
  sqlputdata(pstmt, i+1, data);
 }
 if( pstmt->ndelay )
  return 99;
 if( nnsql_execute(pstmt->yystmt) )
 {
  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);
 }
 if( ! nnsql_getcolnum(pstmt->yystmt)
  && nnsql_getrowcount(pstmt->yystmt) > 1 )
 {
  pstmt->herr = nnodbc_pusherr(pstmt->herr, en_01S04, 0);
  return 1;
 }
 return 0;
}

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

variable_types: npar int

variable_types: flag int

variable_types: csize long

variable_types:
cvt
char *(*)()

variable_types: code int

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


SQLProcedureColumns

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

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

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

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

original_code:
RETCODE SQLProcedureColumns(
                                    HSTMT hstmt,
                                    UCHAR * szProcQualifier,
                                    SWORD cbProcQualifier,
                                    UCHAR * szProcOwner,
                                    SWORD cbProcOwner,
                                    UCHAR * szProcName,
                                    SWORD cbProcName,
                                    UCHAR * szColumnName,
                                    SWORD cbColumnName)
{
static char* const func="SQLProcedureColumns";
 mylog("%s: entering...\n", func);
 SC_log_error(func, "Function not implemented", (StatementClass *) hstmt);
    return (-1);
}

canonical_original_code:
short SQLProcedureColumns(void *hstmt, unsigned char *szProcQualifier, short cbProcQualifier, unsigned char *szProcOwner, short cbProcOwner, unsigned char *szProcName, short cbProcName, unsigned char *szColumnName, short cbColumnName)
{
static char *func = "SQLProcedureColumns";
 mylog("%s: entering...\n", func);
 SC_log_error(func, "Function not implemented", (struct StatementClass_ *) hstmt);
    return (-1);
}

variable_types:
hstmt
void *

variable_types:
szProcQualifier
unsigned char *

variable_types: cbProcQualifier short

variable_types:
szProcOwner
unsigned char *

variable_types: cbProcOwner short

variable_types:
szProcName
unsigned char *

variable_types: cbProcName short

variable_types:
szColumnName
unsigned char *

variable_types: cbColumnName short

variable_types:
func
char *

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


SQLTablePrivileges

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

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

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

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

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

canonical_original_code:
short SQLTablePrivileges(void *hstmt, unsigned char *szTableQualifier, short cbTableQualifier, unsigned char *szTableOwner, short cbTableOwner, unsigned char *szTableName, short cbTableName)
{
static char *func = "SQLTablePrivileges";
 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

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 }


decompiled_code:
__pid_t __fastcall generate_filename(char *src, char *a2, char *s)
{
__uid_t v4; // eax
struct passwd *v5; // r14
__pid_t result; // eax
unsigned int v7; // er13

v4 = getuid();
v5 = getpwuid(v4);
result = getpid();
if ( src )
{
v7 = result;
if ( s )
{
strcpy(s, src);
*(_WORD *)&s[strlen(s)] = 47;
if ( a2 )
strcat(s, a2);
strcat(s, v5->pw_name);
result = sprintf(s, "%s%u%s", s, v7, ".log");
}
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func0(char *src, char *a2, char *s)
{
__uid_t v4; // eax
struct passwd *v5; // r14
__pid_t result; // eax
unsigned int v7; // er13

v4 = getuid();
v5 = getpwuid(v4);
result = getpid();
if ( src )
{
v7 = result;
if ( s )
{
strcpy(s, src);
*(_WORD *)&s[strlen(s)] = 47;
if ( a2 )
strcat(s, a2);
strcat(s, v5->pw_name);
result = sprintf(s, "%s%u%s", s, v7, ".log");
}
}
return result;
}

original_code:
void
generate_filename(char* dirname,char* prefix,char* filename)
{
 int pid = 0;
 struct passwd *ptr = 0;
 ptr = getpwuid(getuid());
 pid = getpid();
 if(dirname == 0 || filename == 0)
  return;
 strcpy(filename,dirname);
 strcat(filename,"/");
 if(prefix != 0)
  strcat(filename,prefix);
 strcat(filename,ptr->pw_name);
 sprintf(filename,"%s%u%s",filename,pid,".log");
 return;
}

canonical_original_code:
void generate_filename(char *dirname, char *prefix, char *filename)
{
 int pid = 0;
 struct passwd *ptr = 0;
 ptr = getpwuid(getuid());
 pid = getpid();
 if(dirname == 0 || filename == 0)
  return;
 strcpy(filename,dirname);
 strcat(filename,"/");
 if(prefix != 0)
  strcat(filename,prefix);
 strcat(filename,ptr->pw_name);
 sprintf(filename,"%s%u%s",filename,pid,".log");
 return;
}

variable_types:
dirname
char *

variable_types:
prefix
char *

variable_types:
filename
char *

variable_types: pid int

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


decompiled_code:
size_t __fastcall my_strcpy(void *dest, int a2, const char *a3, int a4)
{
size_t result; // rax
__int64 v6; // rbx

result = 0LL;
if ( a2 > 0 )
{
if ( a4 == -1 )
{
*(_BYTE *)dest = 0;
result = 4294967294LL;
}
else
{
if ( a4 == -3 )
a4 = strlen(a3);
result = 0LL;
if ( a4 > 0 )
{
if ( a4 >= a2 )
{
memcpy(dest, a3, a2 - 1);
*((char *)dest + a2 - 1) = 0;
result = 0xFFFFFFFFLL;
}
else
{
v6 = a4;
memcpy(dest, a3, a4);
*((_BYTE *)dest + v6) = 0;
result = strlen((const char *)dest);
}
}
}
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func3(void *dest, int a2, const char *a3, int a4)
{
size_t result; // rax
__int64 v6; // rbx

result = 0LL;
if ( a2 > 0 )
{
if ( a4 == -1 )
{
*(_BYTE *)dest = 0;
result = 4294967294LL;
}
else
{
if ( a4 == -3 )
a4 = strlen(a3);
result = 0LL;
if ( a4 > 0 )
{
if ( a4 >= a2 )
{
memcpy(dest, a3, a2 - 1);
*((char *)dest + a2 - 1) = 0;
result = 0xFFFFFFFFLL;
}
else
{
v6 = a4;
memcpy(dest, a3, a4);
*((_BYTE *)dest + v6) = 0;
result = strlen((const char *)dest);
}
}
}
}
return result;
}

original_code:
int
my_strcpy(char *dst, int dst_len, char *src, int src_len)
{
 if (dst_len <= 0)
  return 0;
 if (src_len == (-1)) {
  dst[0] = '\0';
  return -2;
 }
 else if (src_len == (-3))
  src_len = strlen(src);
 if (src_len <= 0)
  return 0;
 else {
  if (src_len < dst_len) {
   memcpy(dst, src, src_len);
   dst[src_len] = '\0';
  }
  else {
   memcpy(dst, src, dst_len-1);
   dst[dst_len-1] = '\0';
   return -1;
  }
 }
 return strlen(dst);
}

variable_types:
dst
char *

variable_types:
src
char *


decompiled_code:
size_t __fastcall my_strlen(const char *a1, int a2)
{
size_t result; // rax

result = 0LL;
if ( a1 )
{
result = (unsigned int)a2;
if ( a2 <= 0 )
{
result = 0LL;
if ( a2 == -3 )
{
if ( *a1 )
result = strlen(a1);
}
}
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func4(const char *a1, int a2)
{
size_t result; // rax

result = 0LL;
if ( a1 )
{
result = (unsigned int)a2;
if ( a2 <= 0 )
{
result = 0LL;
if ( a2 == -3 )
{
if ( *a1 )
result = strlen(a1);
}
}
}
return result;
}

original_code:
int
my_strlen(char *s, int len)
{
 int length = 0;
 if(s && (len > 0 || (len == (-3) && strlen(s) > 0))) {
     length = (len > 0) ? len : strlen(s);
 }
 return length;
}

variable_types:
s
char *

variable_types: len int

variable_types: length int


decompiled_code:
char *__fastcall my_strcat(char *s, char *format, char *a3, int a4)
{
unsigned int v5; // ebx
char *result; // rax
int v7; // eax

if ( !a3 )
return 0LL;
v5 = a4;
if ( a4 > 0 )
goto LABEL_6;
result = 0LL;
if ( a4 == -3 && *a3 )
{
v5 = strlen(a3);
LABEL_6:
v7 = strlen(s);
sprintf(&s[v7], format, v5, a3);
result = s;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func5(char *s, char *format, char *a3, int a4)
{
unsigned int v5; // ebx
char *result; // rax
int v7; // eax

if ( !a3 )
return 0LL;
v5 = a4;
if ( a4 > 0 )
goto LABEL_6;
result = 0LL;
if ( a4 == -3 && *a3 )
{
v5 = strlen(a3);
LABEL_6:
v7 = strlen(s);
sprintf(&s[v7], format, v5, a3);
result = s;
}
return result;
}

original_code:
char *
my_strcat(char *buf, char *fmt, char *s, int len)
{
 if (s && (len > 0 || (len == (-3) && strlen(s) > 0))) {
  int length = (len > 0) ? len : strlen(s);
  int pos = strlen(buf);
  sprintf(&buf[pos], fmt, length, s);
  return buf;
 }
 return ((void *)0);
}

canonical_original_code:
char *my_strcat(char *buf, char *fmt, char *s, int len)
{
 if (s && (len > 0 || (len == (-3) && strlen(s) > 0))) {
  int length = (len > 0) ? len : strlen(s);
  int pos = strlen(buf);
  sprintf(&buf[pos], fmt, length, s);
  return buf;
 }
 return ((void *)0);
}

variable_types:
buf
char *

variable_types:
fmt
char *

variable_types: pos int


decompiled_code:
size_t __fastcall remove_newlines(const char *a1)
{
size_t result; // rax
unsigned __int64 v2; // rsi
unsigned int v3; // edx
char *v4; // rax

result = strlen(a1);
if ( result )
{
v2 = result;
v3 = 0;
result = 0LL;
do
{
v4 = (char *)&a1[result];
if ( *v4 == 10 || *v4 == 13 )
*v4 = 32;
result = ++v3;
}
while ( v3 < v2 );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func6(const char *a1)
{
size_t result; // rax
unsigned __int64 v2; // rsi
unsigned int v3; // edx
char *v4; // rax

result = strlen(a1);
if ( result )
{
v2 = result;
v3 = 0;
result = 0LL;
do
{
v4 = (char *)&a1[result];
if ( *v4 == 10 || *v4 == 13 )
*v4 = 32;
result = ++v3;
}
while ( v3 < v2 );
}
return result;
}

original_code:
void remove_newlines(char *string)
{
 unsigned int i;
 size_t stlen=strlen(string);
 for(i=0; i < stlen; i++) {
  if((string[i] == '\n') ||
     (string[i] == '\r')) {
   string[i] = ' ';
  }
 }
}

canonical_original_code:
void remove_newlines(char *string)
{
 unsigned int i;
 unsigned long stlen = strlen(string);
 for(i=0; i < stlen; i++) {
  if((string[i] == '\n') ||
     (string[i] == '\r')) {
   string[i] = ' ';
  }
 }
}

variable_types:
string
char *

variable_types:
i
unsigned int

variable_types:
stlen
unsigned long


trim

decompiled_code:
const char *__fastcall trim(const char *a1)
{
__int64 v1; // rax

LODWORD(v1) = strlen(a1) - 1;
if ( (int)v1 >= 0 )
{
v1 = (int)v1;
do
{
if ( a1[v1] != 32 )
break;
a1[v1--] = 0;
}
while ( (int)v1 >= 0 );
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func7(const char *a1)
{
__int64 v1; // rax

LODWORD(v1) = strlen(a1) - 1;
if ( (int)v1 >= 0 )
{
v1 = (int)v1;
do
{
if ( a1[v1] != 32 )
break;
a1[v1--] = 0;
}
while ( (int)v1 >= 0 );
}
return a1;
}

original_code:
char *
trim(char *s)
{
 int i;
 for (i = strlen(s) - 1; i >= 0; i--) {
  if (s[i] == ' ')
   s[i] = '\0';
  else
   break;
 }
 return s;
}

canonical_original_code:
char *trim(char *s)
{
 int i;
 for (i = strlen(s) - 1; i >= 0; i--) {
  if (s[i] == ' ')
   s[i] = '\0';
  else
   break;
 }
 return s;
}

variable_types: i int


decompiled_code:
void __fastcall extend_bindings(__int64 a1, unsigned int a2)
{
char *v4; // rbp
__int64 v5; // rax
int v6; // ecx
__int64 v7; // rsi
void *v8; // rdi

mylog(
"%s: entering ... stmt=%u, bindings_allocated=%d, num_columns=%d\n",
"extend_bindings",
a1,
*(unsigned int *)(a1 + 120),
a2);
if ( *(_DWORD *)(a1 + 120) >= (signed int)a2 )
{
LABEL_9:
mylog("exit extend_bindings\n");
return;
}
v4 = create_empty_bindings(a2);
if ( v4 )
{
if ( *(_QWORD *)(a1 + 80) )
{
if ( *(int *)(a1 + 120) > 0 )
{
v5 = 0LL;
v6 = 0;
do
{
v7 = *(_QWORD *)(a1 + 80);
*(__m128i *)&v4[v5] = _mm_loadu_si128((const __m128i *)(v7 + v5));
*(__m128i *)&v4[v5 + 16] = _mm_loadu_si128((const __m128i *)(v7 + v5 + 16));
++v6;
v5 += 32LL;
}
while ( *(_DWORD *)(a1 + 120) > v6 );
}
free(*(void **)(a1 + 80));
}
*(_QWORD *)(a1 + 80) = v4;
*(_DWORD *)(a1 + 120) = a2;
goto LABEL_9;
}
mylog(
"%s: unable to create %d new bindings from %d old bindings\n",
"extend_bindings",
a2,
*(unsigned int *)(a1 + 120));
v8 = *(void **)(a1 + 80);
if ( v8 )
{
free(v8);
*(_QWORD *)(a1 + 80) = 0LL;
}
*(_DWORD *)(a1 + 120) = 0;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, unsigned int a2)
{
char *v4; // rbp
__int64 v5; // rax
int v6; // ecx
__int64 v7; // rsi
void *v8; // rdi

mylog(
"%s: entering ... stmt=%u, bindings_allocated=%d, num_columns=%d\n",
"extend_bindings",
a1,
*(unsigned int *)(a1 + 120),
a2);
if ( *(_DWORD *)(a1 + 120) >= (signed int)a2 )
{
LABEL_9:
mylog("exit extend_bindings\n");
return;
}
v4 = func4(a2);
if ( v4 )
{
if ( *(_QWORD *)(a1 + 80) )
{
if ( *(int *)(a1 + 120) > 0 )
{
v5 = 0LL;
v6 = 0;
do
{
v7 = *(_QWORD *)(a1 + 80);
*(__m128i *)&v4[v5] = _mm_loadu_si128((const __m128i *)(v7 + v5));
*(__m128i *)&v4[v5 + 16] = _mm_loadu_si128((const __m128i *)(v7 + v5 + 16));
++v6;
v5 += 32LL;
}
while ( *(_DWORD *)(a1 + 120) > v6 );
}
free(*(void **)(a1 + 80));
}
*(_QWORD *)(a1 + 80) = v4;
*(_DWORD *)(a1 + 120) = a2;
goto LABEL_9;
}
mylog(
"%s: unable to create %d new bindings from %d old bindings\n",
"extend_bindings",
a2,
*(unsigned int *)(a1 + 120));
v8 = *(void **)(a1 + 80);
if ( v8 )
{
free(v8);
*(_QWORD *)(a1 + 80) = 0LL;
}
*(_DWORD *)(a1 + 120) = 0;
}

original_code:
void
extend_bindings(StatementClass *stmt, int num_columns)
{
static char* const func="extend_bindings";
BindInfoClass *new_bindings;
int i;
mylog("%s: entering ... stmt=%u, bindings_allocated=%d, num_columns=%d\n", func, stmt, stmt->bindings_allocated, num_columns);
 if(stmt->bindings_allocated < num_columns) {
  new_bindings = create_empty_bindings(num_columns);
  if ( ! new_bindings) {
           mylog("%s: unable to create %d new bindings from %d old bindings\n", func, num_columns, stmt->bindings_allocated);
   if (stmt->bindings) {
    free(stmt->bindings);
    stmt->bindings = ((void *)0);
   }
   stmt->bindings_allocated = 0;
   return;
  }
  if(stmt->bindings) {
   for(i=0; i<stmt->bindings_allocated; i++)
    new_bindings[i] = stmt->bindings[i];
   free(stmt->bindings);
  }
  stmt->bindings = new_bindings;
  stmt->bindings_allocated = num_columns;
    }
 mylog("exit extend_bindings\n");
}

canonical_original_code:
void extend_bindings(struct StatementClass_ *stmt, int num_columns)
{
static char *func = "extend_bindings";
struct BindInfoClass_ *new_bindings;
int i;
mylog("%s: entering ... stmt=%u, bindings_allocated=%d, num_columns=%d\n", func, stmt, stmt->bindings_allocated, num_columns);
 if(stmt->bindings_allocated < num_columns) {
  new_bindings = create_empty_bindings(num_columns);
  if ( ! new_bindings) {
           mylog("%s: unable to create %d new bindings from %d old bindings\n", func, num_columns, stmt->bindings_allocated);
   if (stmt->bindings) {
    free(stmt->bindings);
    stmt->bindings = ((void *)0);
   }
   stmt->bindings_allocated = 0;
   return;
  }
  if(stmt->bindings) {
   for(i=0; i<stmt->bindings_allocated; i++)
    new_bindings[i] = stmt->bindings[i];
   free(stmt->bindings);
  }
  stmt->bindings = new_bindings;
  stmt->bindings_allocated = num_columns;
    }
 mylog("exit extend_bindings\n");
}

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:
func
char *

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


decompiled_code:
__int64 __fastcall PG_SQLBindCol(__int64 a1, unsigned __int16 a2, __int16 a3, __int64 a4, int a5, __int64 a6)
{
__int64 result; // rax
__int64 v10; // rdx
unsigned __int16 v11; // bp
__int64 v12; // rax

mylog("%s: entering...\n", "SQLBindCol");
mylog("**** SQLBindCol: stmt = %u, icol = %d\n", a1, a2);
if ( a1 )
{
SC_clear_error(a1);
if ( *(_DWORD *)(a1 + 60) == 4 )
{
SC_set_error(a1, 3LL, "Can't bind columns while statement is still executing.");
SC_log_error("SQLBindCol", &LC2, a1);
result = 0xFFFFFFFFLL;
}
else if ( a2 )
{
if ( a2 > *(int *)(a1 + 120) )
extend_bindings(a1, a2);
v10 = *(_QWORD *)(a1 + 80);
if ( v10 )
{
v11 = a2 - 1;
v12 = 32LL * (unsigned __int16)(a2 - 1);
*(_DWORD *)(v10 + v12 + 4) = -1;
if ( a4 )
{
*(_DWORD *)(*(_QWORD *)(a1 + 80) + 32LL * v11) = a5;
*(_QWORD *)(*(_QWORD *)(a1 + 80) + v12 + 8) = a4;
*(_QWORD *)(*(_QWORD *)(a1 + 80) + v12 + 16) = a6;
*(_WORD *)(*(_QWORD *)(a1 + 80) + v12 + 24) = a3;
mylog(" bound buffer[%d] = %u\n", v11, *(_QWORD *)(*(_QWORD *)(a1 + 80) + v12 + 8));
}
else
{
*(_DWORD *)(*(_QWORD *)(a1 + 80) + 32LL * v11) = 0;
*(_QWORD *)(*(_QWORD *)(a1 + 80) + v12 + 8) = 0LL;
*(_QWORD *)(*(_QWORD *)(a1 + 80) + v12 + 16) = 0LL;
*(_WORD *)(*(_QWORD *)(a1 + 80) + v12 + 24) = 1;
}
result = 0LL;
}
else
{
SC_set_error(a1, 4LL, "Could not allocate memory for bindings.");
SC_log_error("SQLBindCol", &LC2, a1);
result = 0xFFFFFFFFLL;
}
}
else if ( a4 )
{
if ( (a3 & 0xFFEF) == 0xFFEE )
{
*(_QWORD *)(a1 + 96) = a4;
*(_QWORD *)(a1 + 104) = a6;
result = 0LL;
}
else
{
SC_set_error(a1, 26LL, "Column 0 is not of type SQL_C_BOOKMARK");
SC_log_error("SQLBindCol", &LC2, a1);
result = 0xFFFFFFFFLL;
}
}
else
{
*(_QWORD *)(a1 + 96) = 0LL;
*(_QWORD *)(a1 + 104) = 0LL;
result = 0LL;
}
}
else
{
SC_log_error("SQLBindCol", &LC2, 0LL);
result = 4294967294LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned __int16 a2, __int16 a3, __int64 a4, int a5, __int64 a6)
{
__int64 result; // rax
__int64 v10; // rdx
unsigned __int16 v11; // bp
__int64 v12; // rax

mylog("%s: entering...\n", "SQLBindCol");
mylog("**** SQLBindCol: stmt = %u, icol = %d\n", a1, a2);
if ( a1 )
{
SC_clear_error(a1);
if ( *(_DWORD *)(a1 + 60) == 4 )
{
SC_set_error(a1, 3LL, "Can't bind columns while statement is still executing.");
SC_log_error("SQLBindCol", &LC2, a1);
result = 0xFFFFFFFFLL;
}
else if ( a2 )
{
if ( a2 > *(int *)(a1 + 120) )
func5(a1, a2);
v10 = *(_QWORD *)(a1 + 80);
if ( v10 )
{
v11 = a2 - 1;
v12 = 32LL * (unsigned __int16)(a2 - 1);
*(_DWORD *)(v10 + v12 + 4) = -1;
if ( a4 )
{
*(_DWORD *)(*(_QWORD *)(a1 + 80) + 32LL * v11) = a5;
*(_QWORD *)(*(_QWORD *)(a1 + 80) + v12 + 8) = a4;
*(_QWORD *)(*(_QWORD *)(a1 + 80) + v12 + 16) = a6;
*(_WORD *)(*(_QWORD *)(a1 + 80) + v12 + 24) = a3;
mylog(" bound buffer[%d] = %u\n", v11, *(_QWORD *)(*(_QWORD *)(a1 + 80) + v12 + 8));
}
else
{
*(_DWORD *)(*(_QWORD *)(a1 + 80) + 32LL * v11) = 0;
*(_QWORD *)(*(_QWORD *)(a1 + 80) + v12 + 8) = 0LL;
*(_QWORD *)(*(_QWORD *)(a1 + 80) + v12 + 16) = 0LL;
*(_WORD *)(*(_QWORD *)(a1 + 80) + v12 + 24) = 1;
}
result = 0LL;
}
else
{
SC_set_error(a1, 4LL, "Could not allocate memory for bindings.");
SC_log_error("SQLBindCol", &LC2, a1);
result = 0xFFFFFFFFLL;
}
}
else if ( a4 )
{
if ( (a3 & 0xFFEF) == 0xFFEE )
{
*(_QWORD *)(a1 + 96) = a4;
*(_QWORD *)(a1 + 104) = a6;
result = 0LL;
}
else
{
SC_set_error(a1, 26LL, "Column 0 is not of type SQL_C_BOOKMARK");
SC_log_error("SQLBindCol", &LC2, a1);
result = 0xFFFFFFFFLL;
}
}
else
{
*(_QWORD *)(a1 + 96) = 0LL;
*(_QWORD *)(a1 + 104) = 0LL;
result = 0LL;
}
}
else
{
SC_log_error("SQLBindCol", &LC2, 0LL);
result = 4294967294LL;
}
return result;
}

original_code:
RETCODE PG_SQLBindCol(
        HSTMT hstmt,
        UWORD icol,
        SWORD fCType,
        PTR rgbValue,
        SQLINTEGER cbValueMax,
        SQLINTEGER *pcbValue)
{
StatementClass *stmt = (StatementClass *) hstmt;
static char* const func="SQLBindCol";
 mylog( "%s: entering...\n", func);
mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol);
 if ( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 SC_clear_error(stmt);
 if( stmt->status == STMT_EXECUTING) {
  SC_set_error(stmt, 3, "Can't bind columns while statement is still executing.");
  SC_log_error(func, "", stmt);
  return (-1);
 }
 if (icol == 0) {
  if (rgbValue == ((void *)0)) {
   stmt->bookmark.buffer = ((void *)0);
   stmt->bookmark.used = ((void *)0);
  }
  else {
   if ( fCType != (4 +(-22)) && fCType != (-2) ) {
    SC_set_error(stmt, 26, "Column 0 is not of type SQL_C_BOOKMARK");
    SC_log_error(func, "", stmt);
    return (-1);
   }
   stmt->bookmark.buffer = rgbValue;
   stmt->bookmark.used = pcbValue;
  }
  return 0;
 }
 if ( icol > stmt->bindings_allocated)
  extend_bindings(stmt, icol);
 if ( ! stmt->bindings) {
  SC_set_error(stmt, 4, "Could not allocate memory for bindings.");
  SC_log_error(func, "", stmt);
  return (-1);
 }
 icol--;
 stmt->bindings[icol].data_left = -1;
 if (rgbValue == ((void *)0)) {
  stmt->bindings[icol].buflen = 0;
  stmt->bindings[icol].buffer = ((void *)0);
  stmt->bindings[icol].used = ((void *)0);
  stmt->bindings[icol].returntype = 1;
 } else {
  stmt->bindings[icol].buflen = cbValueMax;
  stmt->bindings[icol].buffer = rgbValue;
  stmt->bindings[icol].used = pcbValue;
  stmt->bindings[icol].returntype = fCType;
  mylog("       bound buffer[%d] = %u\n", icol, stmt->bindings[icol].buffer);
 }
 return 0;
}

canonical_original_code:
short PG_SQLBindCol(void *hstmt, unsigned short icol, short fCType, void *rgbValue, long cbValueMax, long *pcbValue)
{
struct StatementClass_ *stmt = (StatementClass *) hstmt;
static char *func = "SQLBindCol";
 mylog( "%s: entering...\n", func);
mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol);
 if ( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 SC_clear_error(stmt);
 if( stmt->status == STMT_EXECUTING) {
  SC_set_error(stmt, 3, "Can't bind columns while statement is still executing.");
  SC_log_error(func, "", stmt);
  return (-1);
 }
 if (icol == 0) {
  if (rgbValue == ((void *)0)) {
   stmt->bookmark.buffer = ((void *)0);
   stmt->bookmark.used = ((void *)0);
  }
  else {
   if ( fCType != (4 +(-22)) && fCType != (-2) ) {
    SC_set_error(stmt, 26, "Column 0 is not of type SQL_C_BOOKMARK");
    SC_log_error(func, "", stmt);
    return (-1);
   }
   stmt->bookmark.buffer = rgbValue;
   stmt->bookmark.used = pcbValue;
  }
  return 0;
 }
 if ( icol > stmt->bindings_allocated)
  extend_bindings(stmt, icol);
 if ( ! stmt->bindings) {
  SC_set_error(stmt, 4, "Could not allocate memory for bindings.");
  SC_log_error(func, "", stmt);
  return (-1);
 }
 icol--;
 stmt->bindings[icol].data_left = -1;
 if (rgbValue == ((void *)0)) {
  stmt->bindings[icol].buflen = 0;
  stmt->bindings[icol].buffer = ((void *)0);
  stmt->bindings[icol].used = ((void *)0);
  stmt->bindings[icol].returntype = 1;
 } else {
  stmt->bindings[icol].buflen = cbValueMax;
  stmt->bindings[icol].buffer = rgbValue;
  stmt->bindings[icol].used = pcbValue;
  stmt->bindings[icol].returntype = fCType;
  mylog("       bound buffer[%d] = %u\n", icol, stmt->bindings[icol].buffer);
 }
 return 0;
}

variable_types:
hstmt
void *

variable_types:
icol
unsigned short

variable_types: fCType short

variable_types:
rgbValue
void *

variable_types: cbValueMax long

variable_types:
pcbValue
long *

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


SQLBindParameter

original_code:
SQLRETURN SQLBindParameter(
    SQLHSTMT hstmt,
    SQLUSMALLINT ipar,
    SQLSMALLINT fParamType,
    SQLSMALLINT fCType,
    SQLSMALLINT fSqlType,
    SQLUINTEGER cbColDef,
    SQLSMALLINT ibScale,
    SQLPOINTER rgbValue,
    SQLINTEGER cbValueMax,
    SQLINTEGER *pcbValue)
{
StatementClass *stmt = (StatementClass *) hstmt;
static char* const func="SQLBindParameter";
 mylog( "%s: entering...\n", func);
 if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 if(stmt->parameters_allocated < ipar) {
  ParameterInfoClass *old_parameters;
  int i, old_parameters_allocated;
  old_parameters = stmt->parameters;
  old_parameters_allocated = stmt->parameters_allocated;
  stmt->parameters = (ParameterInfoClass *) malloc(sizeof(ParameterInfoClass)*(ipar));
  if ( ! stmt->parameters) {
   SC_set_error(stmt, 4, "Could not allocate memory for statement parameters");
   SC_log_error(func, "", stmt);
   return (-1);
  }
  stmt->parameters_allocated = ipar;
  for(i = 0; i < old_parameters_allocated; i++) {
   stmt->parameters[i] = old_parameters[i];
  }
  if(old_parameters)
   free(old_parameters);
  for(; i < stmt->parameters_allocated; i++) {
   stmt->parameters[i].buflen = 0;
   stmt->parameters[i].buffer = 0;
   stmt->parameters[i].used = 0;
   stmt->parameters[i].paramType = 0;
   stmt->parameters[i].CType = 0;
   stmt->parameters[i].SQLType = 0;
   stmt->parameters[i].precision = 0;
   stmt->parameters[i].scale = 0;
   stmt->parameters[i].data_at_exec = (int)0;
   stmt->parameters[i].lobj_oid = 0;
   stmt->parameters[i].EXEC_used = ((void *)0);
   stmt->parameters[i].EXEC_buffer = ((void *)0);
  }
 }
 ipar--;
 stmt->parameters[ipar].buflen = cbValueMax;
 stmt->parameters[ipar].buffer = rgbValue;
 stmt->parameters[ipar].used = pcbValue;
 stmt->parameters[ipar].paramType = fParamType;
 stmt->parameters[ipar].CType = fCType;
 stmt->parameters[ipar].SQLType = fSqlType;
 stmt->parameters[ipar].precision = cbColDef;
 stmt->parameters[ipar].scale = ibScale;
 if (stmt->parameters[ipar].EXEC_used) {
  free(stmt->parameters[ipar].EXEC_used);
  stmt->parameters[ipar].EXEC_used = ((void *)0);
 }
 if (stmt->parameters[ipar].EXEC_buffer) {
  if (stmt->parameters[ipar].SQLType != (-4))
   free(stmt->parameters[ipar].EXEC_buffer);
  stmt->parameters[ipar].EXEC_buffer = ((void *)0);
 }
 if ((fSqlType == (-4) || fSqlType == (-1)) && pcbValue && (*pcbValue <= (-100) || *pcbValue == (-2) ))
  stmt->parameters[ipar].data_at_exec = (int)1;
 else
  stmt->parameters[ipar].data_at_exec = (int)0;
 mylog("SQLBindParamater: ipar=%d, paramType=%d, fCType=%d, fSqlType=%d, cbColDef=%d, ibScale=%d, rgbValue=%d, *pcbValue = %d, data_at_exec = %d\n", ipar, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, pcbValue ? *pcbValue: -777, stmt->parameters[ipar].data_at_exec);
 return 0;
}

canonical_original_code:
short SQLBindParameter(void *hstmt, unsigned short ipar, short fParamType, short fCType, short fSqlType, unsigned long cbColDef, short ibScale, void *rgbValue, long cbValueMax, long *pcbValue)
{
struct StatementClass_ *stmt = (StatementClass *) hstmt;
static char *func = "SQLBindParameter";
 mylog( "%s: entering...\n", func);
 if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 if(stmt->parameters_allocated < ipar) {
  struct ParameterInfoClass_ *old_parameters;
  int i; int old_parameters_allocated;
  old_parameters = stmt->parameters;
  old_parameters_allocated = stmt->parameters_allocated;
  stmt->parameters = (struct ParameterInfoClass_ *) malloc(sizeof(ParameterInfoClass)*(ipar));
  if ( ! stmt->parameters) {
   SC_set_error(stmt, 4, "Could not allocate memory for statement parameters");
   SC_log_error(func, "", stmt);
   return (-1);
  }
  stmt->parameters_allocated = ipar;
  for(i = 0; i < old_parameters_allocated; i++) {
   stmt->parameters[i] = old_parameters[i];
  }
  if(old_parameters)
   free(old_parameters);
  for(; i < stmt->parameters_allocated; i++) {
   stmt->parameters[i].buflen = 0;
   stmt->parameters[i].buffer = 0;
   stmt->parameters[i].used = 0;
   stmt->parameters[i].paramType = 0;
   stmt->parameters[i].CType = 0;
   stmt->parameters[i].SQLType = 0;
   stmt->parameters[i].precision = 0;
   stmt->parameters[i].scale = 0;
   stmt->parameters[i].data_at_exec = (int)0;
   stmt->parameters[i].lobj_oid = 0;
   stmt->parameters[i].EXEC_used = ((void *)0);
   stmt->parameters[i].EXEC_buffer = ((void *)0);
  }
 }
 ipar--;
 stmt->parameters[ipar].buflen = cbValueMax;
 stmt->parameters[ipar].buffer = rgbValue;
 stmt->parameters[ipar].used = pcbValue;
 stmt->parameters[ipar].paramType = fParamType;
 stmt->parameters[ipar].CType = fCType;
 stmt->parameters[ipar].SQLType = fSqlType;
 stmt->parameters[ipar].precision = cbColDef;
 stmt->parameters[ipar].scale = ibScale;
 if (stmt->parameters[ipar].EXEC_used) {
  free(stmt->parameters[ipar].EXEC_used);
  stmt->parameters[ipar].EXEC_used = ((void *)0);
 }
 if (stmt->parameters[ipar].EXEC_buffer) {
  if (stmt->parameters[ipar].SQLType != (-4))
   free(stmt->parameters[ipar].EXEC_buffer);
  stmt->parameters[ipar].EXEC_buffer = ((void *)0);
 }
 if ((fSqlType == (-4) || fSqlType == (-1)) && pcbValue && (*pcbValue <= (-100) || *pcbValue == (-2) ))
  stmt->parameters[ipar].data_at_exec = (int)1;
 else
  stmt->parameters[ipar].data_at_exec = (int)0;
 mylog("SQLBindParamater: ipar=%d, paramType=%d, fCType=%d, fSqlType=%d, cbColDef=%d, ibScale=%d, rgbValue=%d, *pcbValue = %d, data_at_exec = %d\n", ipar, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, pcbValue ? *pcbValue: -777, stmt->parameters[ipar].data_at_exec);
 return 0;
}

variable_types:
ipar
unsigned short

variable_types: fParamType short

variable_types: fSqlType short

variable_types:
cbColDef
unsigned long

variable_types: ibScale short

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


SQLDescribeParam

decompiled_code:
__int64 __fastcall SQLDescribeParam(__int64 a1, unsigned __int16 a2, _WORD *a3, _QWORD *a4, _WORD *a5, _WORD *a6)
{
unsigned __int16 v10; // bx
__int64 result; // rax

mylog("%s: entering...\n", "SQLDescribeParam");
if ( a1 )
{
if ( a2 && a2 <= *(int *)(a1 + 124) )
{
v10 = a2 - 1;
if ( a3 )
*a3 = *(_WORD *)(*(_QWORD *)(a1 + 128) + 72LL * v10 + 28);
if ( a4 )
*a4 = *(unsigned int *)(*(_QWORD *)(a1 + 128) + 72LL * v10 + 32);
if ( a5 )
*a5 = *(_WORD *)(*(_QWORD *)(a1 + 128) + 72LL * v10 + 36);
result = 0LL;
if ( a6 )
{
*a6 = pgtype_nullable(a1, (unsigned int)*(__int16 *)(*(_QWORD *)(a1 + 128) + 72LL * v10 + 24));
result = 0LL;
}
}
else
{
SC_set_error(a1, 11LL, "Invalid parameter number for SQLDescribeParam.");
SC_log_error("SQLDescribeParam", &LC2, a1);
result = 0xFFFFFFFFLL;
}
}
else
{
SC_log_error("SQLDescribeParam", &LC2, 0LL);
result = 4294967294LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int16 a2, _WORD *a3, _QWORD *a4, _WORD *a5, _WORD *a6)
{
unsigned __int16 v10; // bx
__int64 result; // rax

mylog("%s: entering...\n", "SQLDescribeParam");
if ( a1 )
{
if ( a2 && a2 <= *(int *)(a1 + 124) )
{
v10 = a2 - 1;
if ( a3 )
*a3 = *(_WORD *)(*(_QWORD *)(a1 + 128) + 72LL * v10 + 28);
if ( a4 )
*a4 = *(unsigned int *)(*(_QWORD *)(a1 + 128) + 72LL * v10 + 32);
if ( a5 )
*a5 = *(_WORD *)(*(_QWORD *)(a1 + 128) + 72LL * v10 + 36);
result = 0LL;
if ( a6 )
{
*a6 = pgtype_nullable(a1, (unsigned int)*(__int16 *)(*(_QWORD *)(a1 + 128) + 72LL * v10 + 24));
result = 0LL;
}
}
else
{
SC_set_error(a1, 11LL, "Invalid parameter number for SQLDescribeParam.");
SC_log_error("SQLDescribeParam", &LC2, a1);
result = 0xFFFFFFFFLL;
}
}
else
{
SC_log_error("SQLDescribeParam", &LC2, 0LL);
result = 4294967294LL;
}
return result;
}

original_code:
RETCODE SQLDescribeParam(
        HSTMT hstmt,
        UWORD ipar,
        SWORD *pfSqlType,
        SQLUINTEGER *pcbColDef,
        SWORD *pibScale,
        SWORD *pfNullable)
{
StatementClass *stmt = (StatementClass *) hstmt;
static char* const func = "SQLDescribeParam";
 mylog( "%s: entering...\n", func);
 if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 if( (ipar < 1) || (ipar > stmt->parameters_allocated) ) {
  SC_set_error(stmt, 11, "Invalid parameter number for SQLDescribeParam.");
  SC_log_error(func, "", stmt);
  return (-1);
 }
 ipar--;
 if(pfSqlType)
  *pfSqlType = stmt->parameters[ipar].SQLType;
 if(pcbColDef)
  *pcbColDef = stmt->parameters[ipar].precision;
 if(pibScale)
  *pibScale = stmt->parameters[ipar].scale;
 if(pfNullable)
  *pfNullable = pgtype_nullable(stmt, stmt->parameters[ipar].paramType);
 return 0;
}

canonical_original_code:
short SQLDescribeParam(void *hstmt, unsigned short ipar, short *pfSqlType, unsigned long *pcbColDef, short *pibScale, short *pfNullable)
{
struct StatementClass_ *stmt = (StatementClass *) hstmt;
static char *func = "SQLDescribeParam";
 mylog( "%s: entering...\n", func);
 if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 if( (ipar < 1) || (ipar > stmt->parameters_allocated) ) {
  SC_set_error(stmt, 11, "Invalid parameter number for SQLDescribeParam.");
  SC_log_error(func, "", stmt);
  return (-1);
 }
 ipar--;
 if(pfSqlType)
  *pfSqlType = stmt->parameters[ipar].SQLType;
 if(pcbColDef)
  *pcbColDef = stmt->parameters[ipar].precision;
 if(pibScale)
  *pibScale = stmt->parameters[ipar].scale;
 if(pfNullable)
  *pfNullable = pgtype_nullable(stmt, stmt->parameters[ipar].paramType);
 return 0;
}

variable_types:
pfSqlType
short *

variable_types:
pcbColDef
unsigned long *

variable_types:
pibScale
short *

variable_types:
pfNullable
short *

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


SQLParamOptions

decompiled_code:
__int64 __fastcall SQLParamOptions(__int64 a1)
{
mylog("%s: entering...\n", "SQLParamOptions");
SC_log_error("SQLParamOptions", "Function not implemented", a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
mylog("%s: entering...\n", "SQLParamOptions");
SC_log_error("SQLParamOptions", "Function not implemented", a1);
return 0xFFFFFFFFLL;
}

original_code:
RETCODE SQLParamOptions(
        HSTMT hstmt,
        SQLUINTEGER crow,
        SQLUINTEGER *pirow)
{
static char* const func = "SQLParamOptions";
 mylog( "%s: entering...\n", func);
 SC_log_error(func, "Function not implemented", (StatementClass *) hstmt);
 return (-1);
}

canonical_original_code:
short SQLParamOptions(void *hstmt, unsigned long crow, unsigned long *pirow)
{
static char *func = "SQLParamOptions";
 mylog( "%s: entering...\n", func);
 SC_log_error(func, "Function not implemented", (struct StatementClass_ *) hstmt);
 return (-1);
}

variable_types:
crow
unsigned long

variable_types:
pirow
unsigned long *

variable_types:
func
char *

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


SQLNumParams

decompiled_code:
__int64 __fastcall SQLNumParams(__int64 a1, _WORD *a2)
{
const char *v3; // rdi
size_t v4; // rdi
unsigned int v5; // edx
bool v6; // cl
__int64 v7; // rax
__int64 result; // rax
char v9; // al

mylog("%s: entering...\n", "SQLNumParams");
if ( a1 )
{
if ( a2 )
{
*a2 = 0;
v3 = *(const char **)(a1 + 168);
if ( v3 )
{
v4 = strlen(v3);
if ( v4 )
{
v5 = 0;
v6 = 0;
v7 = 0LL;
do
{
v9 = *(_BYTE *)(*(_QWORD *)(a1 + 168) + v7);
if ( v9 != 63 || v6 )
{
if ( v9 == 39 )
v6 = !v6;
}
else
{
++*a2;
v6 = 0;
}
v7 = ++v5;
}
while ( v5 < v4 );
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
SC_set_error(a1, 3LL, "SQLNumParams called with no statement ready.");
SC_log_error("SQLNumParams", &LC2, a1);
result = 0xFFFFFFFFLL;
}
}
else
{
SC_log_error("SQLNumParams", "pcpar was null", a1);
result = 0xFFFFFFFFLL;
}
}
else
{
SC_log_error("SQLNumParams", &LC2, 0LL);
result = 4294967294LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _WORD *a2)
{
const char *v3; // rdi
size_t v4; // rdi
unsigned int v5; // edx
bool v6; // cl
__int64 v7; // rax
__int64 result; // rax
char v9; // al

mylog("%s: entering...\n", "SQLNumParams");
if ( a1 )
{
if ( a2 )
{
*a2 = 0;
v3 = *(const char **)(a1 + 168);
if ( v3 )
{
v4 = strlen(v3);
if ( v4 )
{
v5 = 0;
v6 = 0;
v7 = 0LL;
do
{
v9 = *(_BYTE *)(*(_QWORD *)(a1 + 168) + v7);
if ( v9 != 63 || v6 )
{
if ( v9 == 39 )
v6 = !v6;
}
else
{
++*a2;
v6 = 0;
}
v7 = ++v5;
}
while ( v5 < v4 );
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
SC_set_error(a1, 3LL, "SQLNumParams called with no statement ready.");
SC_log_error("SQLNumParams", &LC2, a1);
result = 0xFFFFFFFFLL;
}
}
else
{
SC_log_error("SQLNumParams", "pcpar was null", a1);
result = 0xFFFFFFFFLL;
}
}
else
{
SC_log_error("SQLNumParams", &LC2, 0LL);
result = 4294967294LL;
}
return result;
}

original_code:
RETCODE SQLNumParams(
        HSTMT hstmt,
        SWORD *pcpar)
{
StatementClass *stmt = (StatementClass *) hstmt;
char in_quote = (int)0;
unsigned int i;
static char* const func = "SQLNumParams";
 mylog( "%s: entering...\n", func);
 if(!stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 if (pcpar)
  *pcpar = 0;
 else {
  SC_log_error(func, "pcpar was null", stmt);
  return (-1);
 }
 if(!stmt->statement) {
  SC_set_error(stmt, 3, "SQLNumParams called with no statement ready.");
  SC_log_error(func, "", stmt);
  return (-1);
 } else {
  size_t stlen=strlen(stmt->statement);
  for(i=0; i < stlen; i++) {
   if(stmt->statement[i] == '?' && !in_quote)
    (*pcpar)++;
   else {
    if (stmt->statement[i] == '\'')
     in_quote = (in_quote ? (int)0 : (int)1);
   }
  }
  return 0;
 }
}

canonical_original_code:
short SQLNumParams(void *hstmt, short *pcpar)
{
struct StatementClass_ *stmt = (StatementClass *) hstmt;
char in_quote = (int)0;
unsigned int i;
static char *func = "SQLNumParams";
 mylog( "%s: entering...\n", func);
 if(!stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 if (pcpar)
  *pcpar = 0;
 else {
  SC_log_error(func, "pcpar was null", stmt);
  return (-1);
 }
 if(!stmt->statement) {
  SC_set_error(stmt, 3, "SQLNumParams called with no statement ready.");
  SC_log_error(func, "", stmt);
  return (-1);
 } else {
  unsigned long stlen = strlen(stmt->statement);
  for(i=0; i < stlen; i++) {
   if(stmt->statement[i] == '?' && !in_quote)
    (*pcpar)++;
   else {
    if (stmt->statement[i] == '\'')
     in_quote = (in_quote ? (int)0 : (int)1);
   }
  }
  return 0;
 }
}

variable_types:
hstmt
void *

variable_types:
pcpar
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:
i
unsigned int

variable_types:
stlen
unsigned long

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


SQLBindCol

decompiled_code:
__int64 __fastcall SQLBindCol(__int64 a1, unsigned __int16 a2, __int16 a3, __int64 a4, int a5, __int64 a6)
{
return PG_SQLBindCol(a1, a2, a3, a4, a5, a6);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned __int16 a2, __int16 a3, __int64 a4, int a5, __int64 a6)
{
return func6(a1, a2, a3, a4, a5, a6);
}

original_code:
SQLRETURN SQLBindCol(SQLHSTMT hstmt,
     SQLUSMALLINT icol, SQLSMALLINT fCType,
     SQLPOINTER rgbValue, SQLINTEGER cbValueMax,
        SQLINTEGER *pcbValue)
{
    return PG_SQLBindCol( hstmt,
                        icol,
                        fCType,
                        rgbValue,
                        cbValueMax,
                        pcbValue );
}

canonical_original_code:
short SQLBindCol(void *hstmt, unsigned short icol, short fCType, void *rgbValue, long cbValueMax, long *pcbValue)
{
    return PG_SQLBindCol( hstmt,
                        icol,
                        fCType,
                        rgbValue,
                        cbValueMax,
                        pcbValue );
}

variable_types:
icol
unsigned short

variable_types: fCType short

variable_types:
rgbValue
void *

variable_types: cbValueMax long

variable_types:
pcbValue
long *


SQLInstallDriverManager

decompiled_code:
__int64 __fastcall SQLInstallDriverManager(char *s, unsigned __int16 a2, _WORD *a3)
{
const char *v4; // rax
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-518h] BYREF
char dest[1048]; // [rsp+100h] [rbp-418h] BYREF

inst_logClear();
if ( s && a2 > 1u )
{
v4 = (const char *)odbcinst_system_file_path(&v6);
strcpy(dest, v4);
strncpy(s, dest, a2);
result = 1LL;
if ( a3 )
{
*a3 = strlen(s);
result = 1LL;
}
}
else
{
inst_logPushMsg("SQLInstallDriverManager.c", "SQLInstallDriverManager.c", 31LL, 2LL, 1LL, &LC0);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s, unsigned __int16 a2, _WORD *a3)
{
const char *v4; // rax
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-518h] BYREF
char dest[1048]; // [rsp+100h] [rbp-418h] BYREF

inst_logClear();
if ( s && a2 > 1u )
{
v4 = (const char *)odbcinst_system_file_path(&v6);
strcpy(dest, v4);
strncpy(s, dest, a2);
result = 1LL;
if ( a3 )
{
*a3 = strlen(s);
result = 1LL;
}
}
else
{
inst_logPushMsg("SQLInstallDriverManager.c", "SQLInstallDriverManager.c", 31LL, 2LL, 1LL, &LC0);
result = 0LL;
}
return result;
}

original_code:
int SQLInstallDriverManager( LPSTR pszPath,
        WORD nPathMax,
        WORD *pnPathOut )
{
    char szIniName[ 1000 + 1 ];
 char b1[ 256 ];
    inst_logClear();
 if ( pszPath == ((void *)0) || nPathMax < 2 )
 {
        inst_logPushMsg( "SQLInstallDriverManager.c", "SQLInstallDriverManager.c", 31, 2, 1, "" );
  return 0;
 }
    sprintf( szIniName, "%s", odbcinst_system_file_path( b1 ) );
 strncpy( pszPath, szIniName, nPathMax );
 if ( pnPathOut != ((void *)0) )
  *pnPathOut = strlen( pszPath );
 return 1;
}

canonical_original_code:
int SQLInstallDriverManager(char *pszPath, unsigned short nPathMax, unsigned short *pnPathOut)
{
    char szIniName[-1];
 char b1[256];
    inst_logClear();
 if ( pszPath == ((void *)0) || nPathMax < 2 )
 {
        inst_logPushMsg( "SQLInstallDriverManager.c", "SQLInstallDriverManager.c", 31, 2, 1, "" );
  return 0;
 }
    sprintf( szIniName, "%s", odbcinst_system_file_path( b1 ) );
 strncpy( pszPath, szIniName, nPathMax );
 if ( pnPathOut != ((void *)0) )
  *pnPathOut = strlen( pszPath );
 return 1;
}

variable_types:
pszPath
char *

variable_types:
nPathMax
unsigned short

variable_types:
pnPathOut
unsigned short *

variable_types:
szIniName
char [-1]


SQLInstallDriverManagerW

decompiled_code:
__int64 __fastcall SQLInstallDriverManagerW(__int64 a1, unsigned __int16 a2, _WORD *a3)
{
char *v4; // rbp
unsigned int v5; // er12

inst_logClear();
v4 = (char *)calloc(a2, 1uLL);
v5 = SQLInstallDriverManager(v4, a2, a3);
if ( v5 )
single_string_copy_to_wide(a1, v4, a2);
free(v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int16 a2, _WORD *a3)
{
char *v4; // rbp
unsigned int v5; // er12

inst_logClear();
v4 = (char *)calloc(a2, 1uLL);
v5 = func0(v4, a2, a3);
if ( v5 )
single_string_copy_to_wide(a1, v4, a2);
free(v4);
return v5;
}

original_code:
int SQLInstallDriverManagerW (LPWSTR lpszPath,
                                      WORD cbPathMax,
                                      WORD * pcbPathOut)
{
 char *path;
 int ret;
    inst_logClear();
 path = calloc( cbPathMax, 1 );
 ret = SQLInstallDriverManager( path, cbPathMax, pcbPathOut );
 if ( ret )
 {
  _single_string_copy_to_wide( lpszPath, path, cbPathMax );
 }
 free( path );
 return ret;
}

canonical_original_code:
int SQLInstallDriverManagerW(unsigned short *lpszPath, unsigned short cbPathMax, unsigned short *pcbPathOut)
{
 char *path;
 int ret;
    inst_logClear();
 path = calloc( cbPathMax, 1 );
 ret = SQLInstallDriverManager( path, cbPathMax, pcbPathOut );
 if ( ret )
 {
  _single_string_copy_to_wide( lpszPath, path, cbPathMax );
 }
 free( path );
 return ret;
}

variable_types:
lpszPath
unsigned short *

variable_types:
cbPathMax
unsigned short

variable_types:
pcbPathOut
unsigned short *

variable_types:
path
char *

variable_types: ret int