iOS Question Problems with merging two db3 files

Discussion in 'iOS Questions' started by nimsuk, Apr 26, 2018.

  1. nimsuk

    nimsuk Member Licensed User

    So I am currently working on a b4i app that is having some issues when trying to merge two db3 files. The files are supposed to merge by downloading the latest file from a server and then migrating the data from that new file to the old one. However since changing how files are downloaded an error keeps occurring when trying to migrate the data about how the tables in one of the db3 files doesn't exist but they should as the files are pretty much the same. and I was wondering if anybody would be able to help me figure out what could be causing this.

    Here is the output from the console:

    DB Error: 1 "no such table: Status"
    DB Query: Drop Table [Status]
    Path: /var/mobile/Containers/Data/Application/FCDAB994-C7B7-48DF-83B0-46BBAFB6B7E3/Documents/db_folder/data.db3
    Here is the migration code:

    Sub Migrate_Data_Import_New
    If File.Exists(File.DirDocuments & "/" & Main.Corp_UserRef&"_db/",Main.corp_and_userref&"_1.db3") = True Then
    Dim txt As String

    If Main.SQL1.IsInitialized = True Then
    File.DirDocuments & "/" & Main.Corp_UserRef&"_db/", Main.corp_and_userref&".db3"False)
    Log("sql initi")
    End If
    Dim no As NativeObject = Main.sql1
    Dim cSQLAttach As String

    cSQLAttach = 
    "ATTACH DATABASE '" & File.Combine(File.DirDocuments & "/" & Main.Corp_UserRef&"_db/",Main.corp_and_userref&"_1.db3") & "' AS 'TRANSFER_TEMP'"

    "ExecNonQueryInsideTransaction::"Array(cSQLAttach, Null))

    Dim TableName As String

    TableName = 
    "Drop Table ["&TableName&"] "
    ' this is where it crashes
            txt="CREATE TABLE ["&TableName&"] As Select * FROM TRANSFER_TEMP."&TableName
    and Here is the new ftp code:

    Public Sub Show_Import
    db_filename = Main.corp_and_userref & 
        db_filename_migrate= Main.corp_and_userref & 

    "FTP",Main.FTP_IP, Main.FTP_Port, Main.FTP_Username, Main.FTP_Password)
        Main.FTP.PassiveMode = 
    If menu.force_import = True Then
    "//Incoming//"&db_filename,False,File.DirDocuments & "//" & Main.Corp_UserRef&"_db//",db_filename)
    "//Incoming//"&db_filename,False,File.DirDocuments & "//" & Main.Corp_UserRef&"_db//",db_filename_migrate)
    End If
    I should also mention that the migrate sub is called in the FTP_DownloadComplete subroutine and that there is an b4a version of this app which uses a similar method as above and works fine

  2. Erel

    Erel Administrator Staff Member Licensed User

    Why are you using ExecNonQueryInsideTransaction?

    You can try to merge the two databases with two SQL objects. Read the data from one database and add it to the second one.
  3. OliverA

    OliverA Well-Known Member Licensed User

    Could it just be that there is no Status table?
    Dim tableExists As Int
    tableExists = Main.SQL1.ExecQuerySingleResult(
    $"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='${TableName}'"$)
    If tableExists > 0 Then
    "Drop Table ["&TableName&"] "
    End If
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice