Raised This Month: $ Target: $400
 0% 

[SOLVED] MySQL - 3 queries


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
T-z3P
Senior Member
Join Date: Apr 2008
Location: Iasi, Romania
Old 07-26-2012 , 06:26   [SOLVED] MySQL - 3 queries
Reply With Quote #1

Hi, I need some help. I'm trying to execute 3 queries in the same function but I don't need them to be executed at the same time. The plan is pretty much like this: execute first query, execute second query, take some data with second query from database and use it to execute third query. How to do this?
__________________



Last edited by T-z3P; 08-01-2012 at 20:36.
T-z3P is offline
Send a message via Yahoo to T-z3P Send a message via Skype™ to T-z3P
doondook
Member
Join Date: Dec 2010
Old 07-26-2012 , 07:58   Re: MySQL - 3 queries
Reply With Quote #2

set_task
doondook is offline
mabaclu
Senior Member
Join Date: Jun 2010
Location: Portugal
Old 07-26-2012 , 08:08   Re: MySQL - 3 queries
Reply With Quote #3

Use threaded queries so that you only make the second one after the first is done.
__________________
mabaclu is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 07-26-2012 , 08:19   Re: MySQL - 3 queries
Reply With Quote #4

??? I dont get the Problem... PseudoCode:

funktion()
{
query1()
result = query2()
query3(result) //<- Do things with the result of query 2
}
__________________
Quote:
#define true ((rand() % 2)? true: false) //Happy debugging suckers
mottzi is offline
Send a message via MSN to mottzi
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 07-26-2012 , 08:22   Re: MySQL - 3 queries
Reply With Quote #5

PHP Code:
SQL_ThreadQuery Handle:db_tuple, const handler[], const query[], const data[]=""dataSize=
the handler is a forward which is called when the Query is finished, there you can put the second query you need.
DjOptimuS is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 07-26-2012 , 08:27   Re: MySQL - 3 queries
Reply With Quote #6

Yeah if he is using threaded queries.
__________________
Quote:
#define true ((rand() % 2)? true: false) //Happy debugging suckers
mottzi is offline
Send a message via MSN to mottzi
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 07-26-2012 , 08:37   Re: MySQL - 3 queries
Reply With Quote #7

post the full code
DjOptimuS is offline
T-z3P
Senior Member
Join Date: Apr 2008
Location: Iasi, Romania
Old 07-27-2012 , 10:44   Re: MySQL - 3 queries
Reply With Quote #8

