我收到數據庫中存儲數組值的錯誤。我最後的數組值存儲在數據庫中。我認爲櫃檯是正確的。在這段代碼中,我做錯了什麼?我在數據庫中創建一個計數器來存儲數組值。 我得到這個錯誤信息保存錯誤:呼叫順序 在這個網上圖書館例行############如何將數組值存儲在iphone中的sqlite中
-(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;
}
請說明您在哪個步驟收到錯誤以及錯誤消息是什麼。 – 2012-03-28 09:42:11
讓我們知道你在哪裏面臨的錯誤... – Kiran 2012-03-28 10:02:18
kiran我面臨錯誤的計數器陣列請檢查我做錯了事情因爲在數據庫中它只插入最後一個數組值爲什麼不是所有什麼錯誤 – Rocky 2012-03-28 10:06:30