Raised This Month: $ Target: $400
 0% 

Sql name problem...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 07-02-2012 , 21:16   Sql name problem...
Reply With Quote #1

Code:
public client_disconnect(id) {     if(solorun == true)     {         if(id == soloid && is_user_alive(soloid)) // Didn't die         {             new name[32]             get_user_name(soloid, name, 31)     // Solo Gunner name             replace_all(name,31,"'","")             replace_all(name, 31, "^"", "")             //formatex(selectquery, 255, "USE %s", db)             //SQL_ThreadQuery(sql, "query", selectquery)             formatex(g_query, 511, "UPDATE played_time SET playedtime=playedtime-%d WHERE name=^"%s^"", get_pcvar_num(g_Ddisconnect) , name)             SQL_ThreadQuery(sql,"query", g_query)             remove_task(soloid)             return PLUGIN_HANDLED         }         return PLUGIN_HANDLED     }     return PLUGIN_HANDLED }
I'm trying to make a bonus time plugin for played time plugin, the problem is the name, I can't get the name correctly, I tried to comment these 2 lines (the ones that are highlighted) and the name worked perfectly, but as for SQL, I must remove these characters ' & ^, and I don't know how to solve it.
Could someone post an explanation of what's wrong, and how to fix it, if possible?
PS: I took these two lines from the played time plugin.
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.

Last edited by pokemonmaster; 07-03-2012 at 07:24.
pokemonmaster is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-02-2012 , 22:27   Re: Sql name problem...
Reply With Quote #2

why do you need to remove those? They aren't escape chars untill they're called to be as such. Put the name in quotes. (Wrapped in ^")
Either way....replace it with an underscore or soemthing. For whatever reason string natives have troubles with EOS calls. (i.e. an empty string)
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 07-02-2012 at 22:29.
Liverwiz is offline
doondook
Member
Join Date: Dec 2010
Old 07-03-2012 , 02:00   Re: Sql name problem...
Reply With Quote #3

Liverwiz, in SQL symbol " ' " is reserved, and can't be used in a random place, because it separates column names for example.

Last edited by doondook; 07-03-2012 at 02:06.
doondook is offline
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 07-03-2012 , 07:11   Re: Sql name problem...
Reply With Quote #4

But I don't see anything wrong in the code, is there?
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
pokemonmaster is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 07-03-2012 , 08:25   Re: Sql name problem...
Reply With Quote #5

Shouldn't you only be replacing ' \ ` symbols?
Code:
SecureSqlString(input[], len) {     replace_all(input, len, "\", "\\");     replace_all(input, len, "'", "\'");     replace_all(input, len, "`", "\`"); }

Last edited by hleV; 07-03-2012 at 08:26.
hleV is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-03-2012 , 10:27   Re: Sql name problem...
Reply With Quote #6

Quote:
Originally Posted by doondook View Post
Liverwiz, in SQL symbol " ' " is reserved, and can't be used in a random place, because it separates column names for example.
I've always had a fond hatred of SQL.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-03-2012 , 10:35   Re: Sql name problem...
Reply With Quote #7

In names, all you have to worry about are single quotes.
However, since your query wraps the name in double quotes, you don't have to escape it at all.
You can't even have backslashes in your name anyway.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 07-03-2012 , 12:34   Re: Sql name problem...
Reply With Quote #8

So what should I do?
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
pokemonmaster is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-03-2012 , 12:35   Re: Sql name problem...
Reply With Quote #9

Quote:
Originally Posted by pokemonmaster View Post
So what should I do?
Nothing. You don't have to remove any characters from the name.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 07-03-2012 , 16:05   Re: Sql name problem...
Reply With Quote #10

Just a quick question, can client_disconnect() detect if the user was alive before disconnecting?
Maybe the problem is because of this:
Code:
       if(id == soloid && is_user_alive(soloid))
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.

Last edited by pokemonmaster; 07-03-2012 at 16:08.
pokemonmaster 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 15:25.


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