aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/sqlite/stmt.v
diff options
context:
space:
mode:
authorIndrajith K L2022-12-03 17:00:20 +0530
committerIndrajith K L2022-12-03 17:00:20 +0530
commitf5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch)
tree2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/vlib/sqlite/stmt.v
downloadcli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'v_windows/v/vlib/sqlite/stmt.v')
-rw-r--r--v_windows/v/vlib/sqlite/stmt.v74
1 files changed, 74 insertions, 0 deletions
diff --git a/v_windows/v/vlib/sqlite/stmt.v b/v_windows/v/vlib/sqlite/stmt.v
new file mode 100644
index 0000000..da07e82
--- /dev/null
+++ b/v_windows/v/vlib/sqlite/stmt.v
@@ -0,0 +1,74 @@
+module sqlite
+
+fn C.sqlite3_bind_double(&C.sqlite3_stmt, int, f64) int
+fn C.sqlite3_bind_int(&C.sqlite3_stmt, int, int) int
+fn C.sqlite3_bind_int64(&C.sqlite3_stmt, int, i64) int
+fn C.sqlite3_bind_text(&C.sqlite3_stmt, int, &char, int, voidptr) int
+
+// Only for V ORM
+fn (db DB) init_stmt(query string) (&C.sqlite3_stmt, int) {
+ // println('init_stmt("$query")')
+ stmt := &C.sqlite3_stmt(0)
+ err := C.sqlite3_prepare_v2(db.conn, &char(query.str), query.len, &stmt, 0)
+ return stmt, err
+}
+
+fn (db DB) new_init_stmt(query string) ?Stmt {
+ stmt, err := db.init_stmt(query)
+ if err != sqlite_ok {
+ return db.error_message(err, query)
+ }
+ return Stmt{stmt, unsafe { &db }}
+}
+
+fn (stmt Stmt) bind_int(idx int, v int) int {
+ return C.sqlite3_bind_int(stmt.stmt, idx, v)
+}
+
+fn (stmt Stmt) bind_i64(idx int, v i64) int {
+ return C.sqlite3_bind_int64(stmt.stmt, idx, v)
+}
+
+fn (stmt Stmt) bind_f64(idx int, v f64) int {
+ return C.sqlite3_bind_double(stmt.stmt, idx, v)
+}
+
+fn (stmt Stmt) bind_text(idx int, s string) int {
+ return C.sqlite3_bind_text(stmt.stmt, idx, voidptr(s.str), s.len, 0)
+}
+
+fn (stmt Stmt) get_int(idx int) int {
+ return C.sqlite3_column_int(stmt.stmt, idx)
+}
+
+fn (stmt Stmt) get_i64(idx int) i64 {
+ return C.sqlite3_column_int64(stmt.stmt, idx)
+}
+
+fn (stmt Stmt) get_f64(idx int) f64 {
+ return C.sqlite3_column_double(stmt.stmt, idx)
+}
+
+fn (stmt Stmt) get_text(idx int) string {
+ b := &char(C.sqlite3_column_text(stmt.stmt, idx))
+ return unsafe { b.vstring() }
+}
+
+fn (stmt Stmt) get_count() int {
+ return C.sqlite3_column_count(stmt.stmt)
+}
+
+fn (stmt Stmt) step() int {
+ return C.sqlite3_step(stmt.stmt)
+}
+
+fn (stmt Stmt) orm_step(query string) ? {
+ res := stmt.step()
+ if res != sqlite_ok && res != sqlite_done && res != sqlite_row {
+ return stmt.db.error_message(res, query)
+ }
+}
+
+fn (stmt Stmt) finalize() {
+ C.sqlite3_finalize(stmt.stmt)
+}