Android Question Newbie to B4A - SQLite Database questions

tseyfarth

Member
Licensed User
Longtime User
Hello all,

I am very very new to B4A so please bear with me! I have used SQLIte Expert for some years now and really enjoy the ease at which I can design a SQLite database outside of an application. I've done this several times when creating apps with Xojo for Windows and Rasberry Pi.

I would like to do the same thing with B4A on Android first, then iOS later.

A few questions:
1. Following creation of the db, how is the file then added to the Phone, in this case? Or do I use the DDL output from SQLite expert to incorporate into the B4A app?

DDL Output from SQLite Expert:
CREATE TABLE [graphix_site_defaults] (
  [rowid] INTEGER PRIMARY KEY,
  [connection_method] integer,
  [license_path] CHAR(255),
  [site_data_path] CHAR(255),
  [site_name] CHAR(25),
  [last_site_ip] CHAR(20),
  [siteid] INTEGER,
  [loginid] CHAR(25),
  [ui_id] INTEGER,
  [email_address] CHAR(100),
  [auto_print] CHAR(1),
  [defaults_override] CHAR(1),
  [langauge] CHAR(25),
  [date_format] CHAR(10),
  [in_debug_mode] INTEGER,
  [ip_update_interval] INTEGER,
  [ip_update_retries] INTEGER,
  [site_login_retries] INTEGER,
  [site_login_retry_interval] INTEGER,
  [resend_cmd_interval] INTEGER,
  [resend_cmd_max_retries] INTEGER,
  [server_data_path] CHAR(100),
  [graphics_data_path] CHAR(100),
  [background_image_path] CHAR(100),
  [brackgroun_image] CHAR(100),
  [graphics_update_interval] INTEGER,
  [graphics_data_update_retries] INTEGER,
  [draw_border] CHAR(1),
  [scroll_interval] INTEGER,
  [scroll_pixel_size] INTEGER,
  [scroll_display_width] INTEGER,
  [scroll_display_heigth] INTEGER,
  [font_size] INTEGER);

2. How would this DDL code be incorporated in B4A code? What might that look like?
3. Is there a method to simply call the SQL command that is what the DDL Output is?
4. Is there a way to check, programatically, if the database exists, and to check the tables to see if they match the current database?
5. Any other hints or help materials I should be looking at?

Thank you,
Tim
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
Upvote 0

tseyfarth

Member
Licensed User
Longtime User
Hello emexes! Hope you had a great new year celebration.
Type-O. That was a sample from a while ago on a different project. Was only used here as an example.

Tim
 
Upvote 0

tseyfarth

Member
Licensed User
Longtime User
Hi Emexes,

I am trying to view the list of files that are on my device, from the app I am working on.
Using this code:
B4X:
sql.Initialize(File.dirInternal, "Axcys.db", True)
   
    Dim loc As String
    loc = File.DirInternal
    Log("File Location = " & loc)

Loc is stated to be "/data/user/0/b4a.example/files

But when I go to the device using Cx File Explorer, I am not seeing anything like that. There's no search either like on Windows Explorer. Any idea where the file really is? I'm trying to confirm that it actually exists.... independent of the app I'm working on.

While on the subject, what file location *should* be specified? The need is for the location of the database file along with images and other stuff as necessary.

One more thing. Made some improvements with the BLE app, it now has all of the permissions automated. Before it would require certain to be done manually.

Thanks,
Tim
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
Loc is stated to be "/data/user/0/b4a.example/files

But when I go to the device using Cx File Explorer, I am not seeing anything like that. There's no search either like on Windows Explorer. Any idea where the file really is?

Yeah I was having that problem a few months ago too. I think later versions of Android are becoming more and more paranoid secure, and this might also be why the FTP Server aspect of B4X Bridge disappeared recently too. What version of Android are you running?

While on the subject, what file location *should* be specified? The need is for the location of the database file along with images and other stuff as necessary.

My reflex thought for a folder accessible to the outside world was GetSafeDirExternal although now that I read the documentation, it says this might return File.DirInternal, so... 🤔 going to have to try this on actual phones.

Also, now I'm having flashbacks to recently having to install an FTP Server app (would have been from PlayStore) to get at app files screenshots on the phone. 🙃
 
Upvote 0

tseyfarth

Member
Licensed User
Longtime User
So these areas are not visible to other apps?

Check my previous msg too, I edited it apparently after/during your reply
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
Directory Internal is not visible to the other apps on the device, and is not easily accessible to file explorer Unless you are using a ROOTED device and a file explorer that can access the Root directory. Or an emulator with Root Access.

On the other hand, you can have access to your files using Runtime permission with GetSafeDirDefaultExternal.
Your files will be created and located at
Device Internal Storage->Android->Media->{YOUR APP PACKAGE NAME}->Files
 
Last edited:
Upvote 0

MicroDrie

Well-Known Member
Licensed User
So these areas are not visible to other apps?
to quote Erel:
B4A Library [class] FileProvider - share files
Starting from Android 7 (API 24) you cannot directly share file uris with other applications. You need to use FileProvider.
And also be aware that a file location in Debug mode and when running the final application is different.
 
Upvote 0
Top