Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func insertWordData() {
- if openDatabase() {
- if let path = Bundle.main.path(forResource: "messagesToRead", ofType: "json") {
- var query = ""
- do {
- let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .alwaysMapped)
- let jsonObj = JSON(data: data)
- if jsonObj != JSON.null {
- for (_, jsonObj) in jsonObj {
- let WordString = jsonObj["FIELD1"]
- let WordDefinition = jsonObj["FIELD2"]
- query += "insert into words ((field_WordID), (field_WordString), (field_WordDefinition)) values (null, '(WordString)', '(WordDefinition)');"
- }
- }
- if !database.executeStatements(query) {
- print("Failed to insert initial data into the database.")
- print(database.lastError(), database.lastErrorMessage())
- }
- else {
- //print(words)
- }
- } catch let error {
- print(error.localizedDescription)
- }
- } else {
- print("Invalid filename/path.")
- }
- database.close()
- }
- }
Add Comment
Please, Sign In to add comment