From 42d6ad0eac4d238ea7623cc744e0163fe50156bf Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sat, 19 Aug 2017 15:15:43 +0100 Subject: [PATCH] Accept c-string queries. --- include/pq/connection.hpp | 1 + src/pq/connection.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/pq/connection.hpp b/include/pq/connection.hpp index 2099b69..111a3ef 100644 --- a/include/pq/connection.hpp +++ b/include/pq/connection.hpp @@ -42,6 +42,7 @@ namespace pq { void connect ( void ); void disconnect ( void ); ResultSet query ( const std::string& parQuery ); + ResultSet query ( const char* parQuery ); std::string escaped_literal ( const std::string& parString ); std::string escaped_literal ( boost::string_ref parString ); diff --git a/src/pq/connection.cpp b/src/pq/connection.cpp index d7b9831..f83120d 100644 --- a/src/pq/connection.cpp +++ b/src/pq/connection.cpp @@ -132,7 +132,13 @@ namespace pq { } ResultSet Connection::query (const std::string& parQuery) { - ResultInfo info(PQexec(m_localData->connection, parQuery.c_str())); + assert(not parQuery.empty()); + return this->query(parQuery.c_str()); + } + + ResultSet Connection::query (const char* parQuery) { + assert(parQuery); + ResultInfo info(PQexec(m_localData->connection, parQuery)); if (not info.result) throw DatabaseException("Error running query", "Error allocating result object", __FILE__, __LINE__); const int ress = PQresultStatus(info.result.get());