informix ODBC存储过程始终返回不正确的相同值

时间:2013-08-30 15:14:30

标签: stored-procedures odbc informix

我在Informix中创建了一个简单的sp

create procedure test(arg1 int) returning  int;
if arg1 > 1 then return 10;
else return 0;
end if;
end procedure;

当直接调用Informix时,它按预期工作,但是当我使用ODBC从VB.NET调用它时,它总是返回1.

这是我的vb代码

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 个答案:

答案 0 :(得分:2)

我不使用VB.NET,但在JDBC中,您必须显示该函数需要带有? char的参数。因此,请尝试"{call test(?)}"而不是"{call test()}"

修改

我已经测试了你的函数重命名为test_so(),它适用于Jython的JDBC-ODBC桥。我还更改了调用字符串以检索结果。整个代码:

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')