Solved

Record exists in two queries code

Posted on 2001-07-09
10
162 Views
Last Modified: 2010-04-06
I use this code to see if a record exists in two different queries, the code works fine. But crashes when there is a blob field. Is there anything I can do to fix this error ?
Without writing a custom OnFilterRecord event.


function TFrmSync.RecordExists(ValueQuery, LookInQuery: TQuery): boolean;
var
    KeyFields: string;
    KeyValues: Variant;
    i: integer;
begin
    for i := 0 to ValueQuery.FieldCount-1 do
    begin
        KeyFields := KeyFields + ValueQuery.Fields[i].FieldName;
        if i < ValueQuery.FieldCount-1 then
            KeyFields := KeyFields+';';
    end;

    KeyValues := VarArrayCreate([0,ValueQuery.FieldCount-1], varVariant);
    for i := 0 to ValueQuery.FieldCount-1 do
        KeyValues[i] := ValueQuery.Fields[i].AsVariant;

    Result := LookInQuery.Locate( KeyFields, KeyValues, [] );
end;
0
Comment
Question by:sorentop
  • 5
  • 4
10 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6266477
as you can't use blob-data for retrieval, just exclude it
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6266510
for exclude ask the field
if not valuequery.fields[I].isBlob then ...
0
 

Author Comment

by:sorentop
ID: 6267058
ok, but that the fields must be serched.
Any better?
0
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!

 
LVL 2

Accepted Solution

by:
Felixin earned 100 total points
ID: 6268091
You just can't make a search on a blob unless you access the blob fields contents a go thru it.

If you need to search for that blob you'll have to implement you're own "locate" routine.

I think.

Felixin
0
 

Author Comment

by:sorentop
ID: 6268487
Is there a way to search after the record returned by Locate. A LocateNext procedure.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6275842
why not use q query instead of locate?
0
 

Author Comment

by:sorentop
ID: 6276114
can you search on blobfields in a query?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6276189
no, but you can easily use the next-method
0
 

Author Comment

by:sorentop
ID: 6276276
Ok, actually I have made something like this. But this gives me some ugly and trouble some code. Isn't there a way to search on the whole record with one simple function.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6277061
from my paq:
maybe it matches not your need,
but maybe it gives you a suggestion

you can do it with a sql-query, of course the result-set will not be editable
a sample

procedure TForm1.Button1Click(Sender: TObject);
var
 I : integer;
begin
 query1.close;
 query1.dataBaseName := Table1.DataBaseName ;  //the TTable, which will examined, must be opened
 query1.sql.Clear;                             //Build up SQL-String
 query1.SQL.add('select');                 //Select
 for i := 0 to Table1.FieldCount - 1 do  //all fields
   query1.SQL.add(Table1.Fields[i].FieldName+',');
 query1.SQL.add('count(*) as RecAmount');  //and the amount
 query1.SQL.add('from '+table1.TableName);  //from the table
 query1.SQL.add('group by');                       //grouped by
 for i := 0 to Table1.FieldCount - 2 do           //all fields
   query1.SQL.add(Table1.Fields[i].FieldName+',');
 query1.SQL.add(Table1.Fields[Table1.FieldCount - 1].FieldName);
 query1.SQL.add('Order by RecAmount Desc');   //Descending SortOrder on Duplicates-amount
 query1.open;                                 //establish query
 query1.Filter := 'RecAmount > 1';            //show only duplicates
 query1.Filtered := True;
end;

the query can be shown for example in a dbgrid

meikl
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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…

762 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