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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limiting a number of records.

Status
Not open for further replies.

delphiman

Programmer
Dec 13, 2001
422
ZA
I need to limit the number of records that might be created in a table under a given set of circumstances.

Does anyone know how can I do that please?

(In case anyone thinks I am totally mad I need my (freely downloadable demonstration "Tutorial" sofware from my website)to be limited in this manner. Otherwise it could simply be used without a full licence being obtained. Once a user obtains a full license the limit is removed for THAT licence No.)
 
delphiman,

Depends on what you're using for the connection to the tables themselves.

Case in point, Paradox tables (e.g. TBDEDatasets) have a concept of "record number." You can easily restrict functionality based on the number of records.

OTOH, many remote databases do not have the same concept. In these cases, you will need to research and then restrict results sets returned by various queries.

For example, many databases support something along the lines of LIMIT, which restricts the results returned by a query.

Alternatively, you could simply "walk" the result set. I know that seems prohibitive, however, you'd be suprised how quickly Delphi can execute something like:

Code:
with TDataset1 do
begin
   while ( not eof ) and ( not overLimit() ) do
   next;
end;

Hope this helps...

-- Lance
 
Don't know if this is helpful in this case but in SQL Server there is a TOP command

Select Top 10 * from mytable

which returns only 10 records.

lou
 
Hi,

if you are using a database like sql server or sybase etc,
then you can simply write a trigger on insert for that table
which checks for number of records already present in table.
if it exceeds your desired level then simply use rollback transaction...

bye......
 
Thanks earlrainer!

I am using Interbase.

I'll be trying your suggestion and will get back with results.

Terry.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top