【问题标题】:SQLite Syntax error while compiling: INSERT INTO [duplicate]编译时出现 SQLite 语法错误:INSERT INTO [重复]
【发布时间】:2018-04-10 13:57:26
【问题描述】:

我在执行 AsyncTask 时收到此 RuntimeException:

Caused by: android.database.sqlite.SQLiteException: near ",": syntax error: , while compiling: INSERT INTO 'infrastructure' (lift,name,type,status,_id) VALUES ('2130837612','none','-','2130837600',0),('2130837612','none','-','2130837600',1),('2130837612','none','-','2130837600',2),('2130837612','none','-','2130837600',3),('2130837612','none','-','2130837600',4),('2130837612','none','-','2130837600',5)

除 _id 之外的所有列都是“文本”,_id 是整数和主键。

这是崩溃的地方:

Cursor curtsr = db.rawQuery("SELECT COUNT(*) FROM 'Infrastructure'", null);
if (curtsr != null) {
    curtsr.moveToFirst();                      // Always one row returned.
    if (curtsr.getInt(0) == 0) {               // Zero count means empty table.
        String INSERT_INFRA_VALUES = "INSERT INTO 'Infrastructure' (lift,name,type,status,_id) VALUES ('2130837612','none','-','2130837600',0),('2130837612','none','-','2130837600',1),('2130837612','none','-','2130837600',2),('2130837612','none','-','2130837600',3),('2130837612','none','-','2130837600',4),('2130837612','none','-','2130837600',5)";
        db.execSQL(INSERT_INFRA_VALUES);
    }
    curtsr.close();
}

我找不到崩溃的原因。

在线 SQLite lint 工具 https://sqliteonline.com/ 没有抛出任何错误。

【问题讨论】:

  • 表名和列名不要使用单引号。我投票结束诸如简单的印刷错误之类的问题。
  • @GordonLinoff 从表名中删除引号不会改变任何事情。

标签: java android sqlite android-sqlite runtimeexception


【解决方案1】:

Comma-separated multiple VALUES insert 仅在 sqlite 3.7.11 中引入,您很可能在 device with older sqlite version 上运行。

【讨论】:

  • 嗯,这解释了很多。我正在使用 API 级别 15。3.7.11 适用于 API 16+
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-27
  • 1970-01-01
相关资源
最近更新 更多