我有一个单例类:
class Database {
static let instance:Database = Database()
private var db: Connection?
private init(){
do {
db = try Connection("\(path)/SalesPresenterDatabase.sqlite3")
}catch{print(error)}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我使用Database.instance.xxxxxx访问此类以在类中执行函数.但是,当我从另一个线程访问该实例时,它会抛出奇怪的结果,就像它试图创建另一个实例一样.我应该在同一个线程中引用该实例吗?
澄清奇怪的结果显示数据库I/O错误,因为两个实例一次尝试访问数据库
更新
请参阅此问题以获取有关数据库代码的更多信息:使用事务插入是抛出错误Sqlite.swift
我需要在我的生产服务器上运行以下命令:
EXEC sp_configure 'xp_cmdshell', 1;
GO
RECONFIGURE;
GO
Run Code Online (Sandbox Code Playgroud)
我的问题是,在生产环境中运行此命令是否有任何危险。它会断开任何连接并且最终用户会注意到任何停机时间吗?
我不断收到以下错误:
致命错误:“尝试!” 表达式意外引发错误:磁盘 I/O 错误(代码:10):文件 /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-800.0.63/src/swift/stdlib/public/core/ErrorType .swift,第 178 行
当我实现以下代码时:
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 …Run Code Online (Sandbox Code Playgroud) 我正在使用swift 3,我希望能够遍历我的sqlite数据库中的所有表.有这么简单的功能吗?我只是想检索表名.