X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/641204dfbdb9fc870cdd2e7f9e3169a44693e7bf..881154ef208de52f4f382f5197426a735f5f9c3c:/projects/stargazer/plugins/store/db/pg_driver.cpp?ds=inline diff --git a/projects/stargazer/plugins/store/db/pg_driver.cpp b/projects/stargazer/plugins/store/db/pg_driver.cpp index 4dda25d3..61adda26 100644 --- a/projects/stargazer/plugins/store/db/pg_driver.cpp +++ b/projects/stargazer/plugins/store/db/pg_driver.cpp @@ -21,9 +21,9 @@ PG_DRIVER::~PG_DRIVER() bool PG_DRIVER::Connect() { std::stringstream params; - params << "host=" << host << " " - << "dbname=" << database << " " - << "user=" << user << " " + params << "host=" << host + << "dbname=" << database + << "user=" << user << "password=" << password; std::string str = params.str(); conn = PQconnectdb(str.c_str()); @@ -35,7 +35,8 @@ bool PG_DRIVER::Disconnect() { if (PQstatus(conn) == CONNECTION_OK) { PQfinish(conn); - conn = NULL; + errorMsg = PQerrorMessage(conn); + return PQstatus(conn) != CONNECTION_BAD; } return false; @@ -43,6 +44,9 @@ bool PG_DRIVER::Disconnect() bool PG_DRIVER::Query(const std::string & query) { + cols.erase(cols.begin(), cols.end()); + cols.reserve(columns); + PQclear(result); result = PQexec(conn, query.c_str()); errorMsg = PQerrorMessage(conn); @@ -50,13 +54,9 @@ bool PG_DRIVER::Query(const std::string & query) columns = PQnfields(result); affected = atoi(PQcmdTuples(result)); - cols.erase(cols.begin(), cols.end()); - cols.reserve(columns); - if (tuples) { - for (int i = 0; i < columns; ++i) { + for (int i = 0; i < columns; ++i) cols.push_back(PQfname(result, i)); - } } if (!result)