Raised This Month: $ Target: $400
 0% 

Reading ini file through sql table


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ARES[ro]
Senior Member
Join Date: Apr 2010
Old 06-16-2011 , 16:14   Re: Reading ini file through sql table
Reply With Quote #1

What Exolent means, do that only once. (do not do it more then once), it may add double the entries if you do it twice...
__________________
okay
ARES[ro] is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-16-2011 , 20:19   Re: Reading ini file through sql table
Reply With Quote #2

Quote:
Originally Posted by bibu View Post
So you mean this:

After the "sql_load" function, call "ini_to_sql" and in there again "sql_load", right?
Yes.

Quote:
Originally Posted by ARES[ro] View Post
What Exolent means, do that only once. (do not do it more then once), it may add double the entries if you do it twice...
Updated ini_to_sql() to delete any existing entries in the table.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 06-18-2011 , 12:44   Re: Reading ini file through sql table
Reply With Quote #3

Quote:
Originally Posted by Exolent[jNr] View Post
Updated ini_to_sql() to delete any existing entries in the table.
Alright got it to work. If the entries are deleted and I am changing the map, there will be doubled entries. And after another and another map changes it does double it, so it doesn't delete any existing entries. Or maybe what could be done would be, to delete the entries on "plugin_end"?
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-18-2011 , 20:08   Re: Reading ini file through sql table
Reply With Quote #4

Quote:
Originally Posted by bibu View Post
Alright got it to work. If the entries are deleted and I am changing the map, there will be doubled entries. And after another and another map changes it does double it, so it doesn't delete any existing entries. Or maybe what could be done would be, to delete the entries on "plugin_end"?
You're missing the point of the ini_to_sql() function.

You should only do that 3 function combination I posted once.
Not once every map. Just one time TOTAL.

After you have done it once, you only need to have sql_load() in the plugin_init().

To add your own messages to the table, you can either do it through your hosting, or you can just write a console command to add it.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 06-17-2011 , 16:09   Re: Reading ini file through sql table
Reply With Quote #5

Well, I am getting this:

Quote:
L 06/17/2011 - 21:54:45: [AMXX] Run time error 4: index out of bounds
L 06/17/2011 - 21:54:45: [AMXX] [0] state.sma::setString (line 1216)
L 06/17/2011 - 21:54:45: [AMXX] [1] state.sma::sql_load (line 807)
L 06/17/2011 - 21:54:45: [AMXX] [2] state.sma::ini_to_sql (line 736)
L 06/17/2011 - 21:54:45: [AMXX] [3] state.sma::sql_load (line 823)
L 06/17/2011 - 21:54:45: [AMXX] [4] state.sma::ini_to_sql (line 736)
L 06/17/2011 - 21:54:45: [AMXX] [5] state.sma::sql_load (line 823)
L 06/17/2011 - 21:54:45: [AMXX] [6] state.sma::ini_to_sql (line 736)
L 06/17/2011 - 21:54:45: [AMXX] [7] state.sma::sql_load (line 823)
L 06/17/2011 - 21:54:45: [AMXX] [8] state.sma::ini_to_sql (line 736)
L 06/17/2011 - 21:54:45: [AMXX] [9] state.sma::sql_load (line 823)
L 06/17/2011 - 21:54:45: [AMXX] [10] state.sma::ini_to_sql (line 736)
L 06/17/2011 - 21:54:45: [AMXX] [11] state.sma::sql_load (line 823)
L 06/17/2011 - 21:54:45: [AMXX] [12] state.sma::ini_to_sql (line 736)
L 06/17/2011 - 21:54:45: [AMXX] [13] state.sma::sql_load (line 823)
Line 1216:

