Is it possible to use dbaccess for an existing sqlite database?

My question is, how can I use the dbaccess framework with an existing sqlite database? I have a test.sqlite file in the My Documents folder. I even renamed it to "test.db". When I try to commit an object of my Worker class, nothing happens (I don't get any errors with the databaseError (error: DBError!) Method).

Here's what Worker.swift looks like:

@objc(Worker) class Worker: DBObject { dynamic var lastName: NSString? } 

This is what AppDelegate.swift looks like:

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { DBAccess.setDelegate(self) DBAccess.openDatabaseNamed("test") var w = Worker.new() w.lastName = "WorkerName" w.commit() return true } 
+4
source share
1 answer

Yes, you should be able to, but there will be some reservations. Thus, DBAccess should always have an identifier column, so it will create one of them in existing tables. It will also generate its own PK values ​​for existing records.

The reason your objects are not saved may be because you need to call persistSynthesizedProperties by setting it to true.

Since you have only one field, I can understand why this might seem invalid. Because when we replace the getter / setter method in a fast class, it requires different methods. These are the same methods as when the objc class synthesized properties that need to be preserved.

Thus, when a commit call is made, the columns listed in the list are not saved, so it issues an update without changes, which, of course, is also optimized for the zero operation.

Over time, we would like to end this delegate method, but at present we cannot work in obj-c, from which language the class is implemented. If we can find a way, then we can end this rather annoying and strange quirk.

Thanks Adrian

+1
source

All Articles