Mercurial > code
changeset 189:cc1e5fe1ee2c
Update drivers to style and using instead of typedefs
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 26 Nov 2013 20:36:59 +0100 |
parents | ce3e1c3d6fed |
children | d263f85f43a4 |
files | C++/Driver.cpp C++/Driver.h C++/DriverPostgres.cpp C++/DriverPostgres.h |
diffstat | 4 files changed, 13 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/C++/Driver.cpp Tue Nov 26 20:32:43 2013 +0100 +++ b/C++/Driver.cpp Tue Nov 26 20:36:59 2013 +0100 @@ -45,8 +45,7 @@ std::ostringstream oss; // Out of bounds? - if (row < 0 || row >= countRows()) - { + if (row < 0 || row >= countRows()) { oss << "Invalid row index " << row; oss << ", expected [0.." << countRows() << "]"; @@ -54,8 +53,7 @@ } // Not found or bad column? - if (type(column) != wanted) - { + if (type(column) != wanted) { oss << "Invalid or not found column `" << column << "'"; throw Error(oss.str());
--- a/C++/Driver.h Tue Nov 26 20:32:43 2013 +0100 +++ b/C++/Driver.h Tue Nov 26 20:36:59 2013 +0100 @@ -53,14 +53,13 @@ */ class Query { public: - typedef std::shared_ptr<Query> Ptr; + using Ptr = std::shared_ptr<Query>; /** * @class Error * @brief Query exception on query error */ - class Error : public std::exception - { + class Error : public std::exception { private: std::string m_error;
--- a/C++/DriverPostgres.cpp Tue Nov 26 20:32:43 2013 +0100 +++ b/C++/DriverPostgres.cpp Tue Nov 26 20:36:59 2013 +0100 @@ -71,7 +71,6 @@ int idx = PQfnumber(m_result.get(), column.c_str()); return std::stoi(PQgetvalue(m_result.get(), row, idx)); - } std::string QueryPostgres::getString(int row, const std::string &column) @@ -102,8 +101,7 @@ index = PQfnumber(m_result.get(), column.c_str()); pqType = PQftype(m_result.get(), index); - switch (pqType) - { + switch (pqType) { case 16: type = ColumnType::Boolean; break; @@ -157,13 +155,11 @@ std::cout << countRows() << " rows, "; std::cout << countColumns() << " columns" << std::endl; - for (int r = 0; r < countRows(); ++r) - { + for (int r = 0; r < countRows(); ++r) { std::cout << "Dumping row " << r << std::endl; std::cout << "==============================" << std::endl; - for (int c = 0; c < countColumns(); ++c) - { + for (int c = 0; c < countColumns(); ++c) { std::cout << "\t" << PQfname(m_result.get(), c); std::cout << " = " << PQgetvalue(m_result.get(), r, c) << std::endl; } @@ -252,14 +248,12 @@ Params copy = params; PGconn *conn = PQconnectdb(convert(copy).c_str()); - if (conn == nullptr) - { + if (conn == nullptr) { m_error = strerror(ENOMEM); return false; } - if (PQstatus(conn) == CONNECTION_BAD) - { + if (PQstatus(conn) == CONNECTION_BAD) { m_error = PQerrorMessage(conn); PQfinish(conn); @@ -287,8 +281,7 @@ // If an error occured int errorCode = PQresultStatus(info); - if (errorCode != PGRES_COMMAND_OK && errorCode != PGRES_TUPLES_OK) - { + if (errorCode != PGRES_COMMAND_OK && errorCode != PGRES_TUPLES_OK) { std::string error = PQresultErrorMessage(info); PQclear(info); throw Query::Error(error);
--- a/C++/DriverPostgres.h Tue Nov 26 20:32:43 2013 +0100 +++ b/C++/DriverPostgres.h Tue Nov 26 20:36:59 2013 +0100 @@ -35,15 +35,14 @@ */ class QueryPostgres : public Query { public: - struct PQQueryDeleter - { + struct PQQueryDeleter { void operator()(PGresult *result) { PQclear(result); } }; - typedef std::unique_ptr<PGresult, PQQueryDeleter> PostgresResult; + using PostgresResult = std::unique_ptr<PGresult, PQQueryDeleter>; private: PostgresResult m_result; @@ -165,7 +164,7 @@ } }; - typedef std::unique_ptr<PGconn, PGDeleter> PostgresConn; + using PostgresConn = std::unique_ptr<PGconn, PGDeleter>; private: PostgresConn m_connection;