mirror of
https://github.com/silverqx/TinyORM.git
synced 2026-05-20 08:19:50 -05:00
perf completely avoid the __tiny_func__
For performance reasons, the __tiny_func__ is exclusively used only in the exceptions.
This commit is contained in:
@@ -80,15 +80,18 @@ namespace Concerns
|
||||
/*! Transform a QtSql transaction error to TinyORM SqlTransactionError
|
||||
exception. */
|
||||
static void throwIfTransactionError(
|
||||
QString &&functionName, const QString &queryString, QSqlError &&error);
|
||||
const QString &functionName, const QString &queryString,
|
||||
QSqlError &&error);
|
||||
|
||||
/*! Handle an error returned when beginning a transaction. */
|
||||
void handleStartTransactionError(
|
||||
QString &&functionName, const QString &queryString, QSqlError &&error);
|
||||
const QString &functionName, const QString &queryString,
|
||||
QSqlError &&error);
|
||||
/*! Handle an error returned during a transaction commit, rollBack, savepoint or
|
||||
rollbackToSavepoint. */
|
||||
void handleCommonTransactionError(
|
||||
QString &&functionName, const QString &queryString, QSqlError &&error);
|
||||
const QString &functionName, const QString &queryString,
|
||||
QSqlError &&error);
|
||||
|
||||
/*! The connection is in the transaction state. */
|
||||
bool m_inTransaction = false;
|
||||
|
||||
@@ -1177,7 +1177,10 @@ namespace Orm::Tiny::Concerns
|
||||
const auto &modelAttributesHash = getAttributesHash();
|
||||
|
||||
for (const auto &attribute : attributes) {
|
||||
throwIfNoAttributeInHash(modelAttributesHash, attribute, __tiny_func__);
|
||||
// Initialize as late as possible
|
||||
static const auto functionName = QStringLiteral(
|
||||
"HasAttributes::syncOriginalAttributes");
|
||||
throwIfNoAttributeInHash(modelAttributesHash, attribute, functionName);
|
||||
|
||||
const auto &modelAttributeValue =
|
||||
modelAttributes.at(modelAttributesHash.at(attribute)).value;
|
||||
@@ -1257,7 +1260,7 @@ namespace Orm::Tiny::Concerns
|
||||
/* This can never happen, null values must be handled outside of the asDateTime,
|
||||
asDate, and asTimestamp methods. */
|
||||
Q_ASSERT_X(!value.isNull(),
|
||||
qUtf8Printable(__tiny_func__),
|
||||
"HasAttributes::asDateTime",
|
||||
"null values must be handled outside of the asDateTime, asDate, "
|
||||
"and asTimestamp methods.");
|
||||
|
||||
|
||||
@@ -35,10 +35,14 @@ bool ManagesTransactions::beginTransaction()
|
||||
|
||||
if (!databaseConnection().pretending() &&
|
||||
!databaseConnection().getQtConnection().transaction()
|
||||
)
|
||||
) {
|
||||
// Initialize as late as possible
|
||||
static const auto functionName = QStringLiteral(
|
||||
"ManagesTransactions::beginTransaction");
|
||||
handleStartTransactionError(
|
||||
__tiny_func__, queryString,
|
||||
functionName, queryString,
|
||||
databaseConnection().getRawQtConnection().lastError());
|
||||
}
|
||||
|
||||
m_inTransaction = true;
|
||||
|
||||
@@ -71,10 +75,13 @@ bool ManagesTransactions::commit()
|
||||
|
||||
if (!databaseConnection().pretending() &&
|
||||
!databaseConnection().getRawQtConnection().commit()
|
||||
)
|
||||
) {
|
||||
// Initialize as late as possible
|
||||
static const auto functionName = QStringLiteral("ManagesTransactions::commit");
|
||||
handleCommonTransactionError(
|
||||
__tiny_func__, queryString,
|
||||
functionName, queryString,
|
||||
databaseConnection().getRawQtConnection().lastError());
|
||||
}
|
||||
|
||||
resetTransactions();
|
||||
|
||||
@@ -107,10 +114,13 @@ bool ManagesTransactions::rollBack()
|
||||
|
||||
if (!databaseConnection().pretending() &&
|
||||
!databaseConnection().getRawQtConnection().rollback()
|
||||
)
|
||||
) {
|
||||
// Initialize as late as possible
|
||||
static const auto functionName = QStringLiteral("ManagesTransactions::rollBack");
|
||||
handleCommonTransactionError(
|
||||
__tiny_func__, queryString,
|
||||
functionName, queryString,
|
||||
databaseConnection().getRawQtConnection().lastError());
|
||||
}
|
||||
|
||||
resetTransactions();
|
||||
|
||||
@@ -144,10 +154,13 @@ bool ManagesTransactions::savepoint(const QString &id)
|
||||
timer.start();
|
||||
|
||||
// Execute a savepoint query
|
||||
if (!databaseConnection().pretending() && !savePoint.exec(queryString))
|
||||
if (!databaseConnection().pretending() && !savePoint.exec(queryString)) {
|
||||
static const auto functionName = QStringLiteral(
|
||||
"ManagesTransactions::savepoint");
|
||||
handleCommonTransactionError(
|
||||
__tiny_func__, queryString,
|
||||
functionName, queryString,
|
||||
databaseConnection().getRawQtConnection().lastError());
|
||||
}
|
||||
|
||||
++m_savepoints;
|
||||
|
||||
@@ -187,10 +200,13 @@ bool ManagesTransactions::rollbackToSavepoint(const QString &id)
|
||||
timer.start();
|
||||
|
||||
// Execute a rollback to savepoint query
|
||||
if (!databaseConnection().pretending() && !rollbackToSavepoint.exec(queryString))
|
||||
if (!databaseConnection().pretending() && !rollbackToSavepoint.exec(queryString)) {
|
||||
static const auto functionName = QStringLiteral(
|
||||
"ManagesTransactions::rollbackToSavepoint");
|
||||
handleCommonTransactionError(
|
||||
__tiny_func__, queryString,
|
||||
functionName, queryString,
|
||||
databaseConnection().getRawQtConnection().lastError());
|
||||
}
|
||||
|
||||
m_savepoints = std::max<std::size_t>(0, m_savepoints - 1);
|
||||
|
||||
@@ -242,7 +258,7 @@ CountsQueries &ManagesTransactions::countsQueries()
|
||||
}
|
||||
|
||||
void ManagesTransactions::throwIfTransactionError(
|
||||
QString &&functionName, const QString &queryString, QSqlError &&error)
|
||||
const QString &functionName, const QString &queryString, QSqlError &&error)
|
||||
{
|
||||
throw Exceptions::SqlTransactionError(
|
||||
QStringLiteral("Statement in %1() failed : %2")
|
||||
@@ -251,10 +267,10 @@ void ManagesTransactions::throwIfTransactionError(
|
||||
}
|
||||
|
||||
void ManagesTransactions::handleStartTransactionError(
|
||||
QString &&functionName, const QString &queryString, QSqlError &&error)
|
||||
const QString &functionName, const QString &queryString, QSqlError &&error)
|
||||
{
|
||||
if (!DetectsLostConnections::causedByLostConnection(error))
|
||||
throwIfTransactionError(std::move(functionName), queryString, std::move(error));
|
||||
throwIfTransactionError(functionName, queryString, std::move(error));
|
||||
|
||||
databaseConnection().reconnect();
|
||||
|
||||
@@ -262,12 +278,12 @@ void ManagesTransactions::handleStartTransactionError(
|
||||
}
|
||||
|
||||
void ManagesTransactions::handleCommonTransactionError(
|
||||
QString &&functionName, const QString &queryString, QSqlError &&error)
|
||||
const QString &functionName, const QString &queryString, QSqlError &&error)
|
||||
{
|
||||
if (DetectsLostConnections::causedByLostConnection(error))
|
||||
resetTransactions();
|
||||
|
||||
throwIfTransactionError(std::move(functionName), queryString, std::move(error));
|
||||
throwIfTransactionError(functionName, queryString, std::move(error));
|
||||
}
|
||||
|
||||
} // namespace Orm::Concerns
|
||||
|
||||
@@ -309,7 +309,7 @@ MySqlSchemaGrammar::invokeCompileMethod(const CommandDefinition &command,
|
||||
};
|
||||
|
||||
Q_ASSERT_X(cached.contains(name),
|
||||
qUtf8Printable(__tiny_func__),
|
||||
"MySqlSchemaGrammar::invokeCompileMethod",
|
||||
QStringLiteral("Compile methods map doesn't contain the '%1' key "
|
||||
"(unsupported command).")
|
||||
.arg(name)
|
||||
|
||||
@@ -364,7 +364,7 @@ PostgresSchemaGrammar::invokeCompileMethod(const CommandDefinition &command,
|
||||
};
|
||||
|
||||
Q_ASSERT_X(cached.contains(name),
|
||||
qUtf8Printable(__tiny_func__),
|
||||
"PostgresSchemaGrammar::invokeCompileMethod",
|
||||
QStringLiteral("Compile methods map doesn't contain the '%1' key "
|
||||
"(unsupported command).")
|
||||
.arg(name)
|
||||
|
||||
@@ -292,7 +292,7 @@ SQLiteSchemaGrammar::invokeCompileMethod(const CommandDefinition &command,
|
||||
};
|
||||
|
||||
Q_ASSERT_X(cached.contains(name),
|
||||
qUtf8Printable(__tiny_func__),
|
||||
"SQLiteSchemaGrammar::invokeCompileMethod",
|
||||
QStringLiteral("Compile methods map doesn't contain the '%1' key "
|
||||
"(unsupported command).")
|
||||
.arg(name)
|
||||
|
||||
Reference in New Issue
Block a user