I have a problem with SQLiteAssetHelper (https://github.com/jgilfelt/android-sqlite-asset-helper): I cant open the tables in my database correctly.
我有一个问题SQLiteAssetHelper(https://github.com/jgilfelt/android-sqlite-asset-helper):我无法正确打开数据库中的表。
The database is made using sqlitebrowser.
I have a database with two tables filled with strings which I want to access with a Cursor, but when I try to access them both, it gives me an error:
该数据库使用sqlitebrowser制作。我有一个数据库,其中有两个表填充了字符串,我想用Cursor访问它,但是当我尝试访问它们时,它给了我一个错误:
android.database.sqlite.SQLiteException: no such table: Verbs (code 1): , while compiling: SELECT LatinVerbs FROM Verbs WHERE _rowid_=?
My database contract:
我的数据库合同:
import android.provider.BaseColumns;
public class DatabaseContract {
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "verbtable.db";
private static final String TEXT_TYPE = " TEXT";
private static final String COMMA_SEP = ",";
private DatabaseContract(){}
public static abstract class Table1 implements BaseColumns{
public static final String TABLE_NAME = "Verbs";
public static final String COLUMN_NAME_TITLE_COL1 = "LatinVerbs";
public static final String COLUMN_NAME_TITLE_COL2 = "Translation";
public static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + TABLE_NAME + " (" +
_ID + " INTEGER PRIMARY KEY," +
COLUMN_NAME_TITLE_COL1 + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_TITLE_COL2 + TEXT_TYPE + COMMA_SEP +
" )";
public static final String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS " + TABLE_NAME;
}
public static abstract class Table2 implements BaseColumns{
public static final String TABLE_NAME = "Structure";
public static final String COLUMN_NAME_TITLE_COL1 = "infinitive";
public static final String COLUMN_NAME_TITLE_COL2 = "pers_id";
public static final String COLUMN_NAME_TITLE_COL3 = "ind_praes_act";
public static final String COLUMN_NAME_TITLE_COL4 = "ind_praes_pass";
public static final String COLUMN_NAME_TITLE_COL5 = "ind_impf_act";
public static final String COLUMN_NAME_TITLE_COL6 = "ind_impf_pass";
public static final String COLUMN_NAME_TITLE_COL7 = "ind_fut_act";
public static final String COLUMN_NAME_TITLE_COL8 = "ind_fut_pass";
public static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + TABLE_NAME + " (" +
_ID + " INTEGER PRIMARY KEY," +
COLUMN_NAME_TITLE_COL1 + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_TITLE_COL2 + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_TITLE_COL3 + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_TITLE_COL4 + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_TITLE_COL5 + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_TITLE_COL6 + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_TITLE_COL7 + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_TITLE_COL8 + TEXT_TYPE + COMMA_SEP +
" )";
public static final String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS " + TABLE_NAME;
}
}
My Cursors:
Cursor c = db.query(DatabaseContract.Table1.TABLE_NAME, columns, "_rowid_=?", selectionArgsRoot, null, null, null);
int index = c.getColumnIndexOrThrow(columns[0]);
c.moveToFirst();
do {
rootResult = c.getString(index);
} while (c.moveToNext());
c.close();
c = db.query(DatabaseContract.Table2.TABLE_NAME, columnSuffix, "pers_id=?", selectionArgsSuffix, null, null, null);
index = c.getColumnIndexOrThrow(columnSuffix[0]);
c.moveToFirst();
do{
suffix = c.getString(index);
}while(c.moveToNext());
c.close();
I tried to update the database version and restarted the emulator I was running my code on, but the error still remains.
我试图更新数据库版本并重新启动我运行我的代码的模拟器,但错误仍然存在。
2 个解决方案
#1
0
Have you ever run the program with the database creation before? If you have, you will need to increment your database version number. This has to be done when you make additions.
您以前是否曾使用数据库创建程序运行该程序?如果有,则需要增加数据库版本号。这需要在添加时完成。
You can also try uninstalling the app in the emulator and re-running a fresh install.
您还可以尝试在模拟器中卸载应用程序并重新运行全新安装。
#2
0
Both the tables aren't created.
In facts, you are adding an extra comma after the last column, on each table.
这两个表都没有创建。实际上,您在每个表的最后一列之后添加了一个额外的逗号。
Here:
COLUMN_NAME_TITLE_COL2 + TEXT_TYPE + COMMA_SEP +
" )";
And here:
COLUMN_NAME_TITLE_COL8 + TEXT_TYPE + COMMA_SEP +
" )";
These lines should actually be:
这些行实际上应该是:
COLUMN_NAME_TITLE_COL2 + TEXT_TYPE + ")";
And:
COLUMN_NAME_TITLE_COL8 + TEXT_TYPE + ")";
Respectively
#1
0
Have you ever run the program with the database creation before? If you have, you will need to increment your database version number. This has to be done when you make additions.
您以前是否曾使用数据库创建程序运行该程序?如果有,则需要增加数据库版本号。这需要在添加时完成。
You can also try uninstalling the app in the emulator and re-running a fresh install.
您还可以尝试在模拟器中卸载应用程序并重新运行全新安装。
#2
0
Both the tables aren't created.
In facts, you are adding an extra comma after the last column, on each table.
这两个表都没有创建。实际上,您在每个表的最后一列之后添加了一个额外的逗号。
Here:
COLUMN_NAME_TITLE_COL2 + TEXT_TYPE + COMMA_SEP +
" )";
And here:
COLUMN_NAME_TITLE_COL8 + TEXT_TYPE + COMMA_SEP +
" )";
These lines should actually be:
这些行实际上应该是:
COLUMN_NAME_TITLE_COL2 + TEXT_TYPE + ")";
And:
COLUMN_NAME_TITLE_COL8 + TEXT_TYPE + ")";
Respectively