mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 06:26:00 +00:00
tsql call
This commit is contained in:
@@ -785,7 +785,11 @@ export class SqlDumper implements AlterProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
declareVariable(name: string, type: string, defaultValueLiteral?: string) {}
|
declareVariable(name: string, type: string, defaultValueLiteral?: string) {}
|
||||||
executeCallable(func: CallableObjectInfo, argLiterals: string[]) {
|
executeCallable(func: CallableObjectInfo, argLiteralsByName: { [name: string]: string }) {
|
||||||
this.putCmd('^call %f(%,s)', func, argLiterals);
|
this.putCmd(
|
||||||
|
'^call %f(%,s)',
|
||||||
|
func,
|
||||||
|
(func.parameters || []).map(x => argLiteralsByName[x.parameterName])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
packages/types/dumper.d.ts
vendored
2
packages/types/dumper.d.ts
vendored
@@ -18,7 +18,7 @@ export interface SqlDumper extends AlterProcessor {
|
|||||||
dropDatabase(name: string);
|
dropDatabase(name: string);
|
||||||
|
|
||||||
declareVariable(name: string, type: string, defaultValueLiteral?: string);
|
declareVariable(name: string, type: string, defaultValueLiteral?: string);
|
||||||
executeCallable(func: CallableObjectInfo, argLiterals: string[]);
|
executeCallable(func: CallableObjectInfo, argLiteralsByName: { [name: string]: string });
|
||||||
|
|
||||||
endCommand();
|
endCommand();
|
||||||
allowIdentityInsert(table: NamedObjectInfo, allow: boolean);
|
allowIdentityInsert(table: NamedObjectInfo, allow: boolean);
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export default async function applyScriptTemplate(
|
|||||||
const driver = findEngineDriver(connection, extensions) || driverBase;
|
const driver = findEngineDriver(connection, extensions) || driverBase;
|
||||||
const dmp = driver.createDumper();
|
const dmp = driver.createDumper();
|
||||||
if (procedureInfo) {
|
if (procedureInfo) {
|
||||||
const sqlVars = [];
|
const argLiteralsByName = {};
|
||||||
for (const param of procedureInfo.parameters || []) {
|
for (const param of procedureInfo.parameters || []) {
|
||||||
const sqlVarName = param.parameterName?.startsWith('@')
|
const sqlVarName = param.parameterName?.startsWith('@')
|
||||||
? param.parameterName?.substring(1)
|
? param.parameterName?.substring(1)
|
||||||
@@ -88,9 +88,9 @@ export default async function applyScriptTemplate(
|
|||||||
param.dataType,
|
param.dataType,
|
||||||
param.parameterMode == 'OUT' ? null : `:${sqlVarName}`
|
param.parameterMode == 'OUT' ? null : `:${sqlVarName}`
|
||||||
);
|
);
|
||||||
sqlVars.push(param.parameterName);
|
argLiteralsByName[param.parameterName] = param.parameterName;
|
||||||
}
|
}
|
||||||
dmp.executeCallable(procedureInfo, sqlVars);
|
dmp.executeCallable(procedureInfo, argLiteralsByName);
|
||||||
}
|
}
|
||||||
// if (procedureInfo) dmp.put('^execute %f', procedureInfo);
|
// if (procedureInfo) dmp.put('^execute %f', procedureInfo);
|
||||||
return dmp.s;
|
return dmp.s;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
const { SqlDumper, testEqualColumns, arrayToHexString } = global.DBGATE_PACKAGES['dbgate-tools'];
|
const { SqlDumper, testEqualColumns, arrayToHexString } = global.DBGATE_PACKAGES['dbgate-tools'];
|
||||||
const _zip = require('lodash/zip');
|
|
||||||
|
|
||||||
class MsSqlDumper extends SqlDumper {
|
class MsSqlDumper extends SqlDumper {
|
||||||
constructor(driver, options) {
|
constructor(driver, options) {
|
||||||
@@ -170,18 +169,33 @@ class MsSqlDumper extends SqlDumper {
|
|||||||
this.endCommand();
|
this.endCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
executeCallable(func, argLiterals) {
|
executeCallable(func, argLiteralsByName) {
|
||||||
console.log('executeCallable', func, argLiterals);
|
const putParameters = (parameters, delimiter) => {
|
||||||
if (func.objectTypeField == 'procedures') {
|
this.putCollection(
|
||||||
this.put('^execute %f&>&n', func, argLiterals);
|
delimiter,
|
||||||
|
(parameters || []), param => {
|
||||||
this.putCollection(',&n', _zip(func.parameters || [], argLiterals || []), ([param, value]) => {
|
this.putRaw(argLiteralsByName[param]);
|
||||||
this.putRaw(value);
|
|
||||||
if (param?.parameterMode == 'OUT') this.put(' ^output');
|
if (param?.parameterMode == 'OUT') this.put(' ^output');
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (func.objectTypeField == 'procedures') {
|
||||||
|
this.put('^execute %f&>&n', func);
|
||||||
|
putParameters(func.parameters, ',&n');
|
||||||
this.put('&<&n');
|
this.put('&<&n');
|
||||||
this.endCommand();
|
this.endCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (func.objectTypeField == 'functions') {
|
||||||
|
this.put('^select %f(', func);
|
||||||
|
putParameters(
|
||||||
|
(func.parameters || []).filter(x => x.parameterMode != 'OUT'),
|
||||||
|
', '
|
||||||
|
);
|
||||||
|
this.put(')');
|
||||||
|
this.endCommand();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user