If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Escape Character Not Working

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-03-06, 17:08
Zarathu Zarathu is offline
Registered User
 
Join Date: Nov 2006
Posts: 9
Escape Character Not Working

Code:
INSERT INTO `textpattern` VALUES (18,'2006-04-23 22:18:00','zarathu','2006-10-22 23:10:27','zarathu','Rednecks','','That\'s right.\r\n\r\nThese filthy rednecks think they\'re having the time of their lives while . . . .
Look closer.

Code:
That\'s
Code:
they\'re
For a rather sickening reason that is still unknown to me, those escape characters to show that there is a single quote there is specifically NOT working the way it should. Therefore, it screws up the entire statement.

Help.
Reply With Quote
  #2 (permalink)  
Old 11-03-06, 20:09
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
Not 100% sure about MySQL but the ANSI standard for embedding single quotes in a character literal is two single quotes:
... VALUES ( 'That''s working' )
Reply With Quote
  #3 (permalink)  
Old 11-03-06, 20:12
Zarathu Zarathu is offline
Registered User
 
Join Date: Nov 2006
Posts: 9
Quote:
Originally Posted by shammat
Not 100% sure about MySQL but the ANSI standard for embedding single quotes in a character literal is two single quotes:
... VALUES ( 'That''s working' )
Hmm... Can anybody else confirm this?
Reply With Quote
  #4 (permalink)  
Old 11-04-06, 04:43
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
i can confirm that that is the standard sql way of escaping the single quote embedded in a string (delimited by single quotes)

i can also confirm that mysql supports it
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 11-04-06, 11:34
Zarathu Zarathu is offline
Registered User
 
Join Date: Nov 2006
Posts: 9
Quote:
Originally Posted by r937
i can confirm that that is the standard sql way of escaping the single quote embedded in a string (delimited by single quotes)

i can also confirm that mysql supports it
Alright, so I should replace all:

\'

with:

''

^ The above is two single-quotes.

I'll update if I have any problems.
Reply With Quote
  #6 (permalink)  
Old 11-04-06, 11:50
Zarathu Zarathu is offline
Registered User
 
Join Date: Nov 2006
Posts: 9
Another question--does this apply for double-quotes? The SQL exporter used \" for them, but when I removed the \ character, nothing was affected.
Reply With Quote
  #7 (permalink)  
Old 11-04-06, 17:05
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
double quotes are used only within strings...
Code:
insert into comments (comment) 
values ( '"Oh, no," said Todd. "That''s what she said."' )
double quotes are also the standard sql quoted identifier delimiter ...
Code:
select count(*) as "Total Rows" from ...
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On