[FREE] πŸ”₯ Advanced Sqlite Extension

ggsda

:fire: MySqlite Extension Guide

This extension allows you to create and manage a powerful local SQLite database within your app. All database operations are asynchronous , which means they run in the background to prevent your app from freezing.

The Basic Workflow is always the same:

  1. You call a Function block (like ExecuteSQL or Query).

  2. Your app continues to run without waiting.

  3. When the database operation is finished, an Event block (AfterExecution or AfterQuery) fires, returning the tag you provided along with the result.

Properties (Set these in the Designer)

These blocks allow you to configure the extension's behavior.

DatabaseName (Text)

What it does: Sets the name of your database file.
How to use: Set this in the Designer properties panel or once in the Screen.Initialize block.
Example: my_app_data.db

DatabasePath (Text, Read-Only)

component_set_get(19)

What it does: Returns the full, absolute path to where the database file is stored on the device. This is useful for debugging.

ShowHeader (Boolean)

What it does: Controls if query results include a header row with column names. By default, this is true.
How to use: Set to false if you only want the raw data without column names.

SuppressErrors (Boolean)

What it does: If set to true, the ErrorOccurred event will not fire when something goes wrong. The AfterExecution event will still return success = false. Default is false.

2. Events (React to results here)

These blocks are triggered automatically after a function completes its job.

AfterExecution

component_event(13)

Fires after any function that changes data (like INSERT, UPDATE, CREATE TABLE, DELETE).

success (Boolean): true if the operation worked, false if it failed.

AfterQuery

component_event(11)

Fires after any function that reads data (like Query, RawQuery, GetAllTables).

result (List): A list of lists containing the data from the database.

numberOfRows (Number): The number of actual data rows returned (not including the header).

ErrorOccurred

component_event(12)

Fires if a database operation fails and SuppressErrors is false.

message (Text): A technical message explaining what went wrong.

3. Functions (Call these to do work)

These are the blocks you use to interact with the database.
Core Operations

ExecuteSQL (sql)

component_method(49)

What it does: Executes any single SQL command that does not return data. Perfect for creating tables.

How to use:

  • sql: The full SQL command, e.g., "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)".

ExecuteMultipleSQL

component_method(47)

  • What it is: A block to run a whole list of SQL commands all at once.

  • Key Feature: It's an "all or nothing" operation. If even one command in your list fails, the database automatically undoes all the previous commands from that list. This prevents your database from being left half-updated.

  • How to use: Give it a list of text blocks. Each text block is one full SQL command (like CREATE TABLE... or INSERT INTO...).

Triggers Event: AfterExecution

Query (table, columns, selection, selectionArgs, groupBy, having, orderBy, limit)

component_method(45)

What it does: The main block for safely retrieving data from a table.
How to use:

  • table: The name of the table, e.g., "users".

  • columns: A list of column names you want, e.g., ["name", "age"]. (Use an empty list to get all columns *).

  • selection: The WHERE part of a query without the word WHERE, using ? for values, e.g., "age > ? AND city = ?". (Leave blank to get all rows).

  • selectionArgs: A list of values to replace the ? placeholders, e.g., [21, "London"].

  • groupBy, having, orderBy, limit: Advanced SQL options. Leave blank if you don't need them.

RawQuery

component_method(50)

  • What it is: A block to get data from your database using your own custom SELECT statement.

  • Key Feature: It gives you full power to write complex queries (e.g., with JOINs). For security, you should always use a ? as a placeholder for any variable or user input.

  • How to use:

    1. sql: Write your SELECT statement using ? for values (e.g., SELECT name FROM users WHERE city = ?).

    2. selectionArgs: Provide a list of the values that will safely replace the ? placeholders in order.

Triggers Event: AfterQuery

Insert (table, columns, values)

component_method(44)

What it does: Adds a new row of data to a table.
How to use:

  • table: The table name, e.g., "users".

  • columns: A list of the column names, e.g., ["name", "age"].

  • values: A list of the corresponding values, e.g., ["Jane Doe", 30]. The lists must have the same length.

    Triggers Event: AfterExecution

    Update (table, columns, values, whereClause, whereArgs)

component_method(42)

What it does: Modifies existing rows that match a condition.
How to use:

  • table, columns, values: Same as Insert. These are the new values.

  • whereClause: The condition to find rows to update, e.g., "name = ?".

  • whereArgs: The value for the condition, e.g., ["Jane Doe"].

Triggers Event: AfterExecution

Delete (table, whereClause, whereArgs)

component_method(41)

What it does: Removes rows that match a condition.
How to use:

  • table: The table name, e.g., "users".

  • whereClause: The condition to find rows to delete, e.g., "name = ?".

  • whereArgs: The value for the condition, e.g., ["Jane Doe"].

Triggers Event: AfterExecution

Utility Functions

DropTable (tableName)

component_method(40)

What it does: Deletes an entire table and all its data. Warning: This cannot be undone.
How to use:

  • tableName: The name of the table to delete, e.g., "temporary_data".

Triggers Event: AfterExecution

ClearTable (tableName)

component_method(39)

What it does: Deletes all rows from a table but keeps the table structure.
How to use:

  • tableName: The name of the table to clear, e.g., "highscores".

Triggers Event: AfterExecution

GetAllTables

component_method(38)

What it does: Returns a list of all tables in the database.
How to use:

  • Triggers Event: AfterQuery (The result will be a single column list of table names).

ImportDatabase (filePath)

component_method(36)

What it does: Overwrites the current database by importing one from a file.
How to use:

  • filePath: The absolute path to the .db file you want to import.

Triggers Event: AfterExecution

ExportDatabase (fileName)

component_method(37)

What it does: Saves a copy of the current database to a new file.
How to use:

  • fileName: The name for the backup file, e.g., "backup_2025.db".
    Triggers Event: AfterExecution

:jigsaw: Extension file

MySqlite.aix (20.7 KB)

Any issue, feel free to ask :heart: :heart:

Happy Koding :partying_face: :partying_face:

4 Likes

(added to FAQ)

(welcome to the club!)

1 Like

Advanced ?

No opening or closing of database?

Yeah, The opening and closing of the database connection is handled automatically by the extension's code.

Here's how it works:

  1. When you call any function (like ExecuteSQL or Query), the first thing the extension does is check: "Is the database connection open?"

  2. If it's not open, the extension opens it automatically before running your command.

  3. If it's already open from a previous command, it just reuses the existing connection, which is very efficient.

This automatic connection management is a major advantage because:

  • It's Simple: You don't have to remember Open and Close blocks.

  • It's Safe: It prevents crashes that would happen if you forgot to open the database before trying to use it.

Can you set a path with the name? For example if you want to store your database in the ASD ?

image

Can you export to a path, e.g. your ASD ?

If not, where are these db files stored on the device ?

The current code only lets the user to set the DatabaseName, and it automatically saves it in the app's internal, private directory. but i can adjust the code to do what you want. you can see sample name on the extension property.

So, to answer your second question directly: The exported database files are always stored in the root of your app's ASD.

Still i can modify that. if that is urgent? :blush:

These two seem to be at odds with each other ?

I am not in a hurry for anything, just interested in control of my database files. I don't much like extensions that "decide" for me.

I think those two processes are different. anyways i will adjust based on your suggestion. thanks @TIMAI2