可以在运行时安全地从Delphi TADOCommand中删除参数

时间:2022-10-09 06:14:38

My Delphi 2006 TADOCommand has it's

我的Delphi 2006 TADOCommand有它

    CommandText (including parameters),  
    Prepared (True),  
    ParamCheck (True)

properties all set at design time.

属性全部在设计时设置。

Is there a way for me to go about deleting some of it's Parameters at run time, without having to change the CommandText to accomodate these changes. This is desireable in the case that some of the table columns that the parameters reference do not need updating/inserting.

有没有办法让我在运行时删除它的一些参数,而不必更改CommandText以适应这些更改。在参数引用的一些表列不需要更新/插入的情况下,这是可取的。

I'm thinking of something along the lines of

我正在考虑的事情

TADOCommand.Parameters.ParamByName('MyParam').SafelyRemove;

Many Thanks,
Duncan

非常感谢,邓肯

3 个解决方案

#1


4  

Each item in Parameters collection corresponds to parameter marker in the command text. It is like API to this marker. Removing items from Parameters will not remove the corresponding marker. If you does not need to touch some field in your command text, then you have to modify command text and remove corresponding parameter marker.

Parameters集合中的每个项目对应于命令文本中的参数标记。它就像这个标记的API。从参数中删除项目不会删除相应的标记。如果您不需要触摸命令文本中的某些字段,则必须修改命令文本并删除相应的参数标记。

When command text is prepared, the DBMS has built command execution plan and allocated some resources, required for command execution. If you will change the command text, then DBMS has to build new command execution plan.

在准备命令文本时,DBMS构建了命令执行计划并分配了一些命令执行所需的资源。如果要更改命令文本,则DBMS必须构建新的命令执行计划。

Kind of that ...

有点......

#2


0  

Because parameters placeholders (:PARAMn) are embedded in the SQL text, I don't see how you can add or remove parameters without changing CommandText. You would have a mismatch.

因为参数占位符(:PARAMn)嵌入在SQL文本中,所以我看不到如何在不更改CommandText的情况下添加或删除参数。你会有不匹配的。

#3


0  

In case when the command text is dynamic-updateble i usually working with params like this: *Parameters.Clear; Parameters.ParseSQL(ADOCommand.CommandText, true); * it will automatically create parameter list with correct parameters names.

如果命令文本是动态更新的,我通常使用这样的参数:* Parameters.Clear; Parameters.ParseSQL(ADOCommand.CommandText,true); *它将自动创建具有正确参数名称的参数列表。

#1


4  

Each item in Parameters collection corresponds to parameter marker in the command text. It is like API to this marker. Removing items from Parameters will not remove the corresponding marker. If you does not need to touch some field in your command text, then you have to modify command text and remove corresponding parameter marker.

Parameters集合中的每个项目对应于命令文本中的参数标记。它就像这个标记的API。从参数中删除项目不会删除相应的标记。如果您不需要触摸命令文本中的某些字段,则必须修改命令文本并删除相应的参数标记。

When command text is prepared, the DBMS has built command execution plan and allocated some resources, required for command execution. If you will change the command text, then DBMS has to build new command execution plan.

在准备命令文本时,DBMS构建了命令执行计划并分配了一些命令执行所需的资源。如果要更改命令文本,则DBMS必须构建新的命令执行计划。

Kind of that ...

有点......

#2


0  

Because parameters placeholders (:PARAMn) are embedded in the SQL text, I don't see how you can add or remove parameters without changing CommandText. You would have a mismatch.

因为参数占位符(:PARAMn)嵌入在SQL文本中,所以我看不到如何在不更改CommandText的情况下添加或删除参数。你会有不匹配的。

#3


0  

In case when the command text is dynamic-updateble i usually working with params like this: *Parameters.Clear; Parameters.ParseSQL(ADOCommand.CommandText, true); * it will automatically create parameter list with correct parameters names.

如果命令文本是动态更新的,我通常使用这样的参数:* Parameters.Clear; Parameters.ParseSQL(ADOCommand.CommandText,true); *它将自动创建具有正确参数名称的参数列表。