diff --git a/README.md b/README.md
index 5fb55d2..79c3e4a 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.8
+ 2.6.9
```
diff --git a/pom.xml b/pom.xml
index c3d00b8..e742bf2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
de.jaggl.sqlbuilder
sqlbuilder-core
- 2.6.8
+ 2.6.9
jar
diff --git a/src/main/java/de/jaggl/sqlbuilder/dialect/SybaseDialect.java b/src/main/java/de/jaggl/sqlbuilder/dialect/SybaseDialect.java
index 20a8cb9..585052b 100644
--- a/src/main/java/de/jaggl/sqlbuilder/dialect/SybaseDialect.java
+++ b/src/main/java/de/jaggl/sqlbuilder/dialect/SybaseDialect.java
@@ -1,5 +1,10 @@
package de.jaggl.sqlbuilder.dialect;
+import static de.jaggl.sqlbuilder.utils.BuilderUtils.columnApostrophe;
+
+import java.util.Map;
+
+import de.jaggl.sqlbuilder.columns.Column;
/**
* @author Martin Schumacher
*
@@ -7,7 +12,10 @@
*/
import de.jaggl.sqlbuilder.domain.BuildingContext;
import de.jaggl.sqlbuilder.domain.Limit;
+import de.jaggl.sqlbuilder.domain.Valuable;
+import de.jaggl.sqlbuilder.domain.ValuableColumn;
import de.jaggl.sqlbuilder.queries.Delete;
+import de.jaggl.sqlbuilder.queries.Insert;
import de.jaggl.sqlbuilder.queries.Select;
import de.jaggl.sqlbuilder.utils.Indentation;
@@ -37,6 +45,55 @@ public String getName()
return "Sybase";
}
+ @Override
+ protected void appendInsertStatement(StringBuilder builder, Insert insert, BuildingContext context, Indentation indentation)
+ {
+ builder.append(context.getDialect().getLabels().getInsertInto()).append(" ").append(insert.getTable().getFullName(context));
+ builder.append(indentation.getDelimiter());
+ appendInsertColumns(builder, insert.getValues(), context, indentation.indent());
+ appendInsertValues(builder, insert.getValues(), context, indentation.indent());
+ }
+
+ protected void appendInsertColumns(StringBuilder builder, Map values, BuildingContext context, Indentation indentation)
+ {
+ var counter = 0;
+ builder.append(indentation.getIndent()).append("(");
+ for (var entry : values.entrySet())
+ {
+ var column = entry.getKey();
+ builder.append(columnApostrophe(column.getName(), context));
+ if (++counter < values.size())
+ {
+ builder.append(", ");
+ }
+ }
+ builder.append(")").append(indentation.getDelimiter());
+ }
+
+ protected void appendInsertValues(StringBuilder builder, Map values, BuildingContext context, Indentation indentation)
+ {
+ var counter = 0;
+ builder.append("VALUES").append(indentation.getDelimiter());
+ builder.append(indentation.getIndent()).append("(");
+ for (var entry : values.entrySet())
+ {
+ var value = entry.getValue();
+ if (ValuableColumn.class.isAssignableFrom(value.getClass()))
+ {
+ builder.append(columnApostrophe(((ValuableColumn) value).getName(), context));
+ }
+ else
+ {
+ builder.append(value.getValue(context, indentation));
+ }
+ if (++counter < values.size())
+ {
+ builder.append(", ");
+ }
+ }
+ builder.append(")");
+ }
+
@Override
protected void appendSelectStatement(StringBuilder builder, Select select, BuildingContext context, Indentation indentation)
{
diff --git a/src/main/java/de/jaggl/sqlbuilder/domain/ValuableColumn.java b/src/main/java/de/jaggl/sqlbuilder/domain/ValuableColumn.java
index 306e46a..353decf 100644
--- a/src/main/java/de/jaggl/sqlbuilder/domain/ValuableColumn.java
+++ b/src/main/java/de/jaggl/sqlbuilder/domain/ValuableColumn.java
@@ -21,4 +21,9 @@ public String getValue(BuildingContext context, Indentation indentation)
{
return column.getFullNameOrAlias(context);
}
+
+ public String getName()
+ {
+ return column.getName();
+ }
}
diff --git a/src/test/java/de/jaggl/sqlbuilder/queries/InsertTest.java b/src/test/java/de/jaggl/sqlbuilder/queries/InsertTest.java
index d8b7c5c..edaae70 100644
--- a/src/test/java/de/jaggl/sqlbuilder/queries/InsertTest.java
+++ b/src/test/java/de/jaggl/sqlbuilder/queries/InsertTest.java
@@ -72,8 +72,12 @@ void testBuildInsert()
+ " `persons`.`numbers` = :numbers,\n" //
+ " `persons`.`lastname` = 'Schumacher'");
- assertThat(insert.build(MYSQL)).isEqualTo(insert.build(SYBASE));
- assertThat(insert.build(MYSQL, enabled())).isEqualTo(insert.build(SYBASE, enabled()));
+ assertThat(insert.build(SYBASE))
+ .isEqualTo("INSERT INTO `persons` (`nickname`, `forename`, `birthday`, `deathday`, `lastUpdate`, `count`, `age`, `size`, `numbers`, `lastname`) VALUES (`forename`, 'Martin', NOW(), '2020-04-24', '2020-04-24 13:53:00.000000', 5, 38, 175.89, :numbers, 'Schumacher')");
+ assertThat(insert.build(SYBASE, enabled())).isEqualTo("INSERT INTO `persons`\n" //
+ + " (`nickname`, `forename`, `birthday`, `deathday`, `lastUpdate`, `count`, `age`, `size`, `numbers`, `lastname`)\n" //
+ + "VALUES\n" //
+ + " (`forename`, 'Martin', NOW(), '2020-04-24', '2020-04-24 13:53:00.000000', 5, 38, 175.89, :numbers, 'Schumacher')");
assertThat(Insert.copy(insert).build(MYSQL)).isEqualTo(insert.build(MYSQL));
}