Reputation: 404
I keep getting the following error:
fatal error: 'try!' expression unexpectedly raised an error: disk I/O error (code: 10): file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-800.0.63/src/swift/stdlib/public/core/ErrorType.swift, line 178
when I implement the following code:
try db!.transaction() {
hold = true
for obj in object {
if table.rawValue == DBTableNames.Products.rawValue {
let product : ProductObject = obj as! ProductObject
insert = self.productsTable.insert(
self.productcode <- product.productcode,
self.admincost <- product.admincost,
self.allocatedstock <- product.allocatedstock,
self.availablestock <- product.availablestock,
self.backorderstock <- product.backorderstock,
self.barcode <- product.barcode,
self.binno <- product.binno,
self.casesperlayer <- product.casesperlayer,
self.clearanceprice <- product.clearanceprice,
self.exportprice <- product.exportprice,
self.fulldescription <- product.fulldescription,
self.gqcoded <- product.gqcoded,
self.group <- product.group,
self.innerbarcode <- product.innerbarcode,
self.innerqty <- product.innerqty,
self.lastPoDate <- product.lastPoDate as Date,
self.layersperpallet <- product.layersperpallet,
self.longdescription1 <- product.longdescription1,
self.mtdsales <- product.mtdsales,
self.onorderstock <- product.onorderstock,
self.outerbarcode <- product.outerbarcode,
self.packqty <- product.packqty,
self.palletqty <- product.palletqty,
self.physicalstock <- product.physicalstock,
self.rollingsales <- product.rollingsales,
self.rsp <- product.rsp,
self.shortdescription <- product.shortdescription,
self.threemonth <- product.threemonth,
self.warehouse <- product.warehouse,
self.weight <- product.weight,
self.wholesaleprice <- product.wholesaleprice,
self.ytdsales <- product.wholesaleprice)
}
}
try self.db!.run(insert)
}
I understand its an I/O error but I don't understand what else could be accessing the database blocking the insert
I'm using the following fw:https://github.com/stephencelis/SQLite.swift
Upvotes: 3
Views: 2597
Reputation: 176
I had the exact same problem. My solution was to remove the db reference from my (singleton) manager class and reinitialise it after downloading a new database version. My manager kept the reference for the old database.
Upvotes: 1
Reputation: 5075
If you are getting the error on a simulator, please read part 2. Try part 1 if the error happens on an actual device, but also try running your app in a simulator and try part 2 of my answer.
If you are using actual device and get the SQLite I/O error: The reason for the error might be the location of the database file. The location was:
/var/mobile/Containers/Data/Application/someid/Documents/somedb.sqlite3
and I got rid of the error by moving the db file to:
/var/mobile/Containers/Data/Application/someid/Library/somedb.sqlite3
So instead of:
static var destinationSqliteURL: URL!
let myPath = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
destinationSqliteURL = myPath.appendingPathComponent("somedb.sqlite3")
I used:
static var destinationSqliteURL: URL!
let myPath = fileManager.urls(for: .libraryDirectory, in: .allDomainsMask)[0]
destinationSqliteURL = myPath.appendingPathComponent("somedb.sqlite3")
you should verify the file is ok (using xcode simulator), by printing out myPath and cd into the folder containing the database, then in terminal open the database file with:
sqlite3 somedb.sqlite3
Probably there is no file there or it is corrupted and has to be replaced.
Upvotes: 5