2017-03-22 106 views
0

请帮助我,当我运行我的应用程序使用理念SQLiteException:近“零”:语法错误(代码1):在编译:CREATE TABLE

在这里,我得到这个错误是错误的屏幕

http://prntscr.com/en3lcu

这里是)的部分代码,其中创建表

private String getTableDDL(final Class<? extends GlassContract.Table> table) { 
    return getTableDDL(table, GlassContract.getTableName(table)); 
} 

private String getTableDDL(final Class<? extends GlassContract.Table> table, String tableName) { 
    final StringBuilder sql = new StringBuilder(128); 
    sql.append("create table ").append(tableName).append(" ("); 
    for (final Field field : table.getFields()) { 
     if (field.getName().startsWith("_") || field.isAnnotationPresent(Deprecated.class)) 
      continue; 
     try { 
      sql.append(field.get(null)); 
     } catch (Exception ignore) { 
     } 
     try { 
      final Field type = table.getDeclaredField("_SQL_" + field.getName() + "_TYPE"); 
      sql.append(' ').append(type.get(null)); 
     } catch (Exception ignore) { 
      sql.append(" TEXT"); 
     } 
     sql.append(','); 
    } 

    try { 
     final Field type = table.getDeclaredField("_PK_COMPOSITE"); 
     sql.append("PRIMARY KEY(").append(type.get(null)).append(")"); 
     sql.append(','); 
    } catch (Exception ignore) { 
     // ignore 
    } 
    try { 
     final Field type = table.getDeclaredField("_UNIQUE_COMPOSITE"); 
     sql.append("UNIQUE(").append(type.get(null)).append(")"); 
     sql.append(','); 
    } catch (Exception ignore) { 
     // ignore 
    } 

    sql.setLength(sql.length() - 1); // chop off last comma 

    sql.append(')'); 
    Log.v(TAG, "DDL for " + table.getSimpleName() + ": " + sql); 
    return sql.toString(); 
} 

我,请帮助我,因为我打破了我的头)

+1

请问题的体发布错误消息。 – Compass

+0

getTableDDL()实际返回什么? –

+0

你根本不能使用保留关键字'NULL'。 –

回答

0

你真的想在表格中创建名为null的文本字段吗?

即使这个工作(和我不知道它),你复制这一点,创建两个同名的字段:null

0

CREATE TABLE语句中的第一个字段没有正确的名称(它是“null”)。这就是为什么它爆炸。

还有更多非法域名的字段。

相关问题