Oyvindkg / swiftydb

💀Neither supported nor maintained for years. A type-safe, protocol-based, pure Swift database offering effortless persistence of any object

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TinySQLite.Error: SQL error or missing database (1)

emilpedersen opened this issue · comments

I get TinySQLite.Error: SQL error or missing database (1) when trying to save a object.

 let database = SwiftyDB(databaseName: "Elements")

        let element = Element()
        element.id = 1
        element.name = "hu"

        database.asyncAddObjects([element]) { (result) -> Void in
            if let error = result.error {
                // Handle error
                print(error)
            }
        }

What does your Element class implementation look like?
Are you using v1.1.1?

Yes using v1.1.1

Install using cocoapods. (:

Element class:

//
//  Element.swift
//  Elementaert
//
//  Created by Emil Pedersen on 09/05/16.
//  Copyright © 2016 LET Software. All rights reserved.
//

import Foundation
import SwiftyDB

class Element: NSObject, Storable {

    var id:Int = 0
    var name:String = ""
    var symbol:String = ""
    var atomicNumber:Int = 0
    var atomicWeight:Int = 0
    var group:Int = 0
    var period:Int = 0
    var valenceElectrons:Int = 0
    var primaryOxidationStep:Int = 0
    var secondaryOxidationStep:Int = 0
    var tertiaryOxidationStep:Int = 0
    var electronegativity:Double = 0.0

    override required init() {
        super.init()
    }
}


extension Element: PrimaryKeys {
    class func primaryKeys() -> Set<String> {
        return ["id"]
    }
}

Try updating now. There was an issue with escaping column names in queries. Should be fixed in 1.1.2

It does not work with async. No database is created. No error is printet.

database.asyncAddObject(element) { (result) -> Void in
if let error = result.error {
// Handle error
print(error)
}
}

But if I use database.addObject(element) it works, so I will use that. Thanks :)

I copied your class and retrieval code, and it worked. I'm not saying that there is no problem, only that i cannot reproduce it. If you could provide a project where the bug is present, I would be very grateful :) If not, make sure that you have updated the Podfile with version greater than 1.1.1, and run pod update