I’m planning to use the objective-c-sql-query builder from ziminji on an iPhone and iPad project. This library supports multi-threading, like I need. I’ve initially done my project using Core Data, but the performance is bad when the amount of data grows a lot. For example, when I have to delete everything (hundred-thousands of rows), it takes a long time, which makes sense due to the object-oriented layer. Accessing the database directly is a lot faster.
I looked at the library’s code and I noticed that every time I query the database, it opens a connection to the database. Isn’t this slow? Wouldn’t it be faster to keep the database connection opened while the app is active? Or would it be a problem to implement it like that with multi-threading support?
The Objective-C SQL Query Builder library for SQLite offers three way to open a connection as noted on its Wiki:
The first two alternatives allow for the connection to remain open. In fact, that is the whole purpose of a database connection pool. With the database connection pool, you do not have to worry about opening and closing the connection because the class manages this for you; whereas, the second alternative you manage the connection. In the third alternative, this is just a quick way to open the connection, query, and then close the connection all in one line of code.
If you are going to utilize multi-threading, you will need to use either the first or second alternative. If you chose the second alternative, create an instance variable in your class and open the connection, then start your threads. Once all of your threads have finished running, close the connection…otherwise just leave it open.