0

I am using ormlite for sqlite database in my android application. It's a login based application and I have database in SD card. For user abc, the requirement is when user login with different user like xyz then application authenticate the user from the server and server replace the db for user xyz. But when I am trying to access the login credentials it is giving the old credentials while the database is reflecting the new credentials.

I also tried:

DaoManager.clearCache();

It is not working also I tried:

DatabaseManager<DatabaseHelper> manager = new DatabaseManager<DatabaseHelper>();
manager.releaseHelper(DatabaseHelperGenerator.getDataBaseHelperInstance())

After this when I tried to fire this query:

Dao<LoginAuthentication, Integer> loginAuthenticationDao = null;
DatabaseHelperGenerator.getDataBaseHelperInstance().
    clearLoginDao(LoginAuthentication.class);
loginAuthenticationDao = DatabaseHelperGenerator.getDataBaseHelperInstance().
    getUserDao(LoginAuthentication.class);
List<LoginAuthentication> loginAuthenticationList =
    loginAuthenticationDao.queryForAll();

It is giving IllegalStateException :Database not open

Looking for help.

Gray
  • 115,027
  • 24
  • 293
  • 354
Deepak Goel
  • 5,624
  • 6
  • 39
  • 53

1 Answers1

1

Seems to me that you are going in the wrong direction here.

  • You are assuming that the DAO is caching objects for you but unless you have enabled an object cache on a particular DAO then that's not the case.
  • DaoManager.clearCache() doesn't clear object caches but instead clears the cached DAO objects.
  • Once you release the helper, the database connection is closed which is the reason why you are getting the IllegalStateException.

I'd do some debugging of your application or some logging of values to see where the problem lies. Here are some thoughts:

  • If you are using an object cache, have you tried to disable it? Have you tried flushing the object cache by calling Dao.clearObjectCache()? Again, a cache will only exist if you have turned it on. It is not on by default.
  • What code are you using to persist the login information? Anything different than other calls?
  • How about using the Dao.queryRaw() methods to dump the database right after the insert?
  • Any transactions?

Best of luck.

Gray
  • 115,027
  • 24
  • 293
  • 354
  • sorry buddy.As i was on leave for few days and won't be able to access the net.Any way thanks for your response. Initially i was unable to get what is the problem. The problem is same as suggested by the kagii in this link http://stackoverflow.com/questions/2493331/what-is-best-practice-with-sqlite-and-android but still i am facing the same problem every thing is going fine but the value is not inserted in the table.I am using the single connection as suggested from each thread but the problem is remain same. – Deepak Goel Oct 20 '11 at 18:48
  • Np. I think you should debug it and after the insert happens, take a look at the database using the adb shell tool: http://developer.android.com/guide/developing/tools/adb.html Search for Examining sqlite3 Databases from a Remote Shell. – Gray Oct 20 '11 at 19:38
  • i am using eclipse and i debug the code it is going in the createAndUpdate method and also showing the no of rows affected is same as expected but the problem is that when i open the database in the sqlite browser the db is still empty – Deepak Goel Oct 21 '11 at 06:37
  • Sorry @deepak. I have no idea why this is happening. – Gray Oct 26 '11 at 13:08