diff --git a/README.md b/README.md index fd9f0cb..238cd2e 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ A Java-Library to build SQL-Statements de.jaggl.sqlbuilder sqlbuilder-core - 2.6.6 + 2.6.7 ``` diff --git a/pom.xml b/pom.xml index 365ca8d..cdf9a9d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.jaggl.sqlbuilder sqlbuilder-core - 2.6.6 + 2.6.7 jar diff --git a/src/main/java/de/jaggl/sqlbuilder/queries/Insert.java b/src/main/java/de/jaggl/sqlbuilder/queries/Insert.java index 3f84788..479a848 100644 --- a/src/main/java/de/jaggl/sqlbuilder/queries/Insert.java +++ b/src/main/java/de/jaggl/sqlbuilder/queries/Insert.java @@ -2,10 +2,14 @@ import static lombok.AccessLevel.PACKAGE; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.LinkedHashMap; import java.util.Map; import de.jaggl.sqlbuilder.columns.Column; +import de.jaggl.sqlbuilder.columns.datetime.DateColumn; +import de.jaggl.sqlbuilder.columns.datetime.DateTimeColumn; import de.jaggl.sqlbuilder.columns.number.NumberColumn; import de.jaggl.sqlbuilder.columns.string.StringColumn; import de.jaggl.sqlbuilder.dialect.Dialect; @@ -82,6 +86,16 @@ public Insert set(Column column, Column otherColumn) return addValue(column, new ValuableColumn(otherColumn)); } + public Insert set(DateColumn column, LocalDate value) + { + return addValue(column, new PlainValuable(value)); + } + + public Insert set(DateTimeColumn column, LocalDateTime value) + { + return addValue(column, new PlainValuable(value)); + } + private Insert addValue(Column column, Valuable value) { values.put(column, value); diff --git a/src/main/java/de/jaggl/sqlbuilder/queries/Update.java b/src/main/java/de/jaggl/sqlbuilder/queries/Update.java index 28b30a3..96b123d 100644 --- a/src/main/java/de/jaggl/sqlbuilder/queries/Update.java +++ b/src/main/java/de/jaggl/sqlbuilder/queries/Update.java @@ -5,10 +5,14 @@ import static de.jaggl.sqlbuilder.domain.ConditionType.WHERE_NOT; import static lombok.AccessLevel.PACKAGE; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.LinkedHashMap; import java.util.Map; import de.jaggl.sqlbuilder.columns.Column; +import de.jaggl.sqlbuilder.columns.datetime.DateColumn; +import de.jaggl.sqlbuilder.columns.datetime.DateTimeColumn; import de.jaggl.sqlbuilder.columns.number.NumberColumn; import de.jaggl.sqlbuilder.columns.string.StringColumn; import de.jaggl.sqlbuilder.conditions.Condition; @@ -78,6 +82,16 @@ public Update set(Column column, Column otherColumn) return set(column, new ValuableColumn(otherColumn)); } + public Update set(DateColumn column, LocalDate value) + { + return set(column, new PlainValuable(value)); + } + + public Update set(DateTimeColumn column, LocalDateTime value) + { + return set(column, new PlainValuable(value)); + } + public Update set(Column column, Valuable valuable) { values.put(column, valuable); diff --git a/src/test/java/de/jaggl/sqlbuilder/queries/InsertTest.java b/src/test/java/de/jaggl/sqlbuilder/queries/InsertTest.java index 5d68bab..d8b7c5c 100644 --- a/src/test/java/de/jaggl/sqlbuilder/queries/InsertTest.java +++ b/src/test/java/de/jaggl/sqlbuilder/queries/InsertTest.java @@ -7,9 +7,13 @@ import static de.jaggl.sqlbuilder.utils.Indentation.enabled; import static org.assertj.core.api.Assertions.assertThat; +import java.time.LocalDate; +import java.time.LocalDateTime; + import org.junit.jupiter.api.Test; import de.jaggl.sqlbuilder.columns.datetime.DateColumn; +import de.jaggl.sqlbuilder.columns.datetime.DateTimeColumn; import de.jaggl.sqlbuilder.columns.number.doubletype.DoubleColumn; import de.jaggl.sqlbuilder.columns.number.integer.BigIntColumn; import de.jaggl.sqlbuilder.columns.number.integer.IntColumn; @@ -28,6 +32,8 @@ class InsertTest public static final DoubleColumn SIZE = PERSONS.doubleColumn("size").build(); public static final IntColumn COUNT = PERSONS.intColumn("count").build(); public static final DateColumn BIRTHDAY = PERSONS.dateColumn("birthday").build(); + public static final DateColumn DEATHDAY = PERSONS.dateColumn("deathday").build(); + public static final DateTimeColumn LAST_UPDATE = PERSONS.dateTimeColumn("lastUpdate").build(); public static final BigIntColumn NUMBERS = PERSONS.bigIntColumn("numbers").build(); @Test @@ -37,6 +43,8 @@ void testBuildInsert() .set(NICKNAME, FORENAME) .set(FORENAME, "Martin") .set(BIRTHDAY, now()) + .set(DEATHDAY, LocalDate.of(2020, 4, 24)) + .set(LAST_UPDATE, LocalDateTime.of(2020, 4, 24, 13, 53)) .set(COUNT, Integer.valueOf(5)) .set(AGE, 38) .set(SIZE, 175.89) @@ -47,7 +55,7 @@ void testBuildInsert() insert.println(SYBASE, enabled()); assertThat(insert.build()) - .isEqualTo("INSERT INTO `persons` SET `persons`.`nickname` = `persons`.`forename`, `persons`.`forename` = 'Martin', `persons`.`birthday` = NOW(), `persons`.`count` = 5, `persons`.`age` = 38, `persons`.`size` = 175.89, `persons`.`numbers` = :numbers, `persons`.`lastname` = 'Schumacher'"); + .isEqualTo("INSERT INTO `persons` SET `persons`.`nickname` = `persons`.`forename`, `persons`.`forename` = 'Martin', `persons`.`birthday` = NOW(), `persons`.`deathday` = '2020-04-24', `persons`.`lastUpdate` = '2020-04-24 13:53:00.000000', `persons`.`count` = 5, `persons`.`age` = 38, `persons`.`size` = 175.89, `persons`.`numbers` = :numbers, `persons`.`lastname` = 'Schumacher'"); assertThat(insert.build(enabled())) .isEqualTo("INSERT INTO\n" // @@ -56,6 +64,8 @@ void testBuildInsert() + " `persons`.`nickname` = `persons`.`forename`,\n" // + " `persons`.`forename` = 'Martin',\n" // + " `persons`.`birthday` = NOW(),\n" // + + " `persons`.`deathday` = '2020-04-24',\n" // + + " `persons`.`lastUpdate` = '2020-04-24 13:53:00.000000',\n" // + " `persons`.`count` = 5,\n" // + " `persons`.`age` = 38,\n" // + " `persons`.`size` = 175.89,\n" // diff --git a/src/test/java/de/jaggl/sqlbuilder/queries/UpdateTest.java b/src/test/java/de/jaggl/sqlbuilder/queries/UpdateTest.java index 02ad124..23aef7b 100644 --- a/src/test/java/de/jaggl/sqlbuilder/queries/UpdateTest.java +++ b/src/test/java/de/jaggl/sqlbuilder/queries/UpdateTest.java @@ -11,9 +11,13 @@ import static de.jaggl.sqlbuilder.utils.Indentation.enabled; import static org.assertj.core.api.Assertions.assertThat; +import java.time.LocalDate; +import java.time.LocalDateTime; + import org.junit.jupiter.api.Test; import de.jaggl.sqlbuilder.columns.datetime.DateColumn; +import de.jaggl.sqlbuilder.columns.datetime.DateTimeColumn; import de.jaggl.sqlbuilder.columns.number.doubletype.DoubleColumn; import de.jaggl.sqlbuilder.columns.number.integer.IntColumn; import de.jaggl.sqlbuilder.columns.string.VarCharColumn; @@ -30,6 +34,8 @@ class UpdateTest public static final DoubleColumn SIZE = PERSONS.doubleColumn("size").build(); public static final IntColumn COUNT = PERSONS.intColumn("count").build(); public static final DateColumn BIRTHDAY = PERSONS.dateColumn("birthday").build(); + public static final DateColumn DEATHDAY = PERSONS.dateColumn("deathday").build(); + public static final DateTimeColumn LAST_UPDATE = PERSONS.dateTimeColumn("lastUpdate").build(); @Test void testBuildUpdate() @@ -38,6 +44,8 @@ void testBuildUpdate() .set(NICKNAME, FORENAME) .set(LASTNAME, "Schumacher") .set(BIRTHDAY, now()) + .set(DEATHDAY, LocalDate.of(2020, 4, 24)) + .set(LAST_UPDATE, LocalDateTime.of(2020, 4, 24, 13, 53)) .set(COUNT, Integer.valueOf(5)) .set(AGE, 38) .set(SIZE, 175.89) @@ -50,7 +58,7 @@ void testBuildUpdate() update.println(SYBASE, enabled()); assertThat(update.build(MYSQL)) - .isEqualTo("UPDATE `persons` SET `persons`.`nickname` = `persons`.`forename`, `persons`.`lastname` = 'Schumacher', `persons`.`birthday` = NOW(), `persons`.`count` = 5, `persons`.`age` = 38, `persons`.`size` = 175.89 WHERE (`persons`.`lastname` NOT LIKE 'Nils%' AND MIN(`persons`.`age`) >= 50 AND (`persons`.`lastname` = 'Schumacher' OR IsNull(COL, '') != ''))"); + .isEqualTo("UPDATE `persons` SET `persons`.`nickname` = `persons`.`forename`, `persons`.`lastname` = 'Schumacher', `persons`.`birthday` = NOW(), `persons`.`deathday` = '2020-04-24', `persons`.`lastUpdate` = '2020-04-24 13:53:00.000000', `persons`.`count` = 5, `persons`.`age` = 38, `persons`.`size` = 175.89 WHERE (`persons`.`lastname` NOT LIKE 'Nils%' AND MIN(`persons`.`age`) >= 50 AND (`persons`.`lastname` = 'Schumacher' OR IsNull(COL, '') != ''))"); assertThat(update.build(MYSQL, enabled())).isEqualTo("UPDATE\n" // + " `persons`\n" // @@ -58,6 +66,8 @@ void testBuildUpdate() + " `persons`.`nickname` = `persons`.`forename`,\n" // + " `persons`.`lastname` = 'Schumacher',\n" // + " `persons`.`birthday` = NOW(),\n" // + + " `persons`.`deathday` = '2020-04-24',\n" // + + " `persons`.`lastUpdate` = '2020-04-24 13:53:00.000000',\n" // + " `persons`.`count` = 5,\n" // + " `persons`.`age` = 38,\n" // + " `persons`.`size` = 175.89\n" //