Using Cached Updates

I have a lot of Inserts to do in a Sybase table.  I want to use cached updates to lower network traffic.  I use a Tquery with the query Insert into TAble1 (Field1,field2,...) VAlues ("value1","value2",..).  I change TQuery.SQL for each insert and use Tquery.ExecSQL.  After a hundred inserts I do TDatebase.ApplyUpdates and I receive the error : Tquery isn't a TDatabase dataset.  Is there a way to do this task?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Add the DBiProcs unit to your uses clause and
put DBiSaveChanges(TableName.Handle) in your code to flush all cached changes.
Another option is adding DBiUseIdleTime to your app in the OnIdle event.


brutusAuthor Commented:
I don't think your methods are of some use for cached updates. If they do, I would need more information on that unit because there isn't info in Delphi manuals.
These procs work for me... I used to lose a record now and then after posting it. These functions did the trick for me.
The problem is that there is very little doc's about these procs available, but this is what I have on the DBiSaveChanges proc:

Unit:    DbiProcs

Section: Data Access: Logical Record Level

Description:   Flush all buffered changes

Parameters:    hCursor : hDBICur   Cursor handle

Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

brutusAuthor Commented:
When do I use these procs. After ApplyUpdates? Do I keep the Tquery and Tdatabase?  Can You show me somw code?
I guess you should use it near the TDatabase.ApplyUpdates you mentioned in your question.
I use something like this on Paradox tables:

  with Table1 do
       Table1FirstField.AsString := 'ABCDE';
       Table1SecondField.AsInteger := 123;

brutusAuthor Commented:
I specified in my question that I was working with a Sybase Server. I have to add records to the table with an SQL Insert query so I won't lock the table.  Also there is a autoincrement field in the table. I can specify a value for all the fields except this one. If I use your method, I will receive the error:Field[0] has no specified value. Also I find your method quite confusing since you don't use any of the cached updates' methods like ApplyUpdates, commit, etc.
brutusAuthor Commented:
Adjusted points to 200
What happens when you call the TQuery.ApplyUpdates instead of the TDatabase.ApplyUpdates?



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.