?
Solved

Record exists in two queries code

Posted on 2001-07-09
10
Medium Priority
?
165 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
[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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Accepted Solution

by:
Felixin earned 200 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

Independent Software Vendors: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month12 days, 9 hours left to enroll

777 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