Page 1 of 1

CachedUpdate

Posted: Tue 27 Mar 2007 17:22
by ntoll
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();
    }

Posted: Wed 28 Mar 2007 06:55
by Antaeus
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.

RE: CachedUpdates

Posted: Wed 28 Mar 2007 12:47
by ntoll
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

Posted: Thu 29 Mar 2007 08:17
by Antaeus
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.