PHP Code:
copy(normStore[one], 127string
Line 807:

PHP Code:
setString(STORENORM_ADmessageadCount[NORM_AD]) 
Line 736:

PHP Code:
sql_load(); 
Line 823:

PHP Code:
ini_to_sql(); 
With your functions:

PHP Code:
//in init:

set_task(10.0"sql_load")

public 
ini_to_sql()
{
    new 
Handle:tuple SQL_MakeStdTuple();
    
    if(
tuple == Empty_Handle)
        return;
    
    new 
errcodeerror[128];
    new 
Handle:db SQL_Connect(tupleerrcodeerrorcharsmax(error));
    
    if(
db == Empty_Handle)
    {
        
log_amx("%s"error);
        return;
    }
    
    
//Load the data
    
new filepath[64];
    
get_configsdir(filepath63);
    
format(filepath63"%s/advertisements.ini"filepath);
    
    if(
file_exists(filepath))
    {
        new 
output[512], conditions[128], temp[64], type;
        
        
//Open file
        
new fHandle fopen(filepath"rt");
        
        
//Checks for failure
        
if(!fHandle)
            return;
        
        
//Loop through all lines
        
for(new 0MAXADS && !feof(fHandle); a++)
        {
            
//Get line
            
fgets(fHandleoutput511);
            
            
            
//Work away comments
            
if(output[0] == ';' || !output[0] || output[0] == ' ' || output[0] == 10
            {
                
//Line is not counted
                
a--;
                continue;
            }
            
            
//Reset type
            
type 0;
            
            new 
map[32], minplayers[32], maxplayers[32], said[32];
            
            
//Check if it contains conditions
            
if(output[0] == COND_TKN)
            {
                
//Cut the conditions off the string
                
split(outputconditions127output511DEVIDE_STKN);
                
                
//Determine if its say check or normal ad
                
type output[0] == SAY_TKN 0;
                
                
//Put the conditions in own space
                
for(new 03b++)
                {
                    new 
sort[16], cond[32]
                    
                    
//Remove the % from line 
                    
conditions[0] = ' ';
                    
trim(conditions);
                    
                    
//Get one condition from the line
                    
split(conditionstemp64conditions127COND_STKN);
                    
                    
split(tempsort15cond31" ");
                    
                    if(
equali(sort"map"))
                    {
                        
copy(map31cond);
                    } else if(
equali(sort"min_players"))
                    {
                        
copy(minplayers31cond);
                    } else if(
equali(sort"max_players"))
                    {
                        
copy(maxplayers31cond);
                    } else
                    {
                        continue;
                    }
                    
                    
//Exit if it hasn't got more conditions
                    
if(!conditions[0])
                        break;
                }
            }
            
            if(
type == 0)
                
type output[0] == SAY_TKN 0;
            
            if(
type == SAY_AD)
            {
                
//Remove the @ from line
                
output[0] = ' ';
                
trim(output);
                
                
split(outputsaid31output127DEVIDE_STKN);
            }
            
            new 
Handle:query SQL_PrepareQuery(db,
                
"INSERT INTO ads \
                (message, autorespond, condition_map, condition_minplayers, condition_maxplayers) \
                VALUES \
                (^"
%s^", ^"%s^", ^"%s^", ^"%s^", ^"%s^");",
                
outputsaidmapminplayersmaxplayers);
            
            if(!
SQL_Execute(query))
            {
                
SQL_QueryError(queryoutputcharsmax(output));
                
log_amx("Error inserting ad: %s"output);
            }
            
            
SQL_FreeHandle(query);
        }
        
        
//Close file to prevent lockup
        
fclose(fHandle);    
    }
    
    
SQL_FreeHandle(db);
    
sql_load();
}  

public 
sql_load()
{
    new 
Handle:tuple SQL_MakeStdTuple();
    
    if(
tuple == Empty_Handle)
        return;
    
    new 
errcodeerror[128];
    new 
Handle:db SQL_Connect(tupleerrcodeerrorcharsmax(error));
    
    if(
db == Empty_Handle)
    {
        
log_amx("%s"error);
        return;
    }
    
    new 
Handle:query SQL_PrepareQuery(db,
        
"CREATE TABLE IF NOT EXISTS ads \
        (message VARCHAR(128) NOT NULL, \
        autorespond VARCHAR(32) NOT NULL DEFAULT '', \
        condition_map VARCHAR(32) NOT NULL DEFAULT '', \
        condition_minplayers VARCHAR(32) NOT NULL DEFAULT '', \
        condition_maxplayers VARCHAR(32) NOT NULL DEFAULT '');"
);
    
    if(!
SQL_Execute(query))
    {
        
SQL_QueryError(queryerrorcharsmax(error));
        
log_amx("Error creating table: %s"error);
    }
    
    
SQL_FreeHandle(query);
    
    
query SQL_PrepareQuery(db"SELECT message, autorespond, condition_map, condition_minplayers, condition_maxplayers FROM ads;");
    
    if(!
SQL_Execute(query))
    {
        
SQL_QueryError(queryerrorcharsmax(error));
        
log_amx("Error selecting ads: %s"error);
    }
    else if(
SQL_NumResults(query))
    {
        new 
message[128], said[32], typeicondition[32];
        
        while(
SQL_MoreResults(query))
        {
            
SQL_ReadResult(query0messagecharsmax(message));
            
SQL_ReadResult(query1saidcharsmax(said));
            
            
type said[0] ? SAY_AD NORM_AD;
            
            for(
03i++)
            {
                
SQL_ReadResult(query, (2), conditioncharsmax(condition));
                
                if(!
condition[0])
                    continue;
                
                
setString(CONDtypeconditionadCount[type], i);
            }
            
            
setColor(messagecharsmax(message));
            
            if(
type == SAY_AD)
            {
                
setString(STORESAY_ADsaidadCount[SAY_AD], 0);
                
setString(STORESAY_ADmessageadCount[SAY_AD], 1);
            }
            else
                
setString(STORENORM_ADmessageadCount[NORM_AD]);
            
            
adCount[type]++;
            
            
SQL_NextRow(query);
        }
    }
    
    
SQL_FreeHandle(query);
    
    
SQL_FreeHandle(db);
    
    
//Set a first task, if there are any normal ads
    
if(adCount[NORM_AD] != 0)
        
set_task(random_float(RAND_MINRAND_MAX), "eventTask");
    
    
ini_to_sql();

__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-18-2011 , 00:35   Re: Reading ini file through sql table
Reply With Quote #6

You know, you just called a recursive function between those 2 functions, causing your server to be in an infinite loop?

1. sql_load() calls ini_to_sql()
2. ini_to_sql() calls sql_load().
3. Go to step 1.

You should have done this:

Code:
public plugin_init() {     sql_load();     ini_to_sql();     sql_load(); }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
ARES[ro]
Senior Member
Join Date: Apr 2010
Old 06-18-2011 , 16:52   Re: Reading ini file through sql table
Reply With Quote #7

No use the updated code! in the same post as the original code.
__________________
okay
ARES[ro] is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 06-18-2011 , 17:47   Re: Reading ini file through sql table
Reply With Quote #8

Hmm yes, I accidently forgot to update it in my code. Anyways, is there still a way so I can edit the message from the table without opening the ini? Cause right now it just loads it from the ini.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu 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 23:26.


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