Hashmat Khalil
Hashmat Khalil

Reputation: 1816

iOS core data:how to use preloaded sqlite database which contains multiple tables

my app has a sqlite database which is already preloaded with data. the database has many tables. i want to show a list of tables, so i have to query database or just list my entities?! when user taps a table name the next uitableview shows the data of that specified table. there are no relations between tables. only selecting from database matters right now. what would be the best way to go forward? sqlite api or core data. i'm new to iOS programming. i'm reading about core data. it sounds good but i'm perplexed how to solve this problem.

edit:by the way the table are identical. all of them have the same attributes. i have spilted in tables so that each table represent a category, and i suppose it would best for memory usage on the iDevices.

Upvotes: 1

Views: 1174

Answers (2)

Mundi
Mundi

Reputation: 80273

I would strongly suggest you try to learn the Core Data methods to deal with your data as object graphs. Its is really worth the effort because you get so much additional functionality for table views, etc. all with great automatic memory management. Memory will easily become quite an issue if you deal with raw SQLite and have a lot of data or complex tables.

Do this:

Create the entities in your core data model. Access the existing SQLite store and recreate all the data for your new core data tables. This is normally quite memory and processor intensive, so you typically do this on the simulator, not on the device.

After you have successfully imported the data, you can remove the sqlite libraries and import functions and work with your true core data persistent store.

This is a bit of effort, but I guarantee it is well worth it.

Upvotes: 3

Eugene
Eugene

Reputation: 10045

I'd use SQLite since you already have populated .sqlite file. If you want to painlessly use SQLite I suggest getting along with FMDB.

As for the way that your tables are identical I can only advice you to create a shared method like - (void)itemsWithCategory:(NSString *)category and your whole DB communications will be through this function.

Upvotes: 0

Related Questions