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

Added Stmt::bindOptionalUint64()

parent c796485c
No related branches found
No related tags found
No related merge requests found
......@@ -83,12 +83,28 @@ const std::string &OcciStmt::getSql() const {
}
//------------------------------------------------------------------------------
// bind
// bindUint64
//------------------------------------------------------------------------------
void OcciStmt::bindUint64(const std::string &paramName, const uint64_t paramValue) {
try {
bindOptionalUint64(paramName, paramValue);
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
//------------------------------------------------------------------------------
// bindOptionalUint64
//------------------------------------------------------------------------------
void OcciStmt::bindOptionalUint64(const std::string &paramName, const optional<uint64_t> &paramValue) {
try {
const unsigned paramIdx = m_paramNameToIdx.getIdx(paramName);
m_stmt->setString(paramIdx, std::to_string(paramValue));
if(paramValue) {
// Bind integer as a string in order to support 64-bit integers
m_stmt->setString(paramIdx, std::to_string(paramValue.value()));
} else {
m_stmt->setNull(paramIdx, oracle::occi::OCCINUMBER);
}
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + getSql() + ": " +
ex.getMessage().str());
......
......@@ -86,6 +86,14 @@ public:
*/
virtual void bindUint64(const std::string &paramName, const uint64_t paramValue) override;
/**
* Binds an SQL parameter.
*
* @param paramName The name of the parameter.
* @param paramValue The value to be bound.
*/
virtual void bindOptionalUint64(const std::string &paramName, const optional<uint64_t> &paramValue) override;
/**
* Binds an SQL parameter of type string.
*
......
......@@ -87,25 +87,45 @@ const std::string &SqliteStmt::getSql() const {
}
//------------------------------------------------------------------------------
// bind
// bindUint64
//------------------------------------------------------------------------------
void SqliteStmt::bindUint64(const std::string &paramName, const uint64_t paramValue) {
const unsigned int paramIdx = m_paramNameToIdx.getIdx(paramName);
const int bindRc = sqlite3_bind_int64(m_stmt, paramIdx, (sqlite3_int64)paramValue);
if(SQLITE_OK != bindRc) {
throw exception::Exception(std::string(__FUNCTION__) + "failed for SQL statement " + getSql());
try {
bindOptionalUint64(paramName, paramValue);
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
//------------------------------------------------------------------------------
// bindOptionalUint64
//------------------------------------------------------------------------------
void SqliteStmt::bindOptionalUint64(const std::string &paramName, const optional<uint64_t> &paramValue) {
try {
const unsigned int paramIdx = m_paramNameToIdx.getIdx(paramName);
int bindRc = 0;
if(paramValue) {
bindRc = sqlite3_bind_int64(m_stmt, paramIdx, (sqlite3_int64) paramValue.value());
} else {
bindRc = sqlite3_bind_null(m_stmt, paramIdx);
}
if(SQLITE_OK != bindRc) {
throw exception::Exception("sqlite3_bind_int64() failed");
}
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + getSql() + ": " +
ex.getMessage().str());
}
}
//------------------------------------------------------------------------------
// bind
// bindString
//------------------------------------------------------------------------------
void SqliteStmt::bindString(const std::string &paramName, const std::string &paramValue) {
try {
bindOptionalString(paramName, paramValue);
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + getSql() + ": " +
ex.getMessage().str());
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
......@@ -123,10 +143,10 @@ void SqliteStmt::bindOptionalString(const std::string &paramName, const optional
if(paramValue) {
bindRc = sqlite3_bind_text(m_stmt, paramIdx, paramValue.value().c_str(), -1, SQLITE_TRANSIENT);
} else {
bindRc = sqlite3_bind_text(m_stmt, paramIdx, nullptr, 0, SQLITE_TRANSIENT);
bindRc = sqlite3_bind_null(m_stmt, paramIdx);
}
if(SQLITE_OK != bindRc) {
throw exception::Exception(getSql());
throw exception::Exception("sqlite3_bind_text() failed");
}
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + getSql() + ": " +
......
......@@ -83,6 +83,14 @@ public:
*/
virtual void bindUint64(const std::string &paramName, const uint64_t paramValue) override;
/**
* Binds an SQL parameter.
*
* @param paramName The name of the parameter.
* @param paramValue The value to be bound.
*/
virtual void bindOptionalUint64(const std::string &paramName, const optional<uint64_t> &paramValue) override;
/**
* Binds an SQL parameter of type string.
*
......
......@@ -59,6 +59,14 @@ public:
*/
virtual void bindUint64(const std::string &paramName, const uint64_t paramValue) = 0;
/**
* Binds an SQL parameter.
*
* @param paramName The name of the parameter.
* @param paramValue The value to be bound.
*/
virtual void bindOptionalUint64(const std::string &paramName, const optional<uint64_t> &paramValue) = 0;
/**
* Binds an SQL parameter of type string.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment