Login Retreive lost passwordRegister
Search

Forum Index / General / Show PK

[ This topic is solved ]

  Joao Correa 03 November 08 / 19:46  
Hi all,

How, when opening a form, a non-editable field, display the next number (PK) of my Database?
In addition, we have a problem with the duplicity, because if 2 people open the Form while both may end up getting the same number and this can not happen.

Thank you all

  Johan Wiegel (Admin) 03 November 08 / 20:29  
Changed at 03 November 08 / 20:31
if you use an autoincrement primary key it's not posible to create the same id two times.

What are you trying to achieve?
can you explain that?

Are you using dbFormHandler?
What is the name of the primarykey field? Is the config changed to that?

  Remco van Arkelen (Admin) 03 November 08 / 20:44  
Hi Joao,

Depending on your database, you cannot predict the next number in a autonumeric PK. When using MySQL, the next number is generated based on the table. When using PostgreSQL, the number is a result from a corresponding sequence, if you want to know the next number you can simply refer to the sequence SELECT NEXTVAL() FROM sequence_name....BUT, when you refresh your form the sequence will generate a next number.

When simply adding +1 to the MAX(pk) you will finally enter a problem because people will get the same number....so in this context it's not really possible to achieve this. The final number of a REAL autonumeric column will AND SHOULD be generated by the databasesystem.

Please make sure that normal autonumeric PK's are mostly used to identify records and are not shown to (end)users...it shouldn't matter if there are "holes" in the sequence, it's just an identifier.

Maybe it's an idea to create a form in 2 steps, 1 form to create the record and then immediately return into edit-mode. The new record is created and can be editted.

  Joao Correa 12 November 08 / 19:21  
thanks!

  Top


powered by PHP-GLOBE   © 2004 - 2009 FormHandler. All rights reserved.   -   Open source license