diff options
| author | 2014-12-06 17:33:25 -0500 | |
|---|---|---|
| committer | 2014-12-06 17:33:25 -0500 | |
| commit | 7167ce41b61d2ba2cdb526777a4233eb84a3b66a (patch) | |
| tree | a35c14143716e1f2c98f808c81f89426045a946f /SQLiteStudio3/coreSQLiteStudio/log.cpp | |
Imported Upstream version 2.99.6upstream/2.99.6
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/log.cpp')
| -rw-r--r-- | SQLiteStudio3/coreSQLiteStudio/log.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/log.cpp b/SQLiteStudio3/coreSQLiteStudio/log.cpp new file mode 100644 index 0000000..d54abdb --- /dev/null +++ b/SQLiteStudio3/coreSQLiteStudio/log.cpp @@ -0,0 +1,47 @@ +#include "log.h" +#include <QTime> +#include <QDebug> + +bool SQL_DEBUG = false; +QString SQL_DEBUG_FILTER = ""; + +void setSqlLoggingEnabled(bool enabled) +{ + SQL_DEBUG = enabled; +} + +void setSqlLoggingFilter(const QString& filter) +{ + SQL_DEBUG_FILTER = filter; +} + +void logSql(Db* db, const QString& str, const QHash<QString,QVariant>& args, Db::Flags flags) +{ + if (!SQL_DEBUG) + return; + + if (!SQL_DEBUG_FILTER.isEmpty() && SQL_DEBUG_FILTER != db->getName()) + return; + + qDebug() << QString("SQL %1> %2").arg(db->getName()).arg(str) << "(flags:" << Db::flagsToString(flags) << ")"; + QHashIterator<QString,QVariant> it(args); + while (it.hasNext()) + { + it.next(); + qDebug() << " SQL arg>" << it.key() << "=" << it.value(); + } +} + +void logSql(Db* db, const QString& str, const QList<QVariant>& args, Db::Flags flags) +{ + if (!SQL_DEBUG) + return; + + if (!SQL_DEBUG_FILTER.isEmpty() && SQL_DEBUG_FILTER != db->getName()) + return; + + qDebug() << QString("SQL %1> %2").arg(db->getName()).arg(str) << "(flags:" << Db::flagsToString(flags) << ")"; + int i = 0; + foreach (const QVariant& arg, args) + qDebug() << " SQL arg>" << i++ << "=" << arg; +} |
