• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Escaping Apostrophes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Escaping Apostrophes


  • Subject: Escaping Apostrophes
  • From: Marconi <email@hidden>
  • Date: Fri, 27 Jan 2012 08:01:53 -0700

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?


--

"A man who believes in nothing will fall for anything." -- Malcolm X
_______________________________________________
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


  • Follow-Ups:
    • Re: Escaping Apostrophes
      • From: Stan Cleveland <email@hidden>
  • Prev by Date: Re: scripting the dictionary app
  • Next by Date: Re: How to copy the icon of a selected item
  • Previous by thread: Need infos about Final Cut Pro X
  • Next by thread: Re: Escaping Apostrophes
  • Index(es):
    • Date
    • Thread