How to open TMSQuery without issuing SELECT

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
AntonPlotnikov2018
Posts: 3
Joined: Thu 01 Nov 2018 15:14

How to open TMSQuery without issuing SELECT

Post by AntonPlotnikov2018 » Wed 20 Feb 2019 09:32

Hello.

Is there an ability to open a TMSQuery without issuing of a SELECT SQL? My dataset is intended to insert new items in cached update mode and there is nothing to select from database.

Wbr,
Anton

Stellar
Devart Team
Posts: 248
Joined: Tue 03 Oct 2017 11:00

Re: How to open TMSQuery without issuing SELECT

Post by Stellar » Fri 22 Feb 2019 14:28

We do not quite understand the essence of your question.
So that we can give a more specific answer, describe the problem in more detail.

AntonPlotnikov2018
Posts: 3
Joined: Thu 01 Nov 2018 15:14

Re: How to open TMSQuery without issuing SELECT

Post by AntonPlotnikov2018 » Mon 04 Mar 2019 07:00

I have a form for a document editing. There are two datasets placed In this form: for a document head and for a document content. When I insert new document both datasets have to be opened. And there are two select statements are issued during opening of the datasets. But for the insert mode there is no reason to issue a select statetment, because I want to insert records in datasets then commit them to database. So, a select is excessive and needs a database connection when it is not appropriate

Stellar
Devart Team
Posts: 248
Joined: Tue 03 Oct 2017 11:00

Re: How to open TMSQuery without issuing SELECT

Post by Stellar » Wed 06 Mar 2019 11:33

To add records to a table, you can execute an SQL expression with help of the Execute method. For example:
MSQuery1.SQL.Text := 'INSERT INTO Dept (DName) VALUES (''New'')';
MSQuery1.Execute;

You can also try executing a query on the server which predeterminedly does not return results. For example:
MSQuery1.SQL.Text := ' SELECT * FROM Dept WHERE 1=0 ';
MSQuery1.Open;

AntonPlotnikov2018
Posts: 3
Joined: Thu 01 Nov 2018 15:14

Re: How to open TMSQuery without issuing SELECT

Post by AntonPlotnikov2018 » Tue 02 Apr 2019 07:47

I don't want to issue a SELECT statement In some cases. Look at the .NET DataSet. I can start to use it for data inserting without database connection. A user inputs data to it. Then he presses Save button, and all data saves on the SQL Server. So there is a single query to database. On the other hand, with SDAC there will be at least two query to database. And the first of them is excessive and requires a database connection at the beginning of editing, not at the saving.

Stellar
Devart Team
Posts: 248
Joined: Tue 03 Oct 2017 11:00

Re: How to open TMSQuery without issuing SELECT

Post by Stellar » Thu 04 Apr 2019 14:17

Unfortunately, SDAC does not allow the addition of records when the dataset is inactive. This behaviour comes from the fact that TMSQuery and TMSTable inherit from TDataSet. Adding and updating data in the dataset can be achieved through the standard means.

Post Reply