Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Old 09-22-2004, 01:24 PM escape or replace?
Junior Talker

Posts: 4
Trades: 0
I'm taking over some ASP code that has been ESCAPEing all kinds of data before inserting it into a SQL database. Isn't it smarter to simply use replace(myVar, "'", "''") to get rid of single quotes? That way I wouldn't need to UNESCAPE everything I pull out of the DB. Aren't single quotes the only real concern when inserting into the DB?

Thanks in advance for your insight.

Last edited by MtnMinded; 09-22-2004 at 02:19 PM..
MtnMinded is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-22-2004, 06:31 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
Yes, or you could perform a replace and use ' for single quotes -- this is what I do.

So you would run

replace( myVar, "'", "&#39" ) 'Need to add semicolon after 39

This has the effect of storing the ' to the database instead of the single quote -- but if you only plan to display the information in a browser and if you are not depending on a particular value for String length or otherwise parsing it, it is very convenient.

But it is true that replace() is the more sensible solution and your approach should work fine.

EDIT -- After seeing Webcyte's post, I realized I should have left off my semicolon to make it visible..... Tks, webcyte.
__________________
—Kyrnt

Last edited by Kyrnt; 09-23-2004 at 12:36 AM..
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 09-22-2004, 08:51 PM Better way
WebcyteDesign's Avatar
Registered User

Posts: 159
Location: Hamilton
Trades: 0
replace("""", """)
replace("'", "'")

This way uses the entity number which I find to be a better choice. I find it less confusing.
WebcyteDesign is offline
Reply With Quote
View Public Profile Visit WebcyteDesign's homepage!
 
Old 09-22-2004, 08:53 PM
WebcyteDesign's Avatar
Registered User

Posts: 159
Location: Hamilton
Trades: 0
replace("""", "&#34")
replace("'", "&#39")

remember to put the ; after &#34 and &#39 or you get what you see above
WebcyteDesign is offline
Reply With Quote
View Public Profile Visit WebcyteDesign's homepage!
 
Reply     « Reply to escape or replace?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12633 seconds with 12 queries