问题
I have a simple sp created in Informix
create procedure test(arg1 int) returning int;
if arg1 > 1 then return 10;
else return 0;
end if;
end procedure;
It works as expected when called directly into Informix but when I call it from VB.NET using ODBC, it returns always 1.
Here's my vb code
Dim cmd As OdbcCommand = New OdbcCommand("{call test()}", conn)
With cmd
.CommandType = CommandType.StoredProcedure
.Parameters.AddWithValue("@arg1", 0)
End With
conn.Open()
Dim dt As DataTable = New System.Data.DataTable("resultTableFromDB")
Dim da As OdbcDataAdapter = New OdbcDataAdapter(cmd)
da.Fill(dt)
conn.Close()
回答1:
I do not use VB.NET but in JDBC you must show that function needs parameters with ?
char. So try "{call test(?)}"
instead of "{call test()}"
EDIT:
I have tested your function renamed to test_so()
and it works with JDBC-ODBC bridge from Jython. I also changed call string to retrieve result. Whole code:
import sys
import traceback
from java.sql import DriverManager, Types
from java.lang import Class
Class.forName("com.informix.jdbc.IfxDriver")
def test_call(proc, arg1, expected):
proc.registerOutParameter(1, Types.INTEGER)
proc.setInt(2, arg1);
rs = proc.executeQuery();
while (rs.next()):
r = rs.getInt(1)
ok = 'ok'
if r != expected:
ok = ' ERROR!!!'
print('%d: %s %s' % (arg1, r, ok))
def test(db_url, usr, passwd):
try:
print("\n\n%s\n--------------" % (db_url))
db = DriverManager.getConnection(db_url, usr, passwd)
proc = db.prepareCall("{ ? = call test_so(?) }");
test_call(proc, 0, 0)
test_call(proc, 1, 0)
test_call(proc, 2, 10)
test_call(proc, 10, 10)
test_call(proc, -1, 0)
test_call(proc, -10, 0)
db.close()
except:
print("there were errors!")
s = traceback.format_exc()
sys.stderr.write("%s\n" % (s))
test('jdbc:odbc:MY_SYSTEM_DSN', 'USER', 'PASSWD')
来源:https://stackoverflow.com/questions/18536285/informix-odbc-stored-procedure-always-return-incorrect-same-value