Raised This Month: $12 Target: $400
 3% 

ReplaceString questions..


Post New Thread Reply   
 
Thread Tools Display Modes
Scuzzy
Senior Member
Join Date: Oct 2007
Old 02-10-2008 , 01:05   Re: ReplaceString questions..
Reply With Quote #11

Bail,

I've run into a similiar problem with escape characters and player names in SQL. Check the following example:

Code:
public Action:Command_test2(client, args)
{
 decl String:query[255];
 decl String:player_name[50];
 decl String:quoted_query[255];
 
 strcopy(player_name, sizeof(player_name), "Dave //*SmackDown*\\");
 
 PrintToServer("Player Name: %s", player_name);
 Format(query,
  sizeof(query),
  "insert into player_name (steam_id, name) values ('123','%s')", player_name);
 
 PrintToServer("First Query: %s", query);
 
 SQL_QuoteString(g_db, query, player_name, sizeof(player_name));
 
 Format(quoted_query,
  sizeof(quoted_query),
  "insert into player_name (steam_id, name) values ('123','%s')", player_name);
 
 PrintToServer("Second Query: %s", quoted_query);
 
 DoQuery(client, quoted_query);
 
 return Plugin_Handled;
}
If a player comes into the server with a single slash at the end of their name, the formatted query to insert them will fail, because \' is mistaken as a escape character... (or so I assume). I've been stripping "\" slashes out of names to prevent this...

What would you think about a "SQL_CleanString" function that would fix the quote issues and fix the slash problem?

Scuzzy
Scuzzy is offline
BAILOPAN
Join Date: Jan 2004
Old 02-11-2008 , 16:45   Re: ReplaceString questions..
Reply With Quote #12

I don't understand your code; it doesn't look right though, I think you're quoting the wrong thing. You should call SQL_QuoteString() on the player's name and pass the new string (containing the escaped name) into the final query.

I.e.:
Code:
new String:name[MAX_NAME_LENGTH], String:safe_name[MAX_NAME_LENGTH*2]; GetClientName(client, name, sizeof(name)); SQL_QuoteString(db, name, safe_name, sizeof(safe_name)); Format(query, sizeof(query), "INSERT INTO blah (whatever) VALUES ('%s')", safe_name);

There shouldn't be a need for two functions because the purpose of SQL_QuoteString() is to do all necessary work. So if proper usage is resulting in malfunctioning queries it would be a bug in the driver.
__________________
egg

Last edited by BAILOPAN; 02-11-2008 at 16:49.
BAILOPAN is offline
Scuzzy
Senior Member
Join Date: Oct 2007
Old 02-11-2008 , 17:17   Re: ReplaceString questions..
Reply With Quote #13

That worked, thanks.
Scuzzy is offline
KaOs
Senior Member
Join Date: Apr 2004
Old 02-18-2008 , 00:40   Re: ReplaceString questions..
Reply With Quote #14

Bailo,
Why does quotestring need the db ?
__________________
KaOs is offline
Send a message via AIM to KaOs Send a message via MSN to KaOs
BAILOPAN
Join Date: Jan 2004
Old 02-18-2008 , 07:30   Re: ReplaceString questions..
Reply With Quote #15

As answered in another thread, if it didn't need the DB it would need the driver, since the driver provides the escaping mechanism. Aside from it being easier to pass the DB than the driver Handle, MySQL uses the character set of the DB to determine the exact escaping mechanism.
__________________
egg
BAILOPAN is offline
KaOs
Senior Member
Join Date: Apr 2004
Old 02-18-2008 , 17:29   Re: ReplaceString questions..
Reply With Quote #16

Quote:
Originally Posted by BAILOPAN View Post
As answered in another thread, if it didn't need the DB it would need the driver, since the driver provides the escaping mechanism. Aside from it being easier to pass the DB than the driver Handle, MySQL uses the character set of the DB to determine the exact escaping mechanism.
Beautiful answer, thanks.
__________________
KaOs is offline
Send a message via AIM to KaOs Send a message via MSN to KaOs
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:39.


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