preloaded rows works with autoinc columns (fix for mssql)

This commit is contained in:
SPRINX0\prochazka
2024-08-29 10:53:56 +02:00
parent e982e8cd9b
commit c097e78dd0
5 changed files with 40 additions and 7 deletions

View File

@@ -210,7 +210,6 @@ export class SqlDumper implements AlterProcessor {
} else {
this.putRaw(SqlDumper.convertKeywordCase(type));
}
}
columnDefinition(column: ColumnInfo, { includeDefault = true, includeNullable = true, includeCollate = true } = {}) {
@@ -653,7 +652,14 @@ export class SqlDumper implements AlterProcessor {
this.putCmd('^drop %s %f', this.getSqlObjectSqlName(obj.objectTypeField), obj);
}
fillPreloadedRows(table: NamedObjectInfo, oldRows: any[], newRows: any[], key: string[], insertOnly: string[]) {
fillPreloadedRows(
table: NamedObjectInfo,
oldRows: any[],
newRows: any[],
key: string[],
insertOnly: string[],
autoIncrementColumn: string
) {
let was = false;
for (const row of newRows) {
const old = oldRows?.find(r => key.every(col => r[col] == row[col]));
@@ -676,12 +682,15 @@ export class SqlDumper implements AlterProcessor {
} else {
if (was) this.put(';\n');
was = true;
const autoinc = rowKeys.includes(autoIncrementColumn);
if (autoinc) this.allowIdentityInsert(table, true);
this.put(
'^insert ^into %f (%,i) ^values (%,v)',
table,
rowKeys,
rowKeys.map(x => row[x])
);
if (autoinc) this.allowIdentityInsert(table, false);
}
}
if (was) {