SQL Functions

Posts   
 
    
danvallejo
User
Posts: 6
Joined: 24-May-2007
# Posted on: 24-May-2007 19:25:54   

I have 2.0.0.0 final (Feb 14, 07) Pro.

How do I generate wrappers for SQL DB functions?

I don't see any settings nor do I see any menu options specifically for functions. I do see stored procs though.

thoughts.

Dan

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 24-May-2007 20:36:04   

use the new DBFunction() object call db function, both builtin and user defined.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-May-2007 09:53:08   

Please refer to the LLBLGen Pro manual: "Using the generated code -> Calling a database function"

danvallejo
User
Posts: 6
Joined: 24-May-2007
# Posted on: 25-May-2007 23:21:44   

Why are functions considered differently than sprocs?

Also, the docs have a very obscure example. I just want to see how to call a simple function and the docs go into dynamic list stuff.

The docs don't show how the actual call is made to fn_CalculateOrderTotal.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-May-2007 09:00:14   

Why are functions considered differently than sprocs?

Copied from LLBLGenPro Help - Using the generated code - Calling a database function:

On some databases, the difference between a stored procedure and a function is non-existent. The database function meant here is a function which is either a system function, like GETDATE() on SqlServer, or a user defined function in a schema and is not directly callable from the outside through ADO.NET unless a special crafted SQL statement is used. Rule of thumb: if you need an explicit EXEC statement to execute the function, it's not callable by this mechanism: the function has to be callable from within a SELECT statement for example.

Also, I think that could be very inappropriate to include in the framework a wrapper call for every SQL_DBFuntion frowning

Also, the docs have a very obscure example.

I see everything clear: The DBFuntcion creation and DBFunction call. What do you mean about obscure?

I just want to see how to call a simple function and the docs go into dynamic list stuff.

Well, you can do a very simple call simple_smile :

object thisYear = adapter.GetScalar(CustomersFields.Address.SetExpression(
                    new DbFunctionCall("YEAR", new object[] { DateTime.Now })), AggregateFunction.None);

However, in most cases, we might include the Function in a resulset (dynamic list, typed list, etc.).

The docs don't show how the actual call is made to fn_CalculateOrderTotal.fields[3].ExpressionToApply = new Expression( new DbFunctionCall( "YEAR", new object[] { OrderFields.OrderDate } ), ExOp.Add, 4 );

You can see the SQL generated for the call. Please refer to LLBLGenProHelp - Generated code - Troubleshooting and debugging

You can do very simple and also powerful things with DBFunctionCalls simple_smile

David Elizondo | LLBLGen Support Team
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 26-May-2007 13:37:58   

I think a user has contributed a set of many wrappers for Sql server function calls. Check the user code section.