Hy,
I am trying to understand how the prepare statement works.
I am using Qt C++ library to access db2:
{
....
QSqlQuery cust_query;
cust_query.prep are("SELECT CUST_NAME FROM CUSTOMERS WHERE CUST_ID=?");
cust_query.addB indValue(1);
cust_query.exec ();
cust_query.addB indValue(2);
cust_query.exec ();
....
}
db2 precompiles the select statement first, then binds the parameter
CUST_ID to value 1 and executes the query, then binds the parameter
CUST_ID to value 2 and again executes the query.
So far so good.
But what happens if prepare is executed a second time against the same
sql statement ?
Do I pay the cost of re-preparing the statement again or it's now
cached into db2 and it's does not matter if prepare is executed more
than once against the same statement ?
Thanks for the help.
I am trying to understand how the prepare statement works.
I am using Qt C++ library to access db2:
{
....
QSqlQuery cust_query;
cust_query.prep are("SELECT CUST_NAME FROM CUSTOMERS WHERE CUST_ID=?");
cust_query.addB indValue(1);
cust_query.exec ();
cust_query.addB indValue(2);
cust_query.exec ();
....
}
db2 precompiles the select statement first, then binds the parameter
CUST_ID to value 1 and executes the query, then binds the parameter
CUST_ID to value 2 and again executes the query.
So far so good.
But what happens if prepare is executed a second time against the same
sql statement ?
Do I pay the cost of re-preparing the statement again or it's now
cached into db2 and it's does not matter if prepare is executed more
than once against the same statement ?
Thanks for the help.
Comment