Home > other >  Retrieve a List from NSData, stored as BLOB in SQLite with Core-Data within a Flutter app
Retrieve a List from NSData, stored as BLOB in SQLite with Core-Data within a Flutter app

Time:02-15

I'm pretty new to Flutter and hope for some help. I build an SwiftUI application for iOS with Core-Data. My next step was to build a Flutter app to support iOS and Android for the upcoming version. Therefore I rebuild the whole application.

The nativ iOS app is using Core -Data and I'm saving several things there. For example some Strings and also a list of Double values: [Double] (for example [5.5, 4.3]. I was using a Transformable attributeType to store it (also have the valueTransformerName NSSecureUnarchiveFromDataTransformerName).

I would like to migrate all the "old" data from the iOS app to my new Flutter app. I was able to load the "old" database within my Flutter app and get all the data and save them to the new database with Floor. Currently I have troubles to get the values from [Double].

I could use a DB tool to investigate the data in the "old" database. The list is stored as an BLOB. I can't see any "useful" values/data in the DB tool.

In my Flutter app I tried to get the content of the column with:

Uint8List doubleList = (element["ZSHOOTS"] as Uint8List);

Then I have a list with many items (numbers) (but not mine). I tried to simply cast it, but nothing worked.

My question is, how can I retrieve the BLOB value and get my list with Doubles? In SwiftUI - the native iOS app - everything is working fine. I think SwiftUI is converting my [Double] to a NSData object and save this in the database as a BLOB. While accessing the attribute in the app it converts it automatically back. Now I have to do the converting in my Flutter app, but I don't know how :-)

One possibility would be to write the transformation the same way SwiftUI is doing it while accessing the data. But I don't know where to finde the transformation. Thanks for the help and suggestions.

CodePudding user response:

Core Data is an object-graph management system that also provides data persistence. It’s not a object relational mapping framework. While one of the store types is SQLite, the way an object graph is persisted is an implementation detail that is private to Core Data.

This means Core Data is free to persist your object graph however it sees fit, including by storing properties as blobs or other data types that may only make sense to the Core Data framework.

IOW, this is happening at the Core Data level, not SwiftUI level.

CodePudding user response:

After converting my value from the db via String.fromCharCodes(tableColumn) I got the following:

bplist00Ô\^A\^B\^C\^D\^E\^F\^G
X$versionY$archiverT$topX$objects\^R

That looks like a plist "file". I found this dart library https://pub.dev/packages/propertylistserialization to convert it to a string. But I'm failing to convert the column value to the right format. Error is Unsupported plist objectType 8. Some ideas?

  • Related