updating records with "default" value

Posts   
 
    
HcD avatar
HcD
User
Posts: 214
Joined: 12-May-2005
# Posted on: 20-Oct-2006 14:55:45   

Hi,

i'm not sure if this belongs in the right section, but i've been looking around and can't find an answer. Is it possible to update a record with the "default" value as specified in the design of the database table ? (using MSSQL2000)

For instance, i have some tables which have a column "last_updated" (datetime, not-null, default = "GetDate()")

Now what i want is when i do a .save() on my Entity, i do not wish to set Entity.LastUpdated = DateTime.Now, but i want the DB to fill in the "default" value (GetDate()), so it always uses the clock of the DB server rather then the clock of the client.

Is this possible with LLBLGen ? (Version 1.0.2005.1)

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Oct-2006 15:29:51   

Just don't set the corresponding field to anything. And it won't be included in the generated INSERT command, and so the DB Default Value will be used.

Note: DB Default Values are only used in INSERTS not in UPDATES.

HcD avatar
HcD
User
Posts: 214
Joined: 12-May-2005
# Posted on: 20-Oct-2006 15:33:27   

Yes, but I thought maybe there might be a way (that i don't know of yet) to use the default when doing an update, not only on insert ?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Oct-2006 15:45:15   

I think you can do that by using the field.ExpressionToApply & by using database function calls. Refer to the manual: Using the generated code -> Calling a database function

HcD avatar
HcD
User
Posts: 214
Joined: 12-May-2005
# Posted on: 20-Oct-2006 16:38:53   

Hmm ..this sounds like what i need but ..i can't find it in the manual ? Is this supported in version 1.0.2005.1 ? I have only "calling a stored procedure" but not "calling a database function"..

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 20-Oct-2006 17:44:49   

calling a db function is v2.0 functionality, sorry. You can try this: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=3829

However, you can also implement an update trigger in the DB, if you want to have the server's time/date simple_smile

Frans Bouma | Lead developer LLBLGen Pro