Android Question Update .db File from CODE ||| Actualizar archivo .db desde codigo

FabianGS

Member
So basically what im trying to do is after that i have created some tables in a database, add some values to this tables is update all .db file.
I already had initialize my SQL .db file and check if its no duplicate and stuff like that. All works like a charm but when i close my app, this changes i9t doesnt get reflected into .db file
I already have tried to create this DB from SQLiteBrowserto have this file in the Files folder of the project to know if this changes but nothing happens, wherecan i extract thiscreated file and updated?

1697490396945.png
1697490357417.png

Lo que trato de realizar es que despues de haber insertado tablas y valores a estas tablas, es que el archivo .db se actualize. Ya he creado una base de datos y demas, creado tables e insertado valores, pero mi archivo .db no se actualiza

Sera que tenga que realizar la base de datos desde SQLiteBrowser????
Do i need to create this DB from SQLiteBrowser manually????
Need some help. thanks in advance
Muchas gracias por su ayuda, de antemano, buen dia!
 

josejad

Expert
Licensed User
Longtime User
Hi Fabian:

Please, don't attach code as images, it's better you to paste the code between code tags ([code]... your code here...[/code]).
It's even better to make us easier to help, to upload a small project to test, it's easier to find the issue.

You should too speak English in this part of the forum, you have a Spanish Forum here.

If I'm not wrong, the DB is copied from the assets folder to File.DirInternal. In your ConnectionTestDB sub, you're copying the db everytime you start your app, so you're overwriting the changes you make to the db.

B4X:
 If File.Exists(...)

should be

B4X:
 If NOT(File.Exists....)

As you are a new member, it's probably better and easier for you to start the project as B4XPages, instead of Activities.
 
Last edited:
Upvote 0

FabianGS

Member
Oh I see, sorry for inconveniences!
Thanks for your help.....
Here is my project code

Call this Connection on Main:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    
    Connection.ConnectionTestDB
    
     BTCreateDataBase.Initialize("BTCreateDataBase")
    BTCreateDataBase.TextColor = Colors.Blue
    BTCreateDataBase.Text = "<<+>>"
    Activity.AddView(BTCreateDataBase, 80%x, 80%y, 70dip, 70dip)

    ListViewer.Initialize("ListViewer")
    ListViewer.TwoLinesLayout.Label.TextColor = Colors.Black
    ListViewer.TwoLinesLayout.Label.TextSize = 20
    ListViewer.TwoLinesLayout.SecondLabel.TextColor = Colors.Black
    ListViewer.TwoLinesLayout.SecondLabel.TextSize = 12
    Activity.AddView(ListViewer, 5%x, 5%y, 700dip, 700dip)     
    
    

    ShowDataBase
    
End Sub

Sub ShowDataBase
    
    ListViewer.Clear
    Connection.Cursor = Connection.LocalSQL.ExecQuery("Select * FROM sqlite_master where Type='table'")
    For i = 0 To Connection.Cursor.RowCount - 1
        Connection.Cursor.Position = i
        ListViewer.AddTwoLines(Connection.Cursor.GetString("tbl_name"), Connection.Cursor.GetString("name"))
    Next
    
End Sub
ConnectionModule:
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Public DBFileDir As String
    Public DBFileName = "databasedca.db" As String
    
    
    Dim LocalSQL As SQL
    Dim Cursor As Cursor

End Sub

Sub Activity_Create(FirstTime As Boolean)
    


    
End Sub


 
Sub ConnectionTestDB   
    LocalSQL.Initialize(File.DirInternal, "databasedca.db", True)
    If File.Exists(File.DirInternal, "databasedca.db") Then
        Log("DATA BASE ALREADY CREATED")
        Log(File.DirAssets)
    Else
        Log("CREADA DB")
    End If
        
End Sub
 
Upvote 0
Top