Package: postbooks / 4.1.0-3~bpo70+1

03-check-version.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
diff --git a/common/login2.cpp b/common/login2.cpp
index 6283fa9..e8f2456 100644
--- a/common/login2.cpp
+++ b/common/login2.cpp
@@ -335,6 +335,50 @@ void login2::sLogin()
       break;  // break instead of for-loop condition to preserve methodidx
   }
 
+  // Check that it is a supported PostgreSQL version
+  if (db.isOpen())
+  {
+    XSqlQuery checkVersion(QString("select (regexp_matches(setting, '^(\\d+.\\d+).\\d+'))[1] as version from pg_settings where name = 'server_version'"));
+    bool goodVersion = false;
+    // FIXME:
+    // - should store the range in some constants
+    // - when version numbers use extra digits (e.g v10.1), must use a
+    //   version comparison algorithm
+    if(checkVersion.first()) 
+    {
+      if(!(checkVersion.value("version").toString() < "8.4" ||
+        checkVersion.value("version").toString() > "9.1"))
+      {
+        goodVersion = true;
+      }
+    }
+    if(!goodVersion)
+    {
+      if (_splash)
+        _splash->hide();
+
+      setCursor(QCursor(Qt::ArrowCursor));
+
+      QMessageBox::critical(this, tr("Cannot Connect to xTuple ERP Server"),
+                            tr("<p>Sorry, can't connect to the specified xTuple ERP server. "
+                             "<p>The server version %1 is not supported."
+                             "<p>The minimum supported version is %2 and maximum is %3.")
+                             .arg(checkVersion.value("version").toString())
+                             .arg("8.4").arg("9.1"));
+      db.close();
+      if (!_captive)
+      {
+        _username->setText("");
+        _username->setFocus();
+      }
+      else
+        _password->setFocus();
+
+      _password->setText("");
+      return;
+    }
+  }
+
   // if connected using OpenMFG enhanced auth, remangle the password
   if (db.isOpen() && (methodidx == 2 || methodidx == 5))
       XSqlQuery chgpass(QString("ALTER USER \"%1\" WITH PASSWORD '%2'")