[C++]SQLAPI 'fectchnext' fails?

Joined
Apr 18, 2010
Messages
674
Reaction score
393
Code:
        try
        {
            int nAID = 0;
            sql = new SACommand( &saConnection, szQuery );
            sql->Execute( );

            if(sql->isResultSet()) //Verify that the data is there
            {
                if( sql->FetchNext( ) ) //This loop is causing it..
                    nAID = sql->Field( "aid" ).asLong( );
            }

As soon as the application I'm injecting my dynamic link library to executes this function, the application hangs then crashes.
I know that because I've used the Sleep( ) function throughout the try/catch block and it happens before 'nAID =...' and after 'isResultSet'.

Any thoughts of what could be causing this?
 
Thank you, however, I could not find what was causing it. So I've rooted down from SQLAPI to the applications internal functions.

I am posting because I am kinda stuck on this one issue.
I only need a select few functions from that application (the server for the game I am working with).

void CDatabase::ExecuteQuery( const char* szQuery );
int CODBCRecordset::GetFieldID( const char* szQuery );
int CDBField::AsInt( );
<stdlist...lol> CDBField::AsString( ); //This one I'm not worry about at the moment.

Currently, I have ExecuteQuery working (to my knowledge).
However, GetFieldID is causing problems once called.

Looking at how one function calls GetFieldID, I can see what is wrong.
Code:
004425C9   . 51             PUSH ECX
004425CA   . C645 FC 02     MOV BYTE PTR SS:[EBP-4],2
004425CE   . E8 FD09FCFF    CALL MatchSer.ATL::CStringT<char,StrTraitMFC<char,>
004425D3   . 8B75 EC        MOV ESI,DWORD PTR SS:[EBP-14]
004425D6   . 83C4 0C        ADD ESP,0C
004425D9   . 6A 04          PUSH 4
004425DB   . 6A 02          PUSH 2
004425DD   . 56             PUSH ESI
004425DE   . 8D8D A8FEFFFF  LEA ECX,DWORD PTR SS:[EBP-158]
004425E4   . E8 87890400    CALL MatchSer.CODBCRecordset::Open
004425E9   . 8D46 F0        LEA EAX,DWORD PTR DS:[ESI-10]
004425EC   . 83CB FF        OR EBX,FFFFFFFF
004425EF   . C645 FC 01     MOV BYTE PTR SS:[EBP-4],1
004425F3   . 8D50 0C        LEA EDX,DWORD PTR DS:[EAX+C]
004425F6   . 8BCB           MOV ECX,EBX
004425F8   . F0:0FC10A      LOCK XADD DWORD PTR DS:[EDX],ECX                   ;  LOCK prefix
004425FC   . 49             DEC ECX
004425FD   . 85C9           TEST ECX,ECX
004425FF   . 7F 08          JG SHORT MatchSer.00442609
00442601   . 8B08           MOV ECX,DWORD PTR DS:[EAX]
00442603   . 8B11           MOV EDX,DWORD PTR DS:[ECX]
00442605   . 50             PUSH EAX
00442606   . FF52 04        CALL DWORD PTR DS:[EDX+4]
00442609   > 33F6           XOR ESI,ESI
0044260B   . 8D8D A8FEFFFF  LEA ECX,DWORD PTR SS:[EBP-158]
00442611   . 8975 FC        MOV DWORD PTR SS:[EBP-4],ESI
00442614   . E8 E5ED0500    CALL MatchSer.CRecordset::IsOpen
00442619   . 85C0           TEST EAX,EAX
0044261B   . 0F84 48010000  JE MatchSer.00442769
00442621   . 39B5 44FFFFFF  CMP DWORD PTR SS:[EBP-BC],ESI
00442627   . 0F8E 3C010000  JLE MatchSer.00442769
0044262D   . 83BD 6CFFFFFF >CMP DWORD PTR SS:[EBP-94],1
00442634   . 0F84 2F010000  JE MatchSer.00442769
0044263A   . 68 F4BE5000    PUSH OFFSET MatchSer.??_C@_03IKNANCPO@NUM?$AA@     ;  ASCII "NUM"
0044263F   . 8D8D A8FEFFFF  LEA ECX,DWORD PTR SS:[EBP-158]
00442645   . E8 E6A20400    CALL MatchSer.CODBCRecordset::GetFieldID
0044264A   . 8B4D B8        MOV ECX,DWORD PTR SS:[EBP-48]
0044264D   . 8D0440         LEA EAX,DWORD PTR DS:[EAX+EAX*2]
00442650   . 8D0CC1         LEA ECX,DWORD PTR DS:[ECX+EAX*8]
00442653   . E8 488C0400    CALL MatchSer.CDBField::AsInt

Looking at that, I can see how the server calls it.
Code:
Recordset->GetFieldID( "SELECT lol FROM lol WHERE lol = lol" ).asInt( );

However, I'm not sure how I could do that at all.
Here is part of the base I am working with.
Code:
struct Database
{
	int GetFieldID( const char* szQuery )
	{
		return ( ( int( __thiscall* )( LPVOID, const char* ) )ulODBCGetFieldIDAddress )( this, szQuery );
	}

	void ExecuteSQL( const char* szQuery )
	{
		( ( void( __thiscall* )( LPVOID, const char* ) )ulCDatabaseExecuteSQLAddress )( this, szQuery );
	}
};

struct CBField
{
	int AsInt( )
	{
		return ( ( int( __thiscall* )( ) )ulCDBFieldAsIntAddress )( );
	}
};

I know it's simple, I can see it but I just can't figure it out.
-Edit, I re-looked at the dissasembly, and found at a few issues. I'm not sure if it'll fix my problem yet.

Edit
Here's how it should be, in case someone else has a similar problem.
Code:
struct CDBField
{
	int AsInt( )
	{
		return ( ( int( __thiscall* )( ) )ulCDBFieldAddress )( );
	}
};


struct Database
{
	int GetFieldID( const char* szName )
	{
		return ( ( int( __thiscall* )( LPVOID, const char* ) )ulODBCGetFieldIDAddress )( this, szName );
	}

	void ExecuteSQL( const char* szQuery )
	{
		( ( void( __thiscall* )( LPVOID, const char* ) )ulCDatabaseExecuteSQLAddress )( this, szQuery );
	}

	int Open( const char* szSQL, unsigned int nOpenType, unsigned long ndwOptions )
	{
		return ( ( int( __thiscall* )( LPVOID, const char*, unsigned int, unsigned long ) )ulCDatabaseOpenAddress )( this, szSQL, nOpenType, ndwOptions );
	}

	CDBField* Field( const char* szName )
	{
		return ( ( int( __thiscall* )( LPVOID, const char* ) )ulCDatabaseFieldAddress )( this, szName );
	}
};


//Later...
Database* db = new Database( );
char szQuery[150];
sprintf_s( szQuery, "SELECT lol FROM lol WHERE lol = %s", szLol );
db->Open( szQuery, 2, 4 );
int nLol = db->Field( "lol" )->AsInt( );
 
Last edited:
Back