2015-03-13 00:08:01 +00:00
|
|
|
require "./type"
|
|
|
|
|
2015-03-12 21:21:33 +00:00
|
|
|
@[Link("sqlite3")]
|
|
|
|
lib LibSQLite3
|
|
|
|
type SQLite3 = Void*
|
|
|
|
type Statement = Void*
|
2016-03-15 02:53:51 +00:00
|
|
|
type SQLite3Backup = Void*
|
2020-11-11 18:00:40 +00:00
|
|
|
type SQLite3Context = Void*
|
|
|
|
type SQLite3Value = Void*
|
2015-03-12 21:21:33 +00:00
|
|
|
|
|
|
|
enum Code
|
2018-10-05 14:53:19 +00:00
|
|
|
# Successful result
|
|
|
|
OKAY = 0
|
|
|
|
# Generic error
|
|
|
|
ERROR = 1
|
|
|
|
# Internal logic error in SQLite
|
|
|
|
INTERNAL = 2
|
|
|
|
# Access permission denied
|
|
|
|
PERM = 3
|
|
|
|
# Callback routine requested an abort
|
|
|
|
ABORT = 4
|
|
|
|
# The database file is locked
|
|
|
|
BUSY = 5
|
|
|
|
# A table in the database is locked
|
|
|
|
LOCKED = 6
|
|
|
|
# A malloc() failed
|
|
|
|
NOMEM = 7
|
|
|
|
# Attempt to write a readonly database
|
|
|
|
READONLY = 8
|
|
|
|
# Operation terminated by sqlite3_interrupt()
|
|
|
|
INTERRUPT = 9
|
|
|
|
# Some kind of disk I/O error occurred
|
|
|
|
IOERR = 10
|
|
|
|
# The database disk image is malformed
|
|
|
|
CORRUPT = 11
|
|
|
|
# Unknown opcode in sqlite3_file_control()
|
|
|
|
NOTFOUND = 12
|
|
|
|
# Insertion failed because database is full
|
|
|
|
FULL = 13
|
|
|
|
# Unable to open the database file
|
|
|
|
CANTOPEN = 14
|
|
|
|
# Database lock protocol error
|
|
|
|
PROTOCOL = 15
|
|
|
|
# Internal use only
|
|
|
|
EMPTY = 16
|
|
|
|
# The database schema changed
|
|
|
|
SCHEMA = 17
|
|
|
|
# String or BLOB exceeds size limit
|
|
|
|
TOOBIG = 18
|
|
|
|
# Abort due to constraint violation
|
|
|
|
CONSTRAINT = 19
|
|
|
|
# Data type mismatch
|
|
|
|
MISMATCH = 20
|
|
|
|
# Library used incorrectly
|
|
|
|
MISUSE = 21
|
|
|
|
# Uses OS features not supported on host
|
|
|
|
NOLFS = 22
|
|
|
|
# Authorization denied
|
|
|
|
AUTH = 23
|
|
|
|
# Not used
|
|
|
|
FORMAT = 24
|
|
|
|
# 2nd parameter to sqlite3_bind out of range
|
|
|
|
RANGE = 25
|
|
|
|
# File opened that is not a database file
|
|
|
|
NOTADB = 26
|
|
|
|
# Notifications from sqlite3_log()
|
|
|
|
NOTICE = 27
|
|
|
|
# Warnings from sqlite3_log()
|
|
|
|
WARNING = 28
|
|
|
|
# sqlite3_step() has another row ready
|
|
|
|
ROW = 100
|
|
|
|
# sqlite3_step() has finished executing
|
2015-03-12 21:21:33 +00:00
|
|
|
DONE = 101
|
|
|
|
end
|
|
|
|
|
|
|
|
alias Callback = (Void*, Int32, UInt8**, UInt8**) -> Int32
|
2020-11-11 18:00:40 +00:00
|
|
|
alias FuncCallback = (SQLite3Context, Int32, SQLite3Value*) -> Void
|
2015-03-12 21:21:33 +00:00
|
|
|
|
2016-07-11 18:24:37 +00:00
|
|
|
fun open_v2 = sqlite3_open_v2(filename : UInt8*, db : SQLite3*, flags : ::SQLite3::Flag, zVfs : UInt8*) : Int32
|
2015-03-12 21:21:33 +00:00
|
|
|
|
|
|
|
fun errcode = sqlite3_errcode(SQLite3) : Int32
|
|
|
|
fun errmsg = sqlite3_errmsg(SQLite3) : UInt8*
|
|
|
|
|
2016-03-15 02:53:51 +00:00
|
|
|
fun backup_init = sqlite3_backup_init(SQLite3, UInt8*, SQLite3, UInt8*) : SQLite3Backup
|
2017-01-17 19:57:27 +00:00
|
|
|
fun backup_step = sqlite3_backup_step(SQLite3Backup, Int32) : Code
|
2016-03-17 00:17:56 +00:00
|
|
|
fun backup_finish = sqlite3_backup_finish(SQLite3Backup) : Code
|
2016-03-15 02:53:51 +00:00
|
|
|
|
2015-03-12 21:21:33 +00:00
|
|
|
fun prepare_v2 = sqlite3_prepare_v2(db : SQLite3, zSql : UInt8*, nByte : Int32, ppStmt : Statement*, pzTail : UInt8**) : Int32
|
2023-02-18 20:06:09 +00:00
|
|
|
fun exec = sqlite3_exec(db : SQLite3, zSql : UInt8*, pCallback : Callback, pCallbackArgs : Void*, pzErrMsg : UInt8**) : Int32
|
2015-03-12 21:21:33 +00:00
|
|
|
fun step = sqlite3_step(stmt : Statement) : Int32
|
|
|
|
fun column_count = sqlite3_column_count(stmt : Statement) : Int32
|
2016-07-11 18:24:37 +00:00
|
|
|
fun column_type = sqlite3_column_type(stmt : Statement, iCol : Int32) : ::SQLite3::Type
|
2015-03-12 21:21:33 +00:00
|
|
|
fun column_int64 = sqlite3_column_int64(stmt : Statement, iCol : Int32) : Int64
|
|
|
|
fun column_double = sqlite3_column_double(stmt : Statement, iCol : Int32) : Float64
|
|
|
|
fun column_text = sqlite3_column_text(stmt : Statement, iCol : Int32) : UInt8*
|
|
|
|
fun column_bytes = sqlite3_column_bytes(stmt : Statement, iCol : Int32) : Int32
|
|
|
|
fun column_blob = sqlite3_column_blob(stmt : Statement, iCol : Int32) : UInt8*
|
|
|
|
|
|
|
|
fun bind_int = sqlite3_bind_int(stmt : Statement, idx : Int32, value : Int32) : Int32
|
|
|
|
fun bind_int64 = sqlite3_bind_int64(stmt : Statement, idx : Int32, value : Int64) : Int32
|
|
|
|
fun bind_text = sqlite3_bind_text(stmt : Statement, idx : Int32, value : UInt8*, bytes : Int32, destructor : Void* ->) : Int32
|
2017-09-19 19:48:05 +00:00
|
|
|
fun bind_blob = sqlite3_bind_blob(stmt : Statement, idx : Int32, value : UInt8*, bytes : Int32, destructor : Void* ->) : Int32
|
2015-03-12 21:21:33 +00:00
|
|
|
fun bind_null = sqlite3_bind_null(stmt : Statement, idx : Int32) : Int32
|
|
|
|
fun bind_double = sqlite3_bind_double(stmt : Statement, idx : Int32, value : Float64) : Int32
|
|
|
|
|
|
|
|
fun bind_parameter_index = sqlite3_bind_parameter_index(stmt : Statement, name : UInt8*) : Int32
|
|
|
|
fun reset = sqlite3_reset(stmt : Statement) : Int32
|
|
|
|
fun column_name = sqlite3_column_name(stmt : Statement, idx : Int32) : UInt8*
|
|
|
|
fun last_insert_rowid = sqlite3_last_insert_rowid(db : SQLite3) : Int64
|
2016-02-04 00:29:19 +00:00
|
|
|
fun changes = sqlite3_changes(db : SQLite3) : Int32
|
2015-03-12 21:21:33 +00:00
|
|
|
|
|
|
|
fun finalize = sqlite3_finalize(stmt : Statement) : Int32
|
|
|
|
fun close_v2 = sqlite3_close_v2(SQLite3) : Int32
|
2017-05-29 18:20:32 +00:00
|
|
|
fun close = sqlite3_close(SQLite3) : Int32
|
2020-11-11 18:00:40 +00:00
|
|
|
|
|
|
|
fun create_function = sqlite3_create_function(SQLite3, funcName : UInt8*, nArg : Int32, eTextRep : Int32, pApp : Void*, xFunc : FuncCallback, xStep : Void*, xFinal : Void*) : Int32
|
|
|
|
fun value_text = sqlite3_value_text(SQLite3Value) : UInt8*
|
|
|
|
fun result_int = sqlite3_result_int(SQLite3Context, Int32) : Nil
|
2015-03-12 21:21:33 +00:00
|
|
|
end
|