0
I have a problem in my app, the sqlite apparently is not running. All functions related to it are not working, in this application I use some external mysql based functions these are "ok".
See below how is the construction of my base:
package com.db;
import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DbHelper extends SQLiteOpenHelper {
static final String TAG = "DbHelper";
static final String DB_NAME = "storefinder_db";
static final int DB_VERSION = 1;
static Activity activity;
public DbHelper(Activity act) {
super(act.getApplicationContext(), DB_NAME, null, DB_VERSION);
activity = act;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE IF NOT EXISTS categories("
+ "category_id INTEGER PRIMARY KEY,"
+ "category TEXT,"
+ "category_icon TEXT,"
+ "created_at INTEGER, "
+ "is_deleted INTEGER, "
+ "updated_at INTEGER "
+ ");");
db.execSQL("CREATE TABLE IF NOT EXISTS stores("
+ "store_id INTEGER PRIMARY KEY,"
+ "category_id NTEGER, "
+ "created_at INTEGER, "
+ "distance TEXT, "
+ "email TEXT, "
+ "featured INTEGER, "
+ "icon_id INTEGER, "
+ "lat TEXT, "
+ "lon TEXT, "
+ "phone_no TEXT, "
+ "rating_count TEXT, "
+ "rating_total TEXT, "
+ "sms_no TEXT, "
+ "store_address TEXT, "
+ "store_desc TEXT, "
+ "store_name TEXT, "
+ "is_deleted INTEGER, "
+ "updated_at INTEGER, "
+ "website TEXT "
+ ");");
db.execSQL("CREATE TABLE IF NOT EXISTS reviews("
+ "review_id INTEGER PRIMARY KEY,"
+ "created_at TEXT,"
+ "first_name TEXT,"
+ "last_name TEXT,"
+ "review TEXT,"
+ "store_id INTEGER,"
+ "updated_at INTEGER,"
+ "is_deleted INTEGER, "
+ "user_id INTEGER"
+ ");");
db.execSQL("CREATE TABLE IF NOT EXISTS ratings("
+ "rating_id INTEGER PRIMARY KEY," //AUTOINCREMENT
+ "created_at INTEGER,"
+ "rating TEXT,"
+ "store_id INTEGER,"
+ "updated_at INTEGER,"
+ "is_deleted INTEGER, "
+ "user_id INTEGER"
+ ");");
db.execSQL("CREATE TABLE IF NOT EXISTS photos("
+ "photo_id INTEGER PRIMARY KEY," //AUTOINCREMENT
+ "created_at INTEGER,"
+ "photo_url TEXT,"
+ "store_id INTEGER,"
+ "thumb_url TEXT,"
+ "is_deleted INTEGER, "
+ "updated_at INTEGER"
+ ");");
db.execSQL("CREATE TABLE IF NOT EXISTS news("
+ "news_id INTEGER PRIMARY KEY," //AUTOINCREMENT
+ "created_at INTEGER,"
+ "news_content TEXT,"
+ "news_title TEXT,"
+ "news_url TEXT,"
+ "photo_url TEXT,"
+ "is_deleted INTEGER, "
+ "updated_at INTEGER"
+ ");");
db.execSQL("CREATE TABLE IF NOT EXISTS favorites("
+ "favorite_id INTEGER PRIMARY KEY AUTOINCREMENT," //AUTOINCREMENT
+ "store_id INTEGER"
+ ");");
db.execSQL("CREATE TABLE IF NOT EXISTS pedidos("
+ "pedidos_id INTEGER PRIMARY KEY AUTOINCREMENT," //AUTOINCREMENT
+ "pedidos_email TEXT,"
+ "pedidos_nome TEXT,"
+ "user_id INTEGER"
+ ");");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS categories");
db.execSQL("DROP TABLE IF EXISTS favorites");
db.execSQL("DROP TABLE IF EXISTS stores");
db.execSQL("DROP TABLE IF EXISTS reviews");
db.execSQL("DROP TABLE IF EXISTS ratings");
db.execSQL("DROP TABLE IF EXISTS photos");
db.execSQL("DROP TABLE IF EXISTS news");
db.execSQL("DROP TABLE IF EXISTS favorites");
db.execSQL("DROP TABLE IF EXISTS pedidos");
}
}
It was working properly until I performed a name refactore on my project this morning. After that it stopped working.
The app is running normally and without any logcath however the functions that require sqlite do not work.
I’ve checked all the places that had the old name of the application and fixed them all, yet still nothing working.
Does anyone have any idea what it might be?
I’m not sure, I could be wrong, but the
onCreate
is only called when the schema is first created, no more. Would that be the problem? Or would it be any access to these tables are not working, while recovering thereadableDatabase
orwritetableDatabase
? Another thing I realized is that inonUpgrade
, you end up dropping the tables, but don’t recreate them again, that’s right?– Wakim
Try deleting the data from the app or uninstall it and try again.
– Fabiano Araujo