简体   繁体   English

在Objective-C的varchar字段上使用WHERE语句的sqlite问题

[英]sqlite issue using WHERE statement on a varchar field in Objective-C

I have this sql statement SELECT * FROM Language WHERE LanguageCode=? 我有这个sql语句SELECT * FROM Language WHERE LanguageCode=? where LanguageCode is a varchar(2). 其中LanguageCode是varchar(2)。

When I use sqlite3-prepare-v2 on that statement I got SQLITE_ERROR but if I use SELECT * FROM Language WHERE LanguageID=? 当我在该语句上使用sqlite3-prepare-v2时,出现SQLITE_ERROR,但如果使用SELECT * FROM Language WHERE LanguageID=? where LanguageID is the primary key numeric identity field the statement compiles just fine. 其中LanguageID是主键数字标识字段,该语句可以正常编译。

Is there any issue filtering by a varchar field using WHERE statement? 使用WHERE语句通过varchar字段过滤是否存在任何问题?

Thanks 谢谢

I think there should be no issue with the where statement by using a varchar field. 我认为使用varchar字段的where语句应该没有问题。 Maybe you are having problem with passing the parameter. 也许您在传递参数时遇到问题。 Try to print to NSLog and see the statement that is executed, and execute it with the sqlite command prompt to see if you have return values. 尝试打印到NSLog并查看已执行的语句,然后使用sqlite命令提示符执行该语句以查看是否具有返回值。

Be sure your ? 确定你的? is wrapped in single quotes. 用单引号引起来。

SQLite should also give you an error string which tell you why there is an error. SQLite还应该给您一个错误字符串,告诉您为什么会有错误。

Try to call sqlite3_errmsg and check the error string returned from that call. 尝试调用sqlite3_errmsg并检查该调用返回的错误字符串。 It should give you a more detailed information about what went wrong. 它应该为您提供有关发生问题的更详细的信息。

Claus 克劳斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM