[英]How do I output the value of a parameter in SQL after it has been inserted?
Is it possible to retrieve the SQL statement with the values of parameters after it has been set and inserted into the SQL component? 设置并插入SQL组件后,是否可以使用参数值检索SQL语句?
SQL Statement: SQL语句:
SELECT * FROM SomeTable
WHERE SomeColumn = :pSomeValue;
Code: 码:
procedure LoadParams(aValue: string);
begin
Qry.Close;
Qry.ParamByName('pSomeValue').AsString := aValue;
MessageDlg(Qry.SQL.Text, mtInformation, [mbOK], 0); // this does not show the value but the parameter name.
Qry.Open;
end;
I want to be able to see the statement before it is opened but when I try this now I get the param name instead of the value. 我希望能够在打开语句之前看到该语句,但是当我现在尝试该语句时,我得到的是参数名称而不是值。
Query parameters are normally substituted in the DBMS, ie the values are sent over the connection separately, and not as part of the SQL statement. 查询参数通常在DBMS中替换,即,值是通过连接单独发送的,而不是作为SQL语句的一部分发送的。 If you wish to see the SQL and the values together, the DB's logs might help you with that. 如果您希望同时查看SQL和值,则数据库的日志可能会帮助您。
One thing you can do is duplicate the parameter and put it in the SELECT: 您可以做的一件事是复制参数并将其放入SELECT中:
SELECT :pSomeValueDuplicate AS paraminput, * FROM SomeTable
WHERE SomeColumn = :pSomeValue;
Qry.ParamByName('pSomeValue').AsString := aValue;
Qry.ParamByName('pSomeValueDuplicate').Value := Qry.ParamByName('pSomeValue').Value;
Then you can check the field: paraminput for what you used as input. 然后,您可以检查以下字段:paraminput以用作输入内容。 Somehow I can't get Delphi to use the same parameter twice in 1 query. 不知何故,我无法让Delphi在1个查询中两次使用相同的参数。
SELECT 'SELECT * FROM SomeTable WHERE SomeColumn ='+ :pSomeValueduplicate AS thesqlinput,* FROM SomeTable WHERE SomeColumn = :pSomeValue;
Actually you can do it with just the one parameter: 实际上,您仅需一个参数即可完成此操作:
SELECT 'SELECT * FROM SomeTable WHERE SomeColumn ='+ SomeColumn AS thesqlinput,* FROM SomeTable WHERE SomeColumn = :pSomeValue;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.