diff src/util.cpp @ 248:4f947840c806

Oops, forgot to move slCheckAndReportSQLError() to util.cpp. Fixed.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 08 May 2018 13:21:17 +0300
parents 43a5e09bb832
children 4d2b37a0acf2
line wrap: on
line diff
--- a/src/util.cpp	Tue May 08 13:18:58 2018 +0300
+++ b/src/util.cpp	Tue May 08 13:21:17 2018 +0300
@@ -109,3 +109,29 @@
 }
 
 
+//
+// Check if an SQL error has occured (for given QSqlError) and
+// report it to stdout if so. Return "false" if error has occured,
+// true otherwise.
+//
+bool slCheckAndReportSQLError(const QString where, const QSqlError &err, bool report)
+{
+    if (err.isValid())
+    {
+        // If an error has occured, log it
+        slLog("ERROR",
+            QStringLiteral("SQL %1: %2").
+            arg(where).arg(err.text()));
+        return false;
+    }
+    else
+    {
+        // If no error, but event reporting requested, log it
+        if (report)
+        {
+            slLog("NOTE",
+                QStringLiteral("SQL OK %1").arg(where));
+        }
+        return true;
+    }
+}