mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
orm: fix select .. limit 1 . This case now returns an ?Row.
This commit is contained in:

committed by
Alexander Medvednikov

parent
151686501d
commit
49899c649c
22
vlib/pg/pg.v
22
vlib/pg/pg.v
@@ -29,6 +29,7 @@ pub:
|
||||
host string
|
||||
user string
|
||||
password string
|
||||
dbname string
|
||||
}
|
||||
|
||||
fn C.PQconnectdb(a byteptr) *C.PGconn
|
||||
@@ -106,22 +107,23 @@ pub fn (db DB) exec(query string) []pg.Row {
|
||||
return res_to_rows(res)
|
||||
}
|
||||
|
||||
pub fn (db DB) exec_one(query string) pg.Row {
|
||||
fn rows_first_or_empty(rows []pg.Row) pg.Row? {
|
||||
if rows.len == 0 {
|
||||
return error('no row')
|
||||
}
|
||||
return rows[0]
|
||||
}
|
||||
|
||||
pub fn (db DB) exec_one(query string) pg.Row? {
|
||||
res := C.PQexec(db.conn, query.str)
|
||||
e := string(C.PQerrorMessage(db.conn))
|
||||
if e != '' {
|
||||
println('pg exec error:')
|
||||
println(e)
|
||||
return Row{}
|
||||
return error('pg exec error: "$e"')
|
||||
}
|
||||
rows := res_to_rows(res)
|
||||
if rows.len == 0 {
|
||||
return Row{}
|
||||
}
|
||||
return rows[0]
|
||||
row := rows_first_or_empty( res_to_rows(res) )
|
||||
return row
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
pub fn (db DB) exec_param2(query string, param, param2 string) []pg.Row {
|
||||
mut param_vals := [2]byteptr
|
||||
|
Reference in New Issue
Block a user