package sqlite3_bindings

import "core:c"

ExecProc :: #type proc "c" (
	user_arg: rawptr,
	n_cols: c.int,
	cols: [^]cstring,
	res_cols: [^]cstring,
) -> c.int

foreign import sqlite3 "system:sqlite3"
@(default_calling_convention = "c", link_prefix = "sqlite3_")
foreign sqlite3 {
	open :: proc(filename: cstring, db: ^Connection) -> c.int ---
	close :: proc(db: Connection) -> c.int ---

	prepare :: proc(db: Connection, sql: cstring, n_byte: c.int, stmt: ^Statement, tail: ^cstring) -> c.int ---
	step :: proc(stmt: Statement) -> c.int ---
	finalize :: proc(stmt: Statement) -> c.int ---

	malloc :: proc(size: c.int) -> rawptr ---
	free :: proc(ptr: rawptr) ---

	exec :: proc(db: Connection, sql: cstring, cbfun: ExecProc, user_arg: rawptr, errmsg: ^cstring) -> c.int ---

	bind_blob :: proc(stmt: Statement, idx: c.int, val: rawptr, size: c.int, destruct: proc(_: rawptr) -> rawptr) -> c.int ---
	bind_blob64 :: proc(stmt: Statement, idx: c.int, val: rawptr, size: c.int64_t, destruct: proc(_: rawptr) -> rawptr) -> c.int ---
	bind_double :: proc(stmt: Statement, idx: c.int, val: c.double) -> c.int ---
	bind_int :: proc(stmt: Statement, idx: c.int, val: c.int) -> c.int ---
	bind_int64 :: proc(stmt: Statement, idx: c.int, val: c.int64_t) -> c.int ---
	bind_null :: proc(stmt: Statement, idx: c.int) -> c.int ---
	bind_text :: proc(stmt: Statement, idx: c.int, val: cstring, size: c.int, destruct: proc(_: rawptr) -> rawptr) -> c.int ---
	bind_text16 :: proc(stmt: Statement, idx: c.int, val: cstring, size: c.int, destruct: proc(_: rawptr) -> rawptr) -> c.int ---
	bind_text64 :: proc(stmt: Statement, idx: c.int, val: cstring, size: c.int64_t, destruct: proc(_: rawptr) -> rawptr) -> c.int ---
	bind_value :: proc(stmt: Statement, idx: c.int, val: Value) -> c.int ---
	bind_pointer :: proc(stmt: Statement, idx: c.int, val: rawptr, size: c.int, destruct: proc(_: rawptr) -> rawptr) -> c.int ---
	bind_zeroblob :: proc(stmt: Statement, idx: c.int, size: c.int) -> c.int ---
	bind_zeroblob64 :: proc(stmt: Statement, idx: c.int, size: c.int64_t) -> c.int ---

	column_blob :: proc(stmt: Statement, col: c.int) -> rawptr ---
	column_double :: proc(stmt: Statement, col: c.int) -> c.double ---
	column_int :: proc(stmt: Statement, col: c.int) -> c.int ---
	column_int64 :: proc(stmt: Statement, col: c.int) -> c.int64_t ---
	column_text :: proc(stmt: Statement, col: c.int) -> cstring ---
	column_text16 :: proc(stmt: Statement, col: c.int) -> cstring ---
	column_value :: proc(stmt: Statement, col: c.int) -> Value ---
	column_bytes :: proc(stmt: Statement, col: c.int) -> c.int ---
	column_bytes16 :: proc(stmt: Statement, col: c.int) -> c.int ---
	column_type :: proc(stmt: Statement, col: c.int) -> Datatype ---
}