Solved

Record exists in two queries code

Posted on 2001-07-09
10
159 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 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