;;; Per zbigniew's comments on IRC, I have now wrapped the transaction in ;;; call-with-database, removing the calls to open-database and close-database, ;;; as well as the unnecessary call to database-closed? The procedure now also ;;; only makes a single call to sql to prepare the sql statement, which should ;;; improve performance. Comments welcome. ;;; Insert a list of records into an SQLite3 database. ;;; db-file: string, filename of database ;;; sql-str: string, sql-query string ;;; records: list, where each element is a list containing record values (define (bulk-insert db-file sql-str records) (call-with-database db-file (lambda (db) (let* ((stmt (sql db sql-str)) (insert (lambda () (for-each (lambda (rec) (apply exec stmt rec)) records)))) (with-transaction db insert)))))