Setting fields to expression values in the database

Posts   
 
    
Innes avatar
Innes
User
Posts: 45
Joined: 18-Jun-2004
# Posted on: 26-Jun-2004 11:44:47   

It would be useful to me to be able to set a field value to some expression that would be evaluated by the database server, for example, to set a Date field to 'sysdate' in Oracle, or to the result of a function call. I use timestamps (not SQL Server 'timestamps' and not for concurrency), and want to rely on the 'one true time' on the database server to avoid confusion.

For example, to save an entity, and set one field to the current time and another to 'duration' seconds in the future, using database-evaluated expressions, the hypothetical code might be:

FooEntity foo = ...; ... foo.SetFieldToDatabaseExpression(FooEntityField.StartTime, "systimestamp"); foo.SetFieldToDatabaseExpression(FooEntityField.FinishTime, "add_seconds(systimestamp, 123)");

At the moment, I have worked around the inability to do this sort of thing by adding a 'duration' field that is only used to communicate the 'duration' to the server, and implementing a trigger on the table in question that reads this duration, fills in 'startTime' and 'endtime' fields, and resets the duration field (so that if somebody sets it again, the database 'notices').

I can see issues with this type of functionality of course: a possible SQL injection risk?, and it would add complexity to the DAL code of course.

I'm interested though in people's thoughts on the issue.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 26-Jun-2004 12:15:49   

Expressions will be added with the next runtime revision, design for that starts monday simple_smile , release targeted end of july.

I'm not going to add advanced expression constructions with own statements, it will be mostly up to the developer to make sure it works. (thus for example set a fields value to an expression statement, and if the expression statement is not properly setup, that's the developer's fault). simple_smile I think it will be ok though.

Frans Bouma | Lead developer LLBLGen Pro
Innes avatar
Innes
User
Posts: 45
Joined: 18-Jun-2004
# Posted on: 26-Jun-2004 13:14:36   

Otis wrote:

Expressions will be added with the next runtime revision, design for that starts monday simple_smile , release targeted end of july.

Good stuff!

joer
User
Posts: 26
Joined: 15-Dec-2004
# Posted on: 21-Jan-2005 13:34:40   

Hi - is this implemented now?

is so - how is it done?

may thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 21-Jan-2005 14:17:19   

Yes this is implemented since september 24th. Please upgrade to the latest version and check the documentation for more details on expressions and aggregates. In the documentation about expressions there is an example which shows you how to use expressions to update entities in the db.

Frans Bouma | Lead developer LLBLGen Pro
joer
User
Posts: 26
Joined: 15-Dec-2004
# Posted on: 21-Jan-2005 15:02:44   

Great

sorry for this but I am still having a problem after consulting the documentation

I want to create an Expression object which will simply assign an expression of SysDate to be used by Oracle, but can't see a simple way to do this.

Apologies if this has been covered somewhere

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 21-Jan-2005 15:23:09   

That's usage of a system function, these are not yet supported, just expressions on field values.

Frans Bouma | Lead developer LLBLGen Pro
joer
User
Posts: 26
Joined: 15-Dec-2004
# Posted on: 21-Jan-2005 17:45:44   

OK thanks, I'll work around this.