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

builtin: x.vstring() instead of string(x) (#6102)

This commit is contained in:
Delyan Angelov
2020-08-10 19:05:26 +03:00
committed by GitHub
parent eba413853f
commit 36eae1c175
30 changed files with 143 additions and 72 deletions

View File

@@ -45,7 +45,7 @@ pub fn connect(config Config) ?DB {
println("status=$status")
if status != C.CONNECTION_OK {
error_msg := C.PQerrorMessage(conn)
return error ('Connection to a PG database failed: ' + string(error_msg))
return error ('Connection to a PG database failed: ' + unsafe { error_msg.vstring() } )
}
return DB {conn: conn}
}
@@ -58,7 +58,8 @@ fn res_to_rows(res voidptr) []Row {
mut row := Row{}
for j in 0..nr_cols {
val := C.PQgetvalue(res, i, j)
row.vals << string(val)
sval := unsafe { val.vstring() }
row.vals << sval
}
rows << row
}
@@ -100,7 +101,7 @@ pub fn (db DB) q_strings(query string) []Row {
pub fn (db DB) exec(query string) []Row {
res := C.PQexec(db.conn, query.str)
e := string(C.PQerrorMessage(db.conn))
e := unsafe { C.PQerrorMessage(db.conn).vstring() }
if e != '' {
println('pg exec error:')
println(e)
@@ -118,7 +119,7 @@ fn rows_first_or_empty(rows []Row) ?Row {
pub fn (db DB) exec_one(query string) ?Row {
res := C.PQexec(db.conn, query.str)
e := string(C.PQerrorMessage(db.conn))
e := unsafe { C.PQerrorMessage(db.conn).vstring() }
if e != '' {
return error('pg exec error: "$e"')
}
@@ -156,7 +157,7 @@ pub fn (db DB) exec_param(query string, param string) []Row {
}
fn (db DB) handle_error_or_result(res voidptr, elabel string) []Row {
e := string(C.PQerrorMessage(db.conn))
e := unsafe { C.PQerrorMessage(db.conn).vstring() }
if e != '' {
println('pg $elabel error:')
println(e)