ahmetb / orman

lightweight and minimalist ORM for Java/Android. works with SQLite & MySQL. (not actively maintained)
Other
249 stars 47 forks source link

Problem with cursor finalizing #29

Closed almozavr closed 13 years ago

almozavr commented 13 years ago

Every request to db gives me following errors:

Am I doing something wrong or something wrong with framework? Must admit, that transactions work anyway, but I get all this errors and app crashes.

ahmetb commented 13 years ago

Thanks for noticing that. We will investigate soon.

almozavr commented 13 years ago

I also get another error after dozens of cursor related, but I'm not sure if they are linked somehow:

09-15 12:53:21.619: ERROR/AndroidRuntime(1715): java.util.MissingFormatArgumentException: Format specifier ''' 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at java.util.Formatter.getArgument(Formatter.java:1115) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at java.util.Formatter.doFormat(Formatter.java:1077) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at java.util.Formatter.format(Formatter.java:994) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at java.lang.String.format(String.java:2254) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at java.lang.String.format(String.java:2219) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at org.orman.util.logging.Log.trace(Log.java:48) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at org.orman.dbms.sqliteandroid.QueryExecutionContainerImpl.executeOnly(QueryExecutionContainerImpl.java:36) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at org.orman.mapper.Model.insert(Model.java:86) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at com.sample.project.ui.LauncherActivity$LoadMessagesTask.onPostExecute(LauncherActivity.java:111) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at com.sample.project.ui.LauncherActivity$LoadMessagesTask.onPostExecute(LauncherActivity.java:1) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at android.os.AsyncTask.finish(AsyncTask.java:417) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at android.os.AsyncTask.access$300(AsyncTask.java:127) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at android.os.Handler.dispatchMessage(Handler.java:99) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at android.os.Looper.loop(Looper.java:123) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at android.app.ActivityThread.main(ActivityThread.java:4627) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at java.lang.reflect.Method.invokeNative(Native Method) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at java.lang.reflect.Method.invoke(Method.java:521) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 09-15 12:53:21.619: ERROR/AndroidRuntime(1715): at dalvik.system.NativeStart.main(Native Method)

almozavr commented 13 years ago

Full output for cursor error (sorry for not writing it all from the beginning):

09-15 13:00:00.919: ERROR/Cursor(3580): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/com.sample.project/databases/app.db, table = null, query = SELECT * FROM stream WHERE stream.id LIKE '9767'; 09-15 13:00:00.919: ERROR/Cursor(3580): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here 09-15 13:00:00.919: ERROR/Cursor(3580): at android.database.sqlite.SQLiteCursor.(SQLiteCursor.java:210) 09-15 13:00:00.919: ERROR/Cursor(3580): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53) 09-15 13:00:00.919: ERROR/Cursor(3580): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345) 09-15 13:00:00.919: ERROR/Cursor(3580): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1315) 09-15 13:00:00.919: ERROR/Cursor(3580): at org.orman.dbms.sqliteandroid.QueryExecutionContainerImpl.executeForResultList(QueryExecutionContainerImpl.java:50) 09-15 13:00:00.919: ERROR/Cursor(3580): at org.orman.mapper.Model.fetchQuery(Model.java:425) 09-15 13:00:00.919: ERROR/Cursor(3580): at org.orman.mapper.Model.fetchSingle(Model.java:452) 09-15 13:00:00.919: ERROR/Cursor(3580): at com.sample.project.ui.LauncherActivity$LoadMessagesTask.onPostExecute(LauncherActivity.java:94) 09-15 13:00:00.919: ERROR/Cursor(3580): at com.sample.project.ui.LauncherActivity$LoadMessagesTask.onPostExecute(LauncherActivity.java:1) 09-15 13:00:00.919: ERROR/Cursor(3580): at android.os.AsyncTask.finish(AsyncTask.java:417) 09-15 13:00:00.919: ERROR/Cursor(3580): at android.os.AsyncTask.access$300(AsyncTask.java:127) 09-15 13:00:00.919: ERROR/Cursor(3580): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429) 09-15 13:00:00.919: ERROR/Cursor(3580): at android.os.Handler.dispatchMessage(Handler.java:99) 09-15 13:00:00.919: ERROR/Cursor(3580): at android.os.Looper.loop(Looper.java:123) 09-15 13:00:00.919: ERROR/Cursor(3580): at android.app.ActivityThread.main(ActivityThread.java:4627) 09-15 13:00:00.919: ERROR/Cursor(3580): at java.lang.reflect.Method.invokeNative(Native Method) 09-15 13:00:00.919: ERROR/Cursor(3580): at java.lang.reflect.Method.invoke(Method.java:521) 09-15 13:00:00.919: ERROR/Cursor(3580): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 09-15 13:00:00.919: ERROR/Cursor(3580): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 09-15 13:00:00.919: ERROR/Cursor(3580): at dalvik.system.NativeStart.main(Native Method)

ahmetb commented 13 years ago

The exception

 java.util.MissingFormatArgumentException: Format specifier '''

