pg: hande C calls, move to .c.v files (#19739)

This commit is contained in:
JalonSolov 2023-11-03 14:43:44 -04:00 committed by GitHub
parent be89cbf26f
commit 24befa0ba6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 18 additions and 17 deletions

View File

@ -73,22 +73,6 @@ pub fn (db DB) drop(table string) ! {
// utils
fn pg_stmt_worker(db DB, query string, data orm.QueryData, where orm.QueryData) ![]Row {
mut param_types := []u32{}
mut param_vals := []&char{}
mut param_lens := []int{}
mut param_formats := []int{}
pg_stmt_binder(mut param_types, mut param_vals, mut param_lens, mut param_formats,
data)
pg_stmt_binder(mut param_types, mut param_vals, mut param_lens, mut param_formats,
where)
res := C.PQexecParams(db.conn, &char(query.str), param_vals.len, param_types.data,
param_vals.data, param_lens.data, param_formats.data, 0) // here, the last 0 means require text results, 1 - binary results
return db.handle_error_or_result(res, 'orm_stmt_worker')
}
fn pg_stmt_binder(mut types []u32, mut vals []&char, mut lens []int, mut formats []int, d orm.QueryData) {
for data in d.data {
pg_stmt_match(mut types, mut vals, mut lens, mut formats, data)

View File

@ -1,6 +1,7 @@
module pg
import io
import orm
$if $pkgconfig('libpq') {
#pkgconfig --cflags --libs libpq
@ -363,3 +364,19 @@ pub fn (db DB) copy_expert(query string, mut file io.ReaderWriter) !int {
return 0
}
fn pg_stmt_worker(db DB, query string, data orm.QueryData, where orm.QueryData) ![]Row {
mut param_types := []u32{}
mut param_vals := []&char{}
mut param_lens := []int{}
mut param_formats := []int{}
pg_stmt_binder(mut param_types, mut param_vals, mut param_lens, mut param_formats,
data)
pg_stmt_binder(mut param_types, mut param_vals, mut param_lens, mut param_formats,
where)
res := C.PQexecParams(db.conn, &char(query.str), param_vals.len, param_types.data,
param_vals.data, param_lens.data, param_formats.data, 0) // here, the last 0 means require text results, 1 - binary results
return db.handle_error_or_result(res, 'orm_stmt_worker')
}

View File

@ -214,7 +214,7 @@ fn example_vfsfile_read(file &sqlite.Sqlite3_file, output voidptr, amount int, o
vfsfile.vfs_state.log << 'read file=${vfsfile.name}'
unsafe {
C.memset(output, 0, amount)
vmemset(output, 0, amount)
}
return sqlite.sqlite_ioerr_short_read