Solved

Using Cached Updates

Posted on 1997-07-23
8
173 Views
Last Modified: 2010-04-04
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?
0
Comment
Question by:brutus
  • 4
  • 4
8 Comments
 
LVL 1

Expert Comment

by:jackb022197
Comment Utility
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.

Jack

0
 

Author Comment

by:brutus
Comment Utility
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.
0
 
LVL 1

Expert Comment

by:jackb022197
Comment Utility
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

0
 

Author Comment

by:brutus
Comment Utility
When do I use these procs. After ApplyUpdates? Do I keep the Tquery and Tdatabase?  Can You show me somw code?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:jackb022197
Comment Utility
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
    begin
       Table1.Edit;
       Table1FirstField.AsString := 'ABCDE';
       Table1SecondField.AsInteger := 123;
       Table1.Post;
       DBiSaveChanges(Table1.Handle);
    end;

0
 

Author Comment

by:brutus
Comment Utility
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.
0
 

Author Comment

by:brutus
Comment Utility
Adjusted points to 200
0
 
LVL 1

Accepted Solution

by:
jackb022197 earned 200 total points
Comment Utility
What happens when you call the TQuery.ApplyUpdates instead of the TDatabase.ApplyUpdates?
Sample:

  Database1.StartTransaction;
  try
    Query1.ApplyUpdates;
    Database1.Commit;
  except
    Database1.Rollback;
    raise;
  end;
  Query1.CommitUpdates;

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now