Raised This Month: $ Target: $400
 0% 

SQL native


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 03-02-2010 , 06:38   SQL native
Reply With Quote #1

Need help with making a native, that retrieves information from SQL table. Tried it so many times with SQLx and it didn't work, so I'm out of ideas

I need it like this:
PHP Code:
blablablablabla(id) {
OMG SELECT SOMETHING FROM DB WHERE ID=id
return result

, so I can use it like
new blablabla = blablablablabla(id)

thanks for any help.
Backstabnoob is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 03-02-2010 , 07:00   Re: SQL native
Reply With Quote #2

http://forums.alliedmods.net/showthread.php?t=46779
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 03-02-2010 , 07:03   Re: SQL native
Reply With Quote #3

Code:
new Handle:g_hSQLTuple; // connection has to be made too new g_iValue[ 33 ]; LoadData( iClient ) {     new szQuery[ 50 ], szData[ 2 ];         formatex( szQuery, 49, "SELECT `*` FROM `table_here` WHERE `id` = '%d'", iClient );         szData[ 0 ] = iClient;         SQL_ThreadQuery( g_hSQLTuple, "SQLHandle", szQuery, szData, 1 ); } public SQLHandle( iFailState, Handle:hQuery, szError[ ], iError, szData[ ], iDataSize, Float:fQueueTime ) {     if( iFailState == TQUERY_CONNECT_FAILED     || iFailState == TQUERY_QUERY_FAILED )     {         log_amx( "SQL: Query failed to load data." );                 return;     }         new iClient = szData[ 0 ];         while( SQL_MoreResults( hQuery ) )     {         g_iValue[ iClient ] = SQL_ReadResult( hQuery, 1 ); // the 1 represents the SECOND collumn (0 is the FIRST collumn)     } }

http://www.amxmodx.org/funcwiki.php?go=func&id=1105

Note: This is just an example of how you can retrieve values from collumns using SQL_ReadResult. I don't know if this is faulty or not, correct me if I'm wrong please.
__________________
Achievements API - a simple way for you to create your OWN custom achievements!

Last edited by Xellath; 03-02-2010 at 07:17.
Xellath is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 03-02-2010 , 09:18   Re: SQL native
Reply With Quote #4

AntiBots - read, please, the topic again.

Xellath - thanks, I'll try when I get home.
Backstabnoob is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-02-2010 , 10:01   Re: SQL native
Reply With Quote #5

I put together an include that makes SQLx transactions similar to that of nVault. Take a look: http://forums.alliedmods.net/showpos...54&postcount=6
__________________
Bugsy is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 03-02-2010 , 10:39   Re: SQL native
Reply With Quote #6

Quote:
Originally Posted by Backstabnoob View Post
AntiBots - read, please, the topic again
Just read the Tutorial and you will can do...

Not use Handleds, Just with "SQL_PrepareQuery" and "SQL_Execute".
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 03-06-2010 , 05:19   Re: SQL native
Reply With Quote #7

PHP Code:
LoadKarmaiClient )
{
    new 
szQuery50 ], szData];
    new 
iClientSteamId[32]
    
get_user_authid(iClientiClientSteamId31)
    
formatexszQuery49"SELECT `*` FROM `arp_merit` WHERE `SteamID` = '%s'"iClientSteamId );
    
    
szData] = iClient;
    
    
SQL_ThreadQueryg_SqlHandle"SQLHandle"szQueryszData);
}

public 
SQLHandleiFailStateHandle:hQueryszError[ ], iErrorszData[ ], iDataSizeFloat:fQueueTime )
{
    if( 
iFailState == TQUERY_CONNECT_FAILED 
    
|| iFailState == TQUERY_QUERY_FAILED )
    {
        
log_amx"SQL: Query failed to load data." );
        
        return;
    }
    
    new 
iClient szData];
    
    while( 
SQL_MoreResultshQuery ) )
    {
        
g_KarmaiClient ] = SQL_ReadResulthQuery); // the 1 represents the SECOND collumn (0 is the FIRST collumn)
    
}

This doesn't work. The result is always 0 on every client. There are no errors in the logs.
Edit: Well, there are. SQL: Query failed to load data.
Edit2: Changed the query like this: formatex( szQuery, 49, "SELECT * FROM arp_merit WHERE SteamID='%s'", iClientSteamId ). Now it throws no errors, but still, it retrieves bad data.

Last edited by Backstabnoob; 03-06-2010 at 05:38.
Backstabnoob is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:43.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode