难度逃脱单引号字符,而SQLite数据库插入 [英] Difficulty in escaping single quote character while SQLite database insertion

查看:317
本文介绍了难度逃脱单引号字符,而SQLite数据库插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要插入数据库中的某些文本可能包含单引号和双引号字符。

I have to insert certain text in database which may contain characters with single quotes and double quotes.

有关如:LUMIX或类似的维杰的

我已经成功地躲过了双引号是这样的:

I have successfully escaped the double quotes like this:

if(fdata.search('"') != -1) {


fdata = fdata.replace(/(['"])/g, "\\$1");



}  

但我不理解如何逃脱的单引号。如果没有逃逸单引号SQLite是不接受的数据。如何解决这个问题?在此先感谢!

But I am not understanding how to escape the single quotes. Without escaping the single quotes SQLite is not accepting the data. How to solve the issue? Thanks in advance!

推荐答案

使用参数,那么你不需要逃避什么:

Use parameters, then you don't need to escape anything:

db.execute('INSERT INTO MyTable(ID, Name) VALUES(?, ?)', 123, name);

这篇关于难度逃脱单引号字符,而SQLite数据库插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