2013-04-24 117 views
4

這是我如何嘗試在sqlite數據庫中添加數據一切正常,但數據不會被添加到數據庫中我不明白爲什麼你可以請參考代碼並告訴我我做錯了什麼在sqlite數據庫中插入數據的問題

sqlite3_stmt *stmt; 
    int x; 

    char *update = "insert into PersonNamesAndBirthDates (Names,Birthdates,Phonenumber,Email,Profilepic) values(?,?,?,?,?);"; 
    x = sqlite3_prepare_v2(database1, update, -1, &stmt, nil); 

    if (x == SQLITE_OK) 
    { 
     NSLog(@"PersonName is -->%@",[NSString stringWithFormat:@"%@",[_Namebarray objectAtIndex:0]]); 
     NSLog(@"BirthDates is -->%@",[NSString stringWithFormat:@"%@",[_Birthdatebarray objectAtIndex:0]]); 
     NSLog(@"BirthDates is -->%@",[NSString stringWithFormat:@"%@",[_Phonearray objectAtIndex:0]]); 
     NSLog(@"BirthDates is -->%@",[NSString stringWithFormat:@"%@",[_Emailarray objectAtIndex:0]]); 
     // if else will come here for checking weather images has added or not if added then store Yes Image if not then simply No image for default image. 


     sqlite3_bind_text(stmt, 1, [[NSString stringWithFormat:@"%@",[_Namebarray objectAtIndex:0]] UTF8String],-1, NULL); 
     sqlite3_bind_text(stmt, 2, [[NSString stringWithFormat:@"%@",[_Birthdatebarray objectAtIndex:0]] UTF8String],-1, NULL); 
     sqlite3_bind_text(stmt, 3, [[NSString stringWithFormat:@"%@",[_Phonearray objectAtIndex:0]] UTF8String],-1, NULL); 
     sqlite3_bind_text(stmt, 4, [[NSString stringWithFormat:@"%@",[_Emailarray objectAtIndex:0]] UTF8String],-1, NULL); 
     if(selectImage.image) 
     { 
      sqlite3_bind_text(stmt, 5, [[NSString stringWithFormat:@"%@",[_arrayOfPaths objectAtIndex:0]] UTF8String],-1, NULL); 
     } 
     else{ 
      sqlite3_bind_text(stmt, 5, [[NSString stringWithFormat:@"%@",@"No Image"] UTF8String],-1, NULL); 
     } 
    } 
    if (sqlite3_step(stmt) != SQLITE_DONE){} 
    NSLog(@"Error: "); 
    sqlite3_finalize(stmt); 
+0

你的意思是什麼*數據沒有被添加到數據庫* ?,你是否收到錯誤? – tkanzakic 2013-04-24 08:00:01

+0

我沒有得到任何錯誤只是數據庫沒有得到填充 – 2013-04-24 08:00:48

+0

你的數據庫文件存儲在哪裏,在應用程序包或在文件目錄? – tkanzakic 2013-04-24 08:01:55

回答

1

我看到你的代碼沒有錯誤做檢查你的數據庫是這樣

if (sqlite3_open(dbpath, &database1) == SQLITE_OK) 
+0

謝謝你有什麼問題 – 2013-04-24 08:14:42

+0

此外,如果不是SQLITE_OK,應該捕獲返回代碼並記錄值,如果不是,則應該記錄調用sqlite3_errmsg的結果。特別是在熟悉SQLite時,應該重點檢查並記錄每個「異常」的返回碼。 – 2013-07-11 14:51:23