|
1 | 1 | package de.jaggl.sqlbuilder.dialect; |
2 | 2 |
|
| 3 | +import static de.jaggl.sqlbuilder.utils.BuilderUtils.columnApostrophe; |
| 4 | + |
| 5 | +import java.util.Map; |
| 6 | + |
| 7 | +import de.jaggl.sqlbuilder.columns.Column; |
3 | 8 | /** |
4 | 9 | * @author Martin Schumacher |
5 | 10 | * |
6 | 11 | * @since 2.0.0 |
7 | 12 | */ |
8 | 13 | import de.jaggl.sqlbuilder.domain.BuildingContext; |
9 | 14 | import de.jaggl.sqlbuilder.domain.Limit; |
| 15 | +import de.jaggl.sqlbuilder.domain.Valuable; |
| 16 | +import de.jaggl.sqlbuilder.domain.ValuableColumn; |
10 | 17 | import de.jaggl.sqlbuilder.queries.Delete; |
| 18 | +import de.jaggl.sqlbuilder.queries.Insert; |
11 | 19 | import de.jaggl.sqlbuilder.queries.Select; |
12 | 20 | import de.jaggl.sqlbuilder.utils.Indentation; |
13 | 21 |
|
@@ -37,6 +45,55 @@ public String getName() |
37 | 45 | return "Sybase"; |
38 | 46 | } |
39 | 47 |
|
| 48 | + @Override |
| 49 | + protected void appendInsertStatement(StringBuilder builder, Insert insert, BuildingContext context, Indentation indentation) |
| 50 | + { |
| 51 | + builder.append(context.getDialect().getLabels().getInsertInto()).append(" ").append(insert.getTable().getFullName(context)); |
| 52 | + builder.append(indentation.getDelimiter()); |
| 53 | + appendInsertColumns(builder, insert.getValues(), context, indentation.indent()); |
| 54 | + appendInsertValues(builder, insert.getValues(), context, indentation.indent()); |
| 55 | + } |
| 56 | + |
| 57 | + protected void appendInsertColumns(StringBuilder builder, Map<Column, Valuable> values, BuildingContext context, Indentation indentation) |
| 58 | + { |
| 59 | + var counter = 0; |
| 60 | + builder.append(indentation.getIndent()).append("("); |
| 61 | + for (var entry : values.entrySet()) |
| 62 | + { |
| 63 | + var column = entry.getKey(); |
| 64 | + builder.append(columnApostrophe(column.getName(), context)); |
| 65 | + if (++counter < values.size()) |
| 66 | + { |
| 67 | + builder.append(", "); |
| 68 | + } |
| 69 | + } |
| 70 | + builder.append(")").append(indentation.getDelimiter()); |
| 71 | + } |
| 72 | + |
| 73 | + protected void appendInsertValues(StringBuilder builder, Map<Column, Valuable> values, BuildingContext context, Indentation indentation) |
| 74 | + { |
| 75 | + var counter = 0; |
| 76 | + builder.append("VALUES").append(indentation.getDelimiter()); |
| 77 | + builder.append(indentation.getIndent()).append("("); |
| 78 | + for (var entry : values.entrySet()) |
| 79 | + { |
| 80 | + var value = entry.getValue(); |
| 81 | + if (ValuableColumn.class.isAssignableFrom(value.getClass())) |
| 82 | + { |
| 83 | + builder.append(columnApostrophe(((ValuableColumn) value).getName(), context)); |
| 84 | + } |
| 85 | + else |
| 86 | + { |
| 87 | + builder.append(value.getValue(context, indentation)); |
| 88 | + } |
| 89 | + if (++counter < values.size()) |
| 90 | + { |
| 91 | + builder.append(", "); |
| 92 | + } |
| 93 | + } |
| 94 | + builder.append(")"); |
| 95 | + } |
| 96 | + |
40 | 97 | @Override |
41 | 98 | protected void appendSelectStatement(StringBuilder builder, Select select, BuildingContext context, Indentation indentation) |
42 | 99 | { |
|
0 commit comments