Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.)

like image 546
mrmut Avatar asked Jan 19 '16 18:01

mrmut


People also ask

How do I escape in SQLite?

The SQLite quote() function allows you to escape a string so that it's suitable for inclusion in an SQL statement. Strings are surrounded by single-quotes with escapes on interior quotes. BLOBs are encoded as hexadecimal literals.

What is wildcard in SQLite?

SQLite provides two wildcards for constructing patterns. They are percent sign % and underscore _ : The percent sign % wildcard matches any sequence of zero or more characters. The underscore _ wildcard matches any single character.

Is null or empty in SQLite?

SQLite Null ValuesIf table has Null value, then it will display as blank. The Null value represents represent the absence of a value or empty or no value. By using the NULL keyword, we can represent NULL or empty string values.

Can SQLite column names have spaces?

Blanks spaces are restricted in the naming convention of the database object's name and column name of the table.


1 Answers

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

like image 108
bpoiss Avatar answered Oct 11 '22 08:10

bpoiss