开发者

Connection Status of SQLite in IOS

开发者 https://www.devze.com 2023-03-08 10:53 出处:网络
Is there a way one can check the connec开发者_开发技巧tion status of a SQLite DB in IOS. I do not want to keep opening the db connection again and again. As a work around, I have put the SQLite DB obj

Is there a way one can check the connec开发者_开发技巧tion status of a SQLite DB in IOS. I do not want to keep opening the db connection again and again. As a work around, I have put the SQLite DB object into a static variable and check if the object is NIL, else use the object as is.

Is there a simpler and cleaner way to do this


A lot of SQLite Wrappers for iOS provide this functionality. Here is a library I wrote for handling SQLite connections which you can use to check the status of a connection: https://github.com/ziminji/objective-c-sql-query-builder


First of all, I would recommend using FMDB instead of SQLite directly.

To answer your question: don't bother. I have many apps, with many users and I have never seen the database "connection" fail. It just doesn't fail, it's not a network connection, just an open file.


Try www.github.com/pmurphyjam/DBExample It's an Xcode project that uses SQLite. It abstracts the entire SQL layer for you so you can concentrate on just writing SQL queries. It does large transactions also. The SQL syntax is exactly like FMDB, and it also uses Dictionaries for complex queries. Here's an example: For selects NSMutableArray = GetRecordsForQuery:@"select firstName, lastName from Company where lastName = ? ",@"Smith",nil];

OR For inserts, deletes or updates

BOOL = ExecuteStatement:@"insert into Company (firstName, lastName) values(?,?)",@"John",@"Smith", nil];


There is an example project for using SQLite here you can refer to: https://github.com/AaronBratcher/ABSQLite

It has classes for accessing SQLite in a more traditional database way.

0

精彩评论

暂无评论...
验证码 换一张
取 消