From: Roland Haeder Date: Fri, 14 Aug 2015 10:00:47 +0000 (+0200) Subject: Continued with jcore: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e0dbb3c7b440c5f005bb6874a235a93c73188f55;p=jcore.git Continued with jcore: - Improved handling of null values in doInsertDataSet() - Added emptyStringToNull() to DatabaseFrontend interface Signed-off-by:Roland Häder --- diff --git a/src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java b/src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java index 8d27643..1b4af28 100644 --- a/src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java +++ b/src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java @@ -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 diff --git a/src/org/mxchange/jcore/database/frontend/DatabaseFrontend.java b/src/org/mxchange/jcore/database/frontend/DatabaseFrontend.java index 5286215..9b050dc 100644 --- a/src/org/mxchange/jcore/database/frontend/DatabaseFrontend.java +++ b/src/org/mxchange/jcore/database/frontend/DatabaseFrontend.java @@ -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 *