You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2022/03/17 14:52:29 UTC

[empire-db] branch master updated: EMPIREDB-384 DBCmdParam type conversion

This is an automated email from the ASF dual-hosted git repository.

doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git


The following commit(s) were added to refs/heads/master by this push:
     new e21c7d4  EMPIREDB-384 DBCmdParam type conversion
e21c7d4 is described below

commit e21c7d4657301f361f4d915752cb28cec5598576
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Thu Mar 17 15:52:27 2022 +0100

    EMPIREDB-384 DBCmdParam type conversion
---
 .../main/java/org/apache/empire/db/DBCmdParam.java   | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/empire-db/src/main/java/org/apache/empire/db/DBCmdParam.java b/empire-db/src/main/java/org/apache/empire/db/DBCmdParam.java
index b5503fb..e9961cc 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBCmdParam.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBCmdParam.java
@@ -18,6 +18,7 @@
  */
 package org.apache.empire.db;
 
+import java.math.BigDecimal;
 import java.util.Set;
 
 import org.apache.empire.commons.ObjectUtils;
@@ -60,6 +61,11 @@ public class DBCmdParam extends DBExpr
         // check null
         if (value == null)
             return null;
+        // check for enum
+        if (value instanceof Enum<?>)
+        {   // convert enum
+            return ObjectUtils.getEnumValue((Enum<?>)value, type.isNumeric());
+        }
         // check type
         switch (type)
         {
@@ -77,12 +83,16 @@ public class DBCmdParam extends DBExpr
                 return new DBClobData(value.toString());
             case BOOL:
             	return ObjectUtils.getBoolean(value);
+            case INTEGER:
+                return (value instanceof Number) ? value : ObjectUtils.toLong(value);
+            case FLOAT:
+                return (value instanceof Number) ? value : ObjectUtils.toDouble(value);
+            case DECIMAL:
+                return (value instanceof Number) ? value : ObjectUtils.toDecimal(value);
+            case CHAR:
+            case VARCHAR:
+                return (value instanceof String) ? value : value.toString();
             default:
-                // check for enum
-                if (value instanceof Enum<?>)
-                {   // convert enum
-                    return ObjectUtils.getEnumValue((Enum<?>)value, type.isNumeric());
-                }
                 // use as is
                 return value;
         }