CachedUpdate

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ntoll
Posts: 2
Joined: Tue 27 Mar 2007 17:12

CachedUpdate

Post by ntoll » Tue 27 Mar 2007 17:22

I am trying to use the CachedUpdate option in C++ Builder using MyDac for VCL.

The code I'm using is below. Unfortunately it is executing every REPLACE immediately. What am I doing wrong. I'm a little new to client/serve DB apps. Thanks, NJT

Code: Select all

if(flag==1){

         String SQLtime;
MyQuery->CachedUpdates= true;
for(int i=0; iXValue[i]);
        SQLstr= SQLstr + SQLtime + "','" + fileoforiginVec.at(i) + "',";
        SQLstr= SQLstr + tempGraphVec.at(i) + "," + Series1->YValue[i] +",";
        SQLstr= SQLstr + offsetVec.at(i) + ",'" + flagVec.at(i) + "');";

        MyQuery->SQL->Add(SQLstr);
        MyQuery->Execute();

        MyQuery->SQL->Clear();
        }
        MyQuery->ApplyUpdates();
    }

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 28 Mar 2007 06:55

The Execute method sends the command directly to the server independently of the CachedUpdates value. The CachedUpdates option has an influence on operations like Delete, Insert/Post, Edit/Post. If CachedUpdates is set to True, changes made by using these operations are applied to server only after the ApplyUpdates method has been invoked.

ntoll
Posts: 2
Joined: Tue 27 Mar 2007 17:12

RE: CachedUpdates

Post by ntoll » Wed 28 Mar 2007 12:47

Ok thanks, I have been trying to just get the cachedupdates working using an insert statement... Have managed to use it fine using a DBGrid to modify data.

If I used insert in the code from my orginal post, how could I write a loop that caches the inserts until I apply the updates? I have 10000-40000 records to insert sometimes. i.e. if I used a insert instead of replace how do I cache all those insert statements. I know I'm missing something obvious.

Thanks, NJT

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Thu 29 Mar 2007 08:17

You can try to use the TMyLoader component. It groups records values in a batch and inserts several records at once. The value of the RowsPerQuery property determines the number of records to be inserted at once. See the description of the TMyLoader component in MyDAC help. Also take a look at the TMyLoader.DuplicateKeys property.

Post Reply