TClientDataSet x TMSQuery

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
leocechet
Posts: 5
Joined: Wed 06 Jul 2011 18:54

TClientDataSet x TMSQuery

Post by leocechet » Thu 07 Jul 2011 13:19

Hello, I'm testing the component SDAC 5.10 for Delphi 7 Trial and I have some doubts.

1. DataSetProvider contains events BeforeUpdateRecord and AfterUpdateRecord. These events are called for each record before and after submitting changes. These events have UpdateKind variable that allows you know if the record has been modified, inserted or deleted (ukModify, ukInsert, ukDelete).
I did not find these events in TMSQuery.

2. TClientDataSet ChangeCount has property that indicates the number of records changed. TMSQuery ChangeCount hasn’t the property ChangeCount, only Modified (TDataSet). Is there any other property that indicates the number of rows changed?

3. Is SDAC compatible with Delphi 2010 DataSnap? I couldn’t do this teste yet.

I am analyzing these details to buy SDAC component in the future and these questions will be determining factors for the acquisition. I have no doubt that this is the best component for native access to SQL Server.

Thanks.

AndreyZ

Post by AndreyZ » Fri 08 Jul 2011 08:23

Hello,

1. You can use the BeforeUpdateExecute and AfterUpdateExecute events of the TMSQuery component. These events occur before and after executing insert, delete, update, lock and refresh operations. To determine the exact operation that has been executed, you can use the StatementTypes set of variables. Here is an example:

Code: Select all

procedure TMainForm.MSQueryBeforeUpdateExecute(Sender: TCustomMSDataSet;
  StatementTypes: TStatementTypes; Params: TMSParams);
begin
  if stInsert in StatementTypes then
    //your code
  else
  if stDelete in StatementTypes then
    //your code
  else
  if stUpdate in StatementTypes then
    //your code
end;
2. You can use the RowsAffected property that indicates the number of rows, which were inserted, updated, or deleted during the last query operation.
3. Yes, SDAC is compatible with DataSnap. Please take a look at the example of using Datasnap components in the Midas demo. You can find this demo in the %SDAC_Install_Directory%\Demos\Miscellaneous\Midas directory.

leocechet
Posts: 5
Joined: Wed 06 Jul 2011 18:54

Post by leocechet » Fri 08 Jul 2011 17:40

Hello AndreyZ,

1. Question answered, but did not find the event equivalent to the BeforeApplyUpdates and AfterApplyUpdates of the TClientDataSet. That are executed only once, before and after submitting changes.

2. RowsAffected property, the value returned is always 1, even having more records changed. This is a bug? This property is populated after applying the changes. In TClientDataSet, ChangeCount is populated with each post or delete it, that is, before sending the changes. I used a TMSQUery with CachedUpdates enabled. Follow the code:

Code: Select all

  
  MSConnection.StartTransaction;
  MSQuery.ApplyUpdates;
  MSConnection.Commit;
  ShowMessage(IntToStr(MSQuery.RowsAffected));
3. I will still check out the example of DataSnap.

AndreyZ

Post by AndreyZ » Mon 11 Jul 2011 08:08

1. We've discussed this question, but considered implementing these events superfluous. If you think otherwise, you can leave your suggestion concerning these events at http://devart.uservoice.com/forums/1046 ... components , and if many people vote for it, we will implement it.
2. It's a correct behaviour. The point is that SDAC executes a query for every record thas has been changed. That's why the RowsAffected property returns 1. The RowsAffected returns a value greater than one after the last query inserted, updated, or deleted more than one record on the server.

leocechet
Posts: 5
Joined: Wed 06 Jul 2011 18:54

Post by leocechet » Thu 11 Aug 2011 14:12

Hello again,

I did some testing and it seems that using the TClientDataSet with TMSQuery works perfectly. (TMSConnection + TMSQuery + TDataSetProvider + TClientDataSet).
Can I work this way without risk?

The scenario that was put together the following:

1. TMSConnection used to connect to the database;
2. I turned on the TMSQuey + TMSConnection and filled the property "UpdatingTable" with the name of the table that the update will occur;
3. I turned on the TDataSetProvider + TMSQuery and changed the property "poAllowCommandText" to TRUE;
4. I turned on the TClientDataSet + TDataSetProvider the CommandText property and used a query with JOIN.

This way everything worked.
I noticed that the set automatically TMSQuery what are the keys in the table. Is there a way to do this at run-time?

Thank you.

AndreyZ

Post by AndreyZ » Thu 11 Aug 2011 14:55

Can I work this way without risk?
Yes, you can work this way.
I noticed that the set automatically TMSQuery what are the keys in the table. Is there a way to do this at run-time?
If you want to specify the key fields for the TMSQuery component, you can use the KeyFields property for this. For more information about the KeyFields property, please read the SDAC documentation.

leocechet
Posts: 5
Joined: Wed 06 Jul 2011 18:54

Post by leocechet » Fri 12 Aug 2011 17:27

Okay, thank you for the clarification.

SDAC is perfect in our tests, even being able to work using TClientDataSet + TMSQuery.

In the real environment of our system will be used in three layers, with DataSnap 2010.

Thanks for everything and the quick service.

Dimon
Devart Team
Posts: 2885
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 15 Aug 2011 07:41

Feel free to contact us if you have any further questions about SDAC.

leocechet
Posts: 5
Joined: Wed 06 Jul 2011 18:54

Post by leocechet » Wed 24 Aug 2011 13:24

I have one more question:

The trial version of SDAC, you must download a specific version for the version of Delphi. When buying an installer to come SDAC specific version of Delphi or all the SDAC support?

Thank you.

AndreyZ

Post by AndreyZ » Wed 24 Aug 2011 13:34

When you order SDAC you will have access to SDAC versions for all supported IDEs.

Post Reply