1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2024-11-25 00:53:43 +00:00

Remove query_void() methods. query() is just fine.

This commit is contained in:
King_DuckZ 2015-12-30 10:20:52 +00:00
parent 43bec4711e
commit 9bb5689d48
4 changed files with 13 additions and 22 deletions

View file

@ -70,6 +70,6 @@ namespace din {
boost::copy(dele_ids | boost::adaptors::map_keys, infix_ostream_iterator<uint32_t>(oss, " OR \"id\"="));
oss << ";\nCOMMIT;";
conn.query_void(oss.str());
conn.query(oss.str());
}
} //namespace din

View file

@ -154,7 +154,7 @@ namespace pq {
oss << "Unable to connect to database " << m_address << ':' << m_port << " as user \"" << m_username << '"';
throw DatabaseException(oss.str(), std::move(err), __FILE__, __LINE__);
}
query_void("SET NAMES 'utf8'");
this->query("SET NAMES 'utf8'");
PQinitTypes(m_localData->connection); //Init libpqtypes
}
@ -184,16 +184,6 @@ namespace pq {
return ResultSet(std::move(info));
}
void Connection::query_void (const std::string& parQuery) {
ResultInfo info(PQexec(m_localData->connection, parQuery.c_str()));
if (not info.result)
throw DatabaseException("Error running query", "Error allocating result object", __FILE__, __LINE__);
const int ress = PQresultStatus(info.result.get());
if (ress != PGRES_TUPLES_OK && ress != PGRES_COMMAND_OK) {
throw DatabaseException("Error running query", error_message(), __FILE__, __LINE__);
}
}
std::string Connection::escaped_literal (const std::string& parString) {
return this->escaped_literal(boost::string_ref(parString));
}
@ -205,7 +195,7 @@ namespace pq {
return std::string(clean_str.get());
}
void Connection::query_void_params (const std::string& parQuery, PGParams& parParams) {
ResultSet Connection::query_params (const std::string& parQuery, PGParams& parParams) {
int result_format = 1;
assert(parParams.get());
ResultInfo info(
@ -225,6 +215,8 @@ namespace pq {
if (ress != PGRES_TUPLES_OK && ress != PGRES_COMMAND_OK) {
throw DatabaseException("Error running query", error_message(), __FILE__, __LINE__);
}
return ResultSet(std::move(info));
}
auto Connection::make_params (const std::string* parTypes, ...) -> PGParams {

View file

@ -39,20 +39,19 @@ namespace pq {
bool is_connected ( void ) const noexcept;
void connect ( void );
void disconnect ( void );
void query_void ( const std::string& parQuery );
ResultSet query ( const std::string& parQuery );
std::string escaped_literal ( const std::string& parString );
std::string escaped_literal ( boost::string_ref parString );
template <typename... Args>
void query_void ( const std::string& parQuery, Args&&... parArgs );
ResultSet query ( const std::string& parQuery, Args&&... parArgs );
private:
struct LocalData;
using PGParams = std::unique_ptr<::PGparam, void(*)(::PGparam*)>;
void query_void_params ( const std::string& parQuery, PGParams& parParams );
ResultSet query_params ( const std::string& parQuery, PGParams& parParams );
PGParams make_params ( const std::string* parTypes, ... );
const std::string m_username;
@ -108,7 +107,7 @@ namespace pq {
} //namespace implem
template <typename... Args>
void Connection::query_void (const std::string& parQuery, Args&&... parArgs) {
ResultSet Connection::query (const std::string& parQuery, Args&&... parArgs) {
using std::remove_cv;
using std::remove_reference;
@ -126,7 +125,7 @@ namespace pq {
};
PGParams pgparams = make_pgparams();
this->query_void_params(parQuery, pgparams);
return this->query_params(parQuery, pgparams);
}
} //namespace pq

View file

@ -89,8 +89,8 @@ namespace din {
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
conn.connect();
conn.query_void("BEGIN;");
conn.query_void("INSERT INTO \"sets\" (\"desc\",\"type\") VALUES ($1, $2)",
conn.query("BEGIN;");
conn.query("INSERT INTO \"sets\" (\"desc\",\"type\") VALUES ($1, $2)",
parSetData.name,
std::string(1, parSetData.type)
);
@ -102,7 +102,7 @@ namespace din {
"($1, $2, $3, currval('\"sets_id_seq\"'), $4, $5, $6, $7, $8, $9, $10);";
const auto& itm = parData[z];
conn.query_void(query,
conn.query(query,
itm.path,
tiger_to_string(itm.hash),
itm.level,
@ -115,6 +115,6 @@ namespace din {
itm.unreadable
);
}
conn.query_void("COMMIT;");
conn.query("COMMIT;");
}
} //namespace din