From da0ac6bc0dbddbdcc7d337250544fd0cd6e4a683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Krog?= Date: Tue, 4 Jun 2013 10:18:07 +0200 Subject: [PATCH] Don't truncate log messages unless they contain binary data (removes previous log limit of 300 characters) Adapted from https://github.com/dwarburt/SQLITE-Browser/commit/c4d253287faab37e8a749932c6c988aad4735cd5 --- src/sqlitedb.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/sqlitedb.cpp b/src/sqlitedb.cpp index d84c019c..579a865d 100644 --- a/src/sqlitedb.cpp +++ b/src/sqlitedb.cpp @@ -780,19 +780,35 @@ DBBrowserObject DBBrowserDB::getObjectByName(const QString& name) const void DBBrowserDB::logSQL(const QString& statement, int msgtype) { if(mainWindow) - { + { + bool binary = FALSE; + QString logst = statement; + /*limit log message to a sensible size, this will truncate some binary messages*/ int loglimit = 300; - if ((statement.length() > loglimit)&&(msgtype==kLogMsg_App)) + if ((logst.length() > loglimit)&&(msgtype==kLogMsg_App)) + { + for (int i = 0; i < logst.size(); i++) + { + if (logst.at(i) < 32) + { + binary = TRUE; + // early exit if we detect a binary character, + // to prevent checking all characters in a potential big string + break; + } + } + } + + if (binary) { - QString logst = statement; logst.truncate(32); - logst.append(QObject::tr("... ...")); + logst.append("... ..."); mainWindow->logSql(logst, msgtype); } - else + else { - mainWindow->logSql(statement, msgtype); + mainWindow->logSql(logst, msgtype); } } }