converting unthreaded to threaded.
#1

Hello guys!

I'm having problems trying to convert unthreaded queries to threaded queries.


Orginally in unthreaded I was simply asked to put the "LoadFunctions()" under OnGameModeInit. But after looking at tutorial I learned I can pass it under callback something like this.

THREADED QUEIRIES ATTEMPT:
PHP код:
public OnGameModeInit()
{
    
SetGameModeText("MySQL - Server");
    new 
query[400];
    for (new 
idid MAX_FACTIONSid++)
    {
         
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `Factions` WHERE `ID` = %d LIMIT 1"id);
        
mysql_tquery(mysqlquery"LoadFactions""");
    }
    
mysql_log(LOG_ALL);
    
mysql mysql_connect(MYSQL_HOSTMYSQL_USERMYSQL_DATABASEMYSQL_PASSWORD);
    if(
mysql_errno() != 0)
    {
        
printf("[MySQL] The connection has failed.");
    }
    else
    {
        
printf("[MySQL] The connection was successful.");
    }
    return 
true;
}
forward LoadFactions();
public 
LoadFactions()
{
    new 
rowsfields;
    
cache_get_data(rows,fields);
    if(
rows)
    {
        
cache_get_field_content_int(0"ID");
        
cache_get_field_content(0,"Name",Factions[Total_Factions_Created][Name]);
        
cache_get_field_content(0,"Rank1",Factions[Total_Factions_Created][Rank1]);
        
cache_get_field_content(0,"Rank2",Factions[Total_Factions_Created][Rank2]);
        
cache_get_field_content(0,"Rank3",Factions[Total_Factions_Created][Rank3]);
        
cache_get_field_content(0,"Rank4",Factions[Total_Factions_Created][Rank4]);
         
cache_get_field_content(0,"Rank5",Factions[Total_Factions_Created][Rank5]);
        
Total_Factions_Created++;
    }
    
printf("> %d factions have been loaded from the database."Total_Factions_Created); // Prints out the information of how many factions created
    
return 1;

UNTHREAD QUERIES
PHP код:
public OnGameModeInit()
{
    
LoadFactions();
}
stock LoadFactions()
{
    new 
query[400];
    for(new 
idid MAX_FACTIONSid++) // Goes through all the slots, looking for the data
    
{
        
format(querysizeof(query), "SELECT * FROM Factions WHERE ID = %d"id); // Selects all the information from the table
        
mysql_query(query);
        
mysql_store_result();
        if(
mysql_num_rows())
        if(
mysql_fetch_row_format(query,"|"))
        {
            
sscanf(query"p<|>e<is[64]ds[32]s[32]s[32]s[32]s[32]>",Factions[id]); // SSCANF seperates the data into the variables
            
Total_Factions_Created++; // Counts the factions created
        
}
    }
    
printf("> %d factions have been loaded from the database."Total_Factions_Created); // Prints out the information of how many factions created
    
return 1;

I'm trying to convert to threaded queries, but I'm doing it wrong as it doesn't work at all. If someone could help me convert it. That'd be great!

My table looks like this.
Reply


Messages In This Thread
converting unthreaded to threaded. - by DavidLuango - 31.07.2016, 03:19
Re: converting unthreaded to threaded. - by Gammix - 31.07.2016, 04:41

Forum Jump:


Users browsing this thread: 1 Guest(s)