Raised This Month: $51 Target: $400
 12% 

Creating natives for SQL Querying?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
funxfusion
Junior Member
Join Date: Dec 2009
Old 12-17-2009 , 09:34   Creating natives for SQL Querying?
Reply With Quote #1

Hello,recently I am making some SQL stuffs,and ran into a situation.I want to use natives to link a "core" plugin and some branches,in the "core"plugin,I created some natives for the branches to use,in order to fetch data back from the MySQL server,or write some data into the MySQL server.Luckily,writting was done perfectly but I got trobules with fetching.
As i used SQL_TQuery,there must be a callback,but this callback are not in the process of the native,in other words,the native is not returning what the callback has fetched.
I don't know if I can use native on this situation,as I don't really want to combine both core and branches together,in order to minimize the plugin file size and let myself to check the errors more easily.
Here's the code
Code:
 
public __Native_getpoints(Handle:plugin,numParams)
{
    new client = GetNativeCell(1);
 required[client] = 0; //defined as new required[MAXPLAYERS+1]; at the header
    if (!IsClientConnected(client) && !IsClientInGame(client))
        return ThrowNativeError(SP_ERROR_NATIVE, "L4D STATS is not enabled");
    if (IsClientBot(client))
        return ThrowNativeError(SP_ERROR_NATIVE, "TARGET IS BOT");
 
 
    decl String:SteamID[MAX_LINE_WIDTH];
    GetClientAuthString(GetNativeCell(1), SteamID, sizeof(SteamID));
    decl String:query[256];
    Format(query, sizeof(query), "SELECT points FROM players WHERE steamid = '%s'",SteamID);
    SQL_TQuery(db,__Native_callback_get, query, client);
}
public __Native_callback_get(Handle:owner, Handle:hndl, const String:error[], any:data)
{
    new client = data;
 if (!client)
     return Plugin_Handled;
    if (hndl == INVALID_HANDLE)
        return Plugin_Handled;
 
    while (SQL_FetchRow(hndl))
    {
        required[client] = SQL_FetchInt(hndl, 0);
    }
    return required[client];
}
I am not very experienced to scripting,this is actually my first time for writing my own SQL process,and please,help!

-FF

Last edited by funxfusion; 12-17-2009 at 09:44.
funxfusion 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 06:05.


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