1

我在我的代码中使用了 5 个 SQLite.swift 表。第一个表用于存储位置数据:

数据模型:

typealias Location = (
    latitude: Double,
    longitude: Double,
    timestamp: String,
    speed: Double,
    direction: Double
)

数据助手:

class LocationDataHelper: DataHelperProtocol {
    static let TABLE_NAME = "Location"

    static let locations = Table(TABLE_NAME)
    static let timestamp = Expression<String>("timestamp")
    static let latitude = Expression<Double>("latitude")
    static let longitude = Expression<Double>("longitude")
    static let speed = Expression<Double>("speed")
    static let direction = Expression<Double>("direction")

    typealias T = Location

    static func createTable() throws {
        guard let DB = SQLiteDataStore.sharedInstance.TeleDB else {
            throw DataAccessError.Datastore_Connection_Error
        }
        do {
            let _ = try DB.run( locations.create(ifNotExists: true) {t in
                t.column(timestamp, primaryKey: true)
                t.column(latitude)
                t.column(longitude)
                t.column(speed)
                t.column(direction)
            })

        } catch _ {
            // Error throw if table already exists
        }

    }

static func insert(item: T) throws -> Int64 {
        guard let DB = SQLiteDataStore.sharedInstance.TeleDB else {
            throw DataAccessError.Datastore_Connection_Error
        }
        if (item.timestamp != "") {
            let insert = locations.insert(timestamp <- item.timestamp, latitude <- item.latitude, longitude <- item.longitude, speed <- item.speed, direction <- item.direction, isDriving <- item.isDriving)
            do {
                let rowId = try DB.run(insert)
                guard rowId > 0 else {
                    throw DataAccessError.Insert_Error
                }
                return rowId
            } catch _ {

                throw DataAccessError.Insert_Error
            }
        }
        throw DataAccessError.Nil_In_Data

    }

我在这一行看到一个异常:

let rowId = try DB.run(insert)

在同一部手机(iPhone 6、iOS 9.2)上我的应用程序中的其他 4 个表成功运行非常相似的代码。相同的代码在 iPhone 5s、iOS 9.2 上也可以正常运行。

当我尝试进入 DB.run 时,我看到失败发生在这条线附近,但我不确定它是做什么的:

dispatch_sync(self.queue, block) // FIXME: rdar://problem/21389236

接下来我应该尝试什么?如果您需要任何进一步的信息,请告诉我。

4

0 回答 0