Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing a database

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
0
0
US
Guys, if i search for every records that match a criteria in a database, what is more appropriate: A repeat..until or while...do statement?

Thanks.
Pierrotsc
 
The ONLY difference between a repeat..until and a while...do is that the repeat..until will always execute (whatever is between) at least ONCE.

Therefore, neither is more appropriate. It depends only on your needs.

Roo
Delphi Rules!
 
pierrotsc


i search for every records that match a criteria in a database


I realize you did not completely specify your programs, so in all fairness my 2 cents worth probably won't be worth 2 cents.


If you have a real database (for example, as opposed to data in a TStringGrid), SQL is definitely one of the most appropriate methods. Practically any criteria match can be expressed via the WHERE clause of a SELECT query.

If you would be willing to share some simple details regarding the structure of your table (table name, field names, the data type of each field, and the search criteria), I would be glad to take a stab at creating a working SQL query. Whatever database table access component your are using (TTable, for example) is bound to have a corresponding query component (TQuery for example).


Steve.
 
Thanks Steve. I use absolute database and it does have query capability.
I have a table called Images. Let's keep it simple and give it 3 fields: ImagesNo (autoinc), ImagesPath (string) and trialno (Integer).

I would like to delete all the records in the images database that have a trialno of 3 for example. Right now, i am doing a loop and checking every record. I have a feeling that this is not optimized.
Sincerely,

PS: This is a query example i use. Not sure if every database uses the same syntax.
ABSQuery.SQL.Text := 'UPDATE "'+db.DatabaseFileName+'".trial SET TRIALNO=TRIALNO+(SELECT MAX(TRIALNO) FROM trial)';

ABSQuery.ExecSQL;

 
Based on what you have written above and your search criteria, following is the query I recommend:

Code:
DELETE FROM Images

WHERE trialno = 3;

Steve.
 
Is that it? I will try tomorrow.
Thanks a bunch...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top