我在将我的文本字段电子邮件值与 sqlite 数据库中的值进行比较时遇到问题。如果两个值相同,则会显示“数据库中已存在电子邮件”的警报框。为此,我创建了一个名为 findcontact 的函数,我通过单击按钮调用该函数。按钮单击方法正在工作,因为当我单击按钮时,按钮单击方法会生成我在 findContact 方法中编写的日志。
但对我来说问题是如果两封电子邮件都匹配,如何比较电子邮件并显示警报框
- (void) findContact:(NSString *) email{
const char *dbpath = [path UTF8String];
if (sqlite3_open(dbpath, &database) == SQLITE_OK){
NSString *querySQL = [NSString stringWithFormat: @"SELECT email FROM CONTACT WHERE email=\"%@\"",email];
NSLog(@" email = %@", querySQL);
const char *query_stmt = [querySQL UTF8String];
NSLog(@" char email = %s", query_stmt);
if (sqlite3_prepare_v2(database, query_stmt, -1, &init_statement, NULL) == SQLITE_OK){
if (sqlite3_step(init_statement) == SQLITE_ROW){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"email already exist in database" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK ", nil];
[alert show];
[alert release];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"email not exist" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK ", nil];
[alert show];
[alert release];
}
sqlite3_finalize(init_statement);
}
sqlite3_close(database);
}
}