I want to insert bulk rows in FMDB and I am doing this in transaction as below. Can someone plz check and confirm whether I am doing correctly?
My doubt is whether to put the loop inside transaction or as it is now…
Is there any way to make the insert process even more faster…?
for m = 0; m < self.dataRows.count; m += 1
{
let queue = FMDatabaseQueue(path: databasePath as String)
queue.inTransaction()
{
contactDB, rollback in
if m == 0
{
//print("create_table \(create_table) insertSQL \(insertSQL)")
contactDB.executeStatements("DROP TABLE IF EXISTS " + self.table_name)
if contactDB.executeStatements(createSQL)
{
print(self.table_name + " table created")
}
else
{
rollback.initialize(true)
print("Table not created Error: \(contactDB.lastErrorMessage())")
}
}
let result = contactDB.executeUpdate(insertSQL, withArgumentsInArray: nil)
if !result
{
rollback.initialize(true)
print("Insert Error: \(contactDB.lastErrorMessage())")
}
else
{
//print("Record \(m) inserted in table " + self.table_name )
self.insertCount += 1
}
}
queue.close()
}
}