Skip to main content
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:37 AM UTC

Uniface 9: Need help with Service Stored Procedures (SSPs)

Need help with Service Stored Procedures (SSPs)

Author: tomas.johansson@abilita.fi (tomas.johansson)

Hi, I'm struggling with an external stored procedure I'm trying to call from Uniface. If I run the stored procedure directly within Uniface using the sql command like so: sql "exec STR_TEST '%%name.test',''","mss" I do get value back in $result. However if I try to access the same stored procedure using Service Stored Procedures instead, using the following code: activate "TUSTRUDOK2".STR_TEST(in, out) then I do not receive any value in the out variable. One important thing to note is that in the stored procedure I'm inserting data into a table. If I modify the stored procedure to only perform a select statement I do not have any problems getting value back in the out variable of my SSP. Also note that even though I do not receive a return value the insert statement is still performed correctly. I'm working against Microsoft SQL Server and I'm currenlty using Uniface MSS driver U4.0. Here is the procedure not working with SSP: [spoiler] CREATE PROCEDURE [STR_TEST]   @name as varchar(50) AS BEGIN     declare @returnid table (id uniqueidentifier)     INSERT INTO tjtest(         name     )     output inserted.id into @returnid     VALUES(         @name     )     select 'Hello ' + @name + '! ID: ' + CONVERT(VARCHAR(50), r.id) from @returnid r END GO [/spoiler] And here's a slightly simplified version which do work with SSP: [spoiler]CREATE PROCEDURE [STR_TEST]   @name as varchar(50) AS BEGIN  select 'Hello ' + @name + '! ID: ' + CONVERT(VARCHAR(50), NEWID()) END GO[/spoiler] For completeness here's my test table to where I'm inserting data: [spoiler] CREATE TABLE tjtest(      [id] [uniqueidentifier] NULL,      [name] [varchar](50) NULL ) GO ALTER TABLE [tjtest] ADD CONSTRAINT [DF_tjtest_id]  DEFAULT (newsequentialid()) FOR [id] GO [/spoiler] So how can I configure the SSP to also return back the resulting value when I'm inserting data inside the stored procedure? And then to my second question, when calling a stored procedure that performs inserts I have to explicitly call commit in Uniface in order for the transaction to complete, is there a way to circumvent this and perform insert operations inside the stored procedure without Uniface interfering? Tomas

12 replies

Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:37 AM UTC

Need help with Service Stored Procedures (SSPs)

Author: tomas.johansson@abilita.fi (tomas.johansson)

Hi, I'm struggling with an external stored procedure I'm trying to call from Uniface. If I run the stored procedure directly within Uniface using the sql command like so: sql "exec STR_TEST '%%name.test',''","mss" I do get value back in $result. However if I try to access the same stored procedure using Service Stored Procedures instead, using the following code: activate "TUSTRUDOK2".STR_TEST(in, out) then I do not receive any value in the out variable. One important thing to note is that in the stored procedure I'm inserting data into a table. If I modify the stored procedure to only perform a select statement I do not have any problems getting value back in the out variable of my SSP. Also note that even though I do not receive a return value the insert statement is still performed correctly. I'm working against Microsoft SQL Server and I'm currenlty using Uniface MSS driver U4.0. Here is the procedure not working with SSP: [spoiler] CREATE PROCEDURE [STR_TEST]   @name as varchar(50) AS BEGIN     declare @returnid table (id uniqueidentifier)     INSERT INTO tjtest(         name     )     output inserted.id into @returnid     VALUES(         @name     )     select 'Hello ' + @name + '! ID: ' + CONVERT(VARCHAR(50), r.id) from @returnid r END GO [/spoiler] And here's a slightly simplified version which do work with SSP: [spoiler]CREATE PROCEDURE [STR_TEST]   @name as varchar(50) AS BEGIN  select 'Hello ' + @name + '! ID: ' + CONVERT(VARCHAR(50), NEWID()) END GO[/spoiler] For completeness here's my test table to where I'm inserting data: [spoiler] CREATE TABLE tjtest(      [id] [uniqueidentifier] NULL,      [name] [varchar](50) NULL ) GO ALTER TABLE [tjtest] ADD CONSTRAINT [DF_tjtest_id]  DEFAULT (newsequentialid()) FOR [id] GO [/spoiler] So how can I configure the SSP to also return back the resulting value when I'm inserting data inside the stored procedure? And then to my second question, when calling a stored procedure that performs inserts I have to explicitly call commit in Uniface in order for the transaction to complete, is there a way to circumvent this and perform insert operations inside the stored procedure without Uniface interfering? Tomas

Okay, setting either ANSI_WARNINGS or ARITHABORT to ON at the beginning of my procedure will cause Uniface to return $status = -150 but it still doesn't go into the catch block inside the procedure. So should I just be checking $status after activating my SSP and hope that if $status is equal to 0 everything *should* be okay? I must admit I do not feel very confident about relying on this statuscode rather than my own error logic inside the stored procedure.


Author: tomas.johansson (tomas.johansson@abilita.fi)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:37 AM UTC

Need help with Service Stored Procedures (SSPs)

Author: tomas.johansson@abilita.fi (tomas.johansson)

Hi, I'm struggling with an external stored procedure I'm trying to call from Uniface. If I run the stored procedure directly within Uniface using the sql command like so: sql "exec STR_TEST '%%name.test',''","mss" I do get value back in $result. However if I try to access the same stored procedure using Service Stored Procedures instead, using the following code: activate "TUSTRUDOK2".STR_TEST(in, out) then I do not receive any value in the out variable. One important thing to note is that in the stored procedure I'm inserting data into a table. If I modify the stored procedure to only perform a select statement I do not have any problems getting value back in the out variable of my SSP. Also note that even though I do not receive a return value the insert statement is still performed correctly. I'm working against Microsoft SQL Server and I'm currenlty using Uniface MSS driver U4.0. Here is the procedure not working with SSP: [spoiler] CREATE PROCEDURE [STR_TEST]   @name as varchar(50) AS BEGIN     declare @returnid table (id uniqueidentifier)     INSERT INTO tjtest(         name     )     output inserted.id into @returnid     VALUES(         @name     )     select 'Hello ' + @name + '! ID: ' + CONVERT(VARCHAR(50), r.id) from @returnid r END GO [/spoiler] And here's a slightly simplified version which do work with SSP: [spoiler]CREATE PROCEDURE [STR_TEST]   @name as varchar(50) AS BEGIN  select 'Hello ' + @name + '! ID: ' + CONVERT(VARCHAR(50), NEWID()) END GO[/spoiler] For completeness here's my test table to where I'm inserting data: [spoiler] CREATE TABLE tjtest(      [id] [uniqueidentifier] NULL,      [name] [varchar](50) NULL ) GO ALTER TABLE [tjtest] ADD CONSTRAINT [DF_tjtest_id]  DEFAULT (newsequentialid()) FOR [id] GO [/spoiler] So how can I configure the SSP to also return back the resulting value when I'm inserting data inside the stored procedure? And then to my second question, when calling a stored procedure that performs inserts I have to explicitly call commit in Uniface in order for the transaction to complete, is there a way to circumvent this and perform insert operations inside the stored procedure without Uniface interfering? Tomas

Potentially has

set ANSI_WARNINGS off
set ARITHABORT off

you  can test with 

select SESSIONPROPERTY('ARITHABORT')

You might find it better to use RAISERROR to generate your error to force the try/catch.  Iain


Author: Iain Sharp (i.sharp@pcisystems.co.uk)