wrong return values parameters
wrong return values parameters
Hello,
When I call an Oracle stored procured with in/output paramters (strings) I get the wrong return-values.
I created a simple test:
Oracle stored procedure:
FUNCTION test(param1_iopar IN OUT VARCHAR2, param2_opar OUT VARCHAR2)
RETURN VARCHAR2 IS
BEGIN
param1_iopar := 'Tekst 1e parameter';
param2_opar := 'Tekst 2e parameter';
return 'return functie tekst';
END;
I call this procedure from VS2008:
String param1_iopar = "Init";
string param2_opar;
try
{
string proc = DS.TEST(ref param1_iopar, out param2_opar);
MessageBox.Show("proc: " + proc + "\nparam1_iopar: " + param1_iopar + "\nparam2_opar: " + param2_opar);
In the message box I see the values:
proc: return functie tekst
param1_iopar: return functie tekst
param2_opar: Tekst 1e parameter
This is not what I expect and want to see.
in my output-window I can see the next statement send to Oracle:
BEGIN
:res:=UPLUS.P_INSK.TEST(:p0, :p1);
END;
-- res: ReturnValue VarChar (Size = 0; DbType = String) []
-- p0: InputOutput VarChar (Size = 4; DbType = String) [Init]
-- p1: Output VarChar (Size = 0; DbType = String) []
-- Context: Devart.Data.Oracle.Linq.Provider.OracleDataProvider Model: am Build: 1.20.40.0
What is the problem???
Thank you [/code]
When I call an Oracle stored procured with in/output paramters (strings) I get the wrong return-values.
I created a simple test:
Oracle stored procedure:
FUNCTION test(param1_iopar IN OUT VARCHAR2, param2_opar OUT VARCHAR2)
RETURN VARCHAR2 IS
BEGIN
param1_iopar := 'Tekst 1e parameter';
param2_opar := 'Tekst 2e parameter';
return 'return functie tekst';
END;
I call this procedure from VS2008:
String param1_iopar = "Init";
string param2_opar;
try
{
string proc = DS.TEST(ref param1_iopar, out param2_opar);
MessageBox.Show("proc: " + proc + "\nparam1_iopar: " + param1_iopar + "\nparam2_opar: " + param2_opar);
In the message box I see the values:
proc: return functie tekst
param1_iopar: return functie tekst
param2_opar: Tekst 1e parameter
This is not what I expect and want to see.
in my output-window I can see the next statement send to Oracle:
BEGIN
:res:=UPLUS.P_INSK.TEST(:p0, :p1);
END;
-- res: ReturnValue VarChar (Size = 0; DbType = String) []
-- p0: InputOutput VarChar (Size = 4; DbType = String) [Init]
-- p1: Output VarChar (Size = 0; DbType = String) []
-- Context: Devart.Data.Oracle.Linq.Provider.OracleDataProvider Model: am Build: 1.20.40.0
What is the problem???
Thank you [/code]
hello Andrey,
The problem is in the template.
When I have the FUNCTION TEST() as described above (with a return-value) the template generates the code:
When I change de function in Oracle and make a PROCEDURE TEST() (no return-value) the template generates the code:
This works fine!
As I see it, the return-value from the function is Parameter(0)
((string)(result.GetParameterValue(0)));
The other parameters should start from 1:
PARAM1_IOPAR = ((string)(result.GetParameterValue(1)));
PARAM2_OPAR = ((string)(result.GetParameterValue(2)));
Can you change the template please?
Thank you
The problem is in the template.
When I have the FUNCTION TEST() as described above (with a return-value) the template generates the code:
Code: Select all
[Function(Name=@"UPLUS.P_INSK.TEST", IsComposable=true)]
public System.String TEST([Parameter(Name="PARAM1_IOPAR", DbType="VARCHAR2")] ref string PARAM1_IOPAR, [Parameter(Name="PARAM2_OPAR", DbType="VARCHAR2")] out string PARAM2_OPAR)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), PARAM1_IOPAR, null);
PARAM1_IOPAR = ((string)(result.GetParameterValue(0)));
PARAM2_OPAR = ((string)(result.GetParameterValue(1)));
return ((System.String)(result.ReturnValue));
}
Code: Select all
[Function(Name=@"UPLUS.P_INSK.TEST")]
public System.Int32 TEST([Parameter(Name="PARAM1_IOPAR", DbType="VARCHAR2")] ref string PARAM1_IOPAR, [Parameter(Name="PARAM2_OPAR", DbType="VARCHAR2")] out string PARAM2_OPAR)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), PARAM1_IOPAR, null);
PARAM1_IOPAR = ((string)(result.GetParameterValue(0)));
PARAM2_OPAR = ((string)(result.GetParameterValue(1)));
return ((System.Int32)(result.ReturnValue));
}
As I see it, the return-value from the function is Parameter(0)
((string)(result.GetParameterValue(0)));
The other parameters should start from 1:
PARAM1_IOPAR = ((string)(result.GetParameterValue(1)));
PARAM2_OPAR = ((string)(result.GetParameterValue(2)));
Can you change the template please?
Thank you
As a temporary workaround you can simply change the generated code manually.
You just need to increment the parameter indexes (it is asociated with the fact that Oracle stored function returns the return value as a first element in the output parameters list):
should be replaced by
You just need to increment the parameter indexes (it is asociated with the fact that Oracle stored function returns the return value as a first element in the output parameters list):
Code: Select all
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), Param1Iopar, null);
Param1Iopar = ((string)(result.GetParameterValue(0)));
Param2Opar = ((string)(result.GetParameterValue(1)));
return ((System.String)(result.ReturnValue));
Code: Select all
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), Param1Iopar, null);
Param1Iopar = ((string)(result.GetParameterValue(1)));
Param2Opar = ((string)(result.GetParameterValue(2)));
return ((System.String)(result.ReturnValue));
Just add the following line after the int count = 0 line in the GenerateContextMethods method:
I will let you know as soon as this problem is fixed.
Code: Select all
if (method.MethodType == MethodType.ScalarResult)
count = 1;
Hello,
We just upgraded our Devart products (Devart dotConnect for Oracle 6.60.258.0; Devart Entity Developer 4.2.85.0 ).
I use (the new) template "Linqconnect" to create my entities.
I noticed that you changed the parameter-count, as you suggested in this post to start with 1;
But now it seems to me that this value should be 0;
Is it possible that Oracle also changed something in the return-parameter, so that it is no longer the first parameter?
So in the template the parameter-count should actually start with 0 in case of a call to an Oracle function? Or is there something else I should do?
Thank You,
We just upgraded our Devart products (Devart dotConnect for Oracle 6.60.258.0; Devart Entity Developer 4.2.85.0 ).
I use (the new) template "Linqconnect" to create my entities.
I noticed that you changed the parameter-count, as you suggested in this post to start with 1;
But now it seems to me that this value should be 0;
Is it possible that Oracle also changed something in the return-parameter, so that it is no longer the first parameter?
So in the template the parameter-count should actually start with 0 in case of a call to an Oracle function? Or is there something else I should do?
Thank You,
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
The IExecuteResult interface (which is returned by the DataContext.ExecuteMethodCall method) provides the ReturnValue property and the GetParameterValue method. The first one retrieves the function return value, and the second returns the values of the output parameters. The indexes of these parameters should start from 0, and the initial index used in the code generated by the default LinqConnect template is 0 as well.
The corresponding code from the template is
You may observe some other behaviour, e.g., if you are using some custom template. In this case, please either select the default one or modify the custom one.
The corresponding code from the template is
Code: Select all
IExecuteResult _ = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())) 0 ? ", " + string.Join(", ", parametersNameList.ToArray()) : "" #>);
=
(()
(_.GetParameterValue( 0 ? parameter.ProcedurePosition - 1 : count #>)));