Sybase IN和OUT参数 [英] Sybase IN and OUT parameters

查看:131
本文介绍了Sybase IN和OUT参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Sybase JDBC驱动程序如何处理带有混合的INOUT参数的存储过程非常着迷.看看这个简单的存储过程:

I'm going nuts about how the Sybase JDBC driver handles stored procedures with mixed IN and OUT parameters. Check out this simple stored procedure:

CREATE OR REPLACE PROCEDURE p (IN i1 INT, OUT o1 INT, IN i2 INT, OUT o2 INT)
BEGIN
    set o1 = i1;
    set o2 = i2;
END

这是我用JDBC调用的方式:

And here's how I'd call it with JDBC:

CallableStatement c = connection.prepareCall("{ call dba.p(?, ?, ?, ?) }");
c.setInt(1, 1);
c.setInt(3, 2);
c.registerOutParameter(2, Types.INTEGER);
c.registerOutParameter(4, Types.INTEGER);
c.execute();
System.out.println(c.getObject(2));
System.out.println(c.getObject(4));

但这会导致

1
null

这是怎么回事?这是JDBC驱动程序中一个非常严重的错误吗?还是我完全错过了某些东西?通过反复试验,我发现这是一种工作方式:

What's going on?? Is that a really wicked bug in the JDBC driver or am I completely missing something? By trial and error, I found this to be a way how it works:

c.setInt(1, 1);
c.setInt(2, 2);
c.registerOutParameter(3, Types.INTEGER);
c.registerOutParameter(4, Types.INTEGER);
c.execute();
System.out.println(c.getObject(3));
System.out.println(c.getObject(4));

现在的结果是

1
2

JDBC驱动程序是否秘密地重新排序INOUT参数?

Does the JDBC driver secretly re-order IN and OUT parameters??

我正在使用SQL Anywhere 12和jconn3.jar

I'm using SQL Anywhere 12 and jconn3.jar

推荐答案

看起来像驱动程序中的错误.

Looks like a bug in the driver.

我怀疑越野车司机希望参数按照顺序(即1,2,3,4)传递/注册.当您完成registerOut(2)时,该语句显然会忘记您做了set(3):-)

I suspect the buggy driver expects parameters to be passed/registered in the order (i.e. 1,2,3,4). When you do registerOut(2), the statement apparently forgets you did set(3) :-)

或者,也许所有的OUT应该在所有的IN之后完成.再说一次,这是驱动程序中的错误.

Or, may be, all OUT should be done after all IN. Then again, this is a bug in the driver.

更新

等等,您没有更改第二个变体的步骤吗?该结果没有任何意义.除非如您所说,否则驱动程序会重新排序.至少可以说,这是不寻常.

Wait, you didn't change the procedure for the second variant? That result doesn't make any sense. Unless, as you said, driver does reordering. Which is unusual, to say the least.

更新2

我已经反编译了驱动程序.它围绕参数进行了一些非常有趣的游戏,所有这些慢跑过程让我觉得它们在那里存在潜在的错误,但是到目前为止,我还没有清楚地看到它.

I have decompiled the driver. It does some pretty funny games around out parameters, and with all this joggling I feel they have a fair potential for a bug there, but so far I do not see it plainly.

我注意到的唯一一件有趣的事情是,显然,如果位置n的参数没有消失,驱动程序将向前扫描参数,直到找到该值为止.如果找不到值,则转到下一行:

The only funny thing I noticed is that apparently if the parameter at position n is not out, the driver will scan parameters forward until it will find the value; if value is not found, it goes to the next row:

  s.registerOutParameter(5,Types.INT);
  ...
  // no out value at position 4, it will go to 5 and get the value
  rs.getInteger(4);

更新3

在示例1中看到所有4个参数的输出可能会很有趣,即:

It may be interesting to see the output of all 4 parameters in example 1, i.e.:

CallableStatement c = connection.prepareCall("{ call dba.p(?, ?, ?, ?) }");
c.setInt(1, 1);
c.setInt(3, 2);
c.registerOutParameter(2, Types.INTEGER);
c.registerOutParameter(4, Types.INTEGER);
c.execute();
System.out.println(c.getObject(1));
System.out.println(c.getObject(2));
System.out.println(c.getObject(3));
System.out.println(c.getObject(4));

这篇关于Sybase IN和OUT参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