Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Add initial lib and test files |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | trunk |
| Files: | files | file ages | folders |
| SHA1: |
98c988150ce0e42a84b863ef4724381c |
| User & Date: | jrusso 2017-02-24 03:04:20.439 |
Context
|
2017-02-24
| ||
| 03:04 | Add initial lib and test files Leaf check-in: 98c988150c user: jrusso tags: trunk | |
| 02:42 | initial empty check-in check-in: 563fce22bd user: MadcapJake tags: trunk | |
Changes
Added src/sqlite.stanza.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
defpackage sqlite :
import core
public lostanza deftype Database :
value: ptr<?>
extern sqlite3_open: (ptr<byte>, ptr<ptr<?>>) -> int
; int sqlite3_open(
; const char *filename, /* Database filename (UTF-8) */
; sqlite3 **ppDb /* OUT: SQLite db handle */
; );
public lostanza defn open (filename:ref<String>) -> ref<Database> :
var ppDB:ptr<?>
val status:int = call-c sqlite3_open(addr!(filename.chars), ppDB)
if status != 0 :
fatal(append(String("open failed due to ") String(status)))
return new Database{ppDB}
extern sqlite3_close_v2: (ptr<?>) -> int
; int sqlite3_close_v2(sqlite3*);
public lostanza defn close (db:ref<Database>) -> ref<Int> :
val i:int = sqlite3_close_v2(db.value)
return new Int{i}
public lostanza deftype Statement :
value: ptr<?>
; To execute an SQL query, it must first be compiled into a byte-code program using
; one of these routines.
extern sqlite3_prepare_v2: (ptr<?>, ptr<byte>, int, ptr<?>, ptr<ptr<byte>>) -> int
; int sqlite3_prepare_v2(
; sqlite3 *db, /* Database handle */
; const char *zSql, /* SQL statement, UTF-8 encoded */
; int nByte, /* Maximum length of zSql in bytes. */
; sqlite3_stmt **ppStmt, /* OUT: Statement handle */
; const char **pzTail /* OUT: Pointer to unused portion of zSql */
; );
lostanza defn prepare (db:ptr<?>, sql:ref<String>) -> ref<Statement> :
var stmt:ptr<?>
var tail:ptr<ptr<byte>>
call-c sqlite3_prepare_v2(db, addr!(sql.chars), length(sql).value, stmt, tail)
return new Statement{stmt}
; After a prepared statement has been prepared using either sqlite3_prepare_v2()
; or sqlite3_prepare16_v2() or one of the legacy interfaces sqlite3_prepare() or
; sqlite3_prepare16(), this function must be called one or more times to evaluate
; the statement.
extern sqlite3_step: (ptr<?>) -> int
; int sqlite3_step(sqlite3_stmt*);
lostanza defn step (stmt:ref<Statement>) -> ref<Int> :
val status:int = call-c sqlite3_step(stmt.value)
return new Int{status}
extern sqlite3_column_blob: (ptr<?>, int) -> ptr<byte>
; const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
lostanza defn column-blob (stmt:Statement, col:ref<Int>) -> ref<String> :
val bytes:ptr<byte> = call-c sqlite3_column_blob(stmt.value, col.value)
return String(bytes)
extern sqlite3_column_bytes: (ptr<?>, int) -> int
; int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
lostanza defn column-bytes (stmt:Statement, col:ref<Int>) -> ref<Int> :
val size:int = call-c sqlite3_column_bytes(stmt.value, col.value)
return new Int{size}
extern sqlite3_column_double: (ptr<?>, int) -> double
; double sqlite3_column_double(sqlite3_stmt*, int iCol);
lostanza defn column-double (stmt:Statement, col:ref<Int>) -> ref<Double> :
val rval:double = call-c sqlite3_column_double(stmt.value, col.value)
return new Double{rval}
extern sqlite3_column_int: (ptr<?>, int) -> int
; int sqlite3_column_int(sqlite3_stmt*, int iCol);
lostanza defn column-int (stmt:Statement, col:ref<Int>) -> ref<Int> :
val rval:int = call-c sqlite3_column_int(stmt.value, col.value)
return new Int{rval}
extern sqlite3_column_int64: (ptr<?>, int) -> long
; sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
lostanza defn column-long (stmt:Statement, col:ref<Int>) -> ref<Long> :
val rval:long = call-c sqlite3_column_int64(stmt.value, col.value)
return new Long{rval}
extern sqlite3_column_name: (ptr<?>, int) -> ptr<byte>
; const char *sqlite3_column_name(sqlite3_stmt*, int N);
lostanza defn column-name (stmt:Statement, col:ref<Int>) -> ref<String> :
val bytes:ptr<byte> = call-c sqlite3_column_name(stmt.value, col.value)
return String(bytes)
extern sqlite3_column_text: (ptr<?>, int) -> ptr<byte>
; const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
lostanza defn column-text (stmt:Statement, col:ref<Int>) -> ref<String> :
val bytes:ptr<byte> = call-c sqlite3_column_text(stmt.value, col.value)
return String(bytes)
extern sqlite3_column_type: (ptr<?>, int) -> int
; int sqlite3_column_type(sqlite3_stmt*, int iCol);
lostanza defn column-type (stmt:Statement, col:ref<Int>) -> ref<Int> :
val type-code:int = call-c sqlite3_column_type(stmt.value, col.value)
return new Int{type-code}
|
Added tests/test001.stanza.
> > > > > > > > | 1 2 3 4 5 6 7 8 |
defpackage test-sqlite :
import core
import sqlite
val db = open(":memory:")
println("In-memory database opened")
close(db)
println("In-memory database closed")
|