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

SQL statements in exceptions clipped to 80 chars

parent 1d2ad909
No related branches found
No related tags found
No related merge requests found
......@@ -59,11 +59,12 @@ OcciStmt::OcciStmt(
}
} catch(exception::Exception &ex) {
close();
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + sql + ": " +
ex.getMessage().str());
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " +
sql.substr(0, c_maxSqlLenInExceptions) + ": " + ex.getMessage().str());
} catch(std::exception &se) {
close();
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + sql + ": " + se.what());
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " +
sql.substr(0, c_maxSqlLenInExceptions) + ": " + se.what());
}
}
......@@ -90,10 +91,11 @@ void OcciStmt::close() {
m_stmt = nullptr;
}
} 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 for SQL statement " +
getSql().substr(0, c_maxSqlLenInExceptions) + ": " + ex.getMessage().str());
} catch(std::exception &se) {
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + getSql() + ": " + se.what());
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " +
getSql().substr(0, c_maxSqlLenInExceptions) + ": " + se.what());
}
}
......@@ -128,10 +130,11 @@ void OcciStmt::bindOptionalUint64(const std::string &paramName, const optional<u
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());
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " +
getSql().substr(0, c_maxSqlLenInExceptions) + ": " + ex.getMessage().str());
} catch(std::exception &se) {
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + getSql() + ": " + se.what());
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " +
getSql().substr(0, c_maxSqlLenInExceptions) + ": " + se.what());
}
}
......@@ -163,10 +166,11 @@ void OcciStmt::bindOptionalString(const std::string &paramName, const optional<s
m_stmt->setNull(paramIdx, oracle::occi::OCCISTRING);
}
} 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 for SQL statement " +
getSql().substr(0, c_maxSqlLenInExceptions) + ": " + ex.getMessage().str());
} catch(std::exception &se) {
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + getSql() + ": " + se.what());
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " +
getSql().substr(0, c_maxSqlLenInExceptions) + ": " + se.what());
}
}
......@@ -191,7 +195,8 @@ std::unique_ptr<Rset> OcciStmt::executeQuery() {
} catch(...) {
}
}
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + getSql() + ": " + ex.what());
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " +
getSql().substr(0, c_maxSqlLenInExceptions) + ": " + ex.what());
}
}
......@@ -216,7 +221,8 @@ void OcciStmt::executeNonQuery() {
} catch(...) {
}
}
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + getSql() + ": " + ex.what());
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " +
getSql().substr(0, c_maxSqlLenInExceptions) + ": " + ex.what());
}
}
......
......@@ -94,11 +94,12 @@ SqliteStmt::SqliteStmt(
}
} catch(exception::Exception &ex) {
close();
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + sql + ": " +
ex.getMessage().str());
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " +
sql.substr(0, c_maxSqlLenInExceptions) + ": " + ex.getMessage().str());
} catch(std::exception &se) {
close();
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + sql + ": " + se.what());
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " +
sql.substr(0, c_maxSqlLenInExceptions) + ": " + se.what());
}
}
......@@ -130,8 +131,8 @@ void SqliteStmt::close() {
//------------------------------------------------------------------------------
sqlite3_stmt *SqliteStmt::get() const {
if(nullptr == m_stmt) {
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + getSql() +
": nullptr pointer");
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " +
getSql().substr(0, c_maxSqlLenInExceptions) + ": nullptr pointer");
}
return m_stmt;
}
......@@ -170,8 +171,8 @@ void SqliteStmt::bindOptionalUint64(const std::string &paramName, const optional
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());
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " +
getSql().substr(0, c_maxSqlLenInExceptions) + ": " + ex.getMessage().str());
}
}
......@@ -206,8 +207,8 @@ void SqliteStmt::bindOptionalString(const std::string &paramName, const optional
throw exception::Exception("sqlite3_bind_text() failed");
}
} 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 for SQL statement " +
getSql().substr(0, c_maxSqlLenInExceptions) + ": " + ex.getMessage().str());
}
}
......@@ -228,16 +229,16 @@ void SqliteStmt::executeNonQuery() {
// Throw an exception if the call to sqlite3_step() failed
if(SQLITE_DONE != stepRc && SQLITE_ROW != stepRc) {
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + getSql() + ": " +
Sqlite::rcToStr(stepRc));
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " +
getSql().substr(0, c_maxSqlLenInExceptions) + ": " + Sqlite::rcToStr(stepRc));
}
m_nbAffectedRows = sqlite3_changes(m_conn.m_sqliteConn);
// Throw an exception if the SQL statement returned a result set
if(SQLITE_ROW == stepRc) {
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + getSql() +
": The SQL statment returned a result set");
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " +
getSql().substr(0, c_maxSqlLenInExceptions) + ": The SQL statment returned a result set");
}
}
......
......@@ -177,6 +177,11 @@ protected:
*/
AutocommitMode m_autoCommitMode;
/**
* The maximum length an SQL statement can have in exception error message.
*/
const uint32_t c_maxSqlLenInExceptions = 80;
}; // class Stmt
} // namespace rdbms
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment