SQLGetStmtAttr

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

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

original_code:
SQLRETURN SQLGetStmtAttr( SQLHSTMT statement_handle,
           SQLINTEGER attribute,
           SQLPOINTER value,
           SQLINTEGER buffer_length,
           SQLINTEGER *string_length )
{
    DMHSTMT statement = (DMHSTMT) statement_handle;
    SQLRETURN ret;
    SQLCHAR s1[ 100 + 128 ];
    if ( !__validate_stmt( statement ))
    {
        dm_log_write( "SQLGetStmtAttr.c",
                    198,
                    0,
                    0,
                    "Error: SQL_INVALID_HANDLE" );
        return (-2);
    }
    function_entry( statement );
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg, "\n\t\tEntry:\n\t\t\tStatement = %p\n\t\t\tAttribute = %s\n\t\t\tValue = %p\n\t\t\tBuffer Length = %d\n\t\t\tStrLen = %p",
                statement,
                __stmt_attr_as_string( s1, attribute ),
                value,
                (int)buffer_length,
                (void*)string_length );
        dm_log_write( "SQLGetStmtAttr.c",
                223,
                0,
                0,
                statement -> msg );
    }
    thread_protect( 3, statement );
    if ( attribute == 14 )
    {
        if ( statement -> state == 1 ||
                statement -> state == 2 ||
                statement -> state == 3 ||
                statement -> state == 4 )
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    243,
                    0,
                    0,
                    "Error: 24000" );
            __post_internal_error( &statement -> error,
                    ERROR_24000, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    if ( statement -> state == 8 ||
            statement -> state == 9 ||
            statement -> state == 10 ||
            statement -> state == 11 ||
            statement -> state == 12 )
    {
        dm_log_write( "SQLGetStmtAttr.c",
                263,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> connection -> unicode_driver )
    {
        if ( !(statement -> connection->functions[46].funcW!=((void *)0)) &&
            !(statement -> connection->functions[47].funcW!=((void *)0)) &&
            !(statement -> connection->functions[46].func!=((void *)0)) &&
            !(statement -> connection->functions[47].func!=((void *)0)))
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    287,
                    0,
                    0,
                    "Error: IM001" );
            __post_internal_error( &statement -> error,
                    ERROR_IM001, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    else
    {
        if ( !(statement -> connection->functions[46].func!=((void *)0)) &&
            !(statement -> connection->functions[47].func!=((void *)0)))
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    305,
                    0,
                    0,
                    "Error: IM001" );
            __post_internal_error( &statement -> error,
                    ERROR_IM001, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    if ( attribute == 10010 )
    {
        if ( value )
            memcpy( value, &statement -> ard, sizeof( statement -> ard ));
        ret = 0;
    }
    else if ( attribute == 10011 )
    {
        if ( value )
            memcpy( value, &statement -> apd, sizeof( SQLHANDLE ));
        ret = 0;
    }
    else if ( attribute == 10012 )
    {
        if ( value )
            memcpy( value, &statement -> ird, sizeof( SQLHANDLE ));
        ret = 0;
    }
    else if ( attribute == 10013 )
    {
        if ( value )
            memcpy( value, &statement -> ipd, sizeof( SQLHANDLE ));
        ret = 0;
    }
    else if ( attribute == 16 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)))
    {
        if ( value )
            memcpy( value, &statement -> fetch_bm_ptr, sizeof( SQLUINTEGER * ));
        ret = 0;
    }
    else if ( attribute == 25 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)))
    {
        if ( value )
            memcpy( value, &statement -> row_st_arr, sizeof( SQLUINTEGER * ));
        ret = 0;
    }
    else if ( attribute == 26 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)))
    {
        if ( value )
            memcpy( value, &statement -> row_ct_ptr, sizeof( SQLUINTEGER * ));
        ret = 0;
    }
    else if ( statement -> connection -> unicode_driver &&
            attribute == 27 &&
            statement -> connection -> driver_act_ver == 2UL )
    {
        if ( (statement -> connection->functions[46].funcW!=((void *)0)))
        {
            ret = (statement -> connection->functions[46].funcW) (statement -> driver_stmt,9,value,buffer_length,string_length);
        }
        else
        {
            ret = (statement -> connection->functions[46].func) (statement -> driver_stmt,9,value,buffer_length,string_length);
        }
    }
    else if ( !statement -> connection -> unicode_driver &&
            attribute == 27 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[46].func!=((void *)0)))
    {
        ret = (statement -> connection->functions[46].func) (statement -> driver_stmt,9,value,buffer_length,string_length);
    }
    else if ( attribute == 27 &&
            statement -> connection -> driver_act_ver == 2UL )
    {
        if ( statement -> connection -> unicode_driver &&
                (statement -> connection->functions[47].funcW!=((void *)0)))
        {
            ret = (statement -> connection->functions[47].funcW) (statement -> driver_stmt,9,value);
        }
        else
        {
            ret = (statement -> connection->functions[47].func) (statement -> driver_stmt,9,value);
        }
    }
    else if ( statement -> connection -> unicode_driver &&
            ( (statement -> connection->functions[46].funcW!=((void *)0)) ||
            (statement -> connection->functions[46].func!=((void *)0))))
    {
        if ( (statement -> connection->functions[46].funcW!=((void *)0)))
        {
            ret = (statement -> connection->functions[46].funcW) (statement -> driver_stmt,attribute,value,buffer_length,string_length);
        }
        else
        {
            ret = (statement -> connection->functions[46].func) (statement -> driver_stmt,attribute,value,buffer_length,string_length);
        }
    }
    else if ( !statement -> connection -> unicode_driver &&
            (statement -> connection->functions[46].func!=((void *)0)))
    {
        ret = (statement -> connection->functions[46].func) (statement -> driver_stmt,attribute,value,buffer_length,string_length);
    }
    else if ( statement -> connection -> unicode_driver &&
            (statement -> connection->functions[47].funcW!=((void *)0)))
    {
        if ( attribute < 20000 &&
                ( attribute > 14 || attribute < 0 ))
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    480,
                    0,
                    0,
                    "Error: HY092" );
            __post_internal_error( &statement -> error,
                    ERROR_HY092, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        ret = (statement -> connection->functions[47].funcW) (statement -> driver_stmt,attribute,value);
    }
    else
    {
        if ( attribute < 20000 &&
                ( attribute > 14 || attribute < 0 ))
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    507,
                    0,
                    0,
                    "Error: HY092" );
            __post_internal_error( &statement -> error,
                    ERROR_HY092, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        ret = (statement -> connection->functions[47].func) (statement -> driver_stmt,attribute,value);
    }
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg,
                "\n\t\tExit:[%s]",
                    __get_return_status( ret, s1 ));
        dm_log_write( "SQLGetStmtAttr.c",
                532,
                0,
                0,
                statement -> msg );
    }
    return function_return_ex(3,statement,ret,0);
}

canonical_original_code:
short SQLGetStmtAttr(void *statement_handle, long attribute, void *value, long buffer_length, long *string_length)
{
    struct statement *statement = (DMHSTMT) statement_handle;
    short ret;
    unsigned char s1[-1];
    if ( !__validate_stmt( statement ))
    {
        dm_log_write( "SQLGetStmtAttr.c",
                    198,
                    0,
                    0,
                    "Error: SQL_INVALID_HANDLE" );
        return (-2);
    }
    function_entry( statement );
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg, "\n\t\tEntry:\n\t\t\tStatement = %p\n\t\t\tAttribute = %s\n\t\t\tValue = %p\n\t\t\tBuffer Length = %d\n\t\t\tStrLen = %p",
                statement,
                __stmt_attr_as_string( s1, attribute ),
                value,
                (int)buffer_length,
                (void *)string_length );
        dm_log_write( "SQLGetStmtAttr.c",
                223,
                0,
                0,
                statement -> msg );
    }
    thread_protect( 3, statement );
    if ( attribute == 14 )
    {
        if ( statement -> state == 1 ||
                statement -> state == 2 ||
                statement -> state == 3 ||
                statement -> state == 4 )
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    243,
                    0,
                    0,
                    "Error: 24000" );
            __post_internal_error( &statement -> error,
                    ERROR_24000, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    if ( statement -> state == 8 ||
            statement -> state == 9 ||
            statement -> state == 10 ||
            statement -> state == 11 ||
            statement -> state == 12 )
    {
        dm_log_write( "SQLGetStmtAttr.c",
                263,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> connection -> unicode_driver )
    {
        if ( !(statement -> connection->functions[46].funcW!=((void *)0)) &&
            !(statement -> connection->functions[47].funcW!=((void *)0)) &&
            !(statement -> connection->functions[46].func!=((void *)0)) &&
            !(statement -> connection->functions[47].func!=((void *)0)))
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    287,
                    0,
                    0,
                    "Error: IM001" );
            __post_internal_error( &statement -> error,
                    ERROR_IM001, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    else
    {
        if ( !(statement -> connection->functions[46].func!=((void *)0)) &&
            !(statement -> connection->functions[47].func!=((void *)0)))
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    305,
                    0,
                    0,
                    "Error: IM001" );
            __post_internal_error( &statement -> error,
                    ERROR_IM001, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    if ( attribute == 10010 )
    {
        if ( value )
            memcpy( value, &statement -> ard, sizeof( statement -> ard ));
        ret = 0;
    }
    else if ( attribute == 10011 )
    {
        if ( value )
            memcpy( value, &statement -> apd, sizeof( SQLHANDLE ));
        ret = 0;
    }
    else if ( attribute == 10012 )
    {
        if ( value )
            memcpy( value, &statement -> ird, sizeof( SQLHANDLE ));
        ret = 0;
    }
    else if ( attribute == 10013 )
    {
        if ( value )
            memcpy( value, &statement -> ipd, sizeof( SQLHANDLE ));
        ret = 0;
    }
    else if ( attribute == 16 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)))
    {
        if ( value )
            memcpy( value, &statement -> fetch_bm_ptr, sizeof( unsigned long * ));
        ret = 0;
    }
    else if ( attribute == 25 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)))
    {
        if ( value )
            memcpy( value, &statement -> row_st_arr, sizeof( unsigned long * ));
        ret = 0;
    }
    else if ( attribute == 26 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)))
    {
        if ( value )
            memcpy( value, &statement -> row_ct_ptr, sizeof( unsigned long * ));
        ret = 0;
    }
    else if ( statement -> connection -> unicode_driver &&
            attribute == 27 &&
            statement -> connection -> driver_act_ver == 2UL )
    {
        if ( (statement -> connection->functions[46].funcW!=((void *)0)))
        {
            ret = (statement -> connection->functions[46].funcW) (statement -> driver_stmt,9,value,buffer_length,string_length);
        }
        else
        {
            ret = (statement -> connection->functions[46].func) (statement -> driver_stmt,9,value,buffer_length,string_length);
        }
    }
    else if ( !statement -> connection -> unicode_driver &&
            attribute == 27 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[46].func!=((void *)0)))
    {
        ret = (statement -> connection->functions[46].func) (statement -> driver_stmt,9,value,buffer_length,string_length);
    }
    else if ( attribute == 27 &&
            statement -> connection -> driver_act_ver == 2UL )
    {
        if ( statement -> connection -> unicode_driver &&
                (statement -> connection->functions[47].funcW!=((void *)0)))
        {
            ret = (statement -> connection->functions[47].funcW) (statement -> driver_stmt,9,value);
        }
        else
        {
            ret = (statement -> connection->functions[47].func) (statement -> driver_stmt,9,value);
        }
    }
    else if ( statement -> connection -> unicode_driver &&
            ( (statement -> connection->functions[46].funcW!=((void *)0)) ||
            (statement -> connection->functions[46].func!=((void *)0))))
    {
        if ( (statement -> connection->functions[46].funcW!=((void *)0)))
        {
            ret = (statement -> connection->functions[46].funcW) (statement -> driver_stmt,attribute,value,buffer_length,string_length);
        }
        else
        {
            ret = (statement -> connection->functions[46].func) (statement -> driver_stmt,attribute,value,buffer_length,string_length);
        }
    }
    else if ( !statement -> connection -> unicode_driver &&
            (statement -> connection->functions[46].func!=((void *)0)))
    {
        ret = (statement -> connection->functions[46].func) (statement -> driver_stmt,attribute,value,buffer_length,string_length);
    }
    else if ( statement -> connection -> unicode_driver &&
            (statement -> connection->functions[47].funcW!=((void *)0)))
    {
        if ( attribute < 20000 &&
                ( attribute > 14 || attribute < 0 ))
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    480,
                    0,
                    0,
                    "Error: HY092" );
            __post_internal_error( &statement -> error,
                    ERROR_HY092, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        ret = (statement -> connection->functions[47].funcW) (statement -> driver_stmt,attribute,value);
    }
    else
    {
        if ( attribute < 20000 &&
                ( attribute > 14 || attribute < 0 ))
        {
            dm_log_write( "SQLGetStmtAttr.c",
                    507,
                    0,
                    0,
                    "Error: HY092" );
            __post_internal_error( &statement -> error,
                    ERROR_HY092, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        ret = (statement -> connection->functions[47].func) (statement -> driver_stmt,attribute,value);
    }
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg,
                "\n\t\tExit:[%s]",
                    __get_return_status( ret, s1 ));
        dm_log_write( "SQLGetStmtAttr.c",
                532,
                0,
                0,
                statement -> msg );
    }
    return function_return_ex(3,statement,ret,0);
}

variable_types: attribute long

variable_types:
value
void *

variable_types: struct statement { int type; struct statement *next_class_list; char msg[1024]; int state; struct connection { int type; struct connection *next_class_list; char msg[1024]; int state; struct environment { int type; struct environment *next_class_list; char msg[1024]; int state; long requested_version; int connection_count; int sql_driver_count; struct error_head { struct error_header { int error_count; struct error { unsigned short sqlstate[6]; unsigned short *msg; long native_error; int return_val; short diag_column_number_ret; short diag_row_number_ret; short diag_class_origin_ret; short diag_subclass_origin_ret; short diag_connection_name_ret; short diag_server_name_ret; long diag_column_number; long diag_row_number; unsigned short diag_class_origin[128]; unsigned short diag_subclass_origin[128]; unsigned short diag_connection_name[128]; unsigned short diag_server_name[128]; struct error *next; struct error *prev; } *error_list_head; struct error *error_list_tail; int internal_count; struct error *internal_list_head; struct error *internal_list_tail; } sql_error_head; struct error_header sql_diag_head; void *owning_handle; int handle_type; short return_code; long header_set; short diag_cursor_row_count_ret; short diag_dynamic_function_ret; short diag_dynamic_function_code_ret; short diag_number_ret; short diag_row_count_ret; long diag_cursor_row_count; unsigned short diag_dynamic_function[128]; long diag_dynamic_function_code; long diag_number; long diag_row_count; } error; long connection_pooling; long cp_match; int fetch_mode; int entry; void *sh; struct env_lib_struct { char *lib_name; void *env_handle; int count; struct env_lib_struct *next; } *env_lib_list; } *environment; void *dl_handle; char dl_name[256]; struct driver_func { int ordinal; char *name; void *dm_func; void *dm_funcW; short (*func)(); short (*funcW)(); short (*funcA)(); int can_supply; } *functions; struct driver_func ini_func; struct driver_func fini_func; int unicode_driver; void *driver_env; void *driver_dbc; int driver_version; int driver_act_ver; int statement_count; struct error_head error; char dsn[-1]; int access_mode; int access_mode_set; int login_timeout; int login_timeout_set; int auto_commit; int auto_commit_set; int async_enable; int async_enable_set; int auto_ipd; int auto_ipd_set; int connection_timeout; int connection_timeout_set; int metadata_id; int metadata_id_set; int packet_size; int packet_size_set; long quite_mode; int quite_mode_set; int txn_isolation; int txn_isolation_set; long cursors; void *cl_handle; int trace; char tracefile[-1]; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; int protection_level; int ex_fetch_mapping; int disable_gf; int dont_dlclose; int bookmarks_on; void *pooled_connection; int pooling_timeout; int ttl; char driver_connect_string[1024]; int dsn_length; char server[128]; int server_length; char user[128]; int user_length; char password[128]; int password_length; char cli_year[5]; struct attr_struct { int count; struct attr_set { char *keyword; char *value; int override; int attribute; int is_int_type; int int_value; struct attr_set *next; } *list; } env_attribute; struct attr_struct dbc_attribute; struct attr_struct stmt_attribute; struct save_attr { int attr_type; char *str_attr; int str_len; int int_attr; struct save_attr *next; } *save_attr; void *iconv_cd_uc_to_ascii; void *iconv_cd_ascii_to_uc; char unicode_string[64]; struct env_lib_struct *env_list_ent; char probe_sql[512]; int threading_level; int cbs_found; short ccb_value; short crb_value; } *connection; void *driver_stmt; short hascols; int prepared; int interupted_func; int interupted_state; int bookmarks_on; struct error_head error; long metadata_id; struct descriptor { int type; struct descriptor *next_class_list; char msg[1024]; int state; struct error_head error; void *driver_desc; struct connection *connection; int implicit; void *associated_with; union pthread_mutex_t mutex; } *ipd; struct descriptor *apd; struct descriptor *ird; struct descriptor *ard; struct descriptor *implicit_ipd; struct descriptor *implicit_apd; struct descriptor *implicit_ird; struct descriptor *implicit_ard; unsigned long *fetch_bm_ptr; unsigned long *row_ct_ptr; unsigned short *row_st_arr; unsigned long row_array_size; void *valueptr; union pthread_mutex_t mutex; int eod; } *

variable_types: ret short


SQLProcedures

repo: xiaotmiaomiao/unixODBC-SPEC

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

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

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

canonical_original_code:
short SQLProcedures(void *hstmt, unsigned char *szProcQualifier, short cbProcQualifier, unsigned char *szProcOwner, short cbProcOwner, unsigned char *szProcName, short cbProcName)
{
static char *func = "SQLProcedures";
 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:
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; }


SQLColumns

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

if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLColumns.c", "SQLColumns.c", 81LL, 1LL, 1LL, a1 + 136);
if ( a6 && *a6 )
{
v10 = *(_QWORD **)(a1 + 1168);
if ( *v10 )
((void (__fastcall *)(_QWORD *, const char *, __int64, __int64))FreeResults)(v10, "SQLColumns.c", v8, v9);
v11 = *(void **)(a1 + 128);
if ( v11 )
free(v11);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLColumns.c", "SQLColumns.c", 118LL, 0LL, 0LL, "SQL_SUCCESS");
result = 0LL;
}
else
{
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLColumns.c",
"SQLColumns.c",
85LL,
1LL,
1LL,
"SQL_ERROR Must supply a valid table name");
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLColumns.c", "SQLColumns.c", 81LL, 1LL, 1LL, a1 + 136);
if ( a6 && *a6 )
{
v10 = *(_QWORD **)(a1 + 1168);
if ( *v10 )
((void (__fastcall *)(_QWORD *, const char *, __int64, __int64))FreeResults)(v10, "SQLColumns.c", v8, v9);
v11 = *(void **)(a1 + 128);
if ( v11 )
free(v11);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLColumns.c", "SQLColumns.c", 118LL, 0LL, 0LL, "SQL_SUCCESS");
result = 0LL;
}
else
{
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLColumns.c",
"SQLColumns.c",
85LL,
1LL,
1LL,
"SQL_ERROR Must supply a valid table name");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
RETCODE SQLColumns(
                           HSTMT hstmt,
                           UCHAR * szTableQualifier,
                           SWORD cbTableQualifier,
                           UCHAR * szTableOwner,
                           SWORD cbTableOwner,
                           UCHAR * szTableName,
                           SWORD cbTableName,
                           UCHAR * szColumnName,
                           SWORD cbColumnName)
{
    return PG_SQLColumns( hstmt,
                        szTableQualifier,
                        cbTableQualifier,
                        szTableOwner,
                        cbTableOwner,
                        szTableName,
                        cbTableName,
                        szColumnName,
                        cbColumnName );
}

canonical_original_code:
short SQLColumns(void *hstmt, unsigned char *szTableQualifier, short cbTableQualifier, unsigned char *szTableOwner, short cbTableOwner, unsigned char *szTableName, short cbTableName, unsigned char *szColumnName, short cbColumnName)
{
    return PG_SQLColumns( hstmt,
                        szTableQualifier,
                        cbTableQualifier,
                        szTableOwner,
                        cbTableOwner,
                        szTableName,
                        cbTableName,
                        szColumnName,
                        cbColumnName );
}

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


