Created
January 28, 2018 17:14
-
-
Save SirLynix/f59003fdd4b1d4986d2d0810ba95a7f5 to your computer and use it in GitHub Desktop.
Utopia Postgres client first try
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std::string& dbHost = config.GetStringOption("Database.Host"); | |
const std::string& dbUser = config.GetStringOption("Database.Username"); | |
const std::string& dbPassword = config.GetStringOption("Database.Password"); | |
const std::string& dbName = config.GetStringOption("Database.Name"); | |
long long dbPort = config.GetIntegerOption("Database.Port"); | |
PGconn* conn = PQsetdbLogin(dbHost.c_str(), std::to_string(dbPort).c_str(), "", "", dbName.c_str(), dbUser.c_str(), dbPassword.c_str()); | |
if (!conn) | |
{ | |
std::cout << "Connection failed" << std::endl; | |
return EXIT_FAILURE; | |
} | |
std::cout << PQerrorMessage(conn) << std::endl; | |
PGresult* res = PQexec(conn, "SELECT * FROM account"); | |
if (!res) | |
{ | |
std::cout << "Execution failed" << std::endl; | |
return EXIT_FAILURE; | |
} | |
int columnCount = PQnfields(res); | |
int rowCount = PQntuples(res); | |
for (int j = 0; j < columnCount; ++j) | |
{ | |
if (j != 0) | |
std::cout << " | "; | |
std::cout << PQfname(res, j); | |
} | |
std::cout << std::endl; | |
for (int i = 0; i < rowCount; ++i) | |
{ | |
for (int j = 0; j < columnCount; ++j) | |
{ | |
if (j != 0) | |
std::cout << " | "; | |
std::cout << PQgetvalue(res, i, j); | |
} | |
std::cout << std::endl; | |
} | |
PQclear(res); | |
/*std::cout << PQsslInUse(conn) << std::endl; | |
std::cout << PQerrorMessage(conn) << std::endl;*/ | |
PQfinish(conn); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment