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
Solved

Record exists in two queries code

Posted on 2001-07-09
10
161 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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