views:

25

answers:

2

Hi! I have next stuff:

    private static final String DB_NAME = "MyDebts.db";
 private static final String CREATE_DB_QUERY = 
  "CREATE TABLE " + Dao.CONTACTS_TABLE_NAME + " (ContactId varchar(64), Credit integer);\n" +
  "CREATE TABLE " + Dao.SETTINGS_TABLE_NAME + " (Name varchar(64), Value varchar(64));"
  ;
    @Override
     public void onCreate(SQLiteDatabase db) {
      db.execSQL(CREATE_DB_QUERY);
     }

As i see in debug mode db.execSql proceeds w/o any exceptions, but then in this code:

String lastStepIndexString = null;
  try {
   lastStepIndexString = SettingsDao.readSetting("last-step-index");
  } catch (Exception ex) {
   makeToast(ex.getMessage());
  }

catch()... is triggered by exception with message like 'There is no table with name "Preferences"' anyone can tell me the problem? My head is bursts=) thanks in advance!

A: 

Is there a table named Preferences created?

Use the method described here to examine your database: http://developer.android.com/guide/developing/tools/adb.html#sqlite

I am not sure what is DAO.SETTINGS_TABLE_NAME, maybe you can try to create a database name Preferences directly.

 private static final String CREATE_DB_QUERY = 
  "CREATE TABLE " + Dao.CONTACTS_TABLE_NAME + " (ContactId varchar(64), Credit integer);\n" +
  "CREATE TABLE Preferences(Name varchar(64), Value varchar(64));";
SteD
thanks for link on adb guide. with "adb..." i see that just one table has been created. plain text query (w/o constants) give no results for me. and if i try to switch order of tables to create i saw that emulator creates just one table and it was first table in query: Preferences table. then i try (just now writing rhis comment=)) to separate queries a la "db.execSQL(CREATE_DB_QUERY_1); db.execSQL(CREATE_DB_QUERY_2);" and it works!
semen
A: 

Solution: separate queries a la:

db.execSQL(CREATE_DB_QUERY_1);
db.execSQL(CREATE_DB_QUERY_2);
semen