mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
refactor(sqlite): Removed db_ prefix from db_open and db_close.
This commit is contained in:
4
TODOS.md
4
TODOS.md
@@ -48,6 +48,10 @@
|
||||
|
||||
26. Test all cmds / terminal branches.
|
||||
|
||||
27. Replace `fmt.tprintf("/tmp/envr-test-...-%d", os.get_pid())` + `os.mkdir_all` in test files with `os.mkdir_temp` (race-free, honors `$TMPDIR`, matches `findr/test_env.odin` pattern).
|
||||
|
||||
28. Adopt `core:log` across `db.odin`, `crypto.odin`, `config.odin`, `ssh.odin` — replace ~30 scattered `fmt.printf("Error ...")` calls with leveled logging for consistent stderr routing and source locations.
|
||||
|
||||
## Double-check AI output
|
||||
|
||||
- [ ] cli.odin
|
||||
|
||||
8
db.odin
8
db.odin
@@ -65,7 +65,7 @@ db_open :: proc(cfg_path: string) -> (database: Db, ok: bool) {
|
||||
data_path := data_path(database.cfg.config_path, context.temp_allocator)
|
||||
if os.exists(data_path) {
|
||||
if ok = db_restore_from_encrypted(&database, data_path); !ok {
|
||||
sqlite.db_close(database.db)
|
||||
sqlite.close(database.db)
|
||||
return database, false
|
||||
}
|
||||
} else {
|
||||
@@ -80,7 +80,7 @@ db_open :: proc(cfg_path: string) -> (database: Db, ok: bool) {
|
||||
// In production, you most likely want to use `db_open`.
|
||||
db_init :: proc() -> (database: Db, ok: bool) {
|
||||
db: ^rawptr
|
||||
rc := sqlite.db_open(":memory:", &db)
|
||||
rc := sqlite.open(":memory:", &db)
|
||||
if rc != sqlite.OK {
|
||||
fmt.printf("Error opening in-memory database: %s\n", sqlite.db_errmsg(db))
|
||||
return
|
||||
@@ -90,7 +90,7 @@ db_init :: proc() -> (database: Db, ok: bool) {
|
||||
rc = sqlite.db_exec(db, create_sql, nil, nil, nil)
|
||||
if rc != sqlite.OK {
|
||||
fmt.printf("Error creating table: %s\n", sqlite.db_errmsg(db))
|
||||
sqlite.db_close(db)
|
||||
sqlite.close(db)
|
||||
return
|
||||
}
|
||||
database.db = db
|
||||
@@ -148,7 +148,7 @@ db_close :: proc(d: ^Db) {
|
||||
allocator := db_allocator(d)
|
||||
|
||||
defer {
|
||||
sqlite.db_close(d.db)
|
||||
sqlite.close(d.db)
|
||||
|
||||
delete_config(&d.cfg, allocator)
|
||||
|
||||
|
||||
@@ -166,12 +166,12 @@ test_decrypt_then_deserialize_sqlite :: proc(t: ^testing.T) {
|
||||
defer delete(plaintext)
|
||||
|
||||
mem_db: ^rawptr
|
||||
rc := sqlite.db_open(":memory:", &mem_db)
|
||||
rc := sqlite.open(":memory:", &mem_db)
|
||||
testing.expectf(t, rc == sqlite.OK, "failed to open in-memory db")
|
||||
if rc != sqlite.OK {
|
||||
return
|
||||
}
|
||||
defer sqlite.db_close(mem_db)
|
||||
defer sqlite.close(mem_db)
|
||||
|
||||
n := i64(len(plaintext))
|
||||
buf := sqlite.malloc64(n)
|
||||
|
||||
@@ -12,34 +12,35 @@ DESERIALIZE_FREEONCLOSE :: 1
|
||||
DESERIALIZE_RESIZEABLE :: 2
|
||||
|
||||
foreign lib {
|
||||
@(link_name="sqlite3_open")
|
||||
db_open :: proc(filename: cstring, ppDb: ^^rawptr) -> c.int ---
|
||||
@(link_name="sqlite3_close")
|
||||
db_close :: proc(db: ^rawptr) -> c.int ---
|
||||
@(link_name="sqlite3_errmsg")
|
||||
@(link_name = "sqlite3_open")
|
||||
open :: proc(filename: cstring, ppDb: ^^rawptr) -> c.int ---
|
||||
@(link_name = "sqlite3_close")
|
||||
close :: proc(db: ^rawptr) -> c.int ---
|
||||
@(link_name = "sqlite3_errmsg")
|
||||
db_errmsg :: proc(db: ^rawptr) -> cstring ---
|
||||
@(link_name="sqlite3_exec")
|
||||
@(link_name = "sqlite3_exec")
|
||||
db_exec :: proc(db: ^rawptr, sql: cstring, callback: rawptr, callback_arg: rawptr, errmsg: ^cstring) -> c.int ---
|
||||
@(link_name="sqlite3_prepare_v2")
|
||||
@(link_name = "sqlite3_prepare_v2")
|
||||
prepare_v2 :: proc(db: ^rawptr, sql: cstring, nByte: c.int, ppStmt: ^^rawptr, pzTail: ^cstring) -> c.int ---
|
||||
@(link_name="sqlite3_step")
|
||||
@(link_name = "sqlite3_step")
|
||||
step :: proc(stmt: ^rawptr) -> c.int ---
|
||||
@(link_name="sqlite3_finalize")
|
||||
@(link_name = "sqlite3_finalize")
|
||||
finalize :: proc(stmt: ^rawptr) -> c.int ---
|
||||
@(link_name="sqlite3_column_text")
|
||||
@(link_name = "sqlite3_column_text")
|
||||
column_text :: proc(stmt: ^rawptr, iCol: c.int) -> cstring ---
|
||||
@(link_name="sqlite3_column_bytes")
|
||||
@(link_name = "sqlite3_column_bytes")
|
||||
column_bytes :: proc(stmt: ^rawptr, iCol: c.int) -> c.int ---
|
||||
@(link_name="sqlite3_bind_text")
|
||||
@(link_name = "sqlite3_bind_text")
|
||||
bind_text :: proc(stmt: ^rawptr, idx: c.int, val: cstring, n: c.int, destructor: rawptr) -> c.int ---
|
||||
@(link_name="sqlite3_changes")
|
||||
@(link_name = "sqlite3_changes")
|
||||
changes :: proc(db: ^rawptr) -> c.int ---
|
||||
@(link_name="sqlite3_serialize")
|
||||
@(link_name = "sqlite3_serialize")
|
||||
serialize :: proc(db: ^rawptr, zSchema: cstring, piSize: ^i64, mFlags: u32) -> [^]u8 ---
|
||||
@(link_name="sqlite3_deserialize")
|
||||
@(link_name = "sqlite3_deserialize")
|
||||
deserialize :: proc(db: ^rawptr, zSchema: cstring, pData: [^]u8, szDb: i64, szBuf: i64, mFlags: u32) -> c.int ---
|
||||
@(link_name="sqlite3_malloc64")
|
||||
@(link_name = "sqlite3_malloc64")
|
||||
malloc64 :: proc(n: i64) -> [^]u8 ---
|
||||
@(link_name="sqlite3_free")
|
||||
@(link_name = "sqlite3_free")
|
||||
free :: proc(p: rawptr) ---
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user