]> git.mxchange.org Git - jcore.git/commitdiff
Continued with jcore:
authorRoland Haeder <roland@mxchange.org>
Fri, 14 Aug 2015 10:00:47 +0000 (12:00 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 14 Aug 2015 10:00:47 +0000 (12:00 +0200)
- Improved handling of null values in doInsertDataSet()
- Added emptyStringToNull() to DatabaseFrontend interface
Signed-off-by:Roland Häder <roland@mxchange.org>

src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java
src/org/mxchange/jcore/database/frontend/DatabaseFrontend.java

index 8d276438309ee2b6fa9c2658ad90c60caf4cd145..1b4af28e603014f8660cb4bef0dd648f742fd492 100644 (file)
@@ -164,11 +164,23 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas
                        Object value = entry.getValue();
 
                        // Debug message
-                       this.getLogger().debug(MessageFormat.format("value={0}", value));
+                       this.getLogger().debug(MessageFormat.format("value={0} - BEFORE!", value));
 
-                       // Add value
-                       valueQuery.append("?,");
-                       values.add(value);
+                       // Handle possible empty->null convertion
+                       value = this.getFrontend().emptyStringToNull(entry.getKey(), value);
+
+                       // Debug message
+                       this.getLogger().debug(MessageFormat.format("value={0} - AFTER!", value));
+
+                       // Is the value null?
+                       if (value == null) {
+                               // Add null
+                               valueQuery.append("NULL,");
+                       } else {
+                               // Add value
+                               valueQuery.append("?,");
+                               values.add(value);
+                       }
                }
 
                // Now put all together
index 528621596b26d535bef519bbddb544d5249a2ef8..9b050dc2f4450d65f24bd83ded3c26b6285dbe1b 100644 (file)
@@ -30,6 +30,15 @@ import org.mxchange.jcore.exceptions.BadTokenException;
  * @author Roland Haeder
  */
 public interface DatabaseFrontend extends FrameworkInterface {
+       /**
+        * Depending on column, an empty value may be converted to null
+        *
+        * @param key Key to check
+        * @param value Value to check
+        * @return Possible previous value or null
+        */
+       public Object emptyStringToNull (final String key, final Object value);
+
        /**
         * Gets a Result back from given ResultSet instance
         *