Android Question My App is creating two databasses when i only want it to create one. and renaming the database

cammel8

Member
Licensed User
Longtime User
Ok so every time i run my app it creates an empty database and then one that is used for the stuff i need. what i would like to do is have it create one but only after I have selected the player one name and player two name (Which is lower in the code) and then name it based off them two names. I have tracked it down to the two lines where I have an "---->" in the code below


B4X:
If FirstTime Then
        ---->sql1.Initialize(File.DirDefaultExternal, DateTime.GetMonth(DateTime.Now) &"."& DateTime.GetDayOfMonth(DateTime.Now) &"."& DateTime.GetYear(DateTime.Now) & " " & DateTime.TIME(DateTime.Now) & ".db", True)
      
    End If
    sql1.ExecNonQuery("DROP TABLE IF EXISTS table1")
    ---->sql1.ExecNonQuery("CREATE TABLE table1 (Name TEXT, Makes INTEGER, Misses INTEGER, Defensive INTEGER, Left INTEGER, MOB INTEGER, Dead INTEGER, Error INTEGER, OnBreak INTEGER, BNR INTEGER, Winner TEXT, GamePlayed INTEGER)")

Both lines create a database but if I remove the first line the app crashes.

So my question is, Is there a way to have it only create the one database and rename it to what i want after in code???

Side note, The ----> is not in the actual code!
 

victormedranop

Well-Known Member
Licensed User
Longtime User
i really don' t see why you need that, but what i do is check if file datbase exists.

you should post sample code to check.

B4X:
If File.Exists(File.DirRootExternal,"Signage.db") Then 
        'Log("Internal Database exits")
    Else
        File.Copy(File.DirAssets,"Signage.db",File.DirRootExternal,"Signage.db")   
    End If
 
Upvote 0

cammel8

Member
Licensed User
Longtime User
i really don' t see why you need that, but what i do is check if file datbase exists.

you should post sample code to check.

B4X:
If File.Exists(File.DirRootExternal,"Signage.db") Then
        'Log("Internal Database exits")
    Else
        File.Copy(File.DirAssets,"Signage.db",File.DirRootExternal,"Signage.db")  
    End If
it does not exist when the app starts. so it would create it there to begin with anyway and the second time i would have to search for the name of the file which is created dynamically using the date and time and would be hard to look up later because i could no longer look it up using the time.now and i wouldn't know the original name.
 
Upvote 0

victormedranop

Well-Known Member
Licensed User
Longtime User
i did not créated i just copied from asset, i use sqlite browser too créate the database
more faster tan créate it.
 
Upvote 0

cammel8

Member
Licensed User
Longtime User
i did not créated i just copied from asset, i use sqlite browser too créate the database
more faster tan créate it.
but i need to create it not copy it. i need it to have its own name every time based on the date and time. prefeably with player names as well but havent figured that out yet.
 
Upvote 0

victormedranop

Well-Known Member
Licensed User
Longtime User
You can créate or copied but first you have to know if available the name.
or have just one database ad créate simultaneos table with users names.
 
Upvote 0

cammel8

Member
Licensed User
Longtime User
You can créate or copied but first you have to know if available the name.
or have just one database ad créate simultaneos table with users names.
not exactly sure what you mean. No matter what i have to create a new empty database every time, and it has to be named according to the date and time. everything works perfectly except for the fact it creates two databases every time i run the app. I could judt ignore ther second one but i would like to find out why its doing it aand stop it from doing so. That or just rename the second one so i know what to look for. As in the first one is named from date and time like it is now but when i save all the data it actually renames it to playerone, player2, date and time.
 
Upvote 0

cammel8

Member
Licensed User
Longtime User
How can it create two databases if you only call SQL.Initialize once?
Sorry for the late response. I had something come up and haven't been working on anything last couple days. @Erel, i know, right. @victormedranop, i think oyou may be correct on it being a temp file. I was using two programs to view the db files once created. Both ony showed me part of the name. once i pulled them over to the pc i was able to see the full name and they were not named the same. So it appears it may be a temp file as you said..
 
Upvote 0
Top