Skip to content

Commit 82b6825

Browse files
committed
update based on the most recent version in vlib/db/sqlite/ in V 0.4.12 a26a42d
1 parent e1f974b commit 82b6825

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

orm.v

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn bind(stmt Stmt, mut c &int, data orm.Primitive) int {
133133
err = stmt.bind_i64(c, i64(data))
134134
}
135135
f32, f64 {
136-
err = stmt.bind_f64(c, unsafe { *(&f64(&data)) })
136+
err = stmt.bind_f64(c, f64(data))
137137
}
138138
string {
139139
err = stmt.bind_text(c, data)
@@ -167,7 +167,9 @@ fn (stmt Stmt) sqlite_select_column(idx int, typ int) !orm.Primitive {
167167
return stmt.get_int(idx) or { return orm.Null{} }
168168
} else if typ in orm.num64 {
169169
return stmt.get_i64(idx) or { return orm.Null{} }
170-
} else if typ in orm.float {
170+
} else if typ == typeof[f32]().idx {
171+
return f32(stmt.get_f64(idx) or { return orm.Null{} })
172+
} else if typ == typeof[f64]().idx {
171173
return stmt.get_f64(idx) or { return orm.Null{} }
172174
} else if typ == orm.type_string {
173175
if v := stmt.get_text(idx) {

sqlite_vfs_lowlevel_test.v

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// vtest build: present_sqlite3?
12
import sqlite
23
import rand
34

@@ -281,3 +282,38 @@ fn example_vfs_getlasterror(vfs &sqlite.Sqlite3_vfs, i int, o &char) int {
281282
}
282283
return sqlite.sqlite_ok
283284
}
285+
286+
////////////////////////////////////////////////
287+
288+
struct Human {
289+
name string
290+
age f32
291+
}
292+
293+
fn check_connect_full_default_vfs(vfs_name string) ! {
294+
mut db := sqlite.connect_full(':memory:', [.readwrite, .create, .fullmutex], '')!
295+
sql db {
296+
create table Human
297+
}!
298+
h := Human{'Bilbo', 56}
299+
sql db {
300+
insert h into Human
301+
}!
302+
res := sql db {
303+
select from Human
304+
}!
305+
db.close()!
306+
assert res.len == 1
307+
assert res[0] == h
308+
}
309+
310+
fn test_connect_full_default_vfs() {
311+
// passing '' here as vfs_name should work everywhere, and it should be equivalent
312+
// to 'unix' or 'win32', depending on the current system:
313+
check_connect_full_default_vfs('')!
314+
$if windows {
315+
check_connect_full_default_vfs('win32')!
316+
} $else {
317+
check_connect_full_default_vfs('unix')!
318+
}
319+
}

vfs_lowlevel.c.v

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ pub enum OpenModeFlag {
143143

144144
// connect_full Opens connection to sqlite database. It gives more control than `open`.
145145
// Flags give control over readonly and create decisions. Specific VFS can be chosen.
146+
// Pass '' for vfs_name, if you want to use the default VFS for the current platform,
147+
// (which is equivalent to 'win32' on Windows, and 'unix' on !Windows systems).
146148
pub fn connect_full(path string, mode_flags []OpenModeFlag, vfs_name string) !DB {
147149
db := &C.sqlite3(unsafe { nil })
148150

@@ -152,7 +154,11 @@ pub fn connect_full(path string, mode_flags []OpenModeFlag, vfs_name string) !DB
152154
flags = flags | int(flag)
153155
}
154156

155-
code := C.sqlite3_open_v2(&char(path.str), &db, flags, vfs_name.str)
157+
mut pstr := unsafe { &char(0) }
158+
if vfs_name != '' {
159+
pstr = vfs_name.str
160+
}
161+
code := C.sqlite3_open_v2(&char(path.str), &db, flags, pstr)
156162
if code != 0 {
157163
return &SQLError{
158164
msg: unsafe { cstring_to_vstring(&char(C.sqlite3_errstr(code))) }

0 commit comments

Comments
 (0)