tags:

views:

74

answers:

1

I am having trouble understanding how to create a SQL command batch say in a list and pass it on to sqlite for execution in a transaction.

Basically what I do now is:

sqlite3 db1 $dbFile
db1 eval BEGIN
foreach Key [array names myArray] {
    db1 eval {SQL statement involving $Key}
}
db1 eval COMMIT

I was thinking of a means to generate a list with SQL INSERTs and then passing it to db1 transaction or db1 eval, but this does not seem to work for me. Perhaps I am just making some stupin syntax mistakes. Anyone have a working example?

Thanks!

+2  A: 

I was right about "stupid mistake".

db1 transaction {
    foreach Key [array names myArray] {
        db1 eval {SQL statement involving $Key}
    }
}
Valder
+1: That's the correct way to do a transaction that processes an SQL statement for each element of an array.
Donal Fellows