Where is database and app. SQLite

mrjaw

Active Member
Licensed User
Longtime User
I am developing an application using SQLite to store data. I'm doing the tests directly on the phone using WIFI B4A-Bridge. My problem is I can not find the database when running my application. I wonder where the application is stored as the database on the phone. When I copy the application to the phone I must copy the database separately or it is packed directly in the package?

When I do an update I need to change DB too ?


I use to open the DB

SQL.Initialize(File.DirAssets,"clock.db", True)
 
If you include the DB in your Assets then you are distributing the DB along with your app, what you have to do is to copy the DB from your assets to the device, like this:
Code: Copy
If File.Exists(File.DirDefaultExternal, "clock.db") = False Then
            
   File.Copy(File.DirAssets, "clock.db", File.DirDefaultExternal, "clock.db")
                     
End If

Also, you cannot initialize or use a DB in the assets folder.
 
Upvote 0
OK, but the problem is that I dont know where is.
When I did this I get this error

no such table:clock
 
Upvote 0
OK, but the problem is that I dont know where is.
Where did you copy it and how ?
Post your code because without knowing exactly what you are doing and how it's impossible to give you a concrete answer.

Best regards.
 
Upvote 0
Now I am not copy the app. I am running using B4A-bridge wireless conection but I dont know where is put when it runs
 
Upvote 0
PHP: Copy
Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      'Buscando los datos de la banca locales   
      'SQL.Initialize(File.DirRootExternal, "clock.db", True)
      '
      If File.Exists(File.DirDefaultExternal, "lototouch.db") = False Then        
            File.Copy(File.DirAssets, "clock.db", File.DirDefaultExternal, "clock.db")                           
      End If
      SQL.Initialize(File.DirDefaultExternal,"lototouch.db", True)
      libcode.GetParamBanca
      stCOnect=Banca.id & "#"
    End If
      Bmp.Initialize(File.DirAssets, "android48.png")
      Activity.LoadLayout("Entrada")
   '
End Sub

Sub ExecuteMap(SQL As SQL, Query As String, StringArgs() As String) As Map
Dim cur As Cursor
If StringArgs <> Null Then
cur = SQL.ExecQuery2(Query, StringArgs)
Else
cur = SQL.ExecQuery(Query)
End If
Log("ExecuteMap: " & Query)
If cur.RowCount = 0 Then
Log("No records found.")
Return Null
End If
Dim res As Map
res.Initialize
cur.Position = 0
For i = 0 To cur.ColumnCount - 1
res.Put(cur.GetColumnName(i).ToLowerCase, cur.GetString2(i))
Next
cur.Close
Return res
End Sub




This is the error
PHP: Copy
LogCat connected to: B4A-Bridge: unknown Android-355220000372917
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
** Activity (main) Resume **
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:jq.lotonet
** Activity (main) Create, isFirst = true **
dbutils_executemap (B4A line: 165)
cur = SQL.ExecQuery(Query)
android.database.sqlite.SQLiteException: no such table: t_preferencia: , while compiling: SELECT * FROM t_preferencia
   at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
   at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:122)
   at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:95)
   at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:111)
   at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:77)
   at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:73)
   at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1376)
   at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1346)
   at anywheresoftware.b4a.sql.SQL.ExecQuery2(SQL.java:107)
   at anywheresoftware.b4a.sql.SQL.ExecQuery(SQL.java:95)
   at jq.lotonet.dbutils._executemap(dbutils.java:545)
   at jq.lotonet.libcode._getparambanca(libcode.java:361)
   at jq.lotonet.main._activity_create(main.java:284)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:552)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
   at jq.lotonet.main.afterFirstLayout(main.java:84)
   at jq.lotonet.main.access$100(main.java:16)
   at jq.lotonet.main$WaitForLayout.run(main.java:72)
   at android.os.Handler.handleCallback(Handler.java:618)
   at android.os.Handler.dispatchMessage(Handler.java:123)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:4668)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:552)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:917)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
   at dalvik.system.NativeStart.main(Native Method)
android.database.sqlite.SQLiteException: no such table: t_preferencia: , while compiling: SELECT * FROM t_preferencia
** Activity (main) Resume **
 
Upvote 0
You are mixing things, you are asking for "lototouch.db"
Code: Copy
If File.Exists(File.DirDefaultExternal, "lototouch.db") = False Then

but copying "clock.db"
Code: Copy
If File.Exists(File.DirDefaultExternal, "lototouch.db") = False Then        
   File.Copy(File.DirAssets, "clock.db", File.DirDefaultExternal, "clock.db")                           
End If

And initializing "lototouch.db"
Code: Copy
SQL.Initialize(File.DirDefaultExternal,"lototouch.db", True)
So, which one is the DB you need?
 
Upvote 0
Yes!
You rigth!!
I solve the problem!!!! Thks


My problem now is with DBUtils.ExecuteMap

When I run DBUtils.ExecuteMap and there is no records this functions returns NULL but


PHP: Copy
Dim m As Map
   m.Initialize
   m = DBUtils.ExecuteMap(Main.SQL, "SELECT * FROM t_press",Null)
      
   If m = Null Then 'Null will return if there is no match
      Main.prefer.puid=0      
   Else
      '
      Main.prefer.Initialize
      Main.prefer.codigo=m.Get("f_codigo")
      Main.prefer.nombre=m.Get("f_nombre")
   End If
The problem here is DBUtils.ExecuteMap return NULL but when it ask for NULL doesnt execute true condition because m,map, is not initialized not null so execute the else but how there is no initialize get error

PHP: Copy
java.lang.RuntimeException: Object should first be initialized (Map).
 
Upvote 0
Yes!
You rigth!!
I solve the problem!!!! Thks


My problem now is with DBUtils.ExecuteMap

When I run DBUtils.ExecuteMap and there is no records this functions returns NULL but


PHP: Copy
Dim m As Map
    m.Initialize
    m = DBUtils.ExecuteMap(Main.SQL, "SELECT * FROM t_press",Null)
        
    If m = Null Then 'Null will return if there is no match
        Main.prefer.puid=0        
    Else
        '
        Main.prefer.Initialize
        Main.prefer.codigo=m.Get("f_codigo")
        Main.prefer.nombre=m.Get("f_nombre")
    End If
The problem here is DBUtils.ExecuteMap return NULL but when it ask for NULL doesnt execute true condition because m,map, is not initialized not null so execute the else but how there is no initialize get error

PHP: Copy
java.lang.RuntimeException: Object should first be initialized (Map).


I haven't checked how exactly dbUtils return the map, but you can always use a 'try-catch-end try' block, in order to catch the error and proceed.
 
Upvote 0
Back
Top