Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid 2.3 Sqlite Troubles with while inserting
    primarykey
    data
    text
    <p>I've a straight forward question, I think I'm missing some point. My test app is being deployed on emulator, within an AVD with a virtual SD Card of 30megs. When I call the following from my main activity:</p> <pre><code>DatabaseManager.Initialize(this); DatabaseManager.getEntities(); </code></pre> <p>My app crashes and debugger says no such table ! The table <strong>ITEM</strong> is created in the onCreate() of my database helper and <strong>is</strong> correctly called (Step by step debug). What am I missing there ?</p> <p><strong>database manager</strong></p> <pre><code>public class DatabaseManager { public static final String ITEM_CONTACT = "CONT"; public static final String ITEM_FILE = "FILE"; public static final String ITEM_APP = "AAPP"; public static final String ITEM_OPT = "OPTS"; private static final String DATABASE_NAME = "androfast.sqlite3.db"; private static final Integer DATABASE_VERSION = 1; private static final String TABLE_ITEM = "ITEM"; private static final String TABLE_KEYWORD = "KEYWORD"; private static final String DATABASE_SCHEMA_FILE = "schema.sql"; public static final String ITEM_COLUMN_ID = "id"; public static final String ITEM_COLUMN_NAME = "name"; public static final String ITEM_COLUMN_PACKAGE = "pkg"; public static final String ITEM_COLUMN_TYPE = "kind"; public static final String ITEM_COLUMN_PRIORITY = "karma"; public static final String KEYWORD_COLUMN_ID = "id"; public static final String KEYWORD_COLUMN_VALUE = "word"; public static final String KEYWORD_COLUMN_PRIORITY = "karma"; private static SQLiteDatabase dbSqlite; private static DatabaseHelper dbHelper; private static Context context; public static void Initialize(Context ctx) throws IOException{ context = ctx; InputStream is = ctx.getAssets().open(DATABASE_SCHEMA_FILE); BufferedReader r = new BufferedReader(new InputStreamReader(is)); StringBuilder strQuery = new StringBuilder(""); String s; while ((s = r.readLine()) != null){ strQuery.append(s); } r.close(); dbHelper = new DatabaseHelper(ctx, DATABASE_NAME,null, DATABASE_VERSION, strQuery.toString()); dbSqlite = dbHelper.getWritableDatabase(); } public static SQLiteDatabase getSqliteDatabase(){ return dbSqlite; } public static void runQuery(String strQuery){ dbSqlite.execSQL(strQuery); } public static List&lt;Item&gt; getEntities(){ ArrayList&lt;Item&gt; items = new ArrayList&lt;Item&gt;(); Cursor cursor; dbSqlite.execSQL("INSERT INTO ITEM (name, pkg, kind) VALUES('Don Coreleone', 'life.thug.jail', 'CONT')"); dbSqlite.execSQL("INSERT INTO ITEM (name, pkg, kind) VALUES('slavery.png', 'life.thug.jail', 'FILE')"); dbSqlite.execSQL("INSERT INTO ITEM (name, pkg, kind) VALUES('Alcatraz', 'life.thug.jail', 'AAPP')"); dbSqlite.execSQL("INSERT INTO ITEM (name, pkg, kind) VALUES('BLUETOOTH', 'life.thug.jail', 'OPTS')"); dbSqlite.execSQL("INSERT INTO ITEM (name, pkg, kind) VALUES('Che Guevara', 'life.thug.jail', 'CONT')"); cursor = dbSqlite.query(TABLE_ITEM, null,null,null,null,null,null); if (cursor.moveToFirst()){ do{ Log.d("APP/DB", cursor.getString(cursor.getColumnIndex(ITEM_COLUMN_NAME))); }while(cursor.moveToNext()); } cursor.close(); return items; } } </code></pre> <p><strong>database helper</strong></p> <pre><code>public class DatabaseHelper extends SQLiteOpenHelper { private static final String LOG_TAG = "SQLiteOpenHelper"; private String dbCreateQuery; public DatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, String dbCreate) { super(context, name, factory, version); dbCreateQuery = dbCreate; } @Override public SQLiteDatabase getWritableDatabase() { return super.getWritableDatabase(); //To change body of overridden methods use File | Settings | File Templates. } @Override public SQLiteDatabase getReadableDatabase() { return super.getReadableDatabase(); //To change body of overridden methods use File | Settings | File Templates. } @Override public void close() { super.close(); //To change body of overridden methods use File | Settings | File Templates. } @Override public void onCreate(SQLiteDatabase sqLiteDatabase) { sqLiteDatabase.execSQL(dbCreateQuery); } @Override public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { Log.w(LOG_TAG,"Upgrading database from version " + i + " to version " + i1); // No need to do drops of tables, these must be included in the schema.sql file onCreate(sqLiteDatabase); } @Override public void onOpen(SQLiteDatabase db) { super.onOpen(db); } } </code></pre> <p>Thanks for your directions fellas</p> <p>Kind regards,</p> <p>Miloud B.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload