Raised This Month: $ Target: $400
 0% 

SQLx How to send long query?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
draft
Senior Member
Join Date: Jul 2007
Location: Russia, Saint-Petersburg
Old 12-17-2012 , 19:52   SQLx How to send long query?
Reply With Quote #1

Im having plugin that is storing a lot of events in file to cache them and send in one array at end of map. For example, it writes information about every frag (killer, victim, distance, headshot etc)
So, at the end of map Im reading the file with fgets and making a huge query
INSERT INTO (...) VALUES (file_line1),(file_line2) ...
But the problem is that the file can be huge and small depending on number of lines (line length is about 100 symbols) and i dont know how can i send this data with Sql_ThreadQuery?
For now, Ive created array[40000], read everything in that array, but sometimes its not enough big if game has a lots of frags but im pretty scared to make array of 1 million cells.
Im thinking of using dynamic array, but how can i send it fully as query[] in Sql_ThreadQuery?
native DoNotUse:ArrayGetStringHandle(Array:which, item); looks like will not work for my situation. Any ideas?
__________________
draft is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 12-17-2012 , 23:28   Re: SQLx How to send long query?
Reply With Quote #2

If you are sending it in plugin_end then use non-threaded queries. You don't need very big array, just keep adding file_lines until you run out of space, send the query and repeat.

Why are you storing it in a file? Can't you send it with SQL_ThreadQuery while the server is running?
__________________
Impossible is Nothing
Sylwester is offline
draft
Senior Member
Join Date: Jul 2007
Location: Russia, Saint-Petersburg
Old 12-18-2012 , 11:10   Re: SQLx How to send long query?
Reply With Quote #3

Quote:
Originally Posted by Sylwester View Post
If you are sending it in plugin_end then use non-threaded queries. You don't need very big array, just keep adding file_lines until you run out of space, send the query and repeat.
Thanks for hint, i forgot about non-threaded query!

Quote:
Why are you storing it in a file? Can't you send it with SQL_ThreadQuery while the server is running?
The thing is that this plugin works on about 200 game servers (and will be more) that are putting every event in one table making it hard-locked and working slowly + a lot of connects. Thats why i realized that better is to store all info locally in file and send it at the end of map.
__________________
draft is offline
draft
Senior Member
Join Date: Jul 2007
Location: Russia, Saint-Petersburg
Old 12-18-2012 , 15:05   Re: SQLx How to send long query?
Reply With Quote #4

Again i dont know what to do.
PHP Code:
p_readfile fopen(action_file"r")
if(
p_readfile)
{
    while(
fgets(p_readfiletext127))
    {                    
        
ArrayPushString(frag_query,text)
    }            
}
fclose(p_readfile)
        
Query SQL_PrepareQuery(SqlConnection"^nINSERT INTO mix_stats_action (time, mixid, userid, userid2, action, info, info2, floatinfo) \
VALUES %a"
ArrayGetStringHandle(frag_queryitem)) 
So, the thing is that I must somehow put all items , how it is possible to do?
__________________

Last edited by draft; 12-18-2012 at 15:07.
draft is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 12-18-2012 , 17:40   Re: SQLx How to send long query?
Reply With Quote #5

like this:
PHP Code:
public function(){
    new 
fh fopen(path"rt")
    if(!
fh || feof(fh)){
        
log_amx("Could not open file or no data in file (%s)"path)
        return
    }
    new 
cache[2048], postext[128], lenerror[256]

    do{
        
len fgets(fhtextsizeof(text)-1)
        
trim(text)
        
        if(
pos+len+>= sizeof(cache)){
            
pos 0
            
if(!SQL_SimpleQuery(SqlConnectioncacheerrorsizeof(error)-1)){
                
log_amx("SQL Error: %s"error)
            }
        }
        
        if(
pos == 0){
            
pos formatex(cachesizeof(cache)-1"INSERT INTO mix_stats_action (time, mixid, userid, userid2, action, info, info2, floatinfo) VALUES %s"text)
        }else{
            
pos += formatex(cache[pos], sizeof(cache)-pos-1", %s"text)
        }
    }while(!
feof(fh))
    
    if(!
SQL_SimpleQuery(SqlConnectioncacheerrorsizeof(error)-1)){
        
log_amx("SQL Error: %s"error)
    }
    
    
fclose(fh)

__________________
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 13:59.


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