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

[SQL] Load from DB.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ex3cuTioN
Member
Join Date: May 2010
Old 12-24-2011 , 08:40   [SQL] Load from DB.
Reply With Quote #1

I have in database lj_stats a table called lj, there i have 10 rows, eatch row has 7 fields (id, name, distance, maxspeed, prestrafe, strafes, sync).

How can i load those values in next arrays:
new lj_names[10][33];
new lj_distance[10];
new lj_maxspeed[10];
new lj_prestrafe[10];
new lj_strafes[10];
new lj_sync[10];


PHP Code:
public Load_Tops(id) {
    new 
szTemp[512];
    new 
Data[7];
    
format(szTemp511,"SELECT name,distance,maxspeed,prestrafe,strafes,sync FROM lj_stats");
    
SQL_ThreadQuery(g_SqlTuple"QueryLoadTops"szTempData6);
}

public 
QueryLoadTops(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
    if(
FailState == TQUERY_CONNECT_FAILED)  log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError);
    else if(
FailState == TQUERY_QUERY_FAILED)  log_amx("Load Query failed. [%d] %s"ErrcodeError);
    
    new 
i=0;
    while(
SQL_MoreResults(Query)) {
        
SQL_ReadResult(Query,0,lj_names[i],32);
        
lj_distance[i] = SQL_ReadResult(Query,1);
        
lj_maxspeed[i] = SQL_ReadResult(Query,2);
        
lj_prestrafe[i] = SQL_ReadResult(Query,3);
        
lj_strafes[i] = SQL_ReadResult(Query,4);
        
lj_sync[i] = SQL_ReadResult(Query,5);
        
        
i++;
        
SQL_NextRow(Query);
    }
    
    
SQL_FreeHandle(Query);
    
    return 
PLUGIN_HANDLED;

Is this thing above working?

EDIT : The thing above is not working.


L 12/24/2011 - 15:47:20: [MySQL] Invalid info tuple handle: 0
L 12/24/2011 - 15:47:20: [AMXX] Displaying debug trace (plugin "hns_ljstats_sql.amxx")
L 12/24/2011 - 15:47:20: [AMXX] Run time error 10: native error (native "SQL_ThreadQuery")

Last edited by Ex3cuTioN; 12-24-2011 at 08:53.
Ex3cuTioN is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 12-24-2011 , 09:31   Re: [SQL] Load from DB.
Reply With Quote #2

The error says that g_SqlTuple is invalid handle. To get valid handle you must execute this once:
PHP Code:
g_SqlTuple SQL_MakeDbTuple(hostuserpassdb
__________________
Impossible is Nothing
Sylwester is offline
Ex3cuTioN
Member
Join Date: May 2010
Old 12-30-2011 , 12:08   Re: [SQL] Load from DB.
Reply With Quote #3

I have in plugin_init set_task(1.0, "MySql_Init");

And the public looks like this :

PHP Code:
public MySql_Init() {
    
g_SqlTuple SQL_MakeDbTuple(HostUserPassDb);
   
    new 
ErrorCode,Handle:SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error));
    
    if(
SqlConnection == Empty_Handleset_fail_state(g_Error);

    
SQL_FreeHandle(SqlConnection);

It's executing only once.
Ex3cuTioN is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 12-30-2011 , 14:41   Re: [SQL] Load from DB.
Reply With Quote #4

It must be executed before Load_Tops
__________________
Impossible is Nothing
Sylwester 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 18:38.


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