SQLWriteFileDSNW

decompiled_code:
__int64 __fastcall SQLWriteFileDSNW(char *src, void *ptr, void *a3, void *a4)
{
char *v4; // r14
void *v5; // r13
unsigned int v8; // er15

v4 = src;
v5 = ptr;
if ( src )
v4 = (char *)((__int64 (*)(void))single_string_alloc_and_copy)();
if ( ptr )
v5 = (void *)single_string_alloc_and_copy(ptr);
if ( a3 )
a3 = (void *)single_string_alloc_and_copy(a3);
if ( a4 )
a4 = (void *)single_string_alloc_and_copy(a4);
v8 = SQLWriteFileDSN(v4, (__int64)v5, (__int64)a3, (__int64)a4);
if ( v4 )
free(v4);
if ( v5 )
free(v5);
if ( a3 )
free(a3);
if ( a4 )
free(a4);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, void *ptr, void *a3, void *a4)
{
char *v4; // r14
void *v5; // r13
unsigned int v8; // er15

v4 = src;
v5 = ptr;
if ( src )
v4 = (char *)((__int64 (*)(void))single_string_alloc_and_copy)();
if ( ptr )
v5 = (void *)single_string_alloc_and_copy(ptr);
if ( a3 )
a3 = (void *)single_string_alloc_and_copy(a3);
if ( a4 )
a4 = (void *)single_string_alloc_and_copy(a4);
v8 = func0(v4, (__int64)v5, (__int64)a3, (__int64)a4);
if ( v4 )
free(v4);
if ( v5 )
free(v5);
if ( a3 )
free(a3);
if ( a4 )
free(a4);
return v8;
}

original_code:
int SQLWriteFileDSNW(LPCWSTR lpszFileName,
                              LPCWSTR lpszAppName,
                              LPCWSTR lpszKeyName,
                              LPCWSTR lpszString)
{
 int ret;
 char *file;
 char *app;
 char *key;
 char *str;
 file = lpszFileName ? _single_string_alloc_and_copy( lpszFileName ) : (char*)((void *)0);
 app = lpszAppName ? _single_string_alloc_and_copy( lpszAppName ) : (char*)((void *)0);
 key = lpszKeyName ? _single_string_alloc_and_copy( lpszKeyName ) : (char*)((void *)0);
 str = lpszString ? _single_string_alloc_and_copy( lpszString ) : (char*)((void *)0);
 ret = SQLWriteFileDSN( file, app, key, str );
 if ( file )
  free( file );
 if ( app )
  free( app );
 if ( key )
  free( key );
 if ( str )
  free( str );
 return ret;
}

canonical_original_code:
int SQLWriteFileDSNW(unsigned short *lpszFileName, unsigned short *lpszAppName, unsigned short *lpszKeyName, unsigned short *lpszString)
{
 int ret;
 char *file;
 char *app;
 char *key;
 char *str;
 file = lpszFileName ? _single_string_alloc_and_copy( lpszFileName ) : (char *)((void *)0);
 app = lpszAppName ? _single_string_alloc_and_copy( lpszAppName ) : (char *)((void *)0);
 key = lpszKeyName ? _single_string_alloc_and_copy( lpszKeyName ) : (char *)((void *)0);
 str = lpszString ? _single_string_alloc_and_copy( lpszString ) : (char *)((void *)0);
 ret = SQLWriteFileDSN( file, app, key, str );
 if ( file )
  free( file );
 if ( app )
  free( app );
 if ( key )
  free( key );
 if ( str )
  free( str );
 return ret;
}

variable_types:
lpszFileName
unsigned short *

variable_types:
lpszAppName
unsigned short *

variable_types:
lpszKeyName
unsigned short *

variable_types:
lpszString
unsigned short *

variable_types: ret int

variable_types:
file
char *

variable_types:
app
char *

variable_types:
key
char *

variable_types:
str
char *

return_type: int


variable_types: n int

variable_types: i int


decompiled_code:
__int64 nnodbc_conndialog()
{
return 0xFFFFFFFFLL;
}

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

original_code:
int nnodbc_conndialog()
{
 return -1;
}

canonical_original_code:
int nnodbc_conndialog()
{
 return -1;
}


SQLSetDescField

decompiled_code:
__int64 SQLSetDescField()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0xFFFFFFFFLL;
}

original_code:
SQLRETURN SQLSetDescField( SQLHDESC DescriptorHandle,
                             SQLSMALLINT RecordNumber,
                             SQLSMALLINT FieldIdentifier,
                             SQLPOINTER Value,
                             SQLINTEGER BufferLength
                          )
{
    return (-1);
}

canonical_original_code:
short SQLSetDescField(void *DescriptorHandle, short RecordNumber, short FieldIdentifier, void *Value, long BufferLength)
{
    return (-1);
}

variable_types:
DescriptorHandle
void *

variable_types: RecordNumber short

variable_types: FieldIdentifier short

variable_types:
Value
void *

variable_types: BufferLength long


SQLFetchScroll

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

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

