Skip to content
Snippets Groups Projects
Commit 6d5c0c3f authored by Steven Murray's avatar Steven Murray
Browse files

Made rdbms::Stmt::m_paramNameToIdx private

parent 6c4a51f1
No related branches found
No related tags found
No related merge requests found
......@@ -113,7 +113,7 @@ void OcciStmt::bindUint64(const std::string &paramName, const uint64_t paramValu
//------------------------------------------------------------------------------
void OcciStmt::bindOptionalUint64(const std::string &paramName, const optional<uint64_t> &paramValue) {
try {
const unsigned paramIdx = m_paramNameToIdx.getIdx(paramName);
const unsigned paramIdx = getParamIdx(paramName);
if(paramValue) {
// Bind integer as a string in order to support 64-bit integers
m_stmt->setString(paramIdx, std::to_string(paramValue.value()));
......@@ -150,7 +150,7 @@ void OcciStmt::bindOptionalString(const std::string &paramName, const optional<s
" An optional string parameter should either have a non-empty string value or no value at all.");
}
const unsigned paramIdx = m_paramNameToIdx.getIdx(paramName);
const unsigned paramIdx = getParamIdx(paramName);
if(paramValue) {
m_stmt->setString(paramIdx, paramValue.value());
} else {
......
......@@ -152,7 +152,7 @@ void SqliteStmt::bindUint64(const std::string &paramName, const uint64_t paramVa
//------------------------------------------------------------------------------
void SqliteStmt::bindOptionalUint64(const std::string &paramName, const optional<uint64_t> &paramValue) {
try {
const unsigned int paramIdx = m_paramNameToIdx.getIdx(paramName);
const unsigned int paramIdx = getParamIdx(paramName);
int bindRc = 0;
if(paramValue) {
bindRc = sqlite3_bind_int64(m_stmt, paramIdx, (sqlite3_int64) paramValue.value());
......@@ -188,7 +188,7 @@ void SqliteStmt::bindOptionalString(const std::string &paramName, const optional
throw exception::Exception(std::string("Optional string parameter ") + paramName + " is an empty string. "
" An optional string parameter should either have a non-empty string value or no value at all.");
}
const unsigned int paramIdx = m_paramNameToIdx.getIdx(paramName);
const unsigned int paramIdx = getParamIdx(paramName);
int bindRc = 0;
if(paramValue) {
bindRc = sqlite3_bind_text(m_stmt, paramIdx, paramValue.value().c_str(), -1, SQLITE_TRANSIENT);
......
......@@ -26,8 +26,8 @@ namespace rdbms {
//------------------------------------------------------------------------------
Stmt::Stmt(const std::string &sql, const AutocommitMode autocommitMode):
m_sql(sql),
m_paramNameToIdx(sql),
m_autoCommitMode(autocommitMode) {
m_autoCommitMode(autocommitMode),
m_paramNameToIdx(sql) {
}
//------------------------------------------------------------------------------
......@@ -43,6 +43,13 @@ const std::string &Stmt::getSql() const {
return m_sql;
}
//------------------------------------------------------------------------------
// getParamIdx
//------------------------------------------------------------------------------
uint32_t Stmt::getParamIdx(const std::string &paramName) const {
return m_paramNameToIdx.getIdx(paramName);
}
//------------------------------------------------------------------------------
// getSqlForException
//------------------------------------------------------------------------------
......
......@@ -95,6 +95,14 @@ public:
*/
const std::string &getSql() const;
/**
* Returns the index of the specified SQL parameter.
*
* @param paramName The name of the SQL parameter.
* @return The index of the SQL parameter.
*/
uint32_t getParamIdx(const std::string &paramName) const;
/**
* Binds an SQL parameter.
*
......@@ -179,11 +187,6 @@ protected:
*/
std::string m_sql;
/**
* Map from SQL parameter name to parameter index.
*/
ParamNameToIdx m_paramNameToIdx;
/**
* The autocommit mode of the statement.
*/
......@@ -206,6 +209,13 @@ protected:
*/
std::string getSqlForException() const;
private:
/**
* Map from SQL parameter name to parameter index.
*/
ParamNameToIdx m_paramNameToIdx;
}; // class Stmt
} // namespace rdbms
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment