diff --git a/cmd/tools/vtest-self.v b/cmd/tools/vtest-self.v index aea49b8bed362e..03c62ccdff858d 100644 --- a/cmd/tools/vtest-self.v +++ b/cmd/tools/vtest-self.v @@ -92,6 +92,7 @@ const skip_test_files = [ 'vlib/db/mysql/mysql_test.v', // mysql not installed 'vlib/db/mysql/prepared_stmt_test.v', // mysql not installed 'vlib/db/pg/pg_orm_test.v', // pg not installed + 'vlib/db/pg/pg_test.v', // pg not installed ] // These tests are too slow to be run in the CI on each PR/commit // in the sanitized modes: diff --git a/vlib/db/pg/pg.c.v b/vlib/db/pg/pg.c.v index 1ef90431a5c41d..049a36b967f238 100644 --- a/vlib/db/pg/pg.c.v +++ b/vlib/db/pg/pg.c.v @@ -190,8 +190,7 @@ fn res_to_rows(res voidptr) []Row { row.vals << none } else { val := C.PQgetvalue(res, i, j) - sval := unsafe { val.vstring() } - row.vals << sval + row.vals << unsafe { cstring_to_vstring(val) } } } rows << row diff --git a/vlib/db/pg/pg_test.v b/vlib/db/pg/pg_test.v new file mode 100644 index 00000000000000..261c93c083de7c --- /dev/null +++ b/vlib/db/pg/pg_test.v @@ -0,0 +1,24 @@ +module main + +import db.pg + +const query = 'SELECT ischema.table_schema, c.relname, a.attname, t.typname, t.typalign, t.typlen + FROM pg_class c + JOIN information_schema.tables ischema on ischema.table_name = c.relname + JOIN pg_attribute a ON (a.attrelid = c.oid) + JOIN pg_type t ON (t.oid = a.atttypid) +WHERE + a.attnum >= 0' + +fn test_large_exec() { + db := pg.connect(pg.Config{ user: 'postgres', password: 'secret', dbname: 'postgres' })! + defer { + db.close() + } + + rows := db.exec(query)! + for row in rows { + // We just need to access the memory to ensure it's properly allocated + row.str() + } +}