iOS Question DB Error: 26 "file is encrypted or is not a database"

RichardN

Well-Known Member
Licensed User
Longtime User
This code has been working just fine for ages. Now I recomplile and it halts with the error above.

An SQLite database with a table of filenames is downloaded from the server. The database is then opened and the list of files is downloaded..... Not any more. The database now appears to initialise OK but then it halts when you try to define the first ResultSet from it. The database is NOT encrypted.

iHTTP ver 1.01
iSQL ver 1.30

B4X:
Sub JobDone (Job As HttpJob)
  
    If Job.Success = True Then
          
        Select Job.JobName
          
            Case "FileList"                        'Handle the Filelist database
              
                Dim out As OutputStream = File.OpenOutput(File.DirLibrary,"b747kb.sqlite", False)
                File.Copy2(Job.GetInputStream, out)
                out.Close

                Progress("SQLite Database Downloaded")
                Progress(Job.JobName & "Download")
              
                Main.SQL1.Initialize(File.DirLibrary,"b747kb.sqlite",False)

                                                      'Program halts at this query

                Dim Files As ResultSet = Main.SQL1.ExecQuery("SELECT * FROM FileList ORDER BY File")          
                Dim fname As String

                Do While Files.NextRow
                    Dim Job2 As HttpJob 
                    fname = Files.GetString("File")
                    Progress("Downloading.... " & fname)
                    Job2.Initialize(fname,Me)
                    Job2.Username = usr
                    Job2.Password = pw
                    Job2.Download(URLprefix & fname)
                Loop  
          
            Case Else                                            'Handles the rest
                                          
                Progress(Job.JobName & " .....Downloaded")
              
                Dim out As OutputStream = File.OpenOutput(File.DirLibrary,Job.JobName, False)
                File.Copy2(Job.GetInputStream, out)
                out.Close      
          
        End Select
      
    Else
        Progress("Error: " & Job.ErrorMessage)
    End If
  
End Sub



Application_Start
Application_Active
Unknown error calling sqlite3_step (10: disk I/O error) rs
response success
DB Error: 26 "file is encrypted or is not a database"
DB Query: SELECT * FROM FileList ORDER BY File
DB Path: /var/mobile/Containers/Data/Application/3606C352-8908-4046-9C2D-5A97ACD3C2A1/Library/b747kb.sqlite
Error occurred on line: 76 (UpdateFiles)
ExecQuery error: file is encrypted or is not a database
Stack Trace: (
CoreFoundation <redacted> + 152
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
B747 KB -[B4ISQL ExecQuery2::] + 340
B747 KB -[b4i_updatefiles _jobdone:] + 3486
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 300
B747 KB +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1784
B747 KB -[B4ICommon CallSubDebug4::::] + 1158
B747 KB -[B4ICommon CallSubDebug2::::] + 250
B747 KB -[b4i_httpjob _complete::] + 994
B747 KB -[b4i_httputils2service _completejob::::] + 1680
B747 KB -[b4i_httputils2service _hc_responsesuccess::] + 1106
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 300
B747 KB +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1784
B747 KB -[B4IShell runMethod:] + 590
B747 KB -[B4IShell raiseEventImpl:method:args::] + 2024
B747 KB -[B4IShellBI raiseEvent:eventarams:] + 1552
B747 KB __61-[B4IHttp URLSession:downloadTask:didFinishDownloadingToURL:]_block_invoke + 240
libdispatch.dylib <redacted> + 222
libdispatch.dylib <redacted> + 22
libdispatch.dylib _dispatch_main_queue_callback_4CF + 902
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 848
CoreFoundation CFRunLoopRunSpecific + 470
CoreFoundation CFRunLoopRunInMode + 104
GraphicsServices GSEventRunModal + 80
UIKit UIApplicationMain + 150
B747 KB main + 106
libdyld.dylib <redacted> + 2
 

RichardN

Well-Known Member
Licensed User
Longtime User
This has caused some serious head scratching !

Firstly the database version: SELECT sqlite_version() = 3.10.0 This is the same for all databases I am working with and they all work fine.

Earlier in the program exactly the same database 'b747kb.sqlite' is deployed in the package, initialised and queried without problem.

So I tried changing the database extension from *.sqlite to *.db3. Strangely it now downloads, initialises and queries perfectly.

I can only presume that the iHTTP library is internally treating the two files differently. I guess a file named *.db3 is being treated as a binary download with error correction but the *.sqlite file is downloaded as a text file and therefore without error checking corruptions are getting through.

Can the iHTTP job process be forced to use binary download ?
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
Mystery solved.....

I use FileZilla for my FTP needs. During a recent version upgrade the default transfer method was switched from my setting of Binary back to the default setting of Auto. Consequently the files on the server were being uploaded according to their file type as recognised by FlieZilla... which is not always correct.

Not an easy problem to isolate.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…