Fixes issue 30069: Critical bug with decimals only in PostgreSQL 9.3
authorCarlos Aristu <carlos.aristu@openbravo.com>
Tue, 09 Jun 2015 18:01:36 +0200
changeset 26885 780731085f0c
parent 26884 420fd55d666d
child 26886 ee157fef9c33
Fixes issue 30069: Critical bug with decimals only in PostgreSQL 9.3

A new build validation has been added. This way, when executing update.database the result returned by the to_number() procedure is evaluated.
In case it does not return the expected result, the task will fail, showing a message with the link to the documentation
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/DatabaseDecimalNumberCheck.class
src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/DatabaseDecimalNumberCheckData.class
src-util/buildvalidation/src/org/openbravo/buildvalidation/DatabaseDecimalNumberCheck.java
src-util/buildvalidation/src/org/openbravo/buildvalidation/DatabaseDecimalNumberCheck_data.xsql
Binary file src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/DatabaseDecimalNumberCheck.class has changed
Binary file src-util/buildvalidation/build/classes/org/openbravo/buildvalidation/DatabaseDecimalNumberCheckData.class has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-util/buildvalidation/src/org/openbravo/buildvalidation/DatabaseDecimalNumberCheck.java	Tue Jun 09 18:01:36 2015 +0200
@@ -0,0 +1,55 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2015 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.buildvalidation;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openbravo.database.ConnectionProvider;
+
+/**
+ * This validation is related to this issue: https://issues.openbravo.com/view.php?id=30069 It
+ * checks if the decimal numbers are retrieved properly from the database. In case they are not
+ * retrieved properly, this build validation will fail, showing a message that points users to the
+ * documentation where they can check how to configure the database decimal separator properly.
+ */
+public class DatabaseDecimalNumberCheck extends BuildValidation {
+
+  private final String ORIGINAL_NUMBER = "1.2";
+
+  @Override
+  public List<String> execute() {
+    ConnectionProvider cp = getConnectionProvider();
+    ArrayList<String> errors = new ArrayList<String>();
+    try {
+      String numberString = new BigDecimal(ORIGINAL_NUMBER).toString();
+      String returnedNumber = DatabaseDecimalNumberCheckData.checkToNumber(cp, numberString);
+      if (!ORIGINAL_NUMBER.equals(returnedNumber)) {
+        errors.add("The decimal numbers are not being retrieved properly from the database. "
+            + "This could be caused because the current database locale uses a decimal separator different from a period(.). "
+            + "For more information, please visit the following url: "
+            + "http://wiki.openbravo.com/wiki/Installation/Custom/PostgreSQL_Database");
+      }
+    } catch (Exception e) {
+      return handleError(e);
+    }
+    return errors;
+  }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-util/buildvalidation/src/org/openbravo/buildvalidation/DatabaseDecimalNumberCheck_data.xsql	Tue Jun 09 18:01:36 2015 +0200
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2015 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+-->
+
+<SqlClass name="DatabaseDecimalNumberCheckData" package="org.openbravo.buildvalidation">
+  <SqlMethod name="checkToNumber" type="preparedStatement" return="String">
+      <Sql><![CDATA[
+         SELECT TO_NUMBER(?) as NUM
+         FROM DUAL
+          ]]>
+      </Sql>
+      <Parameter name="number"/>
+  </SqlMethod>
+</SqlClass>