android.database.sqlite.SQLiteException:near“(”:syntax error(code 1):

时间:2015-10-16 13:14:45

标签: android mysql sqlite

我想在DB中创建表,但我得到$xml_src = 'feed.xml'; $document = new DOMDocument(); $document->load($xml_src); $xpath = new DOMXpath($document); $query = '//property[@name = "item"]'; $entries = $xpath->query($query); foreach ($entries as $entry) { if(array_key_exists($entry->nodeValue,$replacements)){ $entry->previousSibling->previousSibling->nodeValue = $replacements[$entries->nodeValue]; } }

这是我创建表的SQL请求:

SQLiteException

错误代码:

String SQL_CREATE_TEMP_CATALOG_CAR_TABLE  = "CREATE TABLE temp_dn_catalog_car (\n"+
        "  catalog_car_id INTEGER PRIMARY KEY AUTOINCREMENT(11) NOT NULL, \n"+
        "  model_id INTEGER KEY(11) NOT NULL, \n"+
        "  generation_id INTEGER KEY(11) NOT NULL, \n"+
        "  body_type_id INTEGER KEY(11) NOT NULL, \n"+
        "  modification_id INTEGER KEY(11) NOT NULL, \n"+
        "  begin_year INTEGER(11) NOT NULL, \n"+
        "  end_year INTEGER(11) NOT NULL);\n";

2 个答案:

答案 0 :(得分:3)

String SQL_CREATE_TEMP_CATALOG_CAR_TABLE  = "CREATE TABLE temp_dn_catalog_car (+
    "  catalog_car_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, +
    "  model_id INTEGER KEY(11) NOT NULL, +
    "  generation_id INTEGER KEY(11) NOT NULL, +
    "  body_type_id INTEGER KEY(11) NOT NULL, +
    "  modification_id INTEGER KEY(11) NOT NULL, +
    "  begin_year INTEGER(11) NOT NULL, +
    "  end_year INTEGER(11) NOT NULL); ";

答案 1 :(得分:1)

删除\n个字符,将AUTOINCREMENT(11)移至AUTOINCREMENT

String SQL_CREATE_TEMP_CATALOG_CAR_TABLE  = 
       "CREATE TABLE temp_dn_catalog_car (catalog_car_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,model_id INTEGER NOT NULL, generation_id INTEGER  NOT NULL, body_type_id INTEGER NOT NULL, modification_id INTEGER NOT NULL, begin_year INTEGER NOT NULL, end_year INTEGER NOT NULL); ";

<强> SqlFiddleDemo