Solved

Search...

Posted on 1998-08-28
11
200 Views
Last Modified: 2010-04-04
This question is easy. I'm developing a batabase system to my university and it must be FAST and ELEGANT. I know that there are a lot of ways to perform a search, but I'd like to know the best in this case:

    I have a form with several DBEdits linked to one table. The first DBEdit is the primary key of the table. I need to search the table to avoid key violations and notify the user. It's easy, but if the key is in the second DBEdit and I perform the search and a key violation ocurrs, the text of first BDEdit is lost. How solve it? I'd like to know your opinions about the best searchs and the right way to use CachedUpdates.

                              Tanks in advance.
0
Comment
Question by:oberdan
11 Comments
 

Expert Comment

by:chrismo
ID: 1338001
So you're creating a form that will link to any table in the database? Or is it fixed to a single table?
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1338002
Best in my opinion, if possible, is SQL queries.
TTable has two ways of searching: TTable.Locate, and the Setkey-gotokey sequence.

CachedUpdates should be used if you want to be able to cancel changes made to the table at some point.

-Please be a bit more detailed with the key violation problem. I can't fully see what causes what...

--Matvey
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1338003
CachedUpdates are also used in C/S dbs. This shouldn't apply to here, right?
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1338004
I think all search methods should be working at the same speed. It's the same BDE, so I don't see a reson for fundamental difference. Anyway, you can only see it in huge dbs. Is it the case here?
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1338005
I see SQL isn't the best idea here. I's use TTable.Locate...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:oberdan
ID: 1338006
To chrismo:

At first, a single table, but is possible that the form needs to be linked to any table.
0
 

Author Comment

by:oberdan
ID: 1338007
To Matvey:

The system will be C/S. The key violation problems are referent to duplicated keys.
0
 
LVL 4

Expert Comment

by:itamar
ID: 1338008
Hi all,

Key-violation in a search operation ? I thought key-violation was related to updating / inserting a record that causes a duplicate key entry or a null one ...

Am I wrong ?
0
 
LVL 2

Expert Comment

by:333
ID: 1338009
oberdan,
if you use Paradox or dBase tables, the fastest way to search will be TTable.Locate (your tables must be indexed). If you use SQL tables or your Pdox or dBase tables aren't indexed, use TQuery instead.
0
 

Author Comment

by:oberdan
ID: 1338010
To Itamar:

      You're not wrong. I don't explain the question. My problem is at insertion. When the user insert data to a primary key field, I want to search to verify if thew data typed are not already present on the table. I'd not like to lost the data typed by user on the fields when I change the table state to perform the search. I hope it can help.


       
0
 
LVL 3

Accepted Solution

by:
Matvey earned 100 total points
ID: 1338011
Here's something I wrote long time ago...

--Matvey
_____________________________________________________
procedure TForm1.Table1BeforePost(DataSet: TDataSet);
var t : TQuery;
begin
  t := TQuery.Create(self);
  t.DataBaseName := table1.DatabaseName;

  //change to your table name...
  t.SQL.Add('select * from animals where name = ''' +             table1.Fields[0].asstring + ''';');

  t.Open;
  if (t.RecordCount > 0) then
  Begin
    ShowMessage('Value exists!');
    Abort;
  end;
  t.close;
  t.free;
end;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

896 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

17 Experts available now in Live!

Get 1:1 Help Now