Dealing with default field values in database

Posts   
 
    
Emmanuel
User
Posts: 167
Joined: 13-Jan-2006
# Posted on: 18-May-2007 12:32:47   

I have a database where several fields get a default value set by the database. In my data entry GUI (web-based), I want to initialize new records that are displayed in an 'Insert Record' page to these default values.

My idea is to create a new record inside a transaction just prior to an 'Insert Record' page being displayed to the user and then process it AS IF it were an Edit Record page. If the user ended up cancelling the Insert operation I could then rollback the new record creation transaction. If the user OKs the 'Insert' (actually an Edit), I would commit the transaction.

Does this sound like a reasonable way to do this? Or am I making it over complicated?

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 18-May-2007 16:11:35   

That's a nice way of doing it.

But I think you should not use a Transaction, since your transaction will be waiting for user input, and that's not a good thing to have. Transactions should be fast without any user interactions.

You can just delete the inserted record if the user canceled the operation.

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 18-May-2007 17:15:43   

what if the user navigates away from the page without using the cancel button. or closes the browser, or uses the browser navigation instead of your navigation controls.

This could create a lot of orphaned records within your system. I would move the default values from the database to the entity initialization function. at a minimum duplicate the default values from the database into the entity.

you also get the added benefit of not opening the db just to get default values. And you don't need to trick your form into inserting a record.

Emmanuel
User
Posts: 167
Joined: 13-Jan-2006
# Posted on: 18-May-2007 19:34:22   

Thanks for the response guys.

I'd love to move the default values out of the db but cannot.

I wonder if there is a way to retrieve the default values from the table row properties throught the llblgen api. If so, I could that initialize values in the GUI as jmeckley suggested without creating duplicate code that has the danger of getting out of sync with the database default values.

Emmanuel
User
Posts: 167
Joined: 13-Jan-2006
# Posted on: 19-May-2007 16:00:35   

I just discovered the UnitOfWork2 class in LLBLGen! Nice. That will do what I was proposing to do in a db transaction which Walaa correctly pointed out was a bad idea simple_smile

The more I learn how to use llblgen, the more I really, really like it simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 21-May-2007 10:46:43   

Emmanuel wrote:

I just discovered the UnitOfWork2 class in LLBLGen! Nice. That will do what I was proposing to do in a db transaction which Walaa correctly pointed out was a bad idea simple_smile

The more I learn how to use llblgen, the more I really, really like it simple_smile

smile

Frans Bouma | Lead developer LLBLGen Pro