where is my database?

mrussell014

Member
Licensed User
Longtime User
:D Hi All,

Can anyone tell me where the database goes. Any answer will be welcome.

I used code from scrollviewlist to read a csv file and write it to table1. This works perfectly except I can't find the table to copy it so a safe place for reuse. My csv file is over 200,000 records and record are added to the table per each use, so I need the table when the app closes.

I have searched for how to create the table in another place but I didn't see anything relating to that. I looked for copying the database but could not identify anything that would do it.

This is all I need and my app can go to market. I made this app for my brotherinlaw who is crippled on the right side of his body. This app addresses his handicap. He is my market.

Thank you for reading, don't be shy please reply,
Mike :BangHead:

'Dim cursora As Cursor
'cursora.IsInitialized
'cursora = SQL1.ExecQuery("Select name from sqlite_master 'WHERE Type= 'table' ORDER BY name;")
'cursora.Position = 0
'Msgbox(cursora.GetString("name"), "table:")

This code find the table but does not tell me where it is.======

Sub SQLCreateTable
SQL1.ExecNonQuery("DROP TABLE IF EXISTS table1")
SQL1.ExecNonQuery("CREATE TABLE table1 (Code TEXT , First TEXT, Name TEXT)")
SQLFillTable
this works=============================

Sub SQLFillTable
' Fills a SQL data base
Dim i As Int
Dim tr As TextReader
tr.Initialize(File.OpenInput(File.DirAssets, "myfile1.csv"))
SQL1.BeginTransaction

Dim InputStream1 As InputStream

line = tr.ReadLine
line = tr.ReadLine
Try
Do While line <> Null
this works =============
plus code that adds records to the database such as
Sub curswrite
' SQL1.BeginTransaction moved to another more optomize spot.
Dim LineArray() As String
LineArray = Regex.Split(",", line)
Dim lwl As Int
lwl = LineArray.Length
If lwl > 1 Then ' this to catch null record at end of file.
SQL1.ExecNonQuery2("INSERT INTO table1 VALUES(?, ?, ?)", Array As Object(LineArray(0), LineArray(1), LineArray(2)))
Else
lwl = lwl

End If
 

mangojack

Expert
Licensed User
Longtime User
What path and filename do you stipulate when initializing ?
B4X:
   SQL1.Initialize(File.DirDefaultExternal,"Data.db",True)

Cheers mj
 
Upvote 0

invaderwt

Member
Licensed User
Longtime User
^^

my problem it´s similiar, I can load the file but I can´t search for anything inside of sqlite , you have something I can do?
I read everything I can but yet i don´t realize to show anything from the database.
B4X:
Dim Cursor1 As Cursor
   SQL1.Initialize(File.DirDefaultExternal,"redesdatabase.sqlite",True)

   Cursor1 = SQL1.ExecQuery ("SELECT * FROM sqlite_master")
   Log("Numeber of row "&Cursor1.RowCount)
   Log("Number of rows = " & SQL1.ExecQuerySingleResult("SELECT count(*) FROM sqlite_master"))
   If Cursor1.RowCount < 1 Then
      Log ("no lines")
   End If

I can´t read the sqlitemaster table and my only creations like the table protrocolosderede where I insert seven registers.
If I research with the select for the table "protrocolosderede" the android don´t found What I can do to get my data?
 

Attachments

  • sqlexport.zip
    9.5 KB · Views: 136
Upvote 0

Mahares

Expert
Licensed User
Longtime User
You needed to copy the database from DirAssets to DefaultExternal first.
Replace the 2 subs you have with these two subs I modified for you:
B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim Cursor1 As Cursor
End Sub

Sub Activity_Create(FirstTime As Boolean)

   If File.Exists(File.DirDefaultExternal,"redesdatabase.sqlite") = False Then
           File.Copy(File.DirAssets,"redesdatabase.sqlite", File.DirDefaultExternal,"redesdatabase.sqlite")
   End If
   If FirstTime Then
      SQL1.Initialize(File.DirDefaultExternal,"redesdatabase.sqlite",True)
  End If
   Cursor1 = SQL1.ExecQuery ("SELECT * FROM protrocolosderede")
   Msgbox("Number of records "& Cursor1.RowCount,"")
   
End Sub
 
Upvote 0

invaderwt

Member
Licensed User
Longtime User
I did the change you said but this error came
android.database.sqlite.SQLiteException: no such table: protrocolosderede (code 1): , while compiling: SELECT * FROM protrocolosderede

How you can solved this?
 
Upvote 0

invaderwt

Member
Licensed User
Longtime User
I did the change you said but this error came
android.database.sqlite.SQLiteException: no such table: protrocolosderede (code 1): , while compiling: SELECT * FROM protrocolosderede

How you can solved this?

I remove the olde vm and create a new one using this code.
B4X:
           DBUtils.CopyDBFromAssets("redesdatabase.sqlite")
    'End If
    If FirstTime Then
        SQL1.Initialize(File.DirDefaultExternal,"redesdatabase.sqlite",True)
  End If
    Cursor1 = SQL1.ExecQuery ("SELECT * FROM protrocolosderede")
    Msgbox("Number of records "& Cursor1.RowCount,"")

and now works.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Uninstall your application first so you get rid of the old database created in DirDefaultExternal, because when you created it with your old code, it only created an empty file without tables. Then, install the application. You should be good then.
 
Upvote 0
Top