Limiting database entries

29 views
Skip to first unread message

mostwanted

unread,
Oct 14, 2020, 12:50:07 AM10/14/20
to web2py-users
Is there a way to limit the number of entries to a database?
Like limiting the number of entries to only 100 and nothing more.

Regards;

Mostwanted

Jim S

unread,
Oct 14, 2020, 10:42:05 AM10/14/20
to web2py-users
I'm not entirely clear on what you're asking for.

Are you trying to limit the number of records in a table in the database?

If so, then I'd probably create a trigger on the database.  The way to do that would be dependent on which database you are using.

If not, can you explain a little more?

-Jim

Clemens

unread,
Oct 14, 2020, 11:33:58 AM10/14/20
to web2py-users
Since you surely have to handle the case, that the limit is reached, I would define a constant value for the limit, stored in your model. Let's call MAX_DB_ENTRIES (=100). Then just check if the the limit is reached by if db(db.table.id>0).count() >= MAX_DB_ENTRIES: <inform the user of whatever the reaction should be>. Then you are independent on what database you use. I'm not sure if the solution fits your requirement. Does it?

Regards
Clemens
Reply all
Reply to author
Forward
0 new messages