Previous Top Index Next

Sqlite Database Functions

BRexx API for accessing Sqlite databases. MySQL can be compiled as static with the brexx program or as a shared library that has to be imported to the interpreter before use with the command CALL import "sqlite.r".


call import "sqlite.r"
call sqlite		/* initialize library */
call sqlopen "test.db"
call sql "create table square (id integer primary key, id2 integer, b blob)"
call sql "insert into square values (?,?,?)"	/* prepare insert statement */
/* insert records */
do i=1 to 10
	call sqlreset
	call sqlbind 1,"i",i
	call sqlbind 2,"i",i**2
	call sqlbind 3,"b",copies("sql",i)
	call sqlstep	/* perform the insertion */

/* read records */
say "Record=" sql("select * from square")
do until sqlstep()=="DONE"
	do i=1 to sqlget()
		call write ,sqlget(i)"|"
call sqlclose
Executes a SQL query specified as a sqlcmd string. Returns the number of affected rows.
sql('select * from test',2)
sql('insert into test set (name="Vasilis")')
sql('select last_insert_id()')

SQLBIND(col, <"B"|"I"|"F"|"D"|"S"|"T"|"N"|Z">, value)

Binds a parameter indexed by a ? at column position col by a value of type:
 B for blob
 I for integer
 D | F for double or float
 S | T for string or text
 N for null
 Z for zero blob
call sqlbind(1,"N")
call sqlbind(1,"D",10.0)


ends the connection with the Sqlite file. Doesn't return anything
call sqlclose


with no options returns then number of columns. When the column is specified then return the value of the column number of the current record.
 V = return value of column
 T = return type of column
 N = return name of column
sqlget() /* 2 */
sqlget(1) /* 'hello' */
sqlget(1,'T') /* TEXT */
sqlget(1,'N') /* name */


Return the last error message if any
say sqlerror() /* Cannot open database */


Initialize the sqlite library and common constants
call sqlite


Opens file database as an sqlite3 database. Returns "0" if ok, otherwise the error number.


Initializes the global variables of SQLITE. Look the sqlite.r library for the description
call sqlite


Resets the current statement
call sqlreset


Moves to the next record and returns the word "ROW" if there is next row or "DONE" then arrives to the end of the query
call sqlstep

Previous Top Index Next