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:
-
You call a Function block (like ExecuteSQL or Query).
-
Your app continues to run without waiting.
-
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)
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
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
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
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)
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
-
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)
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
-
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:
-
sql: Write your SELECT statement using ? for values (e.g., SELECT name FROM users WHERE city = ?).
-
selectionArgs: Provide a list of the values that will safely replace the ? placeholders in order.
-
Triggers Event: AfterQuery
Insert (table, columns, values)
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)
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)
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)
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)
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
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)
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)
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
Extension file
MySqlite.aix (20.7 KB)
Any issue, feel free to ask
Happy Koding