From ddef6ca74563d3403b217dc04986ce74d418d1fb Mon Sep 17 00:00:00 2001 From: shura Date: Fri, 27 Jan 2023 10:51:59 +0200 Subject: [PATCH] fix --- src/pg/pg.c | 4 +++- test/pg/test_pg.c | 15 +++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/pg/pg.c b/src/pg/pg.c index d24acf6..c1b32c9 100644 --- a/src/pg/pg.c +++ b/src/pg/pg.c @@ -519,7 +519,9 @@ static void clear_params (pg_params_t *params) { } static void _get_result (pgres_t *res) { - strcpy(dbcli_state, PQresultErrorField(res->stmt, PG_DIAG_SQLSTATE)); + char *s = PQresultErrorField(res->stmt, PG_DIAG_SQLSTATE); + if (s) + strcpy(dbcli_state, s); switch (PQresultStatus(res->stmt)) { case PGRES_COMMAND_OK: res->nrows = strtol(PQcmdTuples(res->stmt), NULL, 0); diff --git a/test/pg/test_pg.c b/test/pg/test_pg.c index 6e2bbb1..381b8d2 100644 --- a/test/pg/test_pg.c +++ b/test/pg/test_pg.c @@ -4,11 +4,14 @@ #include "pg/pg.h" void test_00 (pgconn_t *conn) { - pgres_t *res = pg_exec(conn, "select * from t01", PG_END); + pgres_t *res = pg_exec(conn, "select * from test", PG_END); if (0 == res->status) { for (int i = 0; i < res->nrecs; ++i) { - if (!pg_isnull(res, i, 4)) - printf("%s\n", pg_getstrptr(res, i, 4)); + const char *a = pg_getstrptr(res, i, 0), + *b = pg_getstrptr(res, i, 1); + int l1 = strlen(a), + l2 = strlen(b); + printf("x\n"); } } pg_close(res); @@ -86,15 +89,15 @@ void test_06 (pgconn_t *conn) { int main () { printf("%d\n", sizeof(pgfld_t)); - pgconn_t *conn = pg_connect("dbname=test"); + pgconn_t *conn = pg_connect("postgres://user:pass@localhost/test"); if (0 == conn->status) { test_00(conn); - test_01(conn); +/* test_01(conn); test_02(conn); test_03(conn); test_04(conn); test_05(conn); - test_06(conn); + test_06(conn);*/ } pg_disconnect(conn); return 0; -- 2.11.4.GIT