mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2024-12-01 01:45:42 +00:00
Remove query_void() methods. query() is just fine.
This commit is contained in:
parent
43bec4711e
commit
9bb5689d48
4 changed files with 13 additions and 22 deletions
|
@ -70,6 +70,6 @@ namespace din {
|
||||||
boost::copy(dele_ids | boost::adaptors::map_keys, infix_ostream_iterator<uint32_t>(oss, " OR \"id\"="));
|
boost::copy(dele_ids | boost::adaptors::map_keys, infix_ostream_iterator<uint32_t>(oss, " OR \"id\"="));
|
||||||
oss << ";\nCOMMIT;";
|
oss << ";\nCOMMIT;";
|
||||||
|
|
||||||
conn.query_void(oss.str());
|
conn.query(oss.str());
|
||||||
}
|
}
|
||||||
} //namespace din
|
} //namespace din
|
||||||
|
|
|
@ -154,7 +154,7 @@ namespace pq {
|
||||||
oss << "Unable to connect to database " << m_address << ':' << m_port << " as user \"" << m_username << '"';
|
oss << "Unable to connect to database " << m_address << ':' << m_port << " as user \"" << m_username << '"';
|
||||||
throw DatabaseException(oss.str(), std::move(err), __FILE__, __LINE__);
|
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
|
PQinitTypes(m_localData->connection); //Init libpqtypes
|
||||||
}
|
}
|
||||||
|
@ -184,16 +184,6 @@ namespace pq {
|
||||||
return ResultSet(std::move(info));
|
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) {
|
std::string Connection::escaped_literal (const std::string& parString) {
|
||||||
return this->escaped_literal(boost::string_ref(parString));
|
return this->escaped_literal(boost::string_ref(parString));
|
||||||
}
|
}
|
||||||
|
@ -205,7 +195,7 @@ namespace pq {
|
||||||
return std::string(clean_str.get());
|
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;
|
int result_format = 1;
|
||||||
assert(parParams.get());
|
assert(parParams.get());
|
||||||
ResultInfo info(
|
ResultInfo info(
|
||||||
|
@ -225,6 +215,8 @@ namespace pq {
|
||||||
if (ress != PGRES_TUPLES_OK && ress != PGRES_COMMAND_OK) {
|
if (ress != PGRES_TUPLES_OK && ress != PGRES_COMMAND_OK) {
|
||||||
throw DatabaseException("Error running query", error_message(), __FILE__, __LINE__);
|
throw DatabaseException("Error running query", error_message(), __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ResultSet(std::move(info));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Connection::make_params (const std::string* parTypes, ...) -> PGParams {
|
auto Connection::make_params (const std::string* parTypes, ...) -> PGParams {
|
||||||
|
|
|
@ -39,20 +39,19 @@ namespace pq {
|
||||||
bool is_connected ( void ) const noexcept;
|
bool is_connected ( void ) const noexcept;
|
||||||
void connect ( void );
|
void connect ( void );
|
||||||
void disconnect ( void );
|
void disconnect ( void );
|
||||||
void query_void ( const std::string& parQuery );
|
|
||||||
ResultSet query ( const std::string& parQuery );
|
ResultSet query ( const std::string& parQuery );
|
||||||
|
|
||||||
std::string escaped_literal ( const std::string& parString );
|
std::string escaped_literal ( const std::string& parString );
|
||||||
std::string escaped_literal ( boost::string_ref parString );
|
std::string escaped_literal ( boost::string_ref parString );
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void query_void ( const std::string& parQuery, Args&&... parArgs );
|
ResultSet query ( const std::string& parQuery, Args&&... parArgs );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct LocalData;
|
struct LocalData;
|
||||||
using PGParams = std::unique_ptr<::PGparam, void(*)(::PGparam*)>;
|
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, ... );
|
PGParams make_params ( const std::string* parTypes, ... );
|
||||||
|
|
||||||
const std::string m_username;
|
const std::string m_username;
|
||||||
|
@ -108,7 +107,7 @@ namespace pq {
|
||||||
} //namespace implem
|
} //namespace implem
|
||||||
|
|
||||||
template <typename... Args>
|
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_cv;
|
||||||
using std::remove_reference;
|
using std::remove_reference;
|
||||||
|
|
||||||
|
@ -126,7 +125,7 @@ namespace pq {
|
||||||
};
|
};
|
||||||
PGParams pgparams = make_pgparams();
|
PGParams pgparams = make_pgparams();
|
||||||
|
|
||||||
this->query_void_params(parQuery, pgparams);
|
return this->query_params(parQuery, pgparams);
|
||||||
}
|
}
|
||||||
} //namespace pq
|
} //namespace pq
|
||||||
|
|
||||||
|
|
|
@ -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);
|
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||||
conn.connect();
|
conn.connect();
|
||||||
|
|
||||||
conn.query_void("BEGIN;");
|
conn.query("BEGIN;");
|
||||||
conn.query_void("INSERT INTO \"sets\" (\"desc\",\"type\") VALUES ($1, $2)",
|
conn.query("INSERT INTO \"sets\" (\"desc\",\"type\") VALUES ($1, $2)",
|
||||||
parSetData.name,
|
parSetData.name,
|
||||||
std::string(1, parSetData.type)
|
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);";
|
"($1, $2, $3, currval('\"sets_id_seq\"'), $4, $5, $6, $7, $8, $9, $10);";
|
||||||
|
|
||||||
const auto& itm = parData[z];
|
const auto& itm = parData[z];
|
||||||
conn.query_void(query,
|
conn.query(query,
|
||||||
itm.path,
|
itm.path,
|
||||||
tiger_to_string(itm.hash),
|
tiger_to_string(itm.hash),
|
||||||
itm.level,
|
itm.level,
|
||||||
|
@ -115,6 +115,6 @@ namespace din {
|
||||||
itm.unreadable
|
itm.unreadable
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
conn.query_void("COMMIT;");
|
conn.query("COMMIT;");
|
||||||
}
|
}
|
||||||
} //namespace din
|
} //namespace din
|
||||||
|
|
Loading…
Reference in a new issue