4
我想在數據庫中搜索employeeName我的查詢是可以的,但是當它綁定時它會給出NScFstring錯誤。 請幫忙。在iPhone中的sqlite3數據庫中搜索
代碼:
sqlite3 *database;
self.array_EmployeeSearch = nil;
[self.array_EmployeeSearch release];
self.array_EmployeeSearch = [[NSMutableArray alloc]init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *path = [documentDirectory stringByAppendingPathComponent:@"Employee.sqlite"];
if(sqlite3_open([path UTF8String], &database) == SQLITE_OK){
NSString *str_Query = [NSString stringWithFormat:@"select EmpName from Employee where EmpName like '%@%@%@'",@"%",str_Emp,@"%"];
const char *sql = [str_Query UTF8String];
sqlite3_stmt *statement;
if(sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK){
while (sqlite3_step(statement) == SQLITE_ROW) {
NSMutableDictionary *dict_Employee;
dict_Employee = [[NSMutableDictionary alloc]init];
[dict_Employee setValue:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 2)] forKey:@"ID"];
}
}
}
- >這一行就崩潰....
[dict_Employee setValue:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 3)] forKey:@"EmpServerID"];
[dict_Employee setValue:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 4)] forKey:@"Name"];
[dict_Employee setValue:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 5)] forKey:@"UserName"];
[dict_Employee setValue:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 6)] forKey:@"Password"];
[dict_Employee setValue:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 7)] forKey:@"Email"];
[dict_Employee setValue:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 8)] forKey:@"Phone"];
[dict_Employee setValue:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 9)] forKey:@"Status"];
NSString *isDelete;
isDelete = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 10)];
if ([isDelete isEqualToString:@"False"]) {
[array_EmployeeSearch addObject:dict_Employee];
}
dict_Employee = nil;
[dict_Employee release];
}
}
sqlite3_finalize(statement);
}
else {
sqlite3_close(database);
NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
}