Solved

Branching a TQuery after executing SQL

Posted on 1998-07-28
7
217 Views
Last Modified: 2010-04-04
A little background info here.  I'm accessing a FoxPro table / database from a CD-ROM (ick!).  There are lots of tables, but one huge *mutha* of a table that takes up most of the CD.  Now, imagine doing a SQL query on that...  sorted, even...  now you have entered my little room in hell.

Okay, I'm going thru various testing ideas here to help speed this thing up.  There comes a point after the first SQL execution where I need to "fine tune" the data, in a branching kind of way.  I need a subset of the original query, while keeping the original query.  

Can this be done without executing a new query?

I know about the Filter property on a query, but that doesn't allow me to branch off...

I wish there was something like a query.assign where it could just transfer over the guts and then I could apply the filters.

Any hints?

thanks,
-gd
0
Comment
Question by:greendot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1358847
... what about using temp queries in SQL code?
0
 
LVL 2

Author Comment

by:greendot
ID: 1358848
Oh mm...
(I'm somewhat of an upper-novice with SQL)
Could you explain a little more about temp queries?

thx,
j

0
 
LVL 1

Expert Comment

by:andrey070798
ID: 1358849
Hi, gd!

I have question.
  You HAVE this Database on the CD and your problem to speed it up for you
     OR
  you CREATING Database (you'll store it in a CD) and all you want to speed up work in the future?
If you're CREATING it I can help a little bit.
But if you already have data structure and it's on the CD I think there is difficult to change it.
May be I'm wrong.
Andrey.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:greendot
ID: 1358850
The tables are already out on the CD.  We can't change them.
(That's the next version.. yay)

I'm just trying to find ways to speed things up.  There is one point where I have to print a report and do a query on the huge (100-600 meg) file.  I can measure this in hour/query. ick.

So I was wanting to branch so I could apply the filters on those seperately, without the entire query being run again.

My thinking is I do the query to gather in the fields and define the sort order, then split it off and filter off the little "subqueries".

-gd
0
 
LVL 3

Accepted Solution

by:
vladika earned 100 total points
ID: 1358851
I wrote small component CloneQuery which can clone existing dataset.
Set MasterQuery property, then open MasterQuery
After MasterQuery opened you can open CloneQuery.
Then you can apply your filter to CloneQuery.
You can improve my component.

unit CloneQuery;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  BDE, Db, DBTables;

type
  TCloneQuery = class(TQuery)
  private
    FMasterQuery: TQuery;
    procedure SetMasterQuery(Value: TQuery);
  protected
    function CreateHandle: HDBICur; override;
    procedure Notification(AComponent: TComponent;
      Operation: TOperation); override;
  published
    property MasterQuery: TQuery read FMasterQuery write SetMasterQuery;
  end;

procedure Register;

implementation

procedure TCloneQuery.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if (Operation = opRemove) and (FMasterQuery <> nil) and
    (AComponent = FMasterQuery) then FMasterQuery := nil;
end;

procedure TCloneQuery.SetMasterQuery(Value: TQuery);
begin
  if Value = Self then Exit;
  FMasterQuery := Value;
  if Value <> nil then Value.FreeNotification(Self);
end;

function TCloneQuery.CreateHandle: HDBICur;
begin
  if (FMasterQuery <> nil) and (FMasterQuery.Active) then
    Check(DbiCloneCursor(FMasterQuery.Handle, False, False, Result))
  else Result := nil;
end;

procedure Register;
begin
  RegisterComponents('ExpertExchange', [TCloneQuery]);
end;

end.

0
 
LVL 3

Expert Comment

by:vladika
ID: 1358852
greendot, where are you?
What do you think about my solution?

0
 
LVL 2

Author Comment

by:greendot
ID: 1358853
Oops,
sorry vladika, but I haven't had a chance to get at it yet.
I made the component, and put it in the component tray..
but haven't tested.  :\

I should be able to get at it either this weekend or on Monday.
But off hand, it looks like this is what I want.  :)

-gd
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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