Cross Database Sqlite Query

Hello All,

I am newbie at Applescript (and working on a Mac in general). I am working on porting some scripts over from the PC that query a couple of SQLite databases. I have had some pretty good success calling sqlite3 from the do shell script command, but I have now ran into a more complicated scenario…cross database join queries.

Now, I have found out how to use the attach method in sqlite, and I can run my queries successfully directly from terminal with the following syntax:

sqlite3;
attach database ‘/Users/Joey/Library/Application Support/MyApp/Master.db3’ as pm;
attach database ‘/Users/Joey/Library/Application Support/MyApp/User.db3’ as pu;
SELECT * FROM MasterTable LEFT JOIN UserTable On MasterTable.Column = UserTable.Column;

When I try to call this from AppleScript using do shell script, I get an error stating “attach command not found”, and it looks to me like it is not detecting my line breaks. My Applescript is :

do shell script "sqlite3; " & "
" & "attach database '/Users/Joey/Library/Application Support/MyApp/Master.db3' as pm; " & "
" & "attach database '/Users/Joey/Library/Application Support/MyApp/User.db3' as pu; " & "
" & "SELECT * FROM MasterTable LEFT JOIN UserTable On MasterTable.Column = UserTable.Column;"

What am I missing? Is there something besides the line breaks that I am leaving out on the Applescript side? I can replace the “do shell script” with “return” and copy and paste that text from the ScriptEditor result window and it runs fine in Terminal.

Also, if there is a better way for me to run cross-database sqlite queries from AppleScript, I am very open to any suggestions.

Thanks for any guidance you can provide.