问题
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