sqlite-如何在插入语句中转义字符串中的分号 [英] sqlite - how to escape semicolons in a string in an insert statement

查看:594
本文介绍了sqlite-如何在插入语句中转义字符串中的分号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:问题已解决...与问题的措辞无关...很抱歉浪费时间:-\

Problem solved... and unrelated to the phrasing of the question... sorry for the waste of time :-\

我意识到通常当iOS和Android之类的平台(如果您正在编写手机应用程序)具有用于此目的的工具时,您希望使用某种抽象层而不为SQLite编写自己的插入语句。

I realize that typically you'd want to use some sort of abstraction layer and not write your own insert statements for SQLite when platforms like iOS and Android (if you're writing phone apps) have tools for this.

不幸的是,由于我可以使用的工具以及所涉及的不同平台/系统的数量,因此我实际上并不是一个选择。

Unfortunately, I'm in a situation where this isn't really an option due to the tools I have at my disposal and the number of different platforms / systems involved.

我的问题确实很简单,但是我似乎无法通过google,stackoverflow等找到答案……我只是想使用Webkit的 executeSql命令来执行以下查询:

The problem I have is REALLY simple, but I can't seem to find an answer via google, stackoverflow, etc... I simply want to do something like the following query, using Webkit's "executeSql" command:

INSERT INTO someTable VALUES (''some string'', ''some string with a semicolon; in it'');

问题是-除非我删除分号,否则此操作将失败。 (注意:加倍的单引号是因为发送到Webkit的executeSql命令的语句需要转义。也许这是问题的一部分?)

Problem is - this fails unless I remove the semicolon. (Note: the doubled up single quotes are because the statement being sent to webkit's executeSql command needs to be escaped.. maybe this is part of the problem?)

如果我从第二个字段的字符串中删除分号-语句运行正常...

If I take the semicolon out of the string in the second field - the statement runs fine...

如果我用反斜杠转义了分号-那就没有运气了!

If I escape the semicolon with a backslash - no luck!

关于sqlite的文档充其量看起来平庸,而我一直无法弄清楚我应该如何逃避分号……任何帮助将不胜感激。

Documentation for sqlite seems mediocre at best, and I've been unable to figure out how I'm supposed to escape that semicolon... Any help would be greatly appreciated.

推荐答案

这很好:

CREATE Table DummyTable(FirstCol VARCHAR(25), SecondCol VARCHAR(25));
INSERT INTO DummyTable VALUES ('This is a test', 'This is test two; OK?');
SELECT * FROM DummyTable;

-- output
FirstCol                  SecondCol
========================= ========================= 
This is a test            This is test two; OK?

问题似乎是SQL语句中的引号加倍。

The problem seems to be the doubling of quotes in your SQL statement.

这篇关于sqlite-如何在插入语句中转义字符串中的分号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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