2013-04-24 109 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