gpt4 book ai didi

android - 在 sqlite (android) 上创建表时收到错误

转载 作者:搜寻专家 更新时间:2023-11-01 07:53:21 25 4
gpt4 key购买 nike

我正在尝试在 sqlite 上创建一个表。我已经创建了 30 多个表,但是这个命令似乎不起作用。

private final String CREATE_TABLE_EVENTS_COLLECTION = "create table " + TABLE_EVENTS_COLLECTION
+ "(" + COLUMN_ID + " integer primary key autoincrement," + COLUMN_EVENT_NAME + " text , "
+ COLUMN_TIMESTAMP + " integer , " + COLUMN_DETECTION_TIMESTAMP + " integer , "
+ COLUMN_RECEIVED_TIMESTAMP + " integer , " + COLUMN_SERVER_STATUS + " integer)";

这是我正在运行的命令:

database.execSQL(CREATE_TABLE_EVENTS_COLLECTION);

但是,我收到一个异常,看起来 TABLE_EVENTS_COLLECTION 是一个空字符串 - 但它不是。

android.database.sqlite.SQLiteException: near "(": syntax error (code 1): , while compiling: create table (id integer primary key autoincrement,event_name text , timestamp  integer , detection_timestamp  integer , received_timestamp  integer , server_status integer)

完整代码:

public class NSQLiteOpenHelper extends SQLiteOpenHelper {
private static final String TAG = NSQLiteOpenHelper.class.getSimpleName();

// Database
private static final String DATABASE_NAME = "db";
private static final int DATABASE_VERSION = 50;

// Tables
public static final String TABLE_NODES = "nodes";
public static final String TABLE_EVENTS_COLLECTION = "events_collection_log"; //Logging all the events received and sending it to the server.

// Columns - Common (TABLE NODES)
public static final String COLUMN_ID = "id";
public static final String COLUMN_PAGE_ID = "page_id";
public static final String COLUMN_TYPE = "type";
public static final String COLUMN_NEURA_ID = "neura_id";
public static final String COLUMN_NODE_DATA = "node_data";
public static final String COLUMN_SENT_TO_SERVER = "sent";
public static final String COLUMN_IMAGE_PATH = "image_path";
public static final String COLUMN_SERVER_STATUS = "server_status";
public static final String COLUMN_SERVER_RESPONSE_CODE = "server_response_code";
public static final String COLUMN_SERVER_RESPONSE_TIMESTAMP = "server_response_timestamp";
public static final String COLUMN_SERVER_LAST_UPDATE = "server_last_update";
public static final String COLUMN_PENDING = "pending";
public static final String COLUMN_AUTHENTICATION_URL = "auth_url";
public static final String COLUMN_VENDOR = "vendor";
public static final String COLUMN_NODE_IMAGE_SYNC_TO_SERVER = "image_sync_to_serve";
public static final String COLUMN_NODE_TYPE = "node_type";
public static final String COLUMN_RELATED_NODE_ID = "related_node_id";
public static final String COLUMN_IS_ME = "isMe";

// Columns (TABLE_DEVICES)
public static final String COLUMN_DEVICE_ID = "device_id";

// Columns (TABLE LIFELINE ITEMS)
public static final String COLUMN_TIMESTAMP = "timestamp";
public static final String COLUMN_DETECTION_TIMESTAMP = "detection_timestamp";
public static final String COLUMN_RECEIVED_TIMESTAMP = "received_timestamp";

public static final String COLUMN_EVENT_NAME = "event_name";

private final String CREATE_TABLE_NODES = "create table " + TABLE_NODES + "(" + COLUMN_ID
+ " integer primary key autoincrement, " + COLUMN_VENDOR + " text, " + COLUMN_NODE_TYPE
+ " text, " + COLUMN_PAGE_ID + " integer ," + COLUMN_TYPE + " integer ,"
+ COLUMN_NEURA_ID + " text UNIQUE ," + COLUMN_NODE_DATA + " text ," + COLUMN_PENDING
+ " integer, " + COLUMN_SENT_TO_SERVER + " integer, " + COLUMN_DEVICE_ID + " text, "
+ COLUMN_IMAGE_PATH + " text, " + COLUMN_NODE_IMAGE_SYNC_TO_SERVER + " integer, "
+ COLUMN_AUTHENTICATION_URL + " text, " + COLUMN_RELATED_NODE_ID + " text, "
+ COLUMN_SERVER_STATUS + " integer, " + COLUMN_SERVER_RESPONSE_CODE + " integer, "
+ COLUMN_SERVER_RESPONSE_TIMESTAMP + " integer, " + COLUMN_IS_ME + " integer, "
+ COLUMN_SERVER_LAST_UPDATE + " integer)";

private final String CREATE_TABLE_EVENTS_COLLECTION = "create table " + TABLE_EVENTS_COLLECTION
+ "(" + COLUMN_ID + " integer primary key autoincrement," + COLUMN_EVENT_NAME + " text , "
+ COLUMN_TIMESTAMP + " integer , " + COLUMN_DETECTION_TIMESTAMP + " integer , "
+ COLUMN_RECEIVED_TIMESTAMP + " integer , " + COLUMN_SERVER_STATUS + " integer)";

public NSQLiteOpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(CREATE_TABLE_NODES);
database.execSQL(CREATE_TABLE_EVENTS_COLLECTION);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}

}

最佳答案

your TABLE_EVENTS_COLLECTION is empty after create table there is no table name.

create table "Your_Table_Name"(id integer primary key autoincrement,event_name text , timestamp  integer , detection_timestamp  integer , received_timestamp  integer , server_status integer)

关于android - 在 sqlite (android) 上创建表时收到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31646436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com