objective c - How to copy PreCreated and Pre Populated complete sqlite database.db file into iOS App -


i have run app on off line mode too, thats why trying copy mydatabase.db file app's document directory.

i have create mydatabase.db terminal , populate it. has 10 tables, want add app,

i have tried login record table copied whole database file not other table. login app , takes data login table , no more table data shown. nslog sqlite error said error no such table: tablename ,that means no other table copied.

**question how copy complete mydatabase.db file?

this have did copy file…

in .m file add method

- (void) copydatabaseifneeded { nsfilemanager *filemanager = [nsfilemanager defaultmanager]; nserror *error; dbpath = [self getdbpath]; bool success = [filemanager fileexistsatpath:dbpath]; if(!success)     {          nsstring *defaultdbpath = [[[nsbundle mainbundle] resourcepath] stringbyappendingpathcomponent:@"mydatabase.db"];         success = [filemanager copyitematpath:defaultdbpath topath:dbpath error:&error];      if (!success)         nsassert1(0, @"failed create writable database file message '%@'.", [error localizeddescription]);     } } - (nsstring *) getdbpath { nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory , nsuserdomainmask, yes); nsstring *documentsdir = [paths objectatindex:0]; nslog(@"dbpath : %@",documentsdir); return [documentsdir stringbyappendingpathcomponent:@"mydatabase.db"]; } 

in viewdidload method

[self copydatabaseifneeded]; database = [dbpath utf8string]; 

then login , move next viewcontroller taking dbpath new view. have checked on viewcontrollers dbpath okay, not records shown should be,

one more thing if change dbpath computer's document directory, database located works perfectly…

now please me resolve issue. appreciated..

try using sqlite database browser check if table has been created , data has been appended in table after database has been copied application's document directory.

to access application's document directory, run application on simulator , go library->application support->iphone simulator-> (simulator version) -> applications-> search ur application -> documents directory->mydatabase.db


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -