Limiting the number of entries in a table/column

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Limiting the number of entries in a table/column

Post by quailcreek » Tue Oct 31, 2017 2:12 am

Hi,
I need to be able to limit the number of entries a user could insert into a table. This would be based upon a parameter. If the parameter is true the user can generate an unlimited number of entries, if the parameter is false, I need to be able to limit the number of entries to <= 15.

Can this be done from within the SQLite database or should I just count the number of entries in the table and if it exceeds 15 just present the user with an answer box stating that they have exceeded the number of allowed entries? Thanks in advance.
Tom
MacBook Pro OS Mojave 10.14

AndyP
Posts: 614
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: Limiting the number of entries in a table/column

Post by AndyP » Tue Oct 31, 2017 8:37 am

The answer is in Your question.

Sqlite supports the LImit clause, so just add

LIMIT 15 to the end of YouTube Sqlite call.
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search

AndyP
Posts: 614
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: Limiting the number of entries in a table/column

Post by AndyP » Tue Oct 31, 2017 9:03 am

Whoops.. just reread the question for inserting it would depend on how your users are inputing the data.

Are they using a form for each entry or entering all data in one go?
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: Limiting the number of entries in a table/column

Post by quailcreek » Tue Oct 31, 2017 7:14 pm

Hi Andy,
they are entering all of the data at one time. It all goes into 1 table which of course has multiple columns. One column for each piece of input data. No cross reference, no foreign keys, etc.
Tom
MacBook Pro OS Mojave 10.14

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Limiting the number of entries in a table/column

Post by MaxV » Fri Dec 15, 2017 12:30 pm

quailcreek wrote:
Tue Oct 31, 2017 2:12 am
should I just count the number of entries in the table and if it exceeds 15 just present the user with an answer box stating that they have exceeded the number of allowed entries? Thanks in advance.
This is the simpler solution.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

teriibi
Posts: 254
Joined: Mon Nov 13, 2017 3:49 pm
Location: Bolivia

Re: Limiting the number of entries in a table/column

Post by teriibi » Fri Jan 12, 2018 3:12 pm

I m also looking for to use such limits for a project...Havent yet get to that part - though.

I figure out that such User account - input limit number- sould be set as an editable variable
(maybe in some extra table)
The reason not to hard code it in the App. is that you may want later on to upgrade/downgrade it for each user´s - by synchronizing the Variable with one stored online.... for whatever reason.

If its only hard-coded... U´re stuck.
unless you´re absolutely certain it ll never change...ever..ever...ever.. ! :lol:
Make sense ?

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: Limiting the number of entries in a table/column

Post by quailcreek » Fri Jan 12, 2018 9:06 pm

Here's what I put together. It could easily be set up to use variables.

Code: Select all

function getLastItemID
  
  put "SELECT COUNT(ItemID) FROM MyItems" into tSQLRowCount
  put revDataFromQuery(,,the uDatabaseID of this stack,tSQLRowCount) into theRowCount
  
  return theRowCount
end getLastItemID
This part goes wherever you need it.

Code: Select all

  put getLastItemID() into theRowCount
  put the uProVersionPurchased of this stack into theVersion
  
  if (theVersion = "false") AND (theRowCount >= 2) then
    answer "Only 2 items can be created using the Free Version of this app" with "Yes" OR "Not Now" titled "Purchase the Pro Version"
    if it is "Not Now" then
      exit to top
    else
      go cd "Settings"
      exit to top
    end if
  end if
Tom
MacBook Pro OS Mojave 10.14

Post Reply

Return to “Databases”