From 37b188010bc58ade5740241c04dc4f1e29610e2c Mon Sep 17 00:00:00 2001
From: Daniel Hornung <d.hornung@indiscale.com>
Date: Thu, 23 Jun 2022 14:14:20 +0200
Subject: [PATCH] ENH: Always apply POV to ints and doubles alike.

---
 .../java/org/caosdb/server/query/POV.java     | 28 ++++++++++---------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/caosdb/server/query/POV.java b/src/main/java/org/caosdb/server/query/POV.java
index 62ad1aa7..ae1ac705 100644
--- a/src/main/java/org/caosdb/server/query/POV.java
+++ b/src/main/java/org/caosdb/server/query/POV.java
@@ -128,10 +128,8 @@ public class POV implements EntityFilterInterface {
         this.vInt = null;
       }
 
-      // try and parse as double
-      if (this.vInt != null) {
-        this.vDouble = (double) this.vInt;
-      } else {
+      // Try and parse as double, if integer parsing was unsuccessful.
+      if (this.vInt == null) {
         try {
           // Doubles are allowed without dots, for example when the integer overflows.
           final Pattern dp = Pattern.compile("^(-?[0-9]+(?:\\.)?(?:[0-9]+))\\s*([^-]*)$");
@@ -217,6 +215,11 @@ public class POV implements EntityFilterInterface {
           "Versioned queries are not supported for subqueries yet. Please file a feature request.");
     }
     final long t1 = System.currentTimeMillis();
+    // Add type-converted substitutes for ints/doubles.
+    final Integer vIntSubst = (this.vDouble != null && this.vDouble % 1 == 0)
+      ? (int) Math.rint(this.vDouble) : null;
+    final Double vDoubleSubst = (this.vInt != null) ? (double) this.vInt : null;
+
     try {
       this.connection = query.getConnection();
       this.targetSet = query.getTargetSet();
@@ -270,15 +273,14 @@ public class POV implements EntityFilterInterface {
       } else {
         callPOV.setNull(6, VARCHAR);
       }
-      if (this.vInt != null) { // vInt
-        callPOV.setInt(7, this.vInt);
-      } else {
-        callPOV.setNull(7, INTEGER);
-      }
-      if (this.vDouble != null) { // vDouble
-        callPOV.setDouble(8, this.vDouble);
-      } else {
-        callPOV.setNull(8, DOUBLE);
+      if (this.vInt != null || this.vDouble != null) { // Some numeric
+        if (this.vInt != null) {
+          callPOV.setInt(7, this.vInt);
+          callPOV.setDouble(8, vDoubleSubst);
+        } else {
+          callPOV.setInt(7, vIntSubst);
+          callPOV.setDouble(8, this.vDouble);
+        }
       }
       if (this.unit != null) {
         final long unitSig = this.unit.getSignature();
-- 
GitLab