0

而不是创建,然后在 sqlite3 中删除一个表,我想创建一个临时表,该表在您结束会话时被销毁。是否可以组合下面的命令,以便临时表不会被分号破坏?

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'); \"")

我将如何实现它的这个版本?

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'); \"")
4

1 回答 1

1

SQLite 本身接受分号分隔的语句。

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 & ";\"")

不过,在某些时候,将它写成一个单独的脚本或可能是一个 here 文档比构建一个巨大do shell script的 .

于 2012-04-06T16:31:40.233 回答