![]() |
Fun API Documentation 0.42.1
The programming language that makes you have fun!
|
SQLite handle registry and helper utilities for the Fun VM extension. More...
#include <sqlite3.h>Go to the source code of this file.
Data Structures | |
| struct | SqlHandle |
| Node in a singly-linked list of registered SQLite handles. More... | |
Typedefs | |
| typedef struct SqlHandle | SqlHandle |
| Node in a singly-linked list of registered SQLite handles. | |
Functions | |
| static SqlHandle * | sql_reg_add (sqlite3 *db) |
| Add a sqlite3 handle to the registry. | |
| static SqlHandle * | sql_reg_get (int id) |
| Look up a registered SQLite handle by id. | |
| static void | sql_reg_del (int id) |
| Remove a SQLite handle entry from the registry. | |
Variables | |
| static SqlHandle * | g_sql_handles = NULL |
| Global head of the SQLite handle list. | |
| static int | g_sql_next_id = 1 |
| Next positive identifier to assign to a newly added handle. | |
SQLite handle registry and helper utilities for the Fun VM extension.
This translation unit implements a tiny in-process registry for SQLite connection handles that can be used by the VM opcodes living under src/vm/sqlite/*.c. The registry abstracts over raw sqlite3* pointers and assigns small positive integer identifiers to each connection. VM opcodes can then pass these identifiers around instead of raw pointers.
The code is compiled only when the CMake option FUN_WITH_SQLITE is enabled (i.e., the preprocessor symbol FUN_WITH_SQLITE is defined). When disabled, this file contributes no symbols and the corresponding opcodes should be compiled out or provide appropriate fallbacks.
Functions in this module perform only basic validation and memory allocation. Allocation failures return NULL (for lookups/additions) or are silently ignored (for deletions of non-existent ids). No SQLite API calls are made here, so no sqlite error codes are produced by this module itself.
The registry is implemented as a simple singly-linked list with no synchronization. It is NOT thread-safe. If the VM uses SQLite from multiple threads, the caller must provide external synchronization around all calls to these helpers.
Definition in file sqlite.c.
| typedef struct SqlHandle SqlHandle |
Node in a singly-linked list of registered SQLite handles.
Each node associates a monotonically increasing positive integer identifier with a raw sqlite3* pointer. The list head is stored in a file-static global (g_sql_handles).
|
static |
Add a sqlite3 handle to the registry.
Allocates a new list node, assigns a fresh positive id, and prepends it to the internal registry list. Ownership of the sqlite3 connection remains with the caller; this registry does not close the handle during deletion.
| db | Valid pointer to an opened sqlite3 connection. |
|
static |
Remove a SQLite handle entry from the registry.
Deletes the list node associated with the given id.
| id | Positive identifier of the entry to remove. |
|
static |
Look up a registered SQLite handle by id.
Performs a linear search over the internal list to find a matching id.
| id | Positive identifier previously returned by sql_reg_add(). |
|
static |