java 从列名包含空格的 SQLite 读取数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14019275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 14:46:23  来源:igfitidea点击:

Read data from SQLite where column name contains spaces

javaandroidsqlite

提问by Vijay YD

I am having a coulmn name called "condition name" (.sql file has been generated from server)

我有一个名为“条件名称”的 coulmn 名称(.sql 文件已从服务器生成)

But in android I am getting following exception while reading data from that table.

但是在android中,我在从该表中读取数据时遇到了以下异常。

12-24 14:34:00.870: W/System.err(269): android.database.sqlite.SQLiteException: no such column: condition: ,

12-24 14:34:00.870:W/System.err(269):android.database.sqlite.SQLiteException:没有这样的列:条件:,

while compiling:

编译时:

SELECT condition, category, subcategory,condition name, local path, remote path, title, content_type FROM library WHERE category = ?

SELECT 条件、类别、子类别、条件名称、本地路径、远程路径、标题、内容类型 FROM 库 WHERE category = ?

Its not recognizing whole table name and breaking at space. if you have any ideas please assist me.

它无法识别整个表名并在空格处中断。如果您有任何想法,请帮助我。

回答by CL.

For quoting identifiers like table/column names, SQLite supports back ticks for compatibility with MySQL, and square brackets for compatibility with SQL Server, but the portable way is to use double quotes:

对于引用表/列名称等标识符,SQLite 支持反引号以与 MySQL 兼容,并支持方括号以与 SQL Server 兼容,但可移植的方式是使用双引号:

SELECT "condition name" FROM library

(Single quotes would be used for string values.)

(单引号将用于字符串值。)

回答by Jorgesys

Use single quotes

使用单引号

SELECT 'condition name' FROM library

or double quotes

或双引号

SELECT "condition name" FROM library


in some cases the name of the table can contain space and even aphostrope, like:

在某些情况下,表的名称可以包含空格甚至 aphostrope,例如:

SELECT condition's name FROM library

in this case replace 'with ''in the name of the table:

在这种情况下'''在表名中替换为:

SELECT 'condition''s' name FROM library