Running SQL Stored Procedures from VL

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
HamadSheikh
Posts: 27
Joined: Fri Mar 18, 2016 3:49 am
Location: USA
Contact:

Running SQL Stored Procedures from VL

Post by HamadSheikh »

Hi Guys, Is there a way to run SQL Server Stored Procedures from within Visual LANSA? A customer has an existing SQL Server database application built with .NET technologies and they're interested in converting it to a Visual LANSA + VL-WEB application. There is a lot invested in SQL stored procedures within the SQL database that they do not want to duplicate that logic using LANSA business rules. I understand that one way of accomplishing this is by using database table triggers on the SQL tables themselves, but I would prefer a solution where the actual SQL tables are left untouched. There are no problems in loading the SQL tables as LANSA OTHER files.
JamesDuignan
Posts: 85
Joined: Thu Nov 26, 2015 1:43 pm

Re: Running SQL Stored Procedures from VL

Post by JamesDuignan »

Hi Hamad,

Yes this is possible to do in LANSA with PC Other Files by using SELECT_SQL Free Format.
The call to the stored procedure is done via the 'Using' parameter, which can either be a direct call to the database such as:

SELECT_SQL FIELDS(#EMPNUMBER #LASTNAME #FIRSTNAME ) FROM_FILES((EMPLOYEEDATA)) USING(DBO.FINDEMPLOYEES)
ADD_ENTRY TO_LIST(#EMPLOYEES)
ENDSELECT

Alternatively a Query can be built up and passed as a string to via the using parameter:

#SQLQUERY:= "DBO. FINDEMPLOYEESNAMED@NAME = '" + #Name + "'"
SELECT_SQL FIELDS(#EMPNUMBER #LASTNAME #FIRSTNAME ) FROM_FILES((EMPLOYEEDATA)) USING(#SQLQUERY)
ADD_ENTRY TO_LIST(#EMPLOYEES)
ENDSELECT

For more examples and considerations for using stored procedures from SELECT_SQL Free Format see the documentation here:
http://docs.lansa.com/14/EN/lansa015/co ... FREE_E_eg5
wizard
Posts: 10
Joined: Thu Aug 25, 2016 12:48 pm

Re: Running SQL Stored Procedures from VL

Post by wizard »

Hello.
How actually this going to work? Did this query need to be done in method routine in the web page where we want to display output or in srvroutine?
User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Re: Running SQL Stored Procedures from VL

Post by Stewart Marshall »

WebPages execute in the browser on the client device and have no access to the server other than by executing SRVRoutines.

This means that ALL database processing must execute on the server, in SRVRoutines coded in Server Modules.
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au
wizard
Posts: 10
Joined: Thu Aug 25, 2016 12:48 pm

Re: Running SQL Stored Procedures from VL

Post by wizard »

This use for one user input only. Correct me if I am wrong.

#SQLQUERY:= "DBO. FINDEMPLOYEESNAMED@NAME = '" + #Name + "'"
SELECT_SQL FIELDS(#EMPNUMBER #LASTNAME #FIRSTNAME ) FROM_FILES((EMPLOYEEDATA)) USING(#SQLQUERY)
ADD_ENTRY TO_LIST(#EMPLOYEES)
ENDSELECT

The #NAME is the user input.

What if I have multiple user input?
How the #SQLQUERY gonna be?
How the SELECT_SQL statement gonna be?

Regards.
Post Reply