Escaping quotes for sqlite3

Go To StackoverFlow.com

1

I want to query a column that has spaces in its name. The shell script is:

select "Column 1" from aTable;

Maybe it is late, but I am having a hard time escaping the Applescript:

set xxx to do shell script "sqlite3 ~/Documents/Databases/test.db \"select \"Address 1\" from aTable limit 10; \""
2012-04-04 05:07
by adayzdone
Is it too late to try to convince you to use real SQLite bindings - Ignacio Vazquez-Abrams 2012-04-04 05:09


2

Use single quotes around your SQL:

set xxx to do shell script "sqlite3 ~/Documents/Databases/test.db 'select \"Address 1\" from aTable limit 10; '"

Or if you want to beat yourself up, keep using double quotes everywhere and add more escaping:

set xxx to do shell script "sqlite3 ~/Documents/Databases/test.db \"select \\\"Address 1\\\" from aTable limit 10; \""

You need three because you have to escape the escapes to get an escaped double quote down to the shell. Ick.

Or better, use a native AppleScript SQLite interface, a couple minutes of googling should find you something nicer than the above nested quote madness.

2012-04-04 05:24
by mu is too short
Right on all three accounts, Thank you - adayzdone 2012-04-04 12:03
Ads