Android Question Starter Service SQLlite

yiankos1

Well-Known Member
Licensed User
Longtime User
Hello my friends,
All these years I used to load and initialize sql in each activity. After I updated my app in order to load them from starter service, I get this NEW error log from firebase crashlytics:
B4X:
Exception android.database.sqlite.SQLiteException: near "WHERE": syntax error (code 1): , while compiling: SELECT id, erwthsh FROM WHERE id = ?
I have never had this problem again. At my sql SELECT statement I didn't changed anything. I have just changed where sql called and initialized.

P. S. 1 After FROM there is a variable name with table name and ? is an argument.
P. S. 2 I googled about that issue, but all users say that the forget a space in the middle of FROM and variable table name.
P. S. 3 I thought if users had a task-service killer and they killed starter service, but code checks every time when an activity started if starter service is running, if not start.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
If the problem was the place where you declared and initialized your db you would receive a different error, for example db not initialized.

Maybe you're using a different version of your project, where the query is incorrect.

What is the complete b4a statement?
 
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
Maybe you're using a different version of your project, where the query is incorrect.
Sorry Luca, but i did not get that. Here is my line that cause ecxeption:
B4X:
    m = DBUtils.ExecuteMap(Starter.SQL1, "SELECT id, erwthsh, apantisi1, apantisi2,apantisi3, swsth FROM " & Main.selectedtest & " WHERE id = ?", Array As String(integer))
where Main.selectedtest is string global variable that gets data from dropdown list and integer is a simple int in order to get all lines. Here is firebase log:
B4X:
Exception android.database.sqlite.SQLiteException: near "WHERE": syntax error (code 1): , while compiling: SELECT id, erwthsh, apantisi1, apantisi2,apantisi3, swsth FROM WHERE id = ?
android.database.sqlite.SQLiteConnection.nativePrepareStatement (SQLiteConnection.java)
android.database.sqlite.SQLiteConnection.acquirePreparedStatement (SQLiteConnection.java:889)
android.database.sqlite.SQLiteConnection.prepare (SQLiteConnection.java:500)
android.database.sqlite.SQLiteSession.prepare (SQLiteSession.java:588)
android.database.sqlite.SQLiteProgram.<init> (SQLiteProgram.java:58)
android.database.sqlite.SQLiteQuery.<init> (SQLiteQuery.java:37)
android.database.sqlite.SQLiteDirectCursorDriver.query (SQLiteDirectCursorDriver.java:44)
android.database.sqlite.SQLiteDatabase.rawQueryWithFactory (SQLiteDatabase.java:1318)
android.database.sqlite.SQLiteDatabase.rawQuery (SQLiteDatabase.java:1257)
anywheresoftware.b4a.sql.SQL.ExecQuery2 (SQL.java:223)
gr.taxabro.DiplomaAytokinitou.dbutils._vvv6 (dbutils.java:415)
gr.taxabro.DiplomaAytokinitou.test._vvvvvvvvvvvvvvvvvvv0 (test.java:896)
gr.taxabro.DiplomaAytokinitou.test._activity_create (test.java:462)
java.lang.reflect.Method.invoke (Method.java)
anywheresoftware.b4a.BA.raiseEvent2 (BA.java:186)
gr.taxabro.DiplomaAytokinitou.test.afterFirstLayout (test.java:102)
gr.taxabro.DiplomaAytokinitou.test.access$000 (test.java:17)
gr.taxabro.DiplomaAytokinitou.test$WaitForLayout.run (test.java:80)
android.os.Handler.handleCallback (Handler.java:754)
android.os.Handler.dispatchMessage (Handler.java:95)
android.os.Looper.loop (Looper.java:163)
android.app.ActivityThread.main (ActivityThread.java:6205)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:904)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:794)

My problem is that i can not reproduce this error! I have tested with 5 different devices low-mid-high range.
 
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
Instead of Array As String(integer)) use Array As Object(integer))
I will try it, but how do you explain all these years I did not get that error? Maybe because now I use sql Through service?
 
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
No; and changing from Array of Strings to Array of Object should not solve the problem.

I don't see errors in your query (you could try to change the variable name "integer" but I think the error is elsewhere).
Do you think M, map, should be loaded at activity or at service?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
try to set the tablename directly in the query. Not paremtrized...
I think tablenames can not be used in this way.
 
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
try to set the tablename directly in the query. Not paremtrized...
I think tablenames can not be used in this way.
I have this app 5 years working without this kind of error. Only after my last update I get this. Really, it gets my out of mind. I have 31 tables, do you think is better use a select case in order to do 31 different sql selects??
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
addition; based on the error it seems that the String with the tablename is EMPTY.
Sorry, the tablename is not parametrized like i though earlier....

Exception android.database.sqlite.SQLiteException: near "WHERE": syntax error (code 1): , while compiling: SELECT id, erwthsh, apantisi1, apantisi2,apantisi3, swsth FROM WHERE id = ?
The tablename between FROM and WHERE is missing.
 
Upvote 0
Top