I am currently experimenting with SQLite on the iOS, but something seems wrong, I can't get to my table, even though I know it exists. The .sqlite file was created using Following code for ,Then I inserted one record into it using the my textfeild but when i clicked save button . However,I get a "no such table" error!
Here's the code:
-(int) createTable:(NSString*) filePath
{
sqlite3* db = NULL;
int rc=0;
rc = sqlite3_open_v2([filePath cStringUsingEncoding:NSUTF8StringEncoding], &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
if (SQLITE_OK != rc)
{
sqlite3_close(db);
NSLog(@"Failed to open db connection");
}
else
{
char * query ="CREATE TABLE IF NOT EXISTS GrowthExamination ( id INTEGER PRIMARY KEY AUTOINCREMENT, date TEXT,day TEXT, ga INTEGER, weight INTEGER,HC INTEGER,lenght INTEGER )";
char * errMsg;
rc = sqlite3_exec(db, query,NULL,NULL,&errMsg);
if(SQLITE_OK != rc)
{
NSLog(@"Failed to create table rc:%d, msg=%s",rc,errMsg);
}
sqlite3_close(db);
}
return rc;
}
-(NSString *) getDbFilePath
{
NSString * docsPath= NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES)[0];
return [docsPath stringByAppendingPathComponent:@"GrowthExamination.db"];
}
-(void)saveButtonClicked:(UIButton *)sender {
int rc= [self insert:[self getDbFilePath] withDate:[ReadindDateButton titleForState:UIControlStateNormal] Day:ReadingDayTextFeild.text GA:(long)GAInt Weight:(long)weightInt HC:(long)HCInt Length:(long)lengthInt];
if(rc != SQLITE_OK)
{
[self showMessage:@"ERROR" withMessage:@"Failed to insert record"];
}
else
[self showMessage:@"SUCCESS" withMessage:@"Record is added"];
}
this code run with fist table.in other class when i use same code for inserting data with second table .then i found error no such table.
Aucun commentaire:
Enregistrer un commentaire