Android Question new version SQL Database prob

DPaul

Active Member
Licensed User
Longtime User
Hi,

I upgraded to the new b4a version yesterday.
It would seem that i get an SQL error that i did not get before.
"Error Code : 1294 (SQLITE_CANTOPEN_ENOENT)"

I checked with some older backup versions that most certainly did not showthat problem, now they do.

Has something changed, or am i seeing things ?

thx,
Paul

EDIT : it's not the SQL , it's something to do with the location of dirRootExternal...?
 
Last edited:

BillMeyer

Well-Known Member
Licensed User
Longtime User
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
To Markus: replaced the debug.jar, maybe good for some things, but not for my problem :(

To Bill: i did not change my sdk version, my manifest says:
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="31"/>

The problem seems to have arisen after the b4a upgrade.

My SQL statement that fails:
SQLdata.Initialize( File.DirRootExternal & "DTCX", xxx_filename , True)

But i 'm pretty sure the line below fails even before the sql statement, and causes the SQL error message:
If File.Exists(File.DirRootExternal & "DTCX", "") = False then File.MakeDir(File.DirRootExternal, "DTCX")

?
Paul
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

OliverA

Expert
Licensed User
Longtime User
File.DirRootExternal & "DTCX"
This does not produce what you want/expect. You're expecting /some/dir/path/DTCX but you're getting /some/dir/pathDTCX. See the difference (hint: missing /). Use File.Combine(File.DirRootExternal, "DTCX") instead, or just add the / to DTCX making it "/DTCX". File.Combine is just a good way of doing it, since it uses the correct path separator and path, no matter what platform.
 
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
To Oliver: yes , although .combine is new to me, i have tried with and without forward slashes, to no avail.

After having tried to make sense of these "runtimepermissions", i succeeded in creating the subdir i want, only where i don't want it:

'File.MakeDir(File.DirRootExternal, "/DTCX") ==>> File.MakeDir(rp.GetSafeDirDefaultExternal(""), "/DTCX")

created in ...==>> Galaxy Tab A (2016)\Card\Android\data\b4a.example\files\DTCX

How do i get it to install into the root of the tablet, as it used to do before the b4a upgrade ?
All this directory/file manipulation stuff seems a bit esoteric to me :)

Paul
 
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
Hi ,

This is still the same question.
File.DirRootExternal does not work anymore, i'm trying to revive it ...

thx,
Paul
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Mahares

Expert
Licensed User
Longtime User
This is still the same question.
File.DirRootExternal does not work anymore, i'm trying to revive it ...
Try this in the Starter service:
B4X:
Sub Process_Globals
    Public rp As RuntimePermissions  'need runtimepermissions lib
    Public SQL1 As SQL   
    Public DBFilePath As String
End Sub

Sub Service_Create
    If File.ExternalWritable Then
        DBFilePath = File.DirRootExternal & "/DTCX"
    Else
        DBFilePath = File.DirInternal & "/DTCX"
    End If
    File.MakeDir(DBFilePath,"")
End Sub
Then in your main activity:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)  '
    Wait For Activity_PermissionResult (Permission As String, PResult As Boolean)
    If PResult = False Then
        MsgboxAsync("No permission to access external storage", "")
        Return
    Else
        Log("permission granted")
        If FirstTime Then
            Starter.SQL1.Initialize(Starter.DBFilePath,"mydatabase",True)
        End If
    End If
End Sub
 
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
@Mahares: i don't know how much they pay you for doing this, but you deserve a raise.:)
After 48 hours of struggle , i am again able to create a path to what used to be called "file.dirRootExternal". (on the tablet, not the SD or USB, ...)

Earlier, I was shown the right path with these runTimePermissions, but i would never have found this syntax.
Of course, your solution with the starter service causes me to rethink certain aspects,
but it seems to be more elegant than what i had before.

Thanks,
Paul
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
@Mahares: i don't know how much they pay you for doing this, but you deserve a raise.:)
After 48 hours of struggle , i am again able to create a path to what used to be called "file.dirRootExternal". (on the tablet, not the SD or USB, ...)

Earlier, I was shown the right path with these runTimePermissions, but i would never have found this syntax.
Of course, your solution with the starter service causes me to rethink certain aspects,
but it seems to be more elegant than what i had before.

Thanks,
Paul

I recommend you to be "up to date" reading threads about changes (like Runtime Permissions). "CANTOPEN_ENOENT" is a always a hint, that the db file isn't accessable.

How I solve such problems: I browse the b4x forum for the error:

1.JPG


So it must be something with path- or filenames. I would then try to create/read a simple file in this dir. Doing this throws an error in the logs about permissions (if I wouldn't know anything about permissions). And here you are...
 
Upvote 0
Top