Way of using prepared statements and some related questions

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ertank
Posts: 172
Joined: Wed 13 Jan 2016 16:00

Way of using prepared statements and some related questions

Post by ertank » Sun 12 Mar 2017 18:06

Hi,

Using Delphi 10.1 Update 2, SQL Server 2012 and PostgreSQL 9.6.2.

My application uses prepared statements using TUniQuery.Prepare() when TUniQuery.Options.AutoPrepare set to False. Preparing is done at the time of application creation.

These prepared queries are not calling TUniQuery.UnPrepare() at the time of application terminate.

I am wondering;
1- Does TUniQuery has a feature to call UnPrepare() automatically at the time of execution of TUniQuery.Free()?
2- Assuming TUniQuery is not automatically calling UnPrepare, will such a usage described above can be a problem for me?
3- Is there a performance difference/server overhead, etc. when using TUniQuery.Options.AutoPrepare set to True and the method I described above.
4- I know that UniDAC has connection pooling. Does it also have Prepared Statement Pooling?

Thanks.

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Way of using prepared statements and some related questions

Post by azyk » Mon 13 Mar 2017 14:51

1,2 - In the TUniQuery destructor there is code call that regardless of the value in TUniQuery.Options.AutoPrepare calls UnPrepare if dataset was prepared.

3- For the described case there will not be any performance difference because when setting TUniQuery.Options.AutoPrepare to True the same method Prepare will be called

4 - When placing a connection to pool UniDAC will call the UnPrepare method for each dataset that uses this connection and was prepared.

ertank
Posts: 172
Joined: Wed 13 Jan 2016 16:00

Re: Way of using prepared statements and some related questions

Post by ertank » Tue 14 Mar 2017 00:13

Hi azyk,

About Number 3:
a- My initial post is calling prepare one time, at the time form is created.
b- When TUniQuery.Options.AutoPrepare is set to True, TUniQuery is calling Prepare each time there is a call to TUniQuery.Open()

My question about performance/server overhead etc was mostly regarding item b above as using this way or TUniQuery there will be lots of prepare/unprepare calls thru the life of the application compared to item a which is just one prepare/unprepare call.

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Way of using prepared statements and some related questions

Post by azyk » Fri 17 Mar 2017 11:51

If TUniQuery.Options.AutoPrepare is set to True, then when calling TUniQuery.Open UniDAC will not prepare a query on the server again if TUniQuery has been already prepared.

Post Reply