Этот код DBHelper работает во всех версиях, но не работает для Android версии 9
public class DBHelper extends SQLiteOpenHelper {
private static int db_version = 1;
private static String db_name = "quote_db";
private String db_path;
private SQLiteDatabase db;
private final Context con;
public DBHelper(Context con) {
super(con, db_name, null, db_version);
// TODO Auto-generated constructor stub
this.con = con;
db_path=con.getDatabasePath(db_name).getPath();
}
@Override
public void onCreate(SQLiteDatabase db) {
}
public void createDB() throws IOException {
this.getReadableDatabase();
copyDB();
Log.d("Database", "copy databse");
}
private boolean checkDB() {
SQLiteDatabase cDB = null;
try {
cDB = SQLiteDatabase.openDatabase(db_path+db_name, null,
SQLiteDatabase.OPEN_READWRITE);
} catch (SQLiteException e) {
}
if (cDB != null) {
cDB.close();
}
return cDB != null ? true : false;
}
private void copyDB() throws IOException {
InputStream inputFile = con.getAssets().open(db_name);
String outFileName = db_path + db_name;
OutputStream outFile = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = inputFile.read(buffer)) > 0) {
outFile.write(buffer, 0, length);
}
outFile.flush();
outFile.close();
inputFile.close();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS var_guj");
db.execSQL("DROP TABLE IF EXISTS var_eng");
onCreate(db);
Log.d("DB Upgrade", "Yes Upgrade");
}
//get category list from database
public Cursor get_categorydatabyid(String colum_name,int cateoryId) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = null;
try {
cursor = db.rawQuery("SELECT id,date,month,"+colum_name+",day FROM quote where category_id="+cateoryId+" ORDER BY id",null);
if (cursor != null) {
cursor.moveToFirst();
db.close();
return cursor;
}
} catch (Exception e) {
db.close();
Log.d("Error-", ""+e);
Toast.makeText(con, "Compai-" + e, Toast.LENGTH_LONG).show();
}
cursor.close();
db.close();
return cursor;
}
public int getmaxid(int todate,int tomonth) {
int maxID = 0;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = null;
try {
cursor = db.rawQuery("SELECT id FROM quote WHERE date="+todate+" and month="+tomonth+"", null);
if (cursor != null) {
cursor.moveToFirst();
maxID = cursor.getInt(0);
db.close();
return maxID;
}
} catch (Exception e) {
db.close();
Log.d("Error-", ""+e);
Toast.makeText(con, "Compai-" + e, Toast.LENGTH_LONG).show();
}
cursor.close();
db.close();
return maxID;
}
}
Ошибка:
Compai-android.database.sqlite.SQLite Exception:no such table : quote(code 1 SQLITE_ERROR):,while compiling:SELECT id FROM quote WHERE date=14 and month=10