Android Question Simple 2 SQlite example (by Klaus)

Beja

Expert
Licensed User
Longtime User
This is about the second example with more functions.

1- First run just after installation is ok
2- next run (run 2) brings exception
LogCat connected to: emulator-5554
** Activity (main) Create, isFirst = true **


** Activity (main) Resume **
ExecuteHtml: SELECT ID, FirstName As [First name], LastName As [Last name], City FROM persons
** Activity (main) Pause, UserClosed = false **
** Activity (edit) Create, isFirst = true **
** Activity (edit) Resume **
** Activity (edit) Pause, UserClosed = true **
** Activity (main) Resume **
ExecuteHtml: SELECT ID, FirstName As [First name], LastName As [Last name], City FROM persons
** Activity (main) Pause, UserClosed = false **
** Activity (edit) Create, isFirst = false **
** Activity (edit) Resume **
** Activity (edit) Pause, UserClosed = true **
** Activity (main) Resume **
ExecuteHtml: SELECT ID, FirstName As [First name], LastName As [Last name], City FROM persons
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
java.lang.IllegalStateException: database not open
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1333)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1315)
at anywheresoftware.b4a.sql.SQL.ExecQuery2(SQL.java:167)
at anywheresoftware.b4a.sql.SQL.ExecQuery(SQL.java:155)
at b4a.sqlitelight2.main._executehtml(main.java:384)
at b4a.sqlitelight2.main._showtable(main.java:573)
at b4a.sqlitelight2.main._activity_resume(main.java:327)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
at b4a.sqlitelight2.main.afterFirstLayout(main.java:104)
at b4a.sqlitelight2.main.access$100(main.java:16)
at b4a.sqlitelight2.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
java.lang.IllegalStateException: database not open

Note:
after the exception I have two options: Continue, yes or no
If I chose yes, database is blank, and next run will be the same error
If I chose No, it will exit the App, but next run the data is there but any editing or added records are lost


Note: no modification.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
You can use the ALTER TABLE command, or you can modify the structure of the db with an external tool and then put it in the Files tab again.

Then you will need to change:

Main Activity:
Colnumber - Line 62
queries in the routine "ShowTable" - lines 129 and 132
the routine UpdateSelectedItem - line 199
many changes in the module "Edit", in which you should add the views for the new fields.

It is not easy to explain better, I think.
Or I should make the changes
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The easiest way, at least for me, would be:
- Modify the database in an external program.
- Adapt everywhere the code to adapt for the new fields.
-- Almost all SQL queries
-- In the Edit Activity add the views for the new fields.
-- Split the Edit layout into two layouts:
--- The basic layout with the buttons and a scrollview.
--- A layout with a Panel and all the Labels and EditText views loaded onto the scrollview.
-- Similar for the Filter Activity.
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
What's the best SQLite DB editor for layman?
Thanks in advance
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Thanks LucaMs,

For quick database creation, Klaus uploaded a very good example in his SQLite tutorial.. but I overlooked that until
I returned to it now.. that's shame.
I just can't thank Klaus enough for what he is doing for us. His examples are extremely easy to use, compact, direct to the
point, highly optimized code and well supported!
All thumps up Klaus.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…