Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在sqlite中逃生?_Sqlite - Fatal编程技术网

如何在sqlite中逃生?

如何在sqlite中逃生?,sqlite,Sqlite,我在下面的代码中用反斜杠转义了两个分号。我在SQLite Database Brower 2.0 for Mac中执行这段代码。天气一直很冷。我猜这是因为一些语法问题 INSERT INTO question (QuestionId, QuestionText, AreaId, AnswerText) VALUES(6019, 'Math Functions', 6, " Added: 9/1/2011 The following is a listing of math functions

我在下面的代码中用反斜杠转义了两个分号。我在SQLite Database Brower 2.0 for Mac中执行这段代码。天气一直很冷。我猜这是因为一些语法问题

INSERT INTO question (QuestionId, QuestionText, AreaId, AnswerText)
VALUES(6019, 'Math Functions', 6, "
Added: 9/1/2011

The following is a listing of math functions available:

Power of:
double pow ( double, double )
Example:
double myvar = pow(2,4)\;
NSLog(@"%.f", myvar)\; //value is 16");

在SQL中,字符串总是用单引号分隔,而不是用双引号分隔

'Added: 9/1/2011

The following is a listing of math functions available:
[...]'
除了这些单引号(甚至分号)外,不会转义任何字符,这是通过加倍来实现的:

SELECT 'That''s not exactly what I''m looking for...';

(这意味着只有一个单引号的字符串在SQL中被编码为
'''

分号不是您的问题,
NSLog
调用中的双引号是:

NSLog(@"%.f", myvar)\; //value is 16"
       ^---^
加倍,SQLite会很高兴:

NSLog(@""%.f"", myvar)\; //value is 16"
或者你可以在整件事上使用单引号:

INSERT INTO question (QuestionId, QuestionText, AreaId, AnswerText)
VALUES(6019, 'Math Functions', 6, '
Added: 9/1/2011

The following is a listing of math functions available:

Power of:
double pow ( double, double )
Example:
double myvar = pow(2,4)\;
NSLog(@"%.f", myvar)\; //value is 16');

单引号是SQL字符串的标准,但SQLite允许您对字符串使用单引号或双引号。

是的,但这显然只是对SQL语句的一种解释。双引号用于标识符,以防它们与关键字冲突。我认为这个答案对于任何语言的说话者都更有用。谢谢