[英]How to store array value in sqlite in iphone
我在将数组值存储在数据库中时出错。 我的最后一个数组值存储在数据库中。 我认为柜台是适当的。 我在这段代码中哪里做错了? 我正在数据库中创建一个计数器来存储数组值。 我收到此错误消息保存错误:在此行上按顺序调用库例程############
-(BOOL)Add
{
NSString *filePath = [BaseModal getDBPath];
NSLog(@"this check:%@",filePath);
sqlite3 *database;
if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement = "insert into Name(name,Date,CDate,Attach form,data) VALUES (?,?,?,?,?)";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM/yyyy"];
NSString* date = [dateFormat stringFromDate:Date];
NSString* cdate = [dateFormat stringFromDate:Cdate];
sqlite3_bind_text( compiledStatement, 1, [name UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 2, [date UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 3, [cdate UTF8String], -1, SQLITE_TRANSIENT);
//sqlite3_bind_text( compiledStatement, 4, [UDate UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_int(compiledStatement, 4, Attach form);
sqlite3_bind_text( compiledStatement, 5, [data UTF8String], -1, SQLITE_TRANSIENT);
//sqlite3_bind_int(compiledStatement, 6, i);
}
if(sqlite3_step(compiledStatement) != SQLITE_DONE ) {
NSLog( @"Save Error: %s", sqlite3_errmsg(database));
sqlite3_finalize(compiledStatement);
sqlite3_close(database);
return FALSE;
}
else {
TaskId=sqlite3_last_insert_rowid(database);
sqlite3_reset(compiledStatement);
//sqlite3_finalize(compiledStatement);
//now insert into name table
const char *sqlStatement3 = "insert into TeaInfo(TitleId,TeaId) VALUES (?,?)";
sqlite3_stmt *compiledStatement3;
if(sqlite3_prepare_v2(database, sqlStatement3, -1, &compiledStatement3, NULL) == SQLITE_OK) {
sqlite3_bind_int(compiledStatement3, 1, TitleId);
for(int counter=0;counter<[self.Tea count];counter++)//***************************
{
Teaclass *teaInfo=(Teaclass*)[self.Teas objectAtIndex:counter];
sqlite3_bind_int( compiledStatement3, 2, teaInfo. TeaId);
}
if(sqlite3_step(compiledStatement3) != SQLITE_DONE )//#############
{
NSLog( @"Save Error: %s", sqlite3_errmsg(database) );
//return FALSE;
}
//}
}
return TRUE;
}
}
return TRUE;
}
在if(sqlite3_prepare_v2(database, sqlStatement3, -1, &compiledStatement3, NULL) == SQLITE_OK)
解决的问题我必须在for循环中写这一行,然后正确插入行。
试试下面的代码,
const char *sqlStatement3 = "insert into TeaInfo(TitleId,TeaId) VALUES (\"VALUE1\",\"VALUE2\)";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.