caused by it is trying to log executed SQL to the stream but your query has % (probably in LIKE clause) and that character behaves like a format parameter (like %s, %d) and causes error. I will fix it later. If you want to continue development, you can comment out org.orman.dbms.sqliteandroid.QueryExecutionContainer.java line 36, 47, 90 (that has Log.trace(..)) and rake again.

Sorry about this bug. I will be investigating cursor issue separately.

almozavr commented 13 years ago

OK, thanks for quick response.

Right now I'm trying to investigate why and when the problem with cursor appears. I must say it seems to be because of "complicated" structure of my entities. I'll try to give a link to sample project a little bit later, where problem could occur clearly.

Regards, Aleksey Malevaniy

On 15 September 2011 13:49, ahmet alp balkan reply@reply.github.com wrote:

The exception

    java.util.MissingFormatArgumentException: Format specifier '''

caused by it is trying to log executed SQL to the stream but your query has % (probably in LIKE clause) I will fix it later. If you want to continue development, you can comment out org.orman.dbms.sqliteandroid.QueryExecutionContainer.java line 36, 47, 90 (that has Log.trace(..)) and rake again.

Sorry about this bug. I will be investigating cursor issue separately.

Reply to this email directly or view it on GitHub: https://github.com/ahmetalpbalkan/orman/issues/29#issuecomment-2103172

almozavr commented 13 years ago

OK, telling long story short the problem appears when: I have a entity class, e.g. Message that has a field ref. entity class User. So when I simply:

   for (int i = 0; i < 50; i++) {
            Message message = new Message("Sample Text", new User("Sample User"));
            User user = new User("Another User);
            user.insert();
    }

After some iterations it starts throwing:

_Finalizing a Cursor that has not been deactivated or closed. database = data/data/com.sample.project/databases/app.db, table = null, query = SELECT last_insert_rowid()_

ahmetb commented 13 years ago

Thanks that's a helpful example. Probably it is caused because we don't close a cursor that we use many times and android is trying to .finalize() it. We will be tracing this.

almozavr commented 13 years ago

Hope it helps! The sad thing, that I was trying to use ORMan on production development but it seems I have to link objects with pure sqlite by hands now and wait while orman would be ready for it. Still think it's the best orm for android, you guys rock!

Regards, Aleksey Malevaniy

On 15 September 2011 14:28, ahmet alp balkan reply@reply.github.com wrote:

Thanks that's a helpful example.  Probably it is caused because we don't close a cursor that we use many times and android is trying to .finalize() it. We will be tracing this.

Reply to this email directly or view it on GitHub: https://github.com/ahmetalpbalkan/orman/issues/29#issuecomment-2103392

almozavr commented 13 years ago

FIXED by adding cur.close where it supposed to be. What should I do next? Here is my code: http://pastebin.com/JgKgd8zA

ahmetb commented 13 years ago

Thanks for that. If you hit java.util.MissingFormatArgumentException, I told you about it here. Do you hit something else?

almozavr commented 13 years ago

Always nice to help!

java.util.MissingFormatArgumentException — I commented lines you told me, thanks! Now everything seems to work.

ahmetb commented 13 years ago

MissingFormatArgumentException issue moved to #32, you can track about it there. I will be fixing soon. Meanwhile cursor issue will be fixed with your solution. Thanks @almozavr.

ahmetb commented 13 years ago

@almozavr please checkout the code from master and build with rake. If it solves your cursor issue you can now close the issue. Thanks for cooperation.

almozavr commented 13 years ago

Great work, thanks.