Make a DBFunctionCall during an Insert

Posts   
 
    
Vonziz
User
Posts: 15
Joined: 05-Feb-2009
# Posted on: 15-Mar-2009 11:16:00   

Hi,

I'm facing a problem to make a DBFunctionCall during an insert in the database.

I want to fill fields "CreationDate" and "LastModDate" by the system date of the server side (by calling the function GETSYSDATE).

The problem is that I can't make the function call in one time. I have to write the element first by an INSERT without two fields and after that, to make an UPDATE with the function call for my two fields.

If I make the query in one call, two fields are not filled by the system date (they stay empty).

Here is my working code :


                pEnt.Status = proBE.StatusOfProcess;
                pEnt.Version = proBE.Version;
                pEnt.InUse = proBE.InUse;
                pEnt.Substance = sEnt;

                adapter.SaveEntity(pEnt, true).
            
                pEnt.Fields["CreationDate"].ExpressionToApply = new DbFunctionCall("GETSYSDATE", null);
                pEnt.Fields["CreationDate"].IsChanged = true;
                pEnt.Fields["LastModDate"].ExpressionToApply = new DbFunctionCall("GETSYSDATE", null);
                pEnt.Fields["LastModDate"].IsChanged = true;
                pEnt.IsDirty = true;

                adapter.SaveEntity(pEnt, true).

That I want (or equivalent) is :


                pEnt.Status = proBE.StatusOfProcess;
                pEnt.Version = proBE.Version;
                pEnt.InUse = proBE.InUse;
                pEnt.Substance = sEnt;
                pEnt.Fields["CreationDate"].ExpressionToApply = new DbFunctionCall("GETSYSDATE", null);
                pEnt.Fields["CreationDate"].IsChanged = true;
                pEnt.Fields["LastModDate"].ExpressionToApply = new DbFunctionCall("GETSYSDATE", null);
                pEnt.Fields["LastModDate"].IsChanged = true;
                pEnt.IsDirty = true;

                adapter.SaveEntity(pEnt, true).

How can I make that?

Thank you for your help.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Mar-2009 21:14:33   

LLBLGen doesn't support DBFunction calls on Inserts, at the moment. So you could

  • Use a transaction to perform the insert-update operation
  • User DB insert-triggers to insert the sysdate to your fields
  • Modify a little bit the DataAccessAdapter class to make this possible (expressions on Inserts). This could require some coding of course.
David Elizondo | LLBLGen Support Team
Vonziz
User
Posts: 15
Joined: 05-Feb-2009
# Posted on: 16-Mar-2009 10:40:07   

Ok, thank you for this information.

I use transactions, so I think that's a good way for the moment...