2012-03-28 49 views
0

データベースに配列の値を格納する際にエラーが発生しました。最後の配列値はデータベースに格納されます。私はカウンターが適切だと思った。このコードでどこが間違っていたのですか?私は配列値を格納するためにデータベースにカウンタを作成しています。 私は、このエラーメッセージの保存エラーを得た:この行############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; 

} 
+0

どの手順でエラーが発生したのか、エラーメッセージは何かを明確にしてください。 –

+0

正確にあなたがエラーに直面している場所を教えてください... – Kiran

+0

kiran私はカウンターの配列にエラーが直面していることを確認してください私は間違って何かベックをデータベースに挿入する最後の配列の値なぜすべてのミスマーク何かはない – Rocky

答えて

2

、以下のコードを試してみてくださいこの行のif(sqlite3_prepare_v2(database, sqlStatement3, -1, &compiledStatement3, NULL) == SQLITE_OK)の問題を解決しました。私はループのために書く必要があり、次に行が正しく挿入されています。

1

にシーケンス の外に呼び出されるライブラリルーチンが

const char *sqlStatement3 = "insert into TeaInfo(TitleId,TeaId) VALUES (\"VALUE1\",\"VALUE2\)"; 
関連する問題