sqlite3 Functions

The mappings of sqlite3 types to/from Idio types is:

Idio to sqlite3

fixnum

SQLITE_INTEGER

integer bignum

SQLITE_INTEGER

non-integer bignum

SQLITE_FLOAT

C/int

SQLITE_INTEGER

C/double

SQLITE_FLOAT

#n

SQLITE_NULL

libc/int64_t

SQLITE_INTEGER

octet-string or pathname

SQLITE_BLOB

string

SQLITE_TEXT

sqlite3 to Idio

SQLITE_BLOB

octet-string

SQLITE_FLOAT

bignum

SQLITE_INTEGER

integer (fixnum or bignum)

SQLITE_NULL

#n

SQLITE_TEXT

string

function sqlite3/sqlite3-open name [flags]

Return the database connection for name

Param name:

database name

Type name:

string

Param flags:

database open flags

Type flags:

C/int

Return:

database connection

Rtype:

sqlite3-db

Raises ^rt-libc-format-error:

if name contains an ASCII NUL

Raises ^rt-sqlite3-error:

Note

On versions of sqlite3 prior to v3.5.0, sqlite3_open() will be called and flags is ignored.

function sqlite3/sqlite3-close db

Close the database connection to db

Param db:

database connection

Type db:

sqlite3-db

Return:

sqlite3 return code

Rtype:

C/int

Raises ^rt-sqlite3-error:

All of the associated stmts will be finalized first.

Note

On versions of sqlite3 prior to v3.7.14, sqlite3_close() will be called which may report errors such as SQLITE_BUSY.

function sqlite3/sqlite3-errmsg db

Return a description of the current error in db

Param db:

database connection

Type db:

sqlite3-db

Return:

error message

Rtype:

string

Raises ^rt-sqlite3-error:

function sqlite3/sqlite3-prepare db sql

Compile sql for db

Param db:

database connection

Type db:

sqlite3-db

Param sql:

SQL statement text

Type sql:

string

Return:

database stmt

Rtype:

C/pointer to a sqlite3/stmt

Raises ^rt-libc-format-error:

if sql contains an ASCII NUL

Raises ^rt-sqlite3-error:

function sqlite3/sqlite3-finalize stmt

Finalize stmt

Param stmt:

prepared statement

Type stmt:

sqlite3/stmt

Return:

sqlite3 return code

Rtype:

C/int

Raises ^rt-sqlite3-error:

function sqlite3/sqlite3-bind-blob stmt i v

Replace parameter i with blob v in stmt

Param stmt:

SQL statement

Type stmt:

C/pointer to sqlite3/stmt

Param i:

parameter index

Type i:

fixnum

Param v:

parameter value

Type v:

octet-string

Return:

sqlite3 return code

Rtype:

C/int

Raises ^rt-sqlite3-error:

Note

On versions of sqlite3 prior to v3.8.7 sqlite3_bind_blob() will be called which will limit the valid size of v to a C/int.

function sqlite3/sqlite3-bind-double stmt i v

Replace parameter i with blob v in stmt

Param stmt:

SQL statement

Type stmt:

C/pointer to sqlite3/stmt

Param i:

parameter index

Type i:

fixnum

Param v:

parameter value

Type v:

C/double or bignum

Return:

sqlite3 return code

Rtype:

C/int

Raises ^rt-sqlite3-error:

function sqlite3/sqlite3-bind-int stmt i v

Replace parameter i with blob v in stmt

Param stmt:

SQL statement

Type stmt:

C/pointer to sqlite3/stmt

Param i:

parameter index

Type i:

fixnum

Param v:

parameter value

Type v:

C/int|libc/int64_t|fixnum|integer bignum

Return:

sqlite3 return code

Rtype:

C/int

Raises ^rt-sqlite3-error:

function sqlite3/sqlite3-bind-null stmt i v

Replace parameter i with blob v in stmt

Param stmt:

SQL statement

Type stmt:

C/pointer to sqlite3/stmt

Param i:

parameter index

Type i:

fixnum

Param v:

parameter value

Type v:

#n

Return:

sqlite3 return code

Rtype:

C/int

Raises ^rt-sqlite3-error:

function sqlite3/sqlite3-bind-text stmt i v

Replace parameter i with blob v in stmt

Param stmt:

SQL statement

Type stmt:

C/pointer to sqlite3/stmt

Param i:

parameter index

Type i:

fixnum

Param v:

parameter value

Type v:

string

Return:

sqlite3 return code

Rtype:

C/int

Raises ^rt-sqlite3-error:

Note

On versions of sqlite3 prior to v3.8.7 sqlite3_bind_text() will be called which will limit the valid size of v to a C/int.

function sqlite3/sqlite3-bind stmt [idx val ...]

Replace parameters in stmt

Param stmt:

SQL statement

Type stmt:

C/pointer to sqlite3/stmt

Return:

sqlite3 return code

Rtype:

C/int

Raises ^rt-sqlite3-error:

Arguments should be supplied in idx val tuples.

idx can be an integer or a (named parameter) string.

The sqlite3 type will be inferred from val’s Idio type.

Tip

parameters are indexed from 1

function sqlite3/sqlite3-bind-parameter-index stmt key

Return the index of parameter key in stmt

Param stmt:

SQL statement

Type stmt:

C/pointer to sqlite3/stmt

Param key:

parameter name

Type key:

string

Return:

parameter index

Rtype:

fixnum

Raises ^rt-sqlite3-error:

function sqlite3/sqlite3-step stmt

Return the next row for stmt

Param stmt:

SQL statement

Type stmt:

C/pointer to sqlite3/stmt

Return:

list of columns

Rtype:

list or #f

Raises ^rt-sqlite3-error:

function sqlite3/sqlite3-column stmt idx

Return column idx for the current row of stmt

Param stmt:

SQL statement

Type stmt:

C/pointer to sqlite3/stmt

Param idx:

column index

Type idx:

fixnum

Return:

column

Rtype:

based on column type

Raises ^rt-sqlite3-error:

Tip

columns are indexed from 0

function sqlite3/sqlite3-reset stmt

Reset stmt

Param stmt:

SQL statement

Type stmt:

C/pointer to sqlite3/stmt

Return:

sqlite3 return code

Rtype:

C/int

Raises ^rt-sqlite3-error:

function sqlite3/sqlite3-exec db sql [callback]

Execute sql against db

Param db:

SQL statement

Type db:

C/pointer to sqlite3-db

Param sql:

SQL statement text

Type sql:

string

Param callback:

callback function, defaults to none

Type callback:

function, optional

Return:

sqlite3 return code

Rtype:

C/int

Raises ^rt-sqlite3-error:

For each row in the results, callback will be invoked with two arguments: a list of column values as strings; a list of column names.

function sqlite3/sqlite3-version

Return the sqlite3 version

Return:

sqlite3 version

Rtype:

string

Last built at 2024-12-21T07:10:43Z+0000 from 62cca4c (dev) for Idio 0.3.b.6