J. *_*fer 11
它可以有像'/'这样的字符吗?
所有示例都来自在Linux上运行的SQlite 3.5.9.
如果用双引号括住列名称,则可以:
> CREATE TABLE test_forward ( /test_column INTEGER );
SQL error: near "/": syntax error
> CREATE TABLE test_forward ("/test_column" INTEGER );
> INSERT INTO test_forward("/test_column") VALUES (1);
> SELECT test_forward."/test_column" from test_forward;
1
Run Code Online (Sandbox Code Playgroud)
也就是说,你可能不应该这样做.
以下答案基于 SQLite 源代码,主要依赖于文件parse.y(柠檬解析器的输入)。
CREATE TABLE语句中列名和表名允许的一系列字符是
'- 任何类型的转义字符串(甚至关键字)INDEXED因为它是非标准的JOIN我不知道的原因关键字。SELECT语句中结果列允许的一系列字符是
AS让我们看看CREATE TABLE列的语法
// The name of a column or table can be any of the following:
//
%type nm {Token}
nm(A) ::= id(X). {A = X;}
nm(A) ::= STRING(X). {A = X;}
nm(A) ::= JOIN_KW(X). {A = X;}
Run Code Online (Sandbox Code Playgroud)深入挖掘,我们发现
// An IDENTIFIER can be a generic identifier, or one of several
// keywords. Any non-standard keyword can also be an identifier.
//
%type id {Token}
id(A) ::= ID(X). {A = X;}
id(A) ::= INDEXED(X). {A = X;}
Run Code Online (Sandbox Code Playgroud)
“通用标识符”听起来很陌生。tokenize.c然而,快速浏览一下定义
/*
** The sqlite3KeywordCode function looks up an identifier to determine if
** it is a keyword. If it is a keyword, the token code of that keyword is
** returned. If the input is not a keyword, TK_ID is returned.
*/
/*
** If X is a character that can be used in an identifier then
** IdChar(X) will be true. Otherwise it is false.
**
** For ASCII, any character with the high-order bit set is
** allowed in an identifier. For 7-bit characters,
** sqlite3IsIdChar[X] must be 1.
**
** Ticket #1066. the SQL standard does not allow '$' in the
** middle of identfiers. But many SQL implementations do.
** SQLite will allow '$' in identifiers for compatibility.
** But the feature is undocumented.
*/
Run Code Online (Sandbox Code Playgroud)
有关标识符字符的完整映射,请参阅tokenize.c.
目前还不清楚 a 的可用名称是什么result-column(即在SELECT语句中分配的列名或别名)。parse.y在这里再次有帮助。
// An option "AS <id>" phrase that can follow one of the expressions that
// define the result set, or one of the tables in the FROM clause.
//
%type as {Token}
as(X) ::= AS nm(Y). {X = Y;}
as(X) ::= ids(Y). {X = Y;}
as(X) ::= . {X.n = 0;}
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
28116 次 |
| 最近记录: |