Flutter: SQFLite database is not showing data in application - flutter

In my Android application, I need to add about 300 customers. As application have database import/export feature available so I decided to do insert customers on computer, instead of mobile.
Here's how I did that:
Install app on mobile
Exported db using export feature
Inserted data using SQLite Editor tool
Saved the DB
Transferred on mobile and imported back
Logically, it should work but it's not working.
Export/Import Feature:
This feature does work as expected, I've tested like this:
Added some dummy data
Exported data on SD card
Delete the App
Re-install (dummy data wasn't available)
Imported data back and it worked
What I noticed:
The exported database zip file contains a file with same name as database but with an additional word e.g DBNAME.db-journal. When I added data in db using SQLite Editor, and save it. The -journal file was removed.
As application doesn't show added data in app, but if we export db from app and open it in editor, then it shows all data.
I've even tried to remove previous -journal file, right before importing but no luck.

Related

Realm browser data import error and does it have relation?

How can I set relation when I input the data into realm?
There was menu for importing on CSV or Excel files only, but for relation
How can I make it if I need to bring it with data joined.
I created a db file using the realm browser and imported a xlsx file, but it did not work. What was wrong? I followed the steps below.
Run the Generate Demo Database menu and created a db file in the realm browser.
Opened the files made saw realmTestClass(), realmtestclass1, realmtestclass2 files. I imported the data I made using the import menu, but it did not work.
The Realm Browser data importing features are still heavily in development.
If you've got any specific use cases where it is consistently crashing, or any feature requests, it would be a big help to file issues over at the Realm Browser GitHub repo. :)

Reading a list of records SQLite - Need advice

I have some data (Student info), and my app should be able to read and display these student records in a UITableView.
I need to know the following;
) Where should i store these student records ? I know that i could store them in the SQLITE query browser (in the MAC) but, when users install the app on the device how are they going to read the student records from (because the iPhone doesn't have a query browser for someone to enter the records) ?
when you will create a sqlite database, you have to store it in your application folder only just like any local image for app like Default.png or icon.png.... and when you run your app on device the sqlite database also will be loaded together with the application....sqlite database will be stored as a file with extension .sqlite onle...copy it in your app...it will just execute just fine.....when you write coding like "Select *..." or "INsert into..." or "delete from...." remember to give the correct name of the sqlite file copied in your app...
After creating Database in SQLITE save that Database, which gives you file with extension .sqlite then drag and drop that .sqlite file in to Resources folder of you application program in XCODE and then install in you iPhone It will work. and you can use Sqlite using iPhoen

App Crashed due to change in datamodel

My app is crashing when ever i change the data model. Inorder to run it again i should delete the app from simulator and the run it. Instead of doing this is there any means that we can run the app without deleting whenever we change the datamodel. i want the previous data to be used. Thanks in advance
The answer is a bit tricky but this always works for me. This is for a clean installation of a new compatible .sqlite file, not a migration!
launch simulator, delete the app and the data (the popup after you delete the app).
quit simulator
open X-Code, after making any edits to your data model
if needed update the datamodel version:
Editor > Add Model Version...
set your prefs in the dialog that appears (counting up is preferable)
click on the {appname}.xcdatamodeld then in the far right pane
click the left icon of the 3 icons on top of the far right column
under Versioned Core Data Model select the one you just created
delete the {*appname*}.sqlite file (or back it up, remove it from project folder, and delete reference)
clean the app (Product > Clean)
Run the app in a simulator (for this tutorial I will assume 4.2)
While the simulator is running, in a Finder window, navigate to:
{*home*} > Library > Application Support > iPhone Simulator > 4.2 > Applications > {*random identifier*} > Documents > {*appname*}.sqlite
Copy this file to another location
Stop running your app in X-Code
Drag and drop the {appname}.sqlite file into the files list in X-Code.
In the dialog that pops up, make sure the copy to folder checkbox, is checked.
Product > Clean
Then run the app in the simulator again
Now you should have a working sqlite file!
Cheers,
Robert
Basically you need to be able to migrate existing data to the new schema -- read up on Core Data Versioning and Data Migration.
The file being used for NSPersistentStore can only correspond to one version of a Data Model at a time. You need to either do a migration of the data to the new version or tell your application to delete the persistent store file each time you start (for development purposes only).
Just saw that you want to keep your old data. You can try serializing your data to a NSDictionary and then saving it to a plist/json/xml file. Then, when your program starts you can delete the old NSPersistantStore file and create a new one. Import the data from the plist/json/xml file to the new empty persistent store file.
Remember, in order for light migration to work you need to keep the previous version of the data model in addition to the new one. Core data needs to know both models, past and present, in order to perform a migration.
I have the same problem and I haven't fixed it yet. I don't care yet. While my app is in development I just clear the data every time I change the model.
I think to use Lightweight Migration, you still have to make a copy of your data model for every version of the data model you want to migrate from or to. It's lightweight, but not lightweight enough for when you're changing your data model frequently in early development.
I suggest you catch the exception it throws when it can't load the data, and have your program automatically delete the data in that case and recreate it in an initial state. It's the same as the ignore the problem answer but you don't have to manually delete the data every time. You probably ought to leave that code in for production, as a backup in case migration doesn't work for some reason, but maybe you ought to ask the user if they want to delete the data.

Prefilled version of Core Data?

My app involves getting a large json file via the internet, and then parsing it into Core Data.
Thats fine, but how could I get the already filled version of this Core Data database into my app, so it is there when they first launch it. And the user can decide to refresh it later.
There's a reasonable tutorial about pre-loading over at Ray Wenderlich's site.
Generally - create a separate project, parse the JSON file into a core data database. Create your real project, copy the Object model and the database file to this new project.
Now, at app start up, check if the database exists in the document's directory, and if it does not, copy your prefilled one from your app bundle.
Make sure that the Persistent Store Coordinator works with the database in the documents folder and not the one in the app bundle.
Update June 2012
I've got a small example project on GitHub called PromNight which demonstrates using an Xcode Workspace with an iPad project and a OS X project to preload the data for Core Data. This uses an object model that is shared between the the two applications which helps to keep changes in sync when preloading.
Core Data uses a backing store, which is essentially a sqlite database (or, on Mac OS, optionally an XML file). You should simply add that file to your app's bundle and ship it with the app. As far as getting the data into the database, here's what I would do:
Write some code to import the data from whatever format you have it in.
Run that code.
Copy the sqlite file off of the device or from the simulator.
Add the newly created sqlite file to your project in Xcode.
I wouldn't hand-create the sqlite file, since Core Data does some "voodoo" behind the scenes and messing with the sqlite can break things. Also, I've seen developers use multiple targets. for the import. This way, they can write the code in a compiler conditional and then not have to worry as much about project maintenance. For example:
#ifdef kImportTarget
//run core data import
#else
// run the Core Data stack setup from an existing file
#endif
The Core Data database is just a SQLite database file. You can deliver it in your main bundle and then copy it to your documents folder before associating it with your persistent store coordinator.

load sqlite3 DB with data from external source (Objective-C)

I am developing my first iPhone app, which includes an sqlite3 database that should contain approximately 1.200 records. These records are created by me.
During the tests i have created them in a .txt document and inserted the .txt into the database. This is a very inconvenient method to do this and i would just ask for some advice how to do this in a convenient way. I have been thinking about some external (free) databse, excel
Use the mysqlite3 program on you Mac, to create the database. Then place the database into your App's bundle.
When you program launches, see if the database is in your app's "Documents" directory. If not, copy the one from the bundle to the Documents directory.
The mysqlite3 program on your Mac will generate a database which is compatible, and sufficient to use on your iOS device.
You could use excel to create a csv (comma separated) file - then you'd just need to parse it. If you already have the db started - you could also just use sqlite3 at the command line.