开发者

SQLITE_CORRUPT problem in iphone

开发者 https://www.devze.com 2023-03-07 04:48 出处:网络
Recently I implemented a cache component in my iPhone app, that uses SQLite. I\'m writing and reading the data natively w/o any wrapper framework.

Recently I implemented a cache component in my iPhone app, that uses SQLite. I'm writing and reading the data natively w/o any wrapper framework. The problem is that after using the app for a while it's beginning to get SQLITE_CORRUPT status code in response to a any SQL state开发者_JS百科ment I perform in the DB.

I'm using SQLiteManager as my DB mgmt tool. When the DB becomes corrupted I'm trying to analyze and inspect via the SQLiteManager but it doesn't even allow me to browse through the data in the table and just outputs a laconic message that says data is corrupted.

Anyone can assist with this one ? First of all - How the hell the DB gets to that situation and second - how or where can I see the data anyway ?

Thanks, Guy.


You can refer this official documentation. Here they have mentioned there are very few chances for db to be corrupted.

They have also list out the chances how DB can be corrupted. And from there refer following example which can cause the problem to the db.

  CREATE TABLE ex1(a INTEGER PRIMARY KEY, b);
  INSERT INTO ex1 VALUES(1,2);
  INSERT INTO ex1 VALUES(2,3);
  CREATE TRIGGER ex1_tr1 AFTER UPDATE ON ex1 BEGIN
    DELETE FROM ex1 WHERE a=old.b;
  END;

  UPDATE ex1 SET b=b+1;

In the example above, the first cycle of the UPDATE causes the trigger to fire and delete the second row of the ex1 table. When the second cycle of the UPDATE loop runs, it attempts to process the second row of the ex1 table. SQLite recognized that the second row had been deleted so it aborts the second cycle, but it was failing to clean up after itself properly which could lead to database corruption on subsequent cycles of the loop.

So, Basically you need to find out the situation where this has happened in your code, By debugging or by following steps through your application or any other mechanism.

0

精彩评论

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

关注公众号