我想在网上托管我的SQLite数据库,但我不知道如何导入它。现在,表正在默认文档目录中创建。这是我的代码:
import UIKit
import SQLite
class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource, UITextFieldDelegate {
var database: Connection!
let boxesTable = Table("boxes1")
let ID = Expression<Int>("ID")
let SNO = Expression<String>("Serial_Number")
let condition = Expression<String>("Condition")
override func viewDidLoad() {
super.viewDidLoad()
do{
let doucumentDirectory = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let fileUrl = doucumentDirectory.appendingPathComponent("boxes1").appendingPathExtension("sqlite3")
let database = try Connection(fileUrl.path)
self.database = database
}catch{
print(error)
}
let createTable = self.boxesTable.create { (table) in
table.column(self.ID, primaryKey: true)
table.column(self.SNO, unique: true)
table.column(self.condition)
}
do{
try self.database.run(createTable)
print("Created Table")
}catch{
print(error)
}
}这是我的sqlite数据库的链接:-
https://drive.google.com/open?id=0B7H7vc34uAM6WEVKUC1YeFQ5VkE
我给了这个链接一个可编辑的访问使用Swift 3编码。
还有一个问题:我是直接提供到文件夹的链接还是直接提供文件的链接?
发布于 2017-11-01 18:55:57
你不应该那样做。SQLite不适合像普通数据库那样在主机上使用。
SQLite是一个库,您的真实数据只是磁盘上的一个文件。要在线使用它,就必须使用服务器,并使服务器使用SQLite库在SQLite数据库文件上写入。
但是SQLite并不是设计用来在服务器上使用的。
SQLite是一个进程内库,它实现了一个自包含的、无服务器的、零配置、事务性SQL数据库引擎. SQLite是一个嵌入式SQL数据库引擎。与大多数其他SQL数据库不同,SQLite没有单独的服务器进程。SQLite直接读写普通磁盘文件。
要做到这一点,您应该使用另一个服务,比如Firebase。
来自SQLite官方网站。
https://stackoverflow.com/questions/47058450
复制相似问题