ios - Can't open SQLite database due out of memory error -


i'm having issue opening sqlite database iphone app i'm writing. thought followed tutorials verbatim reason getting "out of memory" error.

-(nsstring *) filepath{     nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentationdirectory, nsuserdomainmask, yes);     return [[paths objectatindex:0] stringbyappendingpathcomponent:@"db.sqlite"]; }  -(sqlite3*)opendb{     if(db == null){         sqlite3 *newdbconnection;          if(sqlite3_open([[self filepath] utf8string], &newdbconnection) != sqlite_ok){             sqlite3_close(db);             nslog(@"%s sql error '%s' (%1d)", __function__, sqlite3_errmsg(db), sqlite3_errcode(db));             db = null;         }         else{             nslog(@"db opened");         }      }     return db; } 

db ivar , calling db = [self opendb]; in initialization method.

this result of use of nsdocumentationdirectory, when intended use nsdocumentdirectory.

the reason you're seeing "out of memory" error you'll whenever call sqlite3_errmsg null sqlite3 pointer. , in case, bet db value null.

it doesn't make sense use sqlite3_errmsg or sqlite3_errcode in conjunction sqlite3_open failure anyway, because if open failed, don't have valid sqlite3 pointer pass these error reporting functions.

i therefore suggest following:

- (sqlite3*)opendb {     if (db == null) {         int rc;          if ((rc = sqlite3_open([[self filepath] utf8string], &db)) != sqlite_ok) {             nslog(@"%s error (%1d)", __function__, rc);             db = null;         } else {             nslog(@"db opened");         }     }     return db; } 

note, i'm logging return code of sqlite3_open function, rather calling sqlite3_errcode null value sqlite3 pointer.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -