AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   SQL native (https://forums.alliedmods.net/showthread.php?t=120228)

Backstabnoob 03-02-2010 06:38

SQL native
 
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.

AntiBots 03-02-2010 07:00

Re: SQL native
 
http://forums.alliedmods.net/showthread.php?t=46779

Xellath 03-02-2010 07:03

Re: SQL native
 
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.

Backstabnoob 03-02-2010 09:18

Re: SQL native
 
AntiBots - read, please, the topic again.

Xellath - thanks, I'll try when I get home.

Bugsy 03-02-2010 10:01

Re: SQL native
 
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

AntiBots 03-02-2010 10:39

Re: SQL native
 
Quote:

Originally Posted by Backstabnoob (Post 1105322)
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".

Backstabnoob 03-06-2010 05:19

Re: SQL native
 
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.


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

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