Setting Timestamps to now()

Posts   
 
    
tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 30-Nov-2010 18:19:00   

LLBLGen Pro v2.6 Postgres 8.4

My search-fu must be failing me, as I'm sure this is probably common and simple. I want to set my create time field to use the server's clock instead of mine, with the now() function. Is there some tool I'm missing in the Entity, or do I have to write some SQL for that?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 30-Nov-2010 21:17:09   

There is nothing built into the entities or the framework to allow you to do this. The easiest way is probably to create a field with a default value of "now()" (I'm assuming PostGres will let you do this) - this means that the field will populated automatically without you needing to do anything.

Matt

tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 01-Dec-2010 17:57:40   

Ok, great, DEFAULT LOCALTIMESTAMP will work for me.

Now, I also use MarkSavedEntitiesAsFetched = true, because up until this point, all values in the entity other than the sequenced id have come from my software. What is the optimal way to get the actual timestamp back after the insert, especially in SaveEntityCollection usage?

Thanks!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Dec-2010 05:42:43   

The better way is use the normal save-refetch approach. So you save the entity indicating to rrefetch it after save.

David Elizondo | LLBLGen Support Team
tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 02-Dec-2010 14:57:27   

Gosh, I'm getting timeouts from my server as it is now. I have a data analysis farm and users are constantly pushing the limits of the number of tasks the system can take. Right now, the db is the limiting factor. I don't think it could take all those re-fetches. Maybe I'm ok with inaccurate timestamps.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 02-Dec-2010 15:56:07   

tmatelich wrote:

Gosh, I'm getting timeouts from my server as it is now. I have a data analysis farm and users are constantly pushing the limits of the number of tasks the system can take. Right now, the db is the limiting factor. I don't think it could take all those re-fetches. Maybe I'm ok with inaccurate timestamps.

Erm... maybe I'm reading your post wrong but... didn't you ask a question to which we simply answered? simple_smile

getting the server-side values back needs a roundtrip, and if you can't spare that roundtrip, because of database performance constraints, then don't refetch. PK values created by the server (Sequences) are always refetched btw. (if possible in the same statement, so no performance loss there).

it of course depends in which scenario you're using the timestamps created on the server...

Frans Bouma | Lead developer LLBLGen Pro
tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 02-Dec-2010 17:44:52   

Sorry, yes, I should have marked it closed, just was still pondering my options. The variance of multiple clients adding results with their own local clocks is causing some consternation, but I think I can't afford that traffic right now.

Is it possible to set LLBLGen up to retrieve other values in the same fashion as the PK by overriding some function for my own needs? Or is that a special case not extendable to other columns?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-Dec-2010 05:11:58   

tmatelich wrote:

Sorry, yes, I should have marked it closed, just was still pondering my options. The variance of multiple clients adding results with their own local clocks is causing some consternation, but I think I can't afford that traffic right now.

Yep. It is this way: If you want to get the value of a field that is filled by DB you must fetch it.

tmatelich wrote:

Is it possible to set LLBLGen up to retrieve other values in the same fashion as the PK by overriding some function for my own needs? Or is that a special case not extendable to other columns?

You could:

A. Fetch the DB NOW() value before save your entity, then set it to your field and save it, without refetching it.

B. Save the entity and set the column's default DB value to NOW(), without refething it. Then you fetch the entity again using ExcludeIncludeFieldsList to just fetch the desire datetime field. This of course is a round-trip but only of the desire fields.

C. Do it as the normal way: save-refetch. I know your roundtrip situation but this is how the world works. A hardware/software configuration or upgrade should be applicable here simple_smile

David Elizondo | LLBLGen Support Team
tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 03-Dec-2010 05:18:51   

Thanks for the feedback!