I'm trying to do a bulk insert with SQLite Swift. However, I'm not 100% sure if my code is correct. I'm somewhat worried because the performance is is slightly worse then SQLite Phonegap. Although possible I never encountered this before (where Phonegap solutions perform better then Native).
The Swift code I've settled on (because it delivered the best performance timewise) is:
do {
try DB.transaction { () -> Void in
for index in 0...num_docs {
table.insert(data <- "test", data_num <- index)
}
}
} catch _ {
throw DataAccessError.Transaction_Error
}
The JS/Phonegap code (for comparison) is:
this.db.transaction(loadDocs, [], querySuccess, errorCB);
function loadDocs(tx) {
var q = "INSERT INTO test_table (data, data_num) VALUES (?,?)";
for (var i = 0; i < number; i++) {
tx.executeSql(q, ["test", i], function (tx, res) {})
}
}
Aucun commentaire:
Enregistrer un commentaire