Solved

Record exists in two queries code

Posted on 2001-07-09
10
157 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Highfive Gives IT Their Time Back

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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

23 Experts available now in Live!

Get 1:1 Help Now