sqlite - how to escape semicolons in a string in an insert statement [closed]

我的梦境 提交于 2020-02-04 14:39:19

问题


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

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.

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'');

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!

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.


回答1:


This works fine:

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?

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



来源:https://stackoverflow.com/questions/10728903/sqlite-how-to-escape-semicolons-in-a-string-in-an-insert-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!