ios - Data not inserting into sqlite database -
ios - Data not inserting into sqlite database -
hi in application have info want insert sqlite
database .so have created database successfully, problem not insert info database.
my database creation code.
- (void)createdatabase { nsarray *directories = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *doctumentsdirectory = [directories lastobject]; self.databasepath = [[nsstring alloc] initwithstring:[doctumentsdirectory stringbyappendingpathcomponent:@"/bp.sqlite"]]; nsfilemanager *filemanager = [nsfilemanager defaultmanager]; // create db if not exists if (![filemanager fileexistsatpath:self.databasepath]) { const char *dbpath = [self.databasepath utf8string]; if (sqlite3_open(dbpath, &_mydatabase) == sqlite_ok) { char *errormsg; const char *sql_statement = "create table if not exists br (id integer primary key autoincrement, name text, cost text,quty text)"; if (sqlite3_exec(_mydatabase, sql_statement, null, null, &errormsg) != sqlite_ok) { [self errorcreatingtable:[nsstring stringwithformat:@"failed creating table. error:%s", errormsg]]; } sqlite3_close(_mydatabase); } else { [self errorcreatingtable:@"failed openning / creating table"]; } } }
my insert code have uibutton action method give insert code.
-(void)amethod2:(uibutton*)sender { nsstring *inr=[intarr objectatindex:sender.tag]; nslog(@"%@",inr); nsstring *item=[self.menuarray objectatindex:sender.tag]; nslog(@"%@",item); nsstring *cost=[self.menuarray1 objectatindex:sender.tag]; nslog(@"%@",cost); nsstring *sql = [nsstring stringwithformat:@"insert br ('name','cost','quty') values ('%@','%@','%@')",item,cost,inr]; nslog(@"%@",sql); }
i have used above code info , inserting database values passing correctly problem not inserting database please tell me how resolve issue have been stuck here long time help me out.
thanks.
try code...
-(void)insertdata:(nsstring*)query{ nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring *databasepath = [documentsdirectory stringbyappendingpathcomponent:@"bp.sqlite"]; nslog(@"%@",databasepath); if(sqlite3_open([databasepath utf8string],&_mydatabase) == sqlite_ok) { nsstring *querysql = [nsstring stringwithformat: @"%@",query]; char *errmsg=nil; if(sqlite3_exec(_mydatabase, [querysql utf8string], null, null, &errmsg)==sqlite_ok) { nslog(@".. inserted .."); } } sqlite3_close(_mydatabase); }
ios ios7 sqlite3 insert
Comments
Post a Comment