[#2995] INSERT INTO table SELECT ... renders bad SQL when column names are omitted and a plain SQL table is given
This commit is contained in:
parent
2d7befeb17
commit
e946359bc2
@ -70,38 +70,39 @@ final class FieldMapForInsert extends AbstractQueryPartMap<Field<?>, Field<?>> {
|
||||
|
||||
ctx.sql('(');
|
||||
|
||||
if (indent) {
|
||||
if (indent)
|
||||
ctx.formatIndentStart();
|
||||
}
|
||||
|
||||
String separator = "";
|
||||
for (Field<?> field : values()) {
|
||||
ctx.sql(separator);
|
||||
|
||||
if (indent) {
|
||||
if (indent)
|
||||
ctx.formatNewLine();
|
||||
}
|
||||
|
||||
ctx.visit(field);
|
||||
separator = ", ";
|
||||
}
|
||||
|
||||
if (indent) {
|
||||
if (indent)
|
||||
ctx.formatIndentEnd()
|
||||
.formatNewLine();
|
||||
}
|
||||
|
||||
ctx.sql(')');
|
||||
}
|
||||
|
||||
final void toSQLReferenceKeys(Context<?> ctx) {
|
||||
|
||||
// [#2995] Do not generate empty column lists.
|
||||
if (size() == 0)
|
||||
return;
|
||||
|
||||
boolean indent = (size() > 1);
|
||||
|
||||
ctx.sql('(');
|
||||
ctx.sql(" (");
|
||||
|
||||
if (indent) {
|
||||
if (indent)
|
||||
ctx.formatIndentStart();
|
||||
}
|
||||
|
||||
// [#989] Avoid qualifying fields in INSERT field declaration
|
||||
boolean qualify = ctx.qualify();
|
||||
@ -111,9 +112,8 @@ final class FieldMapForInsert extends AbstractQueryPartMap<Field<?>, Field<?>> {
|
||||
for (Field<?> field : keySet()) {
|
||||
ctx.sql(separator);
|
||||
|
||||
if (indent) {
|
||||
if (indent)
|
||||
ctx.formatNewLine();
|
||||
}
|
||||
|
||||
ctx.visit(field);
|
||||
separator = ", ";
|
||||
@ -121,10 +121,9 @@ final class FieldMapForInsert extends AbstractQueryPartMap<Field<?>, Field<?>> {
|
||||
|
||||
ctx.qualify(qualify);
|
||||
|
||||
if (indent) {
|
||||
if (indent)
|
||||
ctx.formatIndentEnd()
|
||||
.formatNewLine();
|
||||
}
|
||||
|
||||
ctx.sql(')');
|
||||
}
|
||||
@ -135,20 +134,17 @@ final class FieldMapForInsert extends AbstractQueryPartMap<Field<?>, Field<?>> {
|
||||
}
|
||||
|
||||
final void putFields(Collection<? extends Field<?>> fields) {
|
||||
for (Field<?> field : fields) {
|
||||
for (Field<?> field : fields)
|
||||
put(field, null);
|
||||
}
|
||||
}
|
||||
|
||||
final void putValues(Collection<? extends Field<?>> values) {
|
||||
if (values.size() != size()) {
|
||||
if (values.size() != size())
|
||||
throw new IllegalArgumentException("The number of values must match the number of fields: " + this);
|
||||
}
|
||||
|
||||
Iterator<? extends Field<?>> it = values.iterator();
|
||||
for (Entry<Field<?>, Field<?>> entry : entrySet()) {
|
||||
for (Entry<Field<?>, Field<?>> entry : entrySet())
|
||||
entry.setValue(it.next());
|
||||
}
|
||||
}
|
||||
|
||||
final void set(Map<? extends Field<?>, ?> map) {
|
||||
|
||||
@ -345,7 +345,6 @@ final class InsertQueryImpl<R extends Record> extends AbstractStoreQuery<R> impl
|
||||
|
||||
// [#1506] with DEFAULT VALUES, we might not have any columns to render
|
||||
if (insertMaps.isExecutable()) {
|
||||
ctx.sql(' ');
|
||||
insertMaps.insertMaps.get(0).toSQLReferenceKeys(ctx);
|
||||
}
|
||||
|
||||
|
||||
@ -1509,7 +1509,7 @@ implements
|
||||
// [#999] WHEN NOT MATCHED clause is optional
|
||||
if (notMatchedInsert != null) {
|
||||
ctx.formatSeparator()
|
||||
.keyword("when not matched then insert").sql(' ');
|
||||
.keyword("when not matched then insert");
|
||||
notMatchedInsert.toSQLReferenceKeys(ctx);
|
||||
ctx.formatSeparator()
|
||||
.start(MERGE_VALUES)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user