mirror of
https://github.com/dbgate/dbgate
synced 2024-11-08 04:35:58 +00:00
correct handling null values in update keys
This commit is contained in:
parent
24cfb23b39
commit
7a0f5e171e
@ -1,5 +1,14 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { Command, Insert, Update, Delete, UpdateField, Condition, AllowIdentityInsert } from 'dbgate-sqltree';
|
import {
|
||||||
|
Command,
|
||||||
|
Insert,
|
||||||
|
Update,
|
||||||
|
Delete,
|
||||||
|
UpdateField,
|
||||||
|
Condition,
|
||||||
|
AllowIdentityInsert,
|
||||||
|
Expression,
|
||||||
|
} from 'dbgate-sqltree';
|
||||||
import { NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
|
import { NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
|
||||||
|
|
||||||
export interface ChangeSetItem {
|
export interface ChangeSetItem {
|
||||||
@ -262,12 +271,9 @@ function changeSetInsertToSql(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function extractChangeSetCondition(item: ChangeSetItem, alias?: string): Condition {
|
export function extractChangeSetCondition(item: ChangeSetItem, alias?: string): Condition {
|
||||||
return {
|
function getColumnCondition(columnName: string): Condition {
|
||||||
conditionType: 'and',
|
const value = item.condition[columnName];
|
||||||
conditions: _.keys(item.condition).map(columnName => ({
|
const expr: Expression = {
|
||||||
conditionType: 'binary',
|
|
||||||
operator: '=',
|
|
||||||
left: {
|
|
||||||
exprType: 'column',
|
exprType: 'column',
|
||||||
columnName,
|
columnName,
|
||||||
source: {
|
source: {
|
||||||
@ -277,12 +283,27 @@ export function extractChangeSetCondition(item: ChangeSetItem, alias?: string):
|
|||||||
},
|
},
|
||||||
alias,
|
alias,
|
||||||
},
|
},
|
||||||
},
|
};
|
||||||
|
if (value == null) {
|
||||||
|
return {
|
||||||
|
conditionType: 'isNull',
|
||||||
|
expr,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
conditionType: 'binary',
|
||||||
|
operator: '=',
|
||||||
|
left: expr,
|
||||||
right: {
|
right: {
|
||||||
exprType: 'value',
|
exprType: 'value',
|
||||||
value: item.condition[columnName],
|
value,
|
||||||
},
|
},
|
||||||
})),
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
conditionType: 'and',
|
||||||
|
conditions: _.keys(item.condition).map(columnName => getColumnCondition(columnName)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user