original_code:
SQLRETURN SQLFetchScroll( SQLHSTMT statement_handle,
           SQLSMALLINT fetch_orientation,
           SQLINTEGER fetch_offset )
{
    DMHSTMT statement = (DMHSTMT) statement_handle;
    SQLRETURN ret;
    SQLCHAR s1[ 100 + 128 ];
    if ( !__validate_stmt( statement ))
    {
        dm_log_write( "SQLFetchScroll.c",
                    138,
                    0,
                    0,
                    "Error: SQL_INVALID_HANDLE" );
        return (-2);
    }
    function_entry( statement );
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg, "\n\t\tEntry:\n\t\t\tStatement = %p\n\t\t\tFetch Orentation = %d\n\t\t\tFetch Offset = %d",
                statement,
                fetch_orientation,
                (int)fetch_offset );
        dm_log_write( "SQLFetchScroll.c",
                159,
                0,
                0,
                statement -> msg );
    }
    thread_protect( 3, statement );
    if ( fetch_orientation != 1 &&
            fetch_orientation != 4 &&
            fetch_orientation != 2 &&
            fetch_orientation != 3 &&
            fetch_orientation != 5 &&
            fetch_orientation != 6 &&
            fetch_orientation != 8 )
    {
        dm_log_write( "SQLFetchScroll.c",
                176,
                0,
                0,
                "Error: HY106" );
        __post_internal_error( &statement -> error,
                ERROR_HY106, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 1 ||
            statement -> state == 2 ||
            statement -> state == 3 )
    {
        dm_log_write( "SQLFetchScroll.c",
                197,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 4 )
    {
        dm_log_write( "SQLFetchScroll.c",
                212,
                0,
                0,
                "Error: 24000" );
        __post_internal_error( &statement -> error,
                ERROR_24000, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 7 )
    {
        dm_log_write( "SQLFetchScroll.c",
                227,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 8 ||
            statement -> state == 9 ||
            statement -> state == 10 )
    {
        dm_log_write( "SQLFetchScroll.c",
                244,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 11 ||
            statement -> state == 12 )
    {
        if ( statement -> interupted_func != 1021 )
        {
            dm_log_write( "SQLFetchScroll.c",
                    262,
                    0,
                    0,
                    "Error: HY010" );
            __post_internal_error( &statement -> error,
                    ERROR_HY010, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    if ( (statement -> connection->functions[30].func!=((void *)0)))
    {
        ret = (statement -> connection->functions[30].func) (statement -> driver_stmt,fetch_orientation,fetch_offset);
    }
    else if ( statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)))
    {
        SQLINTEGER bm_ptr = 0;
        if ( fetch_orientation == 8 )
        {
            if ( statement -> fetch_bm_ptr )
                bm_ptr = *statement -> fetch_bm_ptr;
            ret = (statement -> connection->functions[28].func) (statement -> driver_stmt,fetch_orientation,bm_ptr,statement -> row_ct_ptr,statement -> row_st_arr);
        }
        else
        {
            ret = (statement -> connection->functions[28].func) (statement -> driver_stmt,fetch_orientation,fetch_offset,statement -> row_ct_ptr,statement -> row_st_arr);
        }
    }
    else
    {
        dm_log_write( "SQLFetchScroll.c",
                315,
                0,
                0,
                "Error: IM001" );
        __post_internal_error( &statement -> error,
                ERROR_IM001, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( ret == 2 )
    {
        statement -> interupted_func = 1021;
        if ( statement -> state != 11 &&
                statement -> state != 12 )
            statement -> state = 11;
    }
    else if ( (((ret)&(~1))==0))
    {
        statement -> state = 6;
    }
    else if ( ret == 100 ) {
        statement -> eod = 1;
    }
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg,
                "\n\t\tExit:[%s]",
                    __get_return_status( ret, s1 ));
        dm_log_write( "SQLFetchScroll.c",
                349,
                0,
                0,
                statement -> msg );
    }
    return function_return_ex(3,statement,ret,0);
}

canonical_original_code:
short SQLFetchScroll(void *statement_handle, short fetch_orientation, long fetch_offset)
{
    struct statement *statement = (DMHSTMT) statement_handle;
    short ret;
    unsigned char s1[-1];
    if ( !__validate_stmt( statement ))
    {
        dm_log_write( "SQLFetchScroll.c",
                    138,
                    0,
                    0,
                    "Error: SQL_INVALID_HANDLE" );
        return (-2);
    }
    function_entry( statement );
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg, "\n\t\tEntry:\n\t\t\tStatement = %p\n\t\t\tFetch Orentation = %d\n\t\t\tFetch Offset = %d",
                statement,
                fetch_orientation,
                (int)fetch_offset );
        dm_log_write( "SQLFetchScroll.c",
                159,
                0,
                0,
                statement -> msg );
    }
    thread_protect( 3, statement );
    if ( fetch_orientation != 1 &&
            fetch_orientation != 4 &&
            fetch_orientation != 2 &&
            fetch_orientation != 3 &&
            fetch_orientation != 5 &&
            fetch_orientation != 6 &&
            fetch_orientation != 8 )
    {
        dm_log_write( "SQLFetchScroll.c",
                176,
                0,
                0,
                "Error: HY106" );
        __post_internal_error( &statement -> error,
                ERROR_HY106, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 1 ||
            statement -> state == 2 ||
            statement -> state == 3 )
    {
        dm_log_write( "SQLFetchScroll.c",
                197,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 4 )
    {
        dm_log_write( "SQLFetchScroll.c",
                212,
                0,
                0,
                "Error: 24000" );
        __post_internal_error( &statement -> error,
                ERROR_24000, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 7 )
    {
        dm_log_write( "SQLFetchScroll.c",
                227,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 8 ||
            statement -> state == 9 ||
            statement -> state == 10 )
    {
        dm_log_write( "SQLFetchScroll.c",
                244,
                0,
                0,
                "Error: HY010" );
        __post_internal_error( &statement -> error,
                ERROR_HY010, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( statement -> state == 11 ||
            statement -> state == 12 )
    {
        if ( statement -> interupted_func != 1021 )
        {
            dm_log_write( "SQLFetchScroll.c",
                    262,
                    0,
                    0,
                    "Error: HY010" );
            __post_internal_error( &statement -> error,
                    ERROR_HY010, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
    }
    if ( (statement -> connection->functions[30].func!=((void *)0)))
    {
        ret = (statement -> connection->functions[30].func) (statement -> driver_stmt,fetch_orientation,fetch_offset);
    }
    else if ( statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)))
    {
        long bm_ptr = 0;
        if ( fetch_orientation == 8 )
        {
            if ( statement -> fetch_bm_ptr )
                bm_ptr = *statement -> fetch_bm_ptr;
            ret = (statement -> connection->functions[28].func) (statement -> driver_stmt,fetch_orientation,bm_ptr,statement -> row_ct_ptr,statement -> row_st_arr);
        }
        else
        {
            ret = (statement -> connection->functions[28].func) (statement -> driver_stmt,fetch_orientation,fetch_offset,statement -> row_ct_ptr,statement -> row_st_arr);
        }
    }
    else
    {
        dm_log_write( "SQLFetchScroll.c",
                315,
                0,
                0,
                "Error: IM001" );
        __post_internal_error( &statement -> error,
                ERROR_IM001, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    if ( ret == 2 )
    {
        statement -> interupted_func = 1021;
        if ( statement -> state != 11 &&
                statement -> state != 12 )
            statement -> state = 11;
    }
    else if ( (((ret)&(~1))==0))
    {
        statement -> state = 6;
    }
    else if ( ret == 100 ) {
        statement -> eod = 1;
    }
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg,
                "\n\t\tExit:[%s]",
                    __get_return_status( ret, s1 ));
        dm_log_write( "SQLFetchScroll.c",
                349,
                0,
                0,
                statement -> msg );
    }
    return function_return_ex(3,statement,ret,0);
}

variable_types: struct statement { int type; struct statement *next_class_list; char msg[1024]; int state; struct connection { int type; struct connection *next_class_list; char msg[1024]; int state; struct environment { int type; struct environment *next_class_list; char msg[1024]; int state; long requested_version; int connection_count; int sql_driver_count; struct error_head { struct error_header { int error_count; struct error { unsigned short sqlstate[6]; unsigned short *msg; long native_error; int return_val; short diag_column_number_ret; short diag_row_number_ret; short diag_class_origin_ret; short diag_subclass_origin_ret; short diag_connection_name_ret; short diag_server_name_ret; long diag_column_number; long diag_row_number; unsigned short diag_class_origin[128]; unsigned short diag_subclass_origin[128]; unsigned short diag_connection_name[128]; unsigned short diag_server_name[128]; struct error *next; struct error *prev; } *error_list_head; struct error *error_list_tail; int internal_count; struct error *internal_list_head; struct error *internal_list_tail; } sql_error_head; struct error_header sql_diag_head; void *owning_handle; int handle_type; short return_code; long header_set; short diag_cursor_row_count_ret; short diag_dynamic_function_ret; short diag_dynamic_function_code_ret; short diag_number_ret; short diag_row_count_ret; long diag_cursor_row_count; unsigned short diag_dynamic_function[128]; long diag_dynamic_function_code; long diag_number; long diag_row_count; } error; long connection_pooling; long cp_match; int fetch_mode; int entry; void *sh; struct env_lib_struct { char *lib_name; void *env_handle; int count; struct env_lib_struct *next; } *env_lib_list; } *environment; void *dl_handle; char dl_name[256]; struct driver_func { int ordinal; char *name; void *dm_func; void *dm_funcW; short (*func)(); short (*funcW)(); short (*funcA)(); int can_supply; } *functions; struct driver_func ini_func; struct driver_func fini_func; int unicode_driver; void *driver_env; void *driver_dbc; int driver_version; int driver_act_ver; int statement_count; struct error_head error; char dsn[-1]; int access_mode; int access_mode_set; int login_timeout; int login_timeout_set; int auto_commit; int auto_commit_set; int async_enable; int async_enable_set; int auto_ipd; int auto_ipd_set; int connection_timeout; int connection_timeout_set; int metadata_id; int metadata_id_set; int packet_size; int packet_size_set; long quite_mode; int quite_mode_set; int txn_isolation; int txn_isolation_set; long cursors; void *cl_handle; int trace; char tracefile[-1]; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; int protection_level; int ex_fetch_mapping; int disable_gf; int dont_dlclose; int bookmarks_on; void *pooled_connection; int pooling_timeout; int ttl; char driver_connect_string[1024]; int dsn_length; char server[128]; int server_length; char user[128]; int user_length; char password[128]; int password_length; char cli_year[5]; struct attr_struct { int count; struct attr_set { char *keyword; char *value; int override; int attribute; int is_int_type; int int_value; struct attr_set *next; } *list; } env_attribute; struct attr_struct dbc_attribute; struct attr_struct stmt_attribute; struct save_attr { int attr_type; char *str_attr; int str_len; int int_attr; struct save_attr *next; } *save_attr; void *iconv_cd_uc_to_ascii; void *iconv_cd_ascii_to_uc; char unicode_string[64]; struct env_lib_struct *env_list_ent; char probe_sql[512]; int threading_level; int cbs_found; short ccb_value; short crb_value; } *connection; void *driver_stmt; short hascols; int prepared; int interupted_func; int interupted_state; int bookmarks_on; struct error_head error; long metadata_id; struct descriptor { int type; struct descriptor *next_class_list; char msg[1024]; int state; struct error_head error; void *driver_desc; struct connection *connection; int implicit; void *associated_with; union pthread_mutex_t mutex; } *ipd; struct descriptor *apd; struct descriptor *ird; struct descriptor *ard; struct descriptor *implicit_ipd; struct descriptor *implicit_apd; struct descriptor *implicit_ird; struct descriptor *implicit_ard; unsigned long *fetch_bm_ptr; unsigned long *row_ct_ptr; unsigned short *row_st_arr; unsigned long row_array_size; void *valueptr; union pthread_mutex_t mutex; int eod; } *

variable_types: ret short

user_defined_types: struct statement { int type; struct statement *next_class_list; char msg[1024]; int state; struct connection *connection; void *driver_stmt; short hascols; int prepared; int interupted_func; int interupted_state; int bookmarks_on; struct error_head error; long metadata_id; struct descriptor *ipd; struct descriptor *apd; struct descriptor *ird; struct descriptor *ard; struct descriptor *implicit_ipd; struct descriptor *implicit_apd; struct descriptor *implicit_ird; struct descriptor *implicit_ard; unsigned long *fetch_bm_ptr; unsigned long *row_ct_ptr; unsigned short *row_st_arr; unsigned long row_array_size; void *valueptr; union pthread_mutex_t mutex; int eod; }

user_defined_types: struct connection { int type; struct connection *next_class_list; char msg[1024]; int state; struct environment *environment; void *dl_handle; char dl_name[256]; struct driver_func *functions; struct driver_func ini_func; struct driver_func fini_func; int unicode_driver; void *driver_env; void *driver_dbc; int driver_version; int driver_act_ver; int statement_count; struct error_head error; char dsn[-1]; int access_mode; int access_mode_set; int login_timeout; int login_timeout_set; int auto_commit; int auto_commit_set; int async_enable; int async_enable_set; int auto_ipd; int auto_ipd_set; int connection_timeout; int connection_timeout_set; int metadata_id; int metadata_id_set; int packet_size; int packet_size_set; long quite_mode; int quite_mode_set; int txn_isolation; int txn_isolation_set; long cursors; void *cl_handle; int trace; char tracefile[-1]; union pthread_mutex_t mutex; int protection_level; int ex_fetch_mapping; int disable_gf; int dont_dlclose; int bookmarks_on; void *pooled_connection; int pooling_timeout; int ttl; char driver_connect_string[1024]; int dsn_length; char server[128]; int server_length; char user[128]; int user_length; char password[128]; int password_length; char cli_year[5]; struct attr_struct env_attribute; struct attr_struct dbc_attribute; struct attr_struct stmt_attribute; struct save_attr *save_attr; void *iconv_cd_uc_to_ascii; void *iconv_cd_ascii_to_uc; char unicode_string[64]; struct env_lib_struct *env_list_ent; char probe_sql[512]; int threading_level; int cbs_found; short ccb_value; short crb_value; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct attr_struct { int count; struct attr_set *list; }

user_defined_types: struct environment { int type; struct environment *next_class_list; char msg[1024]; int state; long requested_version; int connection_count; int sql_driver_count; struct error_head error; long connection_pooling; long cp_match; int fetch_mode; int entry; void *sh; struct env_lib_struct *env_lib_list; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct error_head { struct error_header sql_error_head; struct error_header sql_diag_head; void *owning_handle; int handle_type; short return_code; long header_set; short diag_cursor_row_count_ret; short diag_dynamic_function_ret; short diag_dynamic_function_code_ret; short diag_number_ret; short diag_row_count_ret; long diag_cursor_row_count; unsigned short diag_dynamic_function[128]; long diag_dynamic_function_code; long diag_number; long diag_row_count; }

user_defined_types: struct error_header { int error_count; struct error *error_list_head; struct error *error_list_tail; int internal_count; struct error *internal_list_head; struct error *internal_list_tail; }


SQLReadFileDSNW

decompiled_code:
__int64 __fastcall SQLReadFileDSNW(char *src, void *ptr, void *a3, __int64 a4, unsigned __int16 a5, _WORD *a6)
{
char *v6; // r14
void *v9; // rbp
__int128 v11; // rdi
char *v12; // r15
unsigned int v13; // er13
__int128 v15; // rdi
__int16 v17[29]; // [rsp+1Eh] [rbp-3Ah] BYREF

v6 = src;
v9 = ptr;
inst_logClear();
if ( src )
v6 = (char *)single_string_alloc_and_copy(src);
if ( ptr )
v9 = (void *)single_string_alloc_and_copy(ptr);
if ( a3 )
a3 = (void *)single_string_alloc_and_copy(a3);
if ( a5 && a4 )
{
*((_QWORD *)&v15 + 1) = v9;
*(_QWORD *)&v15 = v6;
v12 = (char *)calloc(a5 + 1, 1uLL);
v13 = SQLReadFileDSN(v15, (__int64)a3, v12, a5, v17);
if ( v13 && v12 )
single_copy_to_wide(a4, v12, (unsigned int)(unsigned __int16)v17[0] + 1);
}
else
{
*((_QWORD *)&v11 + 1) = v9;
*(_QWORD *)&v11 = v6;
v12 = 0LL;
v13 = SQLReadFileDSN(v11, (__int64)a3, 0LL, a5, v17);
}
if ( v6 )
free(v6);
if ( v9 )
free(v9);
if ( a3 )
free(a3);
if ( v12 )
free(v12);
if ( a6 )
*a6 = v17[0];
return v13;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src, void *ptr, void *a3, __int64 a4, unsigned __int16 a5, _WORD *a6)
{
char *v6; // r14
void *v9; // rbp
__int128 v11; // rdi
char *v12; // r15
unsigned int v13; // er13
__int128 v15; // rdi
__int16 v17[29]; // [rsp+1Eh] [rbp-3Ah] BYREF

v6 = src;
v9 = ptr;
inst_logClear();
if ( src )
v6 = (char *)single_string_alloc_and_copy(src);
if ( ptr )
v9 = (void *)single_string_alloc_and_copy(ptr);
if ( a3 )
a3 = (void *)single_string_alloc_and_copy(a3);
if ( a5 && a4 )
{
*((_QWORD *)&v15 + 1) = v9;
*(_QWORD *)&v15 = v6;
v12 = (char *)calloc(a5 + 1, 1uLL);
v13 = func2(v15, (__int64)a3, v12, a5, v17);
if ( v13 && v12 )
single_copy_to_wide(a4, v12, (unsigned int)(unsigned __int16)v17[0] + 1);
}
else
{
*((_QWORD *)&v11 + 1) = v9;
*(_QWORD *)&v11 = v6;
v12 = 0LL;
v13 = func2(v11, (__int64)a3, 0LL, a5, v17);
}
if ( v6 )
free(v6);
if ( v9 )
free(v9);
if ( a3 )
free(a3);
if ( v12 )
free(v12);
if ( a6 )
*a6 = v17[0];
return v13;
}

original_code:
int SQLReadFileDSNW(LPCWSTR lpszFileName,
                              LPCWSTR lpszAppName,
                              LPCWSTR lpszKeyName,
                              LPWSTR lpszString,
                              WORD cbString,
                              WORD *pcbString)
{
    char *file;
    char *app;
    char *key;
    char *str;
    WORD len;
    int ret;
    inst_logClear();
    file = lpszFileName ? _single_string_alloc_and_copy( lpszFileName ) : (char*)((void *)0);
    app = lpszAppName ? _single_string_alloc_and_copy( lpszAppName ) : (char*)((void *)0);
    key = lpszKeyName ? _single_string_alloc_and_copy( lpszKeyName ) : (char*)((void *)0);
    if ( lpszString )
    {
        if ( cbString > 0 )
        {
            str = calloc( cbString + 1, 1 );
        }
        else
        {
            str = ((void *)0);
        }
    }
    else
    {
        str = ((void *)0);
    }
    ret = SQLReadFileDSN( file, app, key, str, cbString, &len );
    if ( ret )
    {
        if ( str && lpszString )
        {
            _single_copy_to_wide( lpszString, str, len + 1 );
        }
    }
    if ( file )
        free( file );
    if ( app )
        free( app );
    if ( key )
        free( key );
    if ( str )
        free( str );
    if ( pcbString )
        *pcbString = len;
    return ret;
}

canonical_original_code:
int SQLReadFileDSNW(unsigned short *lpszFileName, unsigned short *lpszAppName, unsigned short *lpszKeyName, unsigned short *lpszString, unsigned short cbString, unsigned short *pcbString)
{
    char *file;
    char *app;
    char *key;
    char *str;
    unsigned short len;
    int ret;
    inst_logClear();
    file = lpszFileName ? _single_string_alloc_and_copy( lpszFileName ) : (char *)((void *)0);
    app = lpszAppName ? _single_string_alloc_and_copy( lpszAppName ) : (char *)((void *)0);
    key = lpszKeyName ? _single_string_alloc_and_copy( lpszKeyName ) : (char *)((void *)0);
    if ( lpszString )
    {
        if ( cbString > 0 )
        {
            str = calloc( cbString + 1, 1 );
        }
        else
        {
            str = ((void *)0);
        }
    }
    else
    {
        str = ((void *)0);
    }
    ret = SQLReadFileDSN( file, app, key, str, cbString, &len );
    if ( ret )
    {
        if ( str && lpszString )
        {
            _single_copy_to_wide( lpszString, str, len + 1 );
        }
    }
    if ( file )
        free( file );
    if ( app )
        free( app );
    if ( key )
        free( key );
    if ( str )
        free( str );
    if ( pcbString )
        *pcbString = len;
    return ret;
}

variable_types:
lpszFileName
unsigned short *

variable_types:
lpszAppName
unsigned short *

variable_types:
cbString
unsigned short

variable_types:
pcbString
unsigned short *

variable_types:
len
unsigned short


SQLSetCursorName

decompiled_code:
__int64 __fastcall SQLSetCursorName(__int64 a1, const char *a2, __int16 a3)
{
__int64 result; // rax

if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLSetCursorName.c", "SQLSetCursorName.c", 27LL, 1LL, 1LL, a1 + 136);
if ( a2 && ((*_ctype_b_loc())[*(unsigned __int8 *)a2] & 0x400) != 0 )
{
if ( a3 == -3 )
strncpy((char *)(a1 + 24), a2, 0x64uLL);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLSetCursorName.c", "SQLSetCursorName.c", 48LL, 0LL, 0LL, "SQL_SUCCESS");
result = 0LL;
}
else
{
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLSetCursorName.c",
"SQLSetCursorName.c",
31LL,
1LL,
1LL,
"SQL_ERROR Invalid cursor name");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2, __int16 a3)
{
__int64 result; // rax

if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLSetCursorName.c", "SQLSetCursorName.c", 27LL, 1LL, 1LL, a1 + 136);
if ( a2 && ((*_ctype_b_loc())[*(unsigned __int8 *)a2] & 0x400) != 0 )
{
if ( a3 == -3 )
strncpy((char *)(a1 + 24), a2, 0x64uLL);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLSetCursorName.c", "SQLSetCursorName.c", 48LL, 0LL, 0LL, "SQL_SUCCESS");
result = 0LL;
}
else
{
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLSetCursorName.c",
"SQLSetCursorName.c",
31LL,
1LL,
1LL,
"SQL_ERROR Invalid cursor name");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
RETCODE SQLSetCursorName(
        HSTMT hstmt,
        UCHAR *szCursor,
        SWORD cbCursor)
{
static char* const func="SQLSetCursorName";
StatementClass *stmt = (StatementClass *) hstmt;
int len;
mylog("SQLSetCursorName: hstmt=%u, szCursor=%u, cbCursorMax=%d\n", hstmt, szCursor, cbCursor);
 if ( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 len = (cbCursor == (-3)) ? strlen((char*)szCursor) : cbCursor;
 if (len <= 0 || len > sizeof(stmt->cursor_name) - 1) {
  SC_set_error(stmt, 19, "Invalid Cursor Name");
  SC_log_error(func, "", stmt);
  return (-1);
 }
 strncpy_null((char*)stmt->cursor_name, (char*)szCursor, len+1);
 return 0;
}

canonical_original_code:
short SQLSetCursorName(void *hstmt, unsigned char *szCursor, short cbCursor)
{
static char *func = "SQLSetCursorName";
struct StatementClass_ *stmt = (StatementClass *) hstmt;
int len;
mylog("SQLSetCursorName: hstmt=%u, szCursor=%u, cbCursorMax=%d\n", hstmt, szCursor, cbCursor);
 if ( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 len = (cbCursor == (-3)) ? strlen((char *)szCursor) : cbCursor;
 if (len <= 0 || len > sizeof(stmt->cursor_name) - 1) {
  SC_set_error(stmt, 19, "Invalid Cursor Name");
  SC_log_error(func, "", stmt);
  return (-1);
 }
 strncpy_null((char *)stmt->cursor_name, (char *)szCursor, len+1);
 return 0;
}

variable_types:
hstmt
void *

variable_types:
szCursor
unsigned char *

variable_types: cbCursor short

variable_types:
func
char *

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

variable_types: len int

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

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


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


decompiled_code:
__int64 __fastcall nnodbc_sqlfreestmt(void *ptr, int a2)
{
void *v3; // rdi
void *v4; // rdi
int v6; // eax
int v7; // er13
__int64 v8; // r12
int v9; // ebx
__int64 v10; // rsi
__int64 v11; // rax
int v12; // ecx
__int64 v13; // rax
bool v14; // si
_QWORD *v15; // rax
int v16; // edx

if ( a2 == 2 )
{
v12 = nnsql_max_column();
v13 = *((_QWORD *)ptr + 2);
if ( v12 >= 0 )
{
v14 = v13 != 0;
v15 = (_QWORD *)(v13 + 8);
v16 = 0;
if ( v14 )
{
do
{
++v16;
*v15 = 0LL;
v15 += 5;
}
while ( v12 >= v16 );
return 0LL;
}
}
return 0LL;
}
if ( a2 > 2 )
{
if ( a2 != 3 )
return 0xFFFFFFFFLL;
v6 = nnsql_max_param();
v7 = v6;
if ( *((_QWORD *)ptr + 3) && v6 > 0 )
{
v8 = 0LL;
v9 = 1;
do
{
v10 = (unsigned int)v9++;
nnsql_yyunbindpar(*((_QWORD *)ptr + 5), v10);
v11 = *((_QWORD *)ptr + 3);
*(_DWORD *)(v11 + v8) = 0;
v8 += 80LL;
}
while ( v11 && v7 >= v9 );
}
return 0LL;
}
if ( !a2 )
{
nnsql_close_cursor();
return 0LL;
}
if ( a2 != 1 )
return 0xFFFFFFFFLL;
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);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr, int a2)
{
void *v3; // rdi
void *v4; // rdi
int v6; // eax
int v7; // er13
__int64 v8; // r12
int v9; // ebx
__int64 v10; // rsi
__int64 v11; // rax
int v12; // ecx
__int64 v13; // rax
bool v14; // si
_QWORD *v15; // rax
int v16; // edx

if ( a2 == 2 )
{
v12 = nnsql_max_column();
v13 = *((_QWORD *)ptr + 2);
if ( v12 >= 0 )
{
v14 = v13 != 0;
v15 = (_QWORD *)(v13 + 8);
v16 = 0;
if ( v14 )
{
do
{
++v16;
*v15 = 0LL;
v15 += 5;
}
while ( v12 >= v16 );
return 0LL;
}
}
return 0LL;
}
if ( a2 > 2 )
{
if ( a2 != 3 )
return 0xFFFFFFFFLL;
v6 = nnsql_max_param();
v7 = v6;
if ( *((_QWORD *)ptr + 3) && v6 > 0 )
{
v8 = 0LL;
v9 = 1;
do
{
v10 = (unsigned int)v9++;
nnsql_yyunbindpar(*((_QWORD *)ptr + 5), v10);
v11 = *((_QWORD *)ptr + 3);
*(_DWORD *)(v11 + v8) = 0;
v8 += 80LL;
}
while ( v11 && v7 >= v9 );
}
return 0LL;
}
if ( !a2 )
{
nnsql_close_cursor();
return 0LL;
}
if ( a2 != 1 )
return 0xFFFFFFFFLL;
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);
return 0LL;
}

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


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]);
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]);
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: 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 *v2; // r8
int v3; // eax
int v4; // ecx
unsigned int v5; // er8

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int *a2)
{
unsigned int *v2; // r8
int v3; // eax
int v4; // ecx
unsigned int v5; // er8

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

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 *v2; // r8
int v3; // edx
int v4; // ecx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2)
{
unsigned int *v2; // r8
int v3; // edx
int v4; // ecx
__int64 result; // rax

func0(a1, a2);
v3 = func0(a1, v2);
result = 0LL;
if ( v3 != 7 )
result = (unsigned int)-(v3 != 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 v2; // rbx
__int64 result; // rax
unsigned int *v4; // r10
__int64 v5; // r9
unsigned int *v6; // r10
int v7; // eax
int v8; // er9
bool v9; // zf
int v10; // er8
int v11; // eax
int v12; // er12
int v13; // eax

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax
unsigned int *v4; // r10
__int64 v5; // r9
unsigned int *v6; // r10
int v7; // eax
int v8; // er9
bool v9; // zf
int v10; // er8
int v11; // eax
int v12; // er12
int v13; // eax

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

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 *