Android Question How to Copy Empty Database?

Pravee7094

Active Member
Hi all,
I write one condition, If database (SQLITE) regstatus (Registration status) is "D" then I just get all the data before entered. and copy the empty database then entered new values. and finally close the activity. (In starter service)
Coding is Here,
B4X:
                  If regstatus = "D" Then
                        Dim rs As ResultSet = Main.gs_sql.ExecQuery("SELECT fullname,mobilenumber,password,regstatus,keyvalue,sendstatus,updateon FROM tablename")
                        Do While rs.NextRow
                            Dim ls_fullname As String = rs.GetString("fullname")
                            Dim ls_mobilenumber As String = rs.GetString("mobilenumber")
                            Dim ls_password As String = rs.GetString("password")
                            Dim ls_regstatus As String = rs.GetString("regstatus")
                            Dim ls_keyvalue As String = rs.GetString("keyvalue")
                            Dim ls_sendstatus As String = rs.GetString("sendstatus")
                            Dim ls_updateon As Int = rs.GetString("updateon")
                        Loop
                        rs.Close
                 
                        Copy_StartupFiles
                 
                        Dim co_mobile_registration As List
                        co_mobile_registration.Initialize
                        Dim lm_map As Map
                        lm_map.Initialize
                        lm_map.Put("fullname",ls_fullname)
                        lm_map.Put("mobilenumber", ls_mobilenumber )
                        lm_map.Put("password", ls_password)
                        lm_map.Put("regstatus", "D" )
                        lm_map.Put("keyvalue", ls_keyvalue )
                        lm_map.Put("sendstatus", ls_sendstatus )
                        lm_map.Put("updateon", ls_updateon)

                        co_mobile_registration.Add(lm_map)

                        DBUtils.InsertMaps(Main.gs_sql, "tablename", co_mobile_registration)

                        Close_Activity
                        StartActivity(login_choice)
                        ToastMessageShow("Your Login has been deleted. Contact HeadOffice / Admin",True)
                    End If

B4X:
Sub Copy_StartupFiles
    File.Copy(File.DirAssets,Main.gs_databasename,File.DirInternal,Main.gs_databasename)
'    Log("DataBase Name : " & Main.gs_databasename)
End Sub

but it does not copy the empty database.
Anybody Help?

Regards
Praveen
 
Last edited:

Pravee7094

Active Member
Hello sir, Thanks for your suggestion.
This Delete_db function works successfully when run with normal condition. Like
B4X:
    If ls_regstatus = "E" Then
                        Delete_db
                        list_files
                        Copy_StartupFiles
                        list_files
                        Close_Activity
                        StartActivity(login_choice)
                        ToastMessageShow("Your Database has been deleted. Contact HeadOffice / Admin",True)
     End If

But It does not work with these condition :

B4X:
 If ls_regstatus = "D" Then
                        
                        Dim rs As ResultSet = Main.gs_sql.ExecQuery("SELECT mobileregistrationpk,fullname,mobilenumber,password,regstatus,keyvalue,sendstatus,updateon FROM tablename")
                        Do While rs.NextRow
                            Dim ls_fullname As String = rs.GetString("fullname")
                            Dim ls_mobilenumber As String = rs.GetString("mobilenumber")
                            Dim ls_password As String = rs.GetString("password")
                            Dim ls_regstatus As String = rs.GetString("regstatus")
                            Dim ls_keyvalue As String = rs.GetString("keyvalue")
                            Dim ls_sendstatus As String = rs.GetString("sendstatus")
                            Dim ls_updateon As Int = rs.GetString("updateon")
                        Loop
                        rs.Close
                        
                        Delete_db
                        Copy_StartupFiles
                        
                        Dim co_mobile_registration As List
                        co_mobile_registration.Initialize
                        Dim lm_map As Map
                        lm_map.Initialize
                        lm_map.Put("mobileregistrationpk", ls_mobileregistrationpk)
                        lm_map.Put("fullname",ls_fullname)
                        lm_map.Put("mobilenumber", ls_mobilenumber )
                        lm_map.Put("password", ls_password)
                        lm_map.Put("regstatus", "D" )
                        lm_map.Put("keyvalue", ls_keyvalue )
                        lm_map.Put("sendstatus", ls_sendstatus )
                        lm_map.Put("updateon", ls_updateon)
    
                        co_mobile_registration.Add(lm_map)
    
                        DBUtils.InsertMaps(Main.gs_sql, "tablename", co_mobile_registration)

                        Close_Activity
                        StartActivity(login_choice)
                        ToastMessageShow("Your Login has been deleted. Contact HeadOffice / Admin",True)
                    End If

B4X:
Sub Delete_db
    For Each f As String In File.ListFiles(File.DirInternal)
     If f.StartsWith(Main.gs_databasename) Then File.Delete(File.DirInternal, f)
    Next
End Sub

Sub Copy_StartupFiles
    File.Copy(File.DirAssets,Main.gs_databasename,File.DirInternal,Main.gs_databasename)
End Sub

Sub list_files
    For Each f As String In File.ListFiles(File.DirInternal)
     Log("List files : " & f)
    Next
End Sub

Anything I miss or doing wrong?
Anybody help?

Regards
Praveen
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…