1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

pg: use unsafe

This commit is contained in:
Major Taylor 2020-02-26 17:17:56 -05:00 committed by GitHub
parent 394d64bfd0
commit c72e505fe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -121,16 +121,19 @@ pub fn (db DB) exec_one(query string) ?pg.Row {
return row
}
//
// The entire function can be considered unsafe because of the malloc and the
// free. This prevents warnings and doesn't seem to affect behavior.
pub fn (db DB) exec_param_many(query string, params []string) []pg.Row {
unsafe {
mut param_vals := &byteptr( malloc( params.len * sizeof(byteptr) ) )
for i in 0..params.len {
param_vals[i] = params[i].str
}
res := C.PQexecParams(db.conn, query.str, params.len, 0, param_vals, 0, 0, 0)
unsafe{ free(param_vals) }
free(param_vals)
return db.handle_error_or_result(res, 'exec_param_many')
}
}
pub fn (db DB) exec_param2(query string, param, param2 string) []pg.Row {
mut param_vals := [2]byteptr