Android Question sqLite Progam - One works one doesn't

rgarnett1955

Active Member
Licensed User
Longtime User
Hi,

Had trouble using sqlite PRAGMA commands in B4J. I had used them in a B4A V 10.0 project and they worked fine.

I created a simple B4A V10 UI Program called sqLiteCheckPointTest, so I could do some more testing, but it keeps crashing when it tries to create the database file "RecentFilesCP.db".


Data base Initialisation that crashes in sqLiteCheckPointTest:
Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
    dbFileName = "RecentFilesCP.db"
    initRecentDatabase(File.DirRootExternal, dbFileName)
    
    fileNameSel = "dummyFileName"
    pathNameSel = "dummyPath"
    
    addOrUpdateFile(fileNameSel, pathNameSel, (pathNameSel & "\" & fileNameSel), "n", 1000)
...

'======================================================================================================
private Sub initRecentDatabase(path As String, dbName As String) As Boolean

    If File.Exists(path, dbName) Then
        Try
            sqlRecent.Initialize(path, dbName, False)
            '                     logOn, setJournal, integrityCheck, doFullCheckPoint, setAutoCheckPoint) As Boolean
            If checkRecentFilesDB(True,  "WAL",      True,           True,             -3) = False Then
                Return False
            End If
        Catch
        Log(LastException)
        Return False
        End Try
    Else
        Try
            sqlRecent.Initialize(path, dbName, True) '********************** ERROR 1 *************************
        Catch
            Log(LastException)
            Return False
        End Try
        
        Try
            'Create the recent files table
            'createRecentTable
            SQLInit
            '                     logOn, setJournal, integrityCheck, doFullCheckPoint, setAutoCheckPoint) As Boolean
            If checkRecentFilesDB(True,  "WAL",      False,          False,            -3) = False Then
                Return False
            End If
        Catch
            Log(LastException)
            Return False
        End Try
    End If
    Return True
End Sub


The error I get is:

Error:
*** Service (starter) Create ***
Error occurred on line: 158 (Starter)
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
    at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:207)
    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:191)
    at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
    at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:806)
    at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
    at anywheresoftware.b4a.sql.SQL.Initialize(SQL.java:44)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at b4a.sqLiteChkPointTest.starter.onCreate(starter.java:56)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2877)
    at android.app.ActivityThread.-wrap4(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

I then took one of the sqLite Tutorial Programs I downloaded from the B4X website called sqLiteLight4 (Created 19 August 2017) and bolted in my code, albeit with the database name as "stock.db" rather than the one above

The exact same code works in the tutorial project, but not in the project I made from scratch using B4A V10. The only difference is the manifest files, however if I copy the manifest from the working sqLiteLight4 program to the sqLiteChackPointTest program the sqLiteChackPointTest program won't install on the emulator.

I have attached a zip of each program. maybe someone could have a look at the problem. I'm at a loss to know what to do.

Best regards
Rob
 

Attachments

  • sqLiteCheckPointTest.zip
    6.1 KB · Views: 211
  • SQLiteLight4.zip
    21.6 KB · Views: 202

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top