I have a fairly long AppleScript that I creates a csv file which then needs
to be imported into a database. I am trying to use the .import command from
AppleScript's "do shell script" command to import a csv file into a
temporary table. I then need to import the temporary table into the Main
table which includes a id integer primary key.

I am having problems creating a  "do shell script" command which includes
both the import command and the insert command. The reason they need to be
combined is that the shells instance ends with the command.

For example:
do shell script "cd ~/Desktop"

do shell script "pwd"
returns / because it is a separate instance of shell

Usually you can separate commands in a "do shell script" with semicolins.
However, this does not seems to work with the .commands.

This is an example of how I would create a table:
---------------------------------------------------------
property databaseFolder : POSIX path of (path to documents folder as text)
& "Databases/"
property databaseName : "MyDatabase"
property databasePath : quoted form of (databaseFolder & databaseName astext)
property table1 : "Main"
set sqlDataFile to POSIX path of (path to desktop as text) & "sql_data"

do shell script ("mkdir -p " & quoted form of databaseFolder & " ;
sqlite3 "& databasePath & "
\"create table if not exists " & table1 & "(id integer primary key, color,
taste); \"")
---------------------------------------------------------
This is an example of how a single .command can be called:

do shell script ("sqlite3 " & databasePath & " .show")
---------------------------------------------------------
Combining .commands does NOT work:

do shell script ("sqlite3 " & databasePath & " .separator \"||\" ; .import
path/to/csv Main")
---------------------------------------------------------

Is my syntax wrong or can .commands not be included in a script? If there
is a better way of doing this ... maybe a bash script (which can then be
called from AppleScript) ?

Thanks for the time.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to