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());
{
if (PQstatus(conn) == CONNECTION_OK) {
PQfinish(conn);
- conn = NULL;
+ errorMsg = PQerrorMessage(conn);
+ return PQstatus(conn) != CONNECTION_BAD;
}
return false;
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);
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)