【发布时间】:2011-08-05 07:06:27
【问题描述】:
我正在尝试开发一个可以与数据库一起使用的登录程序。我使用了一个表emplopyee,列有“Userid”、“Passwd”和“Name”(这三个都是'VARCHAR'类型)。在我的程序中,我添加了两个文本字段“用户名”和“密码”。我得到了“用户名”和“密码”值并将它们存储在两个全局对象(类型为“NSString”)中。
现在我想选择与给定的“Userid”和“Passwd”匹配的“Name”。
我出于上述原因使用的编码部分在这里:
sqlite3 *dB;
sqlite3_stmt *compiledStatement;
if(sqlite3_open([databasePath UTF8String], &dB)==SQLITE_OK){
const char *sql="Select Name from employee Where Userid=? , Passwd=?";
if(sqlite3_prepare_v2(dB, sql, -1, &compiledStatement, NULL)!=SQLITE_OK)
NSAssert1(0,@"Error while reading Employee Name -->%s',sqlite3_errmsg(dB));
}
sqlite3_bind_text(compiledStatement,1,[txt UTF8String],-1,SQLITE_TRANSIENT);
/*txt and txt1 are the global objects i told about they have the values of Userid and Passwd from the texxt fields respectively*/
sqlite3_bind_text(compiledStatement,2,[txt1 UTF8String],-1,SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3_step(compiledStatement))
txt3 =[[NSString alloc] initWithUTF8String:(char*)sqlite3_column_text(compiledStatement,0)];
else
NSAssert1(0, @"Error while getting the username '%s'", sqlite3_errmsg(dB));
sqlite3_reset(compiledStatement);
它在编译时没有错误,但应用程序无法运行,它在查询中显示一些错误(在运行时)。 如果您无法根据给定的数据弄清楚我会为您提供整个代码。
我在此处添加了错误详细信息:
如果我在选择查询中使用“,”(逗号),则会出现此错误:
*** 由于未捕获的异常而终止应用程序
'NSInternalInconsistencyException',原因:'读取员工姓名时出错 --> 'near ",": 语法错误''
当我在选择查询中使用“AND”时会发生这种情况:
*** 由于未捕获的异常而终止应用程序
'NSInternalInconsistencyException',原因:'获取用户名时出错'不是错误''
【问题讨论】: