Raised This Month: $ Target: $400
 0% 

Question about DBI and single-quote delimeter


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mugwump
Senior Member
Join Date: May 2004
Old 09-05-2004 , 13:52   Question about DBI and single-quote delimeter
Reply With Quote #1

Since character fields are generally delimeted by single quotes, if i want to insert a character string like player name that may contain a single-quote or use a WHERE clause and do a comparison against a sting that might contain a single-quote how would I escape the single quote in that string variable?

In perl this is easy,

Code:
$name =~ s/'/\\'/g;
but I am not so sure how to do this in small.

Thanks
Mug
Mugwump is offline
BAILOPAN
Join Date: Jan 2004
Old 09-05-2004 , 14:43  
Reply With Quote #2

replace?
__________________
egg
BAILOPAN is offline
Mugwump
Senior Member
Join Date: May 2004
Old 09-05-2004 , 14:51  
Reply With Quote #3

Ahhh, well that makes sense... ;)

So something like this:

while ( replace( sName, "'", "\\'") ){ }

or instead of \\' do I use ^' , I'm unclear ?

Thanks Bail!
-Mug
Mugwump is offline
devicenull
Veteran Member
Join Date: Mar 2004
Location: CT
Old 09-05-2004 , 15:03  
Reply With Quote #4

replaceall
Its a function thats floating around on the forums somewhere, just search for it
__________________
Various bits of semi-useful code in a bunch of languages: http://code.devicenull.org/
devicenull is offline
Johnny got his gun
Veteran Member
Join Date: Jan 2004
Location: Tokyo
Old 09-06-2004 , 05:31  
Reply With Quote #5

Code:
stock replaceall(text[], const LEN, const WHAT[], const WITH[]) {     while (contain(text, WHAT) != -1)         replace(text, LEN, WHAT, WITH) }

And yes, the escape character is the ^
Johnny got his gun is offline
Mugwump
Senior Member
Join Date: May 2004
Old 09-08-2004 , 17:23  
Reply With Quote #6

replaceall is not a viable solution assuming this is what I wanted to do:

replaceall(name, 32, "'", "^'")

It gets caught in an infinite loop because the index of containi isn't updating as it finds a single-quote

So am I the first person thats wanted to do this or is there some other way that hasn't been suggested yet?

EDIT: I checked string.inc and there does not seem to be a version of contain where you can pass the starting index to search from, that'd be a big help.

-Mug
Mugwump is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 09-08-2004 , 17:38  
Reply With Quote #7

contain(string[startchar], ...)

Might work
__________________
hello, i am pm
PM is offline
Mugwump
Senior Member
Join Date: May 2004
Old 09-09-2004 , 10:24  
Reply With Quote #8

Will give it a try, thanks PM!

-Mug
Mugwump 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 17:27.


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