0

Rather than create, and then drop a table in sqlite3, I would like to create a temporary table which is destroyed when you end your session. Is it possible to combine the commands below so the temporary table is not destroyed by the semicolon ?

set databaseName to "test.db"
set tableName to "tempTable"
do shell script ("mkdir -p ~/Documents/Databases/ ; sqlite3 ~/Documents/Databases/" & databaseName & " \"create table if not exists " & tableName & "(First, Last);  \"")
do shell script ("sqlite3 ~/Documents/Databases/" & databaseName & " \"insert into " & tableName & " (First, Last) values('John', 'Doe'); \"")

How would I implement this version of it?

set databaseName to "test.db"
set tableName to "tempTable"
do shell script ("mkdir -p ~/Documents/Databases/ ; sqlite3 ~/Documents/Databases/" & databaseName & " \"create temp table " & tableName & "(First, Last);  \"")
do shell script ("sqlite3 ~/Documents/Databases/" & databaseName & " \"insert into " & tableName & " (First, Last) values('John', 'Doe'); \"")

1 Answer 1

1

SQLite accepts semicolon-separated statements itself.

do shell script ("sqlite3 ~/Documents/Databases/" & databaseName & " \" & ¬
    "create temp table " & tableName & " (First, Last); " & ¬
    "insert into " & tableName & " (First, Last) values('John', 'Doe'); " & ¬
    " -- other stuff here --" & ¬
    "select * from " & tableName & ";\"")

At some point it becomes easier to write it out as a separate script or possibly a here document than to build up a single huge do shell script, though.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.