Mercurial > malikania
diff database/postgresql/src/driver.cpp @ 30:a1e80d991968
Misc: convert to spaces, #519
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 16 Jun 2016 13:35:31 +0200 |
parents | 99792c6c8b06 |
children | d4f5f7231b84 |
line wrap: on
line diff
--- a/database/postgresql/src/driver.cpp Thu May 26 07:32:05 2016 +0200 +++ b/database/postgresql/src/driver.cpp Thu Jun 16 13:35:31 2016 +0200 @@ -30,26 +30,26 @@ std::shared_ptr<PGresult> exec(const std::string &sql) { - std::shared_ptr<PGresult> ptr(PQexec(connection, sql.c_str()), PQclear); + std::shared_ptr<PGresult> ptr(PQexec(connection, sql.c_str()), PQclear); - if (PQresultStatus(ptr.get()) != PGRES_TUPLES_OK && PQresultStatus(ptr.get()) != PGRES_COMMAND_OK) - throw std::runtime_error(PQresultErrorMessage(ptr.get())); + if (PQresultStatus(ptr.get()) != PGRES_TUPLES_OK && PQresultStatus(ptr.get()) != PGRES_COMMAND_OK) + throw std::runtime_error(PQresultErrorMessage(ptr.get())); - return ptr; + return ptr; } std::string escape(const std::string &input) { - auto text = PQescapeLiteral(connection, input.c_str(), input.length()); + auto text = PQescapeLiteral(connection, input.c_str(), input.length()); - if (!text) - throw std::runtime_error(PQerrorMessage(connection)); + if (!text) + throw std::runtime_error(PQerrorMessage(connection)); - std::string result(text); + std::string result(text); - PQfreemem(text); + PQfreemem(text); - return result; + return result; } } // !pgsql @@ -58,36 +58,36 @@ std::string parameters(const std::unordered_map<std::string, std::string> ¶ms) { - std::ostringstream oss; - std::unordered_map<std::string, std::string>::const_iterator it; + std::ostringstream oss; + std::unordered_map<std::string, std::string>::const_iterator it; - // Host. - if ((it = params.find("host")) == params.end()) - throw std::runtime_error("missing 'host' parameter"); + // Host. + if ((it = params.find("host")) == params.end()) + throw std::runtime_error("missing 'host' parameter"); - oss << "host = " << it->second << " "; + oss << "host = " << it->second << " "; - // Database. - if ((it = params.find("database")) == params.end()) - throw std::runtime_error("missing 'database' parameter"); + // Database. + if ((it = params.find("database")) == params.end()) + throw std::runtime_error("missing 'database' parameter"); - oss << "dbname = " << it->second << " "; + oss << "dbname = " << it->second << " "; - // User. - if ((it = params.find("user")) == params.end()) - throw std::runtime_error("missing 'user' parameter"); + // User. + if ((it = params.find("user")) == params.end()) + throw std::runtime_error("missing 'user' parameter"); - oss << "user = " << it->second << " "; + oss << "user = " << it->second << " "; - // Port (optional). - if ((it = params.find("port")) != params.end()) - oss << "port = " << it->second << " "; + // Port (optional). + if ((it = params.find("port")) != params.end()) + oss << "port = " << it->second << " "; - // Password (optional). - if ((it = params.find("password")) != params.end()) - oss << "password = " << it->second << " "; + // Password (optional). + if ((it = params.find("password")) != params.end()) + oss << "password = " << it->second << " "; - return oss.str(); + return oss.str(); } } // !namespace @@ -96,18 +96,18 @@ DYNLIB_EXPORT void malikania_driver_load(const std::unordered_map<std::string, std::string> ¶ms) { - pgsql::connection = PQconnectdb(parameters(params).c_str()); + pgsql::connection = PQconnectdb(parameters(params).c_str()); - if (!pgsql::connection) - throw std::runtime_error(PQerrorMessage(pgsql::connection)); + if (!pgsql::connection) + throw std::runtime_error(PQerrorMessage(pgsql::connection)); } DYNLIB_EXPORT void malikania_driver_unload() { - if (pgsql::connection) { - PQfinish(pgsql::connection); - pgsql::connection = nullptr; - } + if (pgsql::connection) { + PQfinish(pgsql::connection); + pgsql::connection = nullptr; + } } } // !C