Android Question SQL Error

StarinschiAndrei

Active Member
Licensed User
Longtime User
Hi everyone,
I turn back to my previous post https://www.b4x.com/android/forum/threads/sql-error.162490/#post-996940 regarding the sql db error. Now i try to test my app on samsung j5 ( Android 7) the problem is the same. The code below works perfect on Andoris 13 but on Android 7 db is renamed by OS (i think) as a corrupt.
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    MP=B4XPages.MainPage
    Log(File.Exists(xui.DefaultFolder, "pos.db"))
        For Each flist As String In File.ListFiles(xui.DefaultFolder)
            Log("FileName: " & flist &" FileSize : "&File.Size(xui.DefaultFolder,flist))
        Next

Log(xui.DefaultFolder)  
    If File.Exists(xui.DefaultFolder, "pos.db") = False Then
        File.Copy(File.DirAssets, "pos.db", xui.DefaultFolder, "pos.db")
        Log(File.Exists(xui.DefaultFolder, "pos.db"))
    End If
   
    CHECK_TABEL
    SQL1.Initialize(xui.DefaultFolder,"pos.db",True)
here is the log
true
FileName: virtual_assetsFileSize : 4096
FileName: pos.db FileSize : 0
FileName: pos.db.corrupt FileSize : 303104
/data/user/0/POS.app/files
Can anybody tell me how can i solve this issue ?
Thank you
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
but on Android 7 db is renamed by OS (i think) as a corrupt
I never encountered such case.

Tip: if you are always starting with an existing db then better to set the last parameter in SQL.Initialize to False. You don't want to create a new db.

What happens if you overwrite the existing file - comment line 11?

How did you create the db file? With the default journal mode - WAL, the db consists of 3 files.
 
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
I never encountered such case.

Tip: if you are always starting with an existing db then better to set the last parameter in SQL.Initialize to False. You don't want to create a new db.

What happens if you overwrite the existing file - comment line 11?

How did you create the db file? With the default journal mode - WAL, the db consists of 3 files.
db was created with sqlite studio
I changed the parameter to false
i made a test , first i deleted all pos.* file, than i copied again
here is the code
1735458979762.png

here is the log
true
FileName: virtual_assets FileSize : 4096
FileName: pos.db FileSize : 303104
/data/user/0/POS.app/files
FileName: virtual_assets FileSize : 4096
FileName: pos.db FileSize : 303104
true
Error occurred on line: 84 (B4XMainPage)
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 1294): Could not open database
#################################################################
Error Code : 1294 (SQLITE_CANTOPEN_ENOENT)
Caused By : Specified directory or database file does not exist.
(unknown error (code 1294): Could not open database)
#################################################################
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:242)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:203)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:518)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:209)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:181)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:1167)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:1115)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:832)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:807)
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:157)
 
Upvote 0
Top