|
|
2 dagen geleden | |
|---|---|---|
| .. | ||
| showcase | 2 dagen geleden | |
| tests | 2 dagen geleden | |
| .gitignore | 2 dagen geleden | |
| README.md | 2 dagen geleden | |
| SQLite.def | 2 dagen geleden | |
| run.sh | 2 dagen geleden | |
This is a small, hand-written V3 binding for the core SQLite API:
scalar values, BLOBs, prepared statements, connection control and
callbacks. It is not a replacement for the full m2SQLITE
definition.
(* connection *)
sqlite3_open
sqlite3_open_v2
sqlite3_exec
sqlite3_close
sqlite3_close_v2
(* prepared statements *)
sqlite3_prepare_v2
sqlite3_bind_int
sqlite3_bind_int64
sqlite3_bind_double
sqlite3_bind_null
sqlite3_bind_blob
sqlite3_bind_zeroblob
sqlite3_bind_text
sqlite3_step
sqlite3_reset
sqlite3_clear_bindings
sqlite3_finalize
(* row change metadata *)
sqlite3_changes
sqlite3_total_changes
sqlite3_last_insert_rowid
(* column metadata and scalar results *)
sqlite3_column_count
sqlite3_data_count
sqlite3_column_type
sqlite3_column_bytes
sqlite3_column_int
sqlite3_column_int64
sqlite3_column_double
sqlite3_column_blob
sqlite3_column_text
sqlite3_column_name
sqlite3_column_decltype
(* errors and ownership *)
sqlite3_errmsg
sqlite3_errstr
sqlite3_errcode
sqlite3_extended_errcode
sqlite3_extended_result_codes
sqlite3_free
(* incremental BLOB I/O *)
sqlite3_blob_open
sqlite3_blob_close
sqlite3_blob_read
sqlite3_blob_write
sqlite3_blob_bytes
sqlite3_blob_reopen
(* callbacks and user-defined scalar functions *)
sqlite3_create_function_v2
sqlite3_value_type
sqlite3_value_int
sqlite3_value_int64
sqlite3_value_double
sqlite3_value_text
sqlite3_value_blob
sqlite3_value_bytes
sqlite3_result_null
sqlite3_result_int
sqlite3_result_int64
sqlite3_result_double
sqlite3_result_text
sqlite3_result_blob
sqlite3_result_error
sqlite3_result_error_code
sqlite3_user_data
sqlite3_context_db_handle
(* binding helpers *)
SQLiteArrayAt
SQLiteTransient
The matching constants include the primary result codes
(SQLiteOk, SQLiteConstraint, ...), SQLiteRow, SQLiteDone,
storage classes (SQLiteInteger, SQLiteFloat, SQLiteText,
SQLiteBlob, SQLiteNull), a few extended constraints, the
SQLiteOpen* flags used by sqlite3_open_v2 and sqlite3_blob_open,
and SQLiteUtf* / SQLiteDeterministic for function registration.
run.sh builds and runs:
SQLiteSmoke.mod - open / exec / closeSQLitePrepared.mod - prepared insert and selectSQLiteScalar.mod - int, int64, double, text, NULL and column metadataSQLiteErrors.mod - error codes, errmsg/errstr and sqlite3_freeSQLiteBlob.mod - bind_blob, bind_zeroblob, column_blob and incremental BLOB I/OSQLiteConnection.mod - open_v2, close_v2, changes/rowid and deferred closeSQLiteCallback.mod - exec row callbacks and user-defined scalar functionsshowcase/SQLiteShowcase.mod - prepared-statement walkthroughThe showcase prints:
1: Ada
2: Grace
./run.sh
The script uses pkg-config --libs sqlite3 when available; otherwise it
links the versioned runtime library directly:
/usr/lib/x86_64-linux-gnu/libsqlite3.so.0
That fallback matters on systems with the SQLite runtime installed but
without libsqlite3-dev.
sqlite3_exec now takes VAR errmsg : ADDRESS. A non-NIL message is
allocated by SQLite and must be released with sqlite3_free.sqlite3_errmsg and sqlite3_errstr return borrowed C strings. Copy
them with CStr.Copy if they need to outlive the next SQLite call.sqlite3_column_text and sqlite3_column_blob return pointers valid
only until the next step, reset or finalize; copy or consume them
immediately.ADR(a[0]), not ADR(a):
ADR(a) points at the V3 array descriptor.SQLiteTransient() supplies the SQLITE_TRANSIENT sentinel so SQLite
copies bound text or BLOB data. Passing NIL means SQLITE_STATIC;
the caller's buffer must then stay alive until the statement is reset
or finalized.sqlite3_blob_open needs an explicit SQLiteOpenReadOnly or
SQLiteOpenReadWrite flag. A BLOB handle holds a read/write lock on
its row until sqlite3_blob_close.sqlite3_exec callbacks receive char **argv and char **colNames
as ADDRESS; use SQLiteArrayAt(argv, i) and
SQLiteArrayAt(colNames, i) to reach each entry.sqlite3_value **argv as ADDRESS;
pass each SQLiteArrayAt(argv, i) result to sqlite3_value_* or
sqlite3_result_*.sqlite3_exec and
sqlite3_errcode can report an extended code such as
SQLiteConstraintPrimaryKey (1555) rather than only
SQLiteConstraint (19).Remaining callback hooks (busy handler, authorizer, progress handler, trace/update hooks), backup, extension loading, WAL/checkpoint helpers, connection configuration and statement parameter introspection.