转移到Xcode 5.0和iOS 7.0 SDK。我的整个代码工作正常,但在所有iPad / Ipod / Iphone系列上测试应用程序时,我注意到当我使用iPhone 5S(AKA iPhone Retina - 模拟器上的4英寸64位)时出现以下错误< BR />
Problem with prepare statement: bind or column index out of range
奇怪的是,一切正常但只是在iPhone 5s上我得到了这个错误并且发生了一个错误。所有iPad版本和iPhone版本都使用相同的代码
这是导致此问题的代码段:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSIndexPath *indPath3 = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
UITableViewCell *cell3 = [tableView cellForRowAtIndexPath:indPath3];
NSString *cellText3 = cell3.textLabel.text;
Details22 * vc4 = [self.storyboard instantiateViewControllerWithIdentifier:@"Details22Iphone"];
//FavReal* author;
NSLog(@"This is the showDetailsForIndexPath 2");
@try{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"rahme4.sqlite"];
if(sqlite3_open([writableDBPath UTF8String], &db) == SQLITE_OK) {
NSString *titleString3 = [[NSString alloc] initWithFormat:@"Element row number : %d",indexPath.row];
NSLog(@"This is the row number chosen %@",titleString3);
NSString *SearchedItem = [ cellText3 stringByReplacingOccurrencesOfString:@"'"
withString:@"''"];
// NSString *formatedSql333 = [NSString stringWithFormat:@"Select * from Longman where id = '%@'" , iDtoTake ];
if([SearchedItem isEqualToString:Aa2]){
formatedSql333 = [NSString stringWithFormat:@"Select * from Longman where id = '1'" ];
}
else{
formatedSql333 = [NSString stringWithFormat:@"Select * from Longman where keyword = '%@'" , SearchedItem ];}
const char *formatedSql3333 = [formatedSql333 UTF8String];
NSLog(@"This is the SQLite Approriate Query %@",formatedSql333);
sqlite3_stmt *sqlStatement3;
NSLog(@"This is the SearchedITem Variable %@" , SearchedItem);
if(sqlite3_prepare(db, formatedSql3333, -1, &sqlStatement3, NULL) != SQLITE_OK)
{
NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(db));
}else{
if(sqlite3_step(sqlStatement3)!=SQLITE_ERROR) {
NSLog(@"Entered the While tag");
// NSString *SearchedItem = cellText3;
NSLog(@"This is the SearchedITem Variable %@" , SearchedItem);
Author * author3 = [[Author alloc] init];
NSLog(@" Debug 1 ");
author3.name = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement3,0)];
NSLog(@" Debug 2 ");
NSLog(@"This is the author.name in the FavReal %@" , author3.name);
// / //author3.title = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement3,3)];
// NSLog(@"This is the author.TITLE in the FavReal %@" , author3.title);
author3.iDD = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement3, 5)];
author3.genre = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement3, 1)];
NSLog(@"This is the author.GENRE in the FavReal %@" , author3.genre);
NSLog(@"This is the authorName before %@", authorNAme);
NSLog(@"This is the authorName2 before %@", authorNAme2);
author3.audioAmer = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement3, 7)];
author3.audioBrit = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement3, 8)];
authorNAme = author3.genre;
authorNAme2 = author3.name;
AmericanAudio = author3.audioAmer;
BritishAudio = author3.audioBrit;
iDtoTake = author3.iDD;
// NSLog(@"This is the authorName after %@", authorNAme);
// NSLog(@"This is the authorName2 after %@", authorNAme2);
NSLog(@"This is the idToTake in FavrealIphone %@", iDtoTake);
// author3 = [theFav objectAtIndex:indexPath.row];
// [theFav addObject:author3];
// NSLog(@"Before the break");
// NSLog(@"Before the animation part");
[self.navigationController pushViewController:vc4 animated:true];
// NSLog(@"Passed the should animate part");
// sqlite3_close(db2);
//break;
NSLog(@"After the break");
sqlite3_finalize(sqlStatement3);
}
}
}
// sqlite3_close(db2);
}
@catch (NSException *exception) {
NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(db));
}
@finally {
NSLog(@"The database should NOT be closed here");
}
}
使用调试器时,我注意到调试器到达以下行
author3.audioAmer = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement3, 7)];
author3.audioBrit = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement3, 8)];
如果我发表评论,那么这个错误就会消失,但我需要它,所以任何人都面临任何类似的问题? 谢谢