TADOQuery Prepared
Asked Answered
M

2

6

The TADOQuery component has "prepared" property the manual says that when prepared is set TRUE, the ADO 'prepares' the commmand, what this means??

Here is the manual explanation:

Set Prepared before calling the Execute method to specify whether ADO prepares the command. If Prepared is set to True and the command component is connected to a data store, ADO prepares the command before executing it. If Prepared is set to False, ADO does not prepare the command.

It injects the parameters into SQL Text?

Magdaleno answered 14/3, 2013 at 12:11 Comment(0)
L
6

Here's some better documentation from the Delphi 2007 help file:

Use the Prepared property to have the provider save a prepared (or compiled) version of the query specified in the CommandText property before a Command object's first execution. This may slow a command's first execution, but once the provider compiles a command, the provider will use the compiled version of the command for any subsequent executions, which will result in improved performance.

If the property is False, the provider will execute the Command object directly without creating a compiled version.

If the provider does not support command preparation, it may return an error when this property is set to True. If the provider does not return an error, it simply ignores the request to prepare the command and sets the Prepared property to False.

This basically says that the SQL statement is compiled (pre-parsed and tokenized and analyzed). When the query is used more than once, this compiled version can be used each time just substituting the parameter values, without having to re-compile all of the statement and do the other work.

Lir answered 14/3, 2013 at 12:33 Comment(1)
So if the command will be executed once, it's better set to False, in more the once...set to true!Magdaleno
P
4

Tt's to reduce the parsing and compiling overhead associated with repeatedly executing an SQL statement that is executed numerous times.
An application can execute a parameterized statement more than once by supplying a different parameter set at each execution instead of reconstructing the statement whenever the parameter set is different.
Executing Prepared Statements

Pedrick answered 14/3, 2013 at 12:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.