如何清理 ODBC 数据库输入?
我目前使用 MySql,但更喜欢 ODBC 解决方案以使其面向未来。
在将用户输入传递到 ODBC 数据库之前如何对其进行清理?
而且,当我这样做时,我将字符串用双引号括起来,例如“INSERT INTO VALUES(description) ""` - 但是如果文本本身包含双引号怎么办?
I currently use MySql, but would prefer an ODBC solution to make it future proof.
How do I sanitize user input before passing it to an ODBC database ?
And, while I'm at it, I wrap my string in double quotes, e.g. "INSERT INTO VALUES(description) ""` - but what if the text itself contains a double quote?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用像这样的参数化 SQL 语句
。
查看 embarcadero 上的这篇文章,了解有关如何使用参数的更多信息
在查询中使用参数。
Try using a parametrized SQL sentence
like this.
check this article from embarcadero for more info about how use parameters
Using Parameters in Queries.
如果可以的话,使用hibernate,或许可以通过delphi 中的RMI。尽管它以 java 为中心,但它几乎将程序员与底层数据库完全隔离,并处理您提到的问题以及更多问题。
顺便说一句,要回答您关于双引号的问题,要保存包含双引号的值,将它们转义为双双引号,例如
将保存为
Use hibernate if you can, perhaps via RMI from delphi. Although it's java centric, it almost completely insulates the programmer from the underlying DB, and handles the issues you've mentioned and a whole lot more.
btw, to answer your question re double quotes, to save a value which contains double quotes, escape them as doubled double quotes, eg
would be saved as