PHP Code:
public RNRegister(idlevelcid)
{
    if (!
cmd_access(idlevelcid2))
        return 
PLUGIN_HANDLED
    
    
if (!is_user_connected(id))
    {
        return 
PLUGIN_CONTINUE
    
}
    
    if(
is_user_admin(id))
    {
        
client_print(idprint_console"Your nickname is already registered!")
        
        return 
PLUGIN_HANDLED
    
}
    
    new 
activation_key[25]
    new 
authid[64]
    new 
cache[256]
    new 
email[64]
    new 
error[128]
    new 
errno
    
new Handle:info SQL_MakeStdTuple()
    new 
Handle:query
    
new Handle:sql SQL_Connect(infoerrnoerror127)
    new 
name[32]
    new 
password[64]
    new 
password_field[32]
    new 
prefix[32]
    new 
register_date get_systime()
    
    
random_str(activation_keycharsmax(activation_key))
    
read_argv(1email63)
    
read_argv(2password31)
    
    if(
containi(email"@")==-1)
    {
        
client_print(idprint_console"Invalid e-mail address!")
        
        return 
PLUGIN_HANDLED
    
}
    
    if(
strlen(password) <= 5)
    {
        
client_print(idprint_console"Password must have at least 6 characters!")
        return 
PLUGIN_HANDLED
    
}
    
    
get_cvar_string("amx_password_field"password_field31)
    
get_cvar_string("amx_sql_table_prefix"prefix31)
    
get_user_authid(idauthid63)
    
get_user_name(id,name,31)
        
    if (
sql == Empty_Handle)
    {
        
server_print("[AMXX] SQL Error: %s"error)
        
        return 
PLUGIN_HANDLED
    
}
        
    
query SQL_PrepareQuery(sql"INSERT INTO `%susers` (`login`, `password`, `email`, `register_date`, `active`, `activation_key`, `account_flags`) VALUES ('%s', '%s', '%s', '%d', '1', '%s', 'ab')"prefixnamepasswordemailregister_dateactivation_key)
    
    if (!
SQL_Execute(query))
    {
        
SQL_QueryError(queryerror127)
        
server_print("[AMXX] SQL Error: %s"error)
        
        return 
PLUGIN_HANDLED
    

    
    
SQL_FreeHandle(query)
       
    
formatex(cachesizeof(cache)-1"SELECT ID FROM `%susers` WHERE login='%s'"prefixname)
    
SQL_ThreadQuery(info"RNGetUserID"cache)
    
    
SQL_FreeHandle(sql)
    
SQL_FreeHandle(info)
    
    
client_print(idprint_console"Your account is now registered!")
    
client_print(idprint_console"Write the next line in your console, or you will be kicked in 10 seconds:")
    
client_print(idprint_console"setinfo %s %s"password_fieldpassword)
    
    return 
PLUGIN_CONTINUE
}

public 
RNGetUserID(FailStateHandle:queryerror[], ErrcodeData[], DataSize)
{
    new 
error[128]
    new 
errno
    
new Handle:another_query
    
new Handle:info SQL_MakeStdTuple()
    new 
Handle:sql SQL_Connect(infoerrnoerror127)
    new 
prefix[32]
    new 
rn_account_type get_pcvar_num(amx_rn_account_type)
    new 
server_id[32]
    new 
user_id
    
    
while(SQL_MoreResults(query))
    {
        
user_id SQL_ReadResult(query,0)    
        
SQL_NextRow(query)
    }
    
    
get_cvar_string("amx_sql_table_prefix"prefix31)
    
get_cvar_string("amx_sql_serverid"server_id31)
    
    if(
rn_account_type == 0)
    {
        
another_query SQL_PrepareQuery(sql"INSERT INTO `%susers_access` (`user_ID`, `server_ID`, `group_ID`) VALUES ('%d', '0', '0')"prefixuser_id)
    }
    else
    {
        
another_query SQL_PrepareQuery(sql"INSERT INTO `%susers_access` (`user_ID`, `server_ID`, `group_ID`) VALUES ('%d', '%d', '0')"prefixuser_idserver_id)
    }
    
    if (!
SQL_Execute(another_query))
    {
        
SQL_QueryError(another_queryerror127)
        
server_print("[AMXX] SQL Error: %s"error)
        
        return 
PLUGIN_HANDLED
    

    
    
SQL_FreeHandle(another_query)
    
SQL_FreeHandle(sql)
    
SQL_FreeHandle(info)
    
    
set_task(10.0"cmdReload")
    
    return 
PLUGIN_CONTINUE


random_str(output[], len)
{
    for(new 
i=0i<leni++)
    {
        
output[i] = random_num('0''9');
    }
    
    
output[len]=EOS;
}
#endif 
__________________



Last edited by T-z3P; 07-30-2012 at 05:36.
T-z3P is offline
Send a message via Yahoo to T-z3P Send a message via Skype™ to T-z3P
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-27-2012 , 10:46   Re: MySQL - 3 queries
Reply With Quote #9

Quote:
Originally Posted by T-z3P View Post
PHP Code:
    new activation_key random_num(000000000000000000000000999999999999999999999999
Umm...

Pawn variables are stored as cells, which are 32-bit integers.
32-bit integers range from −2,147,483,648 to 2,147,483,647.

If you want a number that long, you'll have to use a string instead.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
T-z3P
Senior Member
Join Date: Apr 2008
Location: Iasi, Romania
Old 07-27-2012 , 11:07   Re: MySQL - 3 queries
Reply With Quote #10

I didn't knew how to do it, so this was the first idea in my head.. I need a random number of 24 digits.
__________________


T-z3P is offline
Send a message via Yahoo to T-z3P Send a message via Skype™ to T-z3P
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 10:18.


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