当前位置: 动力学知识库 > 问答 > 编程问答 >

sql - Escape table name in SQLite?

问题描述:

I have table named References in SQLite, so I can't target it, it seems. SQLite studio I use to edit databases throws an error.

Is there a way to escape database name?

The query is:

UPDATE References

SET DateTimeLastEdited = datetime('now', 'localtime')

WHERE NewsItemID = old.NewsItemID;

(This is part of the trigger I am making.)

网友答案:

You can escape table names with double quotes:

UPDATE "References" SET DateTimeLastEdited = datetime('now', 'localtime') WHERE NewsItemID = old.NewsItemID;

Depending on what you want to escape, you need to use different delimiters:

If you want to use a keyword as a name, you need to quote it. There are four ways of quoting keywords in SQLite:

'keyword' A keyword in single quotes is a string literal.

"keyword" A keyword in double-quotes is an identifier.

[keyword] A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility.

`keyword` A keyword enclosed in grave accents (ASCII code 96) is an identifier. This is not standard SQL. This quoting mechanism is used by MySQL and is included in SQLite for compatibility.

From SQLite documentation

分享给朋友:
您可能感兴趣的文章:
随机阅读: