Ниже приведен пример использования операции SetDbCommand для изменения текста запроса и задания параметров для команды СУБД. В запросе передается моникёр открытого экземпляра команды СУБД, обновленные метаданные и шаблон, указывающий необходимость изменить запрос и параметры. В ответе приходит обновленная информация о метаданных команды СУБД. Для сохранения примененных изменений после операции SetDbCommand также необходимо выполнить операцию SaveObject или SaveObjectAs.
{
"SetDbCommand" :
{
"tDbCommand" :
{
"id" : "KBCFEJFKABODGOAEODNPLELCGJNJEMEEKKAKMINPLIABGDLF!M!S!MBOKHEBGKABODGOAEKAMLBBHAHOGBCFHEHKLDMOFJPAMIIFNK"
},
"tArg" :
{
"pattern" :
{
"obInst" : "true",
"parsOwnDefVals" : "true",
"text" : "true",
"openArgs" : "true"
},
"meta" :
{
"type" : "Command",
"text" :
{
"sqlText" : "Insert Into T_COUNTRY (ISO_CODE, NAME) values (:ISO_CODE, :NAME)"
},
"openArgs" :
{
"args" :
{
"it" :
[
{
"k" : "-1",
"id" : "ISO_CODE",
"n" : "ISO_CODE",
"vis" : "true",
"value" : "CA",
"dt" : "1"
},
{
"k" : "-1",
"id" : "NAME",
"n" : "NAME",
"vis" : "true",
"value" : "Canada",
"dt" : "1"
}
]
}
}
},
"metaGet" :
{
"obInst" : "true",
"parsOwnDefVals" : "true",
"text" : "true",
"openArgs" : "true"
}
}
}
}
{
"SetDbCommandResult" :
{
"id" :
{
"id" : "KBCFEJFKABODGOAEODNPLELCGJNJEMEEKKAKMINPLIABGDLF!M!S!MBOKHEBGKABODGOAEKAMLBBHAHOGBCFHEHKLDMOFJPAMIIFNK"
},
"meta" :
{
"obInst" :
{
"obDesc" :
{
"@ds" : "",
"@isShortcut" : "0",
"@isLink" : "0",
"@ver" : "1",
"@hf" : "0",
"i" : "OBJ9054",
"n" : "Команда СУБД",
"k" : "9054",
"c" : "3841",
"p" : "9050",
"h" : "0",
"hasPrv" : "0",
"ic" : "0",
"trackElementDependents" : "0",
"isPermanent" : "1",
"isTemp" : "0"
}
},
"dirty" : "1",
"type" : "Command",
"text" :
{
"its" :
{
"it" :
[
{
"driverID" : "ORCL8",
"driverName" : "Oracle",
"sqlText" : ""
},
{
"driverID" : "MSSQL2012",
"driverName" : "Microsoft SQL Server",
"sqlText" : "Insert Into T_COUNTRY (ISO_CODE, NAME) values (:ISO_CODE, :NAME)"
},
{
"driverID" : "MSSQL2012ODBC",
"driverName" : "Microsoft SQL Server (ODBC)",
"sqlText" : "Insert Into T_COUNTRY (ISO_CODE, NAME) values (:ISO_CODE, :NAME)"
},
{
"driverID" : "ODBC(CLICKHOUSE)",
"driverName" : "ClickHouse (ODBC)",
"sqlText" : ""
},
{
"driverID" : "ODBC",
"driverName" : "Generic ODBC",
"sqlText" : ""
},
{
"driverID" : "OLEDB(ODBC HIVE)",
"driverName" : "OLE DB(ODBC HIVE)",
"sqlText" : ""
},
{
"driverID" : "OLEDB(ODBC)",
"driverName" : "OLE DB(ODBC)",
"sqlText" : ""
},
{
"driverID" : "OLEDB",
"driverName" : "OLE DB",
"sqlText" : ""
},
{
"driverID" : "POSTGRES(NO_LO)",
"driverName" : "Greenplum\/Pivotal HD Hawq",
"sqlText" : ""
},
{
"driverID" : "POSTGRES",
"driverName" : "PostgreSQL",
"sqlText" : ""
},
{
"driverID" : "SQLITE",
"driverName" : "SQLite",
"sqlText" : ""
},
{
"driverID" : "WSF",
"driverName" : "WEB Service",
"sqlText" : ""
}
]
},
"sqlText" : "Insert Into T_COUNTRY (ISO_CODE, NAME) values (:ISO_CODE, :NAME)"
},
"openArgs" :
{
"args" :
{
"it" :
[
{
"k" : "1",
"id" : "ISO_CODE",
"n" : "ISO_CODE",
"vis" : "1",
"value" : "CA",
"dt" : "1",
"binding" : "UI="EditBox""
},
{
"k" : "2",
"id" : "NAME",
"n" : "NAME",
"vis" : "1",
"value" : "Canada",
"dt" : "1",
"binding" : "UI="EditBox""
}
]
}
}
}
}
}
public static SetDbCommandResult ChangeSQLObjectParameters(DbCommandId moniker)
{
var somClient = new SomPortTypeClient(); // Прокси-объект для выполнения операций
// Параметры выполнения операции
var tSet = new SetDbCommand()
{
tArg = new SetDbCommandArg()
{
pattern = new DbCommandMdPattern()
{
text = true,
openArgs = true
},
meta = new DbCommandMd()
{
type = DbCommandType.Command,
text = new DbCommandText()
{
sqlText = "Insert Into T_COUNTRY (ISO_CODE, NAME) values (:ISO_CODE, :NAME)"
},
openArgs = new OdOpenArgs
{
args = new OdArg[]
{
new OdArg
{
k = uint.MaxValue,
id = "ISO_CODE",
n = "ISO_CODE",
dt = 1, //DbDataType.String
vis = true,
value = "CA"
},
new OdArg
{
k = uint.MaxValue,
id = "NAME",
n = "NAME",
dt = 1, //DbDataType.String
vis = true,
value = "Canada"
}
}
}
},
metaGet = new DbCommandMdPattern()
{
text = true,
openArgs = true
}
},
tDbCommand = moniker
};
// Изменение параметров
var tResult = somClient.SetDbCommand(tSet);
return tResult;
}
См. также: