我正在尝试在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) {
}
}
答案 0 :(得分:4)
在创建表之后,您的TABLE_EVENTS_COLLECTION为空,没有表名。
std::wstring GetLastExtension(const std::wstring &fileName)
{
auto pos = fileName.rfind(L".");
if (pos == std::wstring::npos)
pos = -1;
return std::wstring(fileName.begin() + pos, fileName.end());
}