我的桌子在插入时没有提升。也没有显示在tableview中,但点击后添加“新记录”消息附带“添加记录”,所以没有任何错误
在表函数中插入:
-(int) insert:(NSString *)filePath withBrand:(NSString *)brand
{
sqlite3* db = NULL;
int rc=0;
rc = sqlite3_open_v2([filePath cStringUsingEncoding:NSUTF8StringEncoding], &db, SQLITE_OPEN_READWRITE , NULL);
if (SQLITE_OK != rc)
{
sqlite3_close(db);
NSLog(@"Failed to open db connection");
}
else
{
NSString * query = [NSString
stringWithFormat:@"INSERT INTO brands (bikeBrandName) VALUES (?)"];
char * errMsg;
rc = sqlite3_exec(db, [query UTF8String] ,NULL,NULL,&errMsg);
if(SQLITE_OK != rc)
{
NSLog(@"Failed to insert record rc:%d, msg=%s",rc,errMsg);
}
sqlite3_close(db);
}
return rc;
}
还试过这个:
-(int) insert:(NSString *)filePath withBrand:(NSString *)brand
{
sqlite3* db = NULL;
int rc=0;
rc = sqlite3_open_v2([filePath cStringUsingEncoding:NSUTF8StringEncoding], &db, SQLITE_OPEN_READWRITE , NULL);
if (SQLITE_OK != rc)
{
sqlite3_close(db);
NSLog(@"Failed to open db connection");
}
else
{
NSString * query = [NSString
stringWithFormat:@"INSERT INTO brands (bikeBrandName) VALUES (\"%@\")",brand];
char * errMsg;
rc = sqlite3_exec(db, [query UTF8String] ,NULL,NULL,&errMsg);
if(SQLITE_OK != rc)
{
NSLog(@"Failed to insert record rc:%d, msg=%s",rc,errMsg);
}
sqlite3_close(db);
}
return rc;
}
答案 0 :(得分:0)
不是
INSERT INTO brands (bikeBrandName) VALUES (\"%@\")",brand
应该是
INSERT INTO brands (bikeBrandName) VALUES ('%@')",brand
^ ^
要进一步调试,请使用check this tutorial
肯定会有帮助