Looking for a script to clean my data of ' for SQL

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
FireWorx
Posts: 362
Joined: Wed Sep 07, 2011 9:39 pm

Looking for a script to clean my data of ' for SQL

Post by FireWorx » Sun Feb 19, 2012 7:54 am

Hi,
I looked over the offset and char commands and searched the forum but no luck. Can anyone chime in on how to clean data of the apostrophe ' symbol so that it doesn't mess up my SQL INSERT command string?
Thanks
Dave

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Looking for a script to clean my data of ' for SQL

Post by bangkok » Sun Feb 19, 2012 11:21 am

Code: Select all

replace "'" with "" in myText
to remove them.

Or you can use :

Code: Select all

replace "'" with "\'" in myText
(the \' will keep the ' in your MySQL data)

FireWorx
Posts: 362
Joined: Wed Sep 07, 2011 9:39 pm

Re: Looking for a script to clean my data of ' for SQL

Post by FireWorx » Mon Feb 20, 2012 8:04 pm

Found this on the SQLite site and combined it with your replace script. Replace with two single quotes in a row does the trick.

Thanks!

FROM THE SQLite documentation below.

(14) How do I use a string literal that contains an embedded single-quote (') character?

The SQL standard specifies that single-quotes in strings are escaped by putting two single quotes in a row. SQL works like the Pascal programming language in the regard. SQLite follows this standard. Example:

INSERT INTO xyz VALUES('5 O''clock');

Post Reply