Re: Escaping Apostrophes
Re: Escaping Apostrophes
- Subject: Re: Escaping Apostrophes
- From: Stan Cleveland <email@hidden>
- Date: Fri, 27 Jan 2012 10:39:50 -0800
On Jan 27, 2012, at 7:01 AM, Marconi wrote:
> I have a droplet AS in which it produces the following as a variable returned by a bundled shell script. The variable is used with an INSERT INTO command for a MySQL database. The problem is that the first line, where the single quote character is being used as an apostrophe needs to have that character escaped before insertion into the DB, otherwise it's taken to be a field delimiter and buggers the INSERT.
>
> I could special case apostrophe-s and apostrophe-t and some others that I'm likely to come across but I think it would be better to do a find/replace of all single quote characters that are not adjacent to a parentheses or a comma. I suspect that a bit of Perl might do it.
>
> Or, I could parse each line ignoring the first single quote, then check each subsequent character to see if it's a single quote. If it is, and the following character is not a comma, escape it ("\"), continuing until the first comma is found, then going to the next line.
>
> ('The Riddler's False Notion','87312','1966-04-28T00:00:00Z',null),
> ('The Ring of Wax','87251','1966-03-30T00:00:00Z',null),
> ('The Sandman Cometh','97151','1966-12-28T00:00:00Z',null),
> ('The Spell of Tut','97091','1966-09-28T00:00:00Z',null),
> ('The Sport of Penguins','17031','1967-10-05T00:00:00Z',null);
>
> What's the most efficient way to escape every single quote that's not a field delimiter?
Hi Marconi,
Perhaps you can rework your droplet to use the 'quoted form' property of any string that might contain troublesome characters. It will do all the heavy lifting for you and handles even the most complex situations.
Stan C.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden