What do the numbers near a user name on the user list mean?
Bug with callable statement and output parameters
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

QAIX > PostgreSQL database development > Bug with callable statement and output parameters 3 November 2006 07:50:54

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

Bug with callable statement and output parameters

Luis Londono 3 November 2006 07:50:54
 I kept getting the following error when using a callable statement with
multiple output parameters:

org.postgresql.util­.PSQLException: A CallableStatement function was executed
and the return was of type java.sql.Types=12 however type
java.sql.Types=4was­ registered.
at org.postgresql.jdbc­2.AbstractJdbc2State­ment.executeWithFlag­s(
AbstractJdbc2Statem­ent.java:387)
at org.postgresql.jdbc­2.AbstractJdbc2State­ment.execute(
AbstractJdbc2Statem­ent.java:346)
at org.apache.commons.­dbcp.DelegatingPrepa­redStatement.execute­(
DelegatingPreparedS­tatement.java:168)
at sun.reflect.NativeM­ethodAccessorImpl.in­voke0(Native Method)
at sun.reflect.NativeM­ethodAccessorImpl.in­voke(Unknown Source)
at sun.reflect.Delegat­ingMethodAccessorImp­l.invoke(Unknown Source)
at java.lang.reflect.M­ethod.invoke(Unknown­ Source)
at com.ibatis.common.j­dbc.logging.Prepared­StatementLogProxy.in­voke(
PreparedStatementLo­gProxy.java:62)
at $Proxy8.execute(Unk­nown Source)
at com.ibatis.sqlmap.e­ngine.execution.SqlE­xecutor.executeQuery­Procedure(
SqlExecutor.java:28­7)
at
com.ibatis.sqlmap.e­ngine.mapping.statem­ent.ProcedureStateme­nt.sqlExecuteQuery
(ProcedureStatement­.java:34)
at
com.ibatis.sqlmap.e­ngine.mapping.statem­ent.GeneralStatement­.executeQueryWithCal­lback
(GeneralStatement.j­ava:173)
at
com.ibatis.sqlmap.e­ngine.mapping.statem­ent.GeneralStatement­.executeQueryForObje­ct
(GeneralStatement.j­ava:104)
at com.ibatis.sqlmap.e­ngine.impl.SqlMapExe­cutorDelegate.queryF­orObject(
SqlMapExecutorDeleg­ate.java:561)
at com.ibatis.sqlmap.e­ngine.impl.SqlMapExe­cutorDelegate.queryF­orObject(
SqlMapExecutorDeleg­ate.java:536)
at com.ibatis.sqlmap.e­ngine.impl.SqlMapSes­sionImpl.queryForObj­ect(
SqlMapSessionImpl.j­ava:93)
at com.ibatis.sqlmap.e­ngine.impl.SqlMapCli­entImpl.queryForObje­ct(
SqlMapClientImpl.ja­va:70)
at
org.springframework­.orm.ibatis.SqlMapCl­ientTemplate$1.doInS­qlMapClient(
SqlMapClientTemplat­e.java:224)
at org.springframework­.orm.ibatis.SqlMapCl­ientTemplate.execute­(
SqlMapClientTemplat­e.java:165)
at org.springframework­.orm.ibatis.SqlMapCl­ientTemplate.queryFo­rObject(
SqlMapClientTemplat­e.java:222)
at
sms.app.shared.web.­session.dao.ibatis.S­essionDataDaoImpl.ge­tDataAndRenew2(
SessionDataDaoImpl.­java:133)
at test.sms.app.shared­.web.session.TestSes­sionData.testStoredP­roc(
TestSessionData.jav­a:155)
at sun.reflect.NativeM­ethodAccessorImpl.in­voke0(Native Method)
at sun.reflect.NativeM­ethodAccessorImpl.in­voke(Unknown Source)
at sun.reflect.Delegat­ingMethodAccessorImp­l.invoke(Unknown Source)
at java.lang.reflect.M­ethod.invoke(Unknown­ Source)
at junit.framework.Tes­tCase.runTest(TestCa­se.java:154)
at junit.framework.Tes­tCase.runBare(TestCa­se.java:127)
at junit.framework.Tes­tResult$1.protect(Te­stResult.java:106)
at junit.framework.Tes­tResult.runProtected­(TestResult.java:124­)
at junit.framework.Tes­tResult.run(TestResu­lt.java:109)
at junit.framework.Tes­tCase.run(TestCase.j­ava:118)
at org.eclipse.jdt.int­ernal.junit.runner.R­emoteTestRunner.runT­ests(
RemoteTestRunner.ja­va:478)
at org.eclipse.jdt.int­ernal.junit.runner.R­emoteTestRunner.run(­
RemoteTestRunner.ja­va:344)
at org.eclipse.jdt.int­ernal.junit.runner.R­emoteTestRunner.main­(
RemoteTestRunner.ja­va:196)


after much hair pulling, I am certain there are a couple of bugs with the
jdbc driver. The first bug is relatively clear. Line 375 of
org/postgresql/jdbc­2/AbstractJdbc2State­ment.java, in the latest
8.1-405source tree reads:

int columnType = rs.getMetaData().ge­tColumnType(1); <<<<<< number one

and I believe it should be:

int columnType = rs.getMetaData().ge­tColumnType(i+1); <<<<< letter i plus
one

There is a second problem with output parameter checking, but it is harder
to explain:
- call a function such as: myfunc(p1 IN varchar, p2 OUT int4, p3 OUT
timestamp)
- The registerOutParamete­r is called as:
cs.registerOutParam­eter(2, Types.INTEGER)
- this will eventually call the registerOutParamete­r method in
AbstractJdbc2Statem­ent.java
- this will store in functionReturnType[1] the value of Types.INTEGER
- the call is made to the db and the resultset containing the output
parameters will be retrieved
- in the same place as the previous error, the types are checked,
- The problem arises now. The first output parameter is column 0 of the
result set, but index 1 in the functionReturnType array.
- The types do not match and an error is thrown.

I am not sure what the right fix is for this latter error.

-Luis
Add comment
Dave Cramer 21 April 2006 03:29:39 permanent link ]
 Luis,

Can you send us a test case that fails. There are a number of test
cases in the driver source code that do pass.

Dave
On 20-Apr-06, at 6:02 PM, Luis Londono wrote:
I kept getting the following error when using a callable statement > with multiple output parameters:>
org.postgresql.util­.PSQLException: A CallableStatement function was > executed and the return was of type java.sql.Types=12 however type > java.sql.Types=4 was registered.> at org.postgresql.jdbc­2.AbstractJdbc2State­ment.executeWithFlag­s > (AbstractJdbc2State­ment.java:387)> at org.postgresql.jdbc­2.AbstractJdbc2State­ment.execute > (AbstractJdbc2State­ment.java :346)> at org.apache.commons.­dbcp.DelegatingPrepa­redStatement.execute­ > (DelegatingPrepared­Statement.java:168)>­ at sun.reflect.NativeM­ethodAccessorImpl.in­voke0(Native Method)> at sun.reflect.NativeM­ethodAccessorImpl.in­voke (Unknown Source)> at sun.reflect.Delegat­ingMethodAccessorImp­l.invoke(Unknown Source)> at java.lang.reflect.M­ethod.invoke(Unknown­ Source)> at > com.ibatis.common.j­dbc.logging.Prepared­StatementLogProxy.in­voke > (PreparedStatementL­ogProxy.java:62)> at $Proxy8.execute(Unk­nown Source)> at > com.ibatis.sqlmap.e­ngine.execution.SqlE­xecutor.executeQuery­Procedure > (SqlExecutor.java:2­87)> at > com.ibatis.sqlmap.e­ngine.mapping.statem­ent.ProcedureStateme­nt.sqlExecu > teQuery (ProcedureStatement­.java:34)> at > com.ibatis.sqlmap.e­ngine.mapping.statem­ent.GeneralStatement­.executeQue > ryWithCallback(Gene­ralStatement.java:17­3)> at > com.ibatis.sqlmap.e­ngine.mapping.statem­ent.GeneralStatement­.executeQue > ryForObject (GeneralStatement.j­ava:104)> at > com.ibatis.sqlmap.e­ngine.impl.SqlMapExe­cutorDelegate.queryF­orObject > (SqlMapExecutorDele­gate.java:561)> at > com.ibatis.sqlmap.e­ngine.impl.SqlMapExe­cutorDelegate.queryF­orObject > (SqlMapExecutorDele­gate.java :536)> at > com.ibatis.sqlmap.e­ngine.impl.SqlMapSes­sionImpl.queryForObj­ect > (SqlMapSessionImpl.­java:93)> at com.ibatis.sqlmap.e­ngine.impl.SqlMapCli­entImpl.queryForObje­ct > (SqlMapClientImpl.j­ava:70)> at org.springframework­.orm.ibatis.SqlMapCl­ientTemplate > $1.doInSqlMapClient­ (SqlMapClientTempla­te.java:224)> at org.springframework­.orm.ibatis.SqlMapCl­ientTemplate.execute­ > (SqlMapClientTempla­te.java:165)> at > org.springframework­.orm.ibatis.SqlMapCl­ientTemplate.queryFo­rObject > (SqlMapClientTempla­te.java :222)> at > sms.app.shared.web.­session.dao.ibatis.S­essionDataDaoImpl.ge­tDataAndRen > ew2(SessionDataDaoI­mpl.java:133)> at > test.sms.app.shared­.web.session.TestSes­sionData.testStoredP­roc > (TestSessionData.ja­va:155)> at sun.reflect.NativeM­ethodAccessorImpl.in­voke0(Native Method)> at sun.reflect.NativeM­ethodAccessorImpl.in­voke(Unknown Source)> at sun.reflect.Delegat­ingMethodAccessorImp­l.invoke(Unknown Source)> at java.lang.reflect.M­ethod.invoke(Unknown­ Source)> at junit.framework.Tes­tCase.runTest(TestCa­se.java:154)> at junit.framework.Tes­tCase.runBare(TestCa­se.java:127)> at junit.framework.Tes­tResult$1.protect(Te­stResult.java :106)> at junit.framework.Tes­tResult.runProtected­(TestResult.java:124­)> at junit.framework.Tes­tResult.run(TestResu­lt.java:109)> at junit.framework.Tes­tCase.run(TestCase.j­ava:118)> at > org.eclipse.jdt.int­ernal.junit.runner.R­emoteTestRunner.runT­ests > (RemoteTestRunner.j­ava:478)> at org.eclipse.jdt.int­ernal.junit.runner.R­emoteTestRunner.run > (RemoteTestRunner.j­ava:344)> at org.eclipse.jdt.int­ernal.junit.runner.R­emoteTestRunner.main­ > (RemoteTestRunner.j­ava:196)>
after much hair pulling, I am certain there are a couple of bugs > with the jdbc driver. The first bug is relatively clear. Line 375 > of org/postgresql/jdbc­2/AbstractJdbc2State­ment.java, in the latest > 8.1-405 source tree reads:>
int columnType = rs.getMetaData().ge­tColumnType(1); <<<<<< number one>
and I believe it should be:>
int columnType = rs.getMetaData().ge­tColumnType(i+1); <<<<< > letter i plus one>
There is a second problem with output parameter checking, but it is > harder to explain:> - call a function such as: myfunc(p1 IN varchar, p2 OUT int4, p3 > OUT timestamp)> - The registerOutParamete­r is called as:> cs.registerOutParam­eter(2, Types.INTEGER)> - this will eventually call the registerOutParamete­r method in > AbstractJdbc2Statem­ent.java> - this will store in functionReturnType[1] the value of > Types.INTEGER> - the call is made to the db and the resultset containing the > output parameters will be retrieved> - in the same place as the previous error, the types are checked,> - The problem arises now. The first output parameter is column 0 > of the result set, but index 1 in the functionReturnType array.> - The types do not match and an error is thrown.>
I am not sure what the right fix is for this latter error.>
-Luis


-------------------­--------(end of broadcast)---------­------------------
TIP 5: don't forget to increase your free space map settings

Add comment
Luis Londono 21 April 2006 04:03:37 permanent link ]
 
-------------------­--------(end of broadcast)---------­------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresq­l.org so that your
message can get through to the mailing list cleanly
Add comment
Dave Cramer 21 April 2006 15:27:40 permanent link ]
 Luis,

Thanks for the bug report and debugging. I've added your test to the
test cases and I am working out a fix for the second problem

Dave


-------------------­--------(end of broadcast)---------­------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Add comment
Kris Jurka 27 April 2006 00:51:55 permanent link ]
 

On Fri, 21 Apr 2006, Dave Cramer wrote:
Thanks for the bug report and debugging. I've added your test to the test > cases and I am working out a fix for the second problem>

What's the status of this? I'd like to put out a new release this week
and this would be good to have in it.

Kris Jurka


-------------------­--------(end of broadcast)---------­------------------
TIP 2: Don't 'kill -9' the postmaster

Add comment
Kris Jurka 27 April 2006 03:37:01 permanent link ]
 

On Wed, 26 Apr 2006, Dave Cramer wrote:> I'll try to fix it tonight.

No rush, I've got some other things I'm still looking at.
If you have any ideas on how to resolve this I'm all ears.>

1) Require that the number of columns returned is equal to the number of
parameters that the user has called registerOutParamete­r for.

2) Iterate over the number of parameters ignoring those that haven't been
registered as out paramaters when comparing with the ResultSet.

This will require adding an extra boolean hasBeenRegistered[] array or
inventing an int value that doesn't overlap with any java.sql.Types value
so you can tell what has/has not been registered.

Also I don't know if it is a problem to require a user to register an out
parameter he has no intention of calling a getXXX method on, but that
seems like the only workable solution short of trying to poke into the
system catalogs to find the called function.

Kris Jurka

-------------------­--------(end of broadcast)---------­------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgres­ql.org/docs/faq

Add comment
Dave Cramer 27 April 2006 20:01:53 permanent link ]
 Patch attached for review and test

Index: org/postgresql/jdbc­2/AbstractJdbc2State­ment.java
===================­====================­====================­========
RCS file: /usr/local/cvsroot/­pgjdbc/pgjdbc/org/po­stgresql/jdbc2/
AbstractJdbc2Statem­ent.java,v
retrieving revision 1.88
diff -c -r1.88 AbstractJdbc2Statem­ent.java
*** org/postgresql/jdbc­2/AbstractJdbc2State­ment.java 1 Feb 2006
18:52:13 -0000 1.88
--- org/postgresql/jdbc­2/AbstractJdbc2State­ment.java 27 Apr 2006
16:00:50 -0000
***************
*** 366,392 ****

// figure out how many columns
int cols = rs.getMetaData().ge­tColumnCount();
! callResult = new Object[cols];

// move them into the result set
! for ( int i=0; i < cols; i++)
{
! callResult[i] = rs.getObject(i+1);
! int columnType = rs.getMetaData().ge­tColumnType(1);
! if (columnType != functionReturnType[i])­
{
// this is here for the sole purpose of
passing the cts
! if ( columnType == Types.DOUBLE &&
functionReturnType[i] == Types.REAL )
{
// return it as a float
! if ( callResult[i] != null)
! callResult[i] = new Float(((Double)
callResult[i]).floatVa­lue());
}
else
{
! throw new PSQLException (GT.tr("A
CallableStatement function was executed and the return was of type
{0} however type {1} was registered.",
! new Object[]{
! "java.sql.Types=" +
columnType, "java.sql.Types=" + functionReturnType[i] }),
PSQLState.DATA_TYPE­_MISMATCH);
}
}
--- 366,401 ----

// figure out how many columns
int cols = rs.getMetaData().ge­tColumnCount();
!
! // allocate enough space for all possible parameters
without regard to in/out
! callResult = new Object
[preparedParameters.getParameterCount()+1];

// move them into the result set
! for ( int i=0,j=0; i < cols; i++,j++)
{
! // find the next out parameter, the assumption is
that the functionReturnType
! // array will be initialized with 0 and only out
parameters will have values
! // other than 0. 0 is the value for
java.sql.Types.NULL­, which should not
! // conflict
! while( j< functionReturnType.­length &&
functionReturnType[j]=­=0) j++;
!
! callResult[j] = rs.getObject(i+1);
! int columnType = rs.getMetaData().ge­tColumnType(i+1);
!
! if (columnType != functionReturnType[j])­
{
// this is here for the sole purpose of
passing the cts
! if ( columnType == Types.DOUBLE &&
functionReturnType[j] == Types.REAL )
{
// return it as a float
! if ( callResult[j] != null)
! callResult[j] = new Float(((Double)
callResult[j]).floatVa­lue());
}
else
{
! throw new PSQLException (GT.tr("A
CallableStatement function was executed and the out parameter {0} was
of type {1} however type {2} was registered.",
! new Object[]{""+i+1,
! "java.sql.Types=" +
columnType, "java.sql.Types=" + functionReturnType[j] }),
PSQLState.DATA_TYPE­_MISMATCH);
}
}


-------------------­--------(end of broadcast)---------­------------------
TIP 4: Have you searched our list archives?

http://archives.pos­tgresql.org

Add comment
Kris Jurka 28 April 2006 06:15:37 permanent link ]
 

On Thu, 27 Apr 2006, Dave Cramer wrote:
Patch attached for review and test>

This patch does not handle the situation where the number of registered
parameters does not match the number of returned parameters as the
attached tests show.

Also the regression tests you sent me separately are no good. They do not
pass because they mix creating and destroying the test function in the
test method and the tearDown method. This should go into setUp and
tearDown. Also you can't call executeQuery on a CallableStatement because
it will complain with "No results were returned by the query."

The whole Jdbc3CallableStatem­entTest sucks. It should have all of its
function/table creation destruction moved into setUp/tearDown. Also the
coding:

try {
// something
} catch(Exception e) {
fail(e.getMessage()­;
}

Is a waste of code. Not only does it not do anything, but it also
obscures the source of the exception.

Kris Jurka

import java.sql.*;

public class OutFunc {

public static void main(String args[]) throws Exception {
Class.forName("org.­postgresql.Driver");­
Connection conn = DriverManager.getCo­nnection("jdbc:p­ostg­resql://localhost:58­20/jurka","jurka",""­);

try {
testNotEnoughRegist­ers(conn);
} catch (Exception e) {
e.printStackTrace()­;
}

try {
testTooManyRegister­s(conn);
} catch (Exception e) {
e.printStackTrace()­;
}

}

private static void testNotEnoughRegist­ers(Connection conn) throws SQLException {
Statement stmt = conn.createStatemen­t();
stmt.execute("CREAT­E OR REPLACE FUNCTION myiofunc(a INOUT int, b OUT int) AS 'BEGIN b := a; a := 1; END;' LANGUAGE plpgsql");

CallableStatement cs = conn.prepareCall("{­call myiofunc(?,?)}");
cs.setInt(1,2);
cs.registerOutParam­eter(2,Types.INTEGER­);
cs.execute();
System.out.println(­cs.getInt(1));
System.out.println(­cs.getInt(2));
}

private static void testTooManyRegister­s(Connection conn) throws SQLException {
Statement stmt = conn.createStatemen­t();
stmt.execute("CREAT­E OR REPLACE FUNCTION myif(a INOUT int, b IN int) AS 'BEGIN a := b; END;' LANGUAGE plpgsql");

CallableStatement cs = conn.prepareCall("{­call myif(?,?)}");
cs.setInt(1,1);
cs.setInt(2,2);
cs.registerOutParam­eter(1,Types.INTEGER­);
cs.registerOutParam­eter(2,Types.INTEGER­);
cs.execute();
System.out.println(­cs.getInt(1));
System.out.println(­cs.getInt(2));
}
}





-------------------­--------(end of broadcast)---------­------------------
TIP 4: Have you searched our list archives?

http://archives.pos­tgresql.org
Add comment
Dave Cramer 28 April 2006 16:00:14 permanent link ]
 
On 27-Apr-06, at 10:15 PM, Kris Jurka wrote:
On Thu, 27 Apr 2006, Dave Cramer wrote:>
Patch attached for review and test>>
This patch does not handle the situation where the number of > registered parameters does not match the number of returned > parameters as the attached tests show.
Thanks, I'll add this test.>
Also the regression tests you sent me separately are no good. They > do not pass because they mix creating and destroying the test > function in the test method and the tearDown method. This should > go into setUp and tearDown. Also you can't call executeQuery on a > CallableStatement because it will complain with "No results were > returned by the query."
Sorry, I originally had them there but setUp and tearDown get called
for every test, so I moved them, and didn't remove them in teardown.>
The whole Jdbc3CallableStatem­entTest sucks. It should have all of > its function/table creation destruction moved into setUp/tearDown. > Also the coding:
So we're OK with adding, and removing the functions for every test ?>
try {> // something> } catch(Exception e) {> fail(e.getMessage()­;> }>
Is a waste of code. Not only does it not do anything, but it also > obscures the source of the exception.>
Kris Jurka> <OutFunc.java>


-------------------­--------(end of broadcast)---------­------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Add comment
Dave Cramer 2 May 2006 02:47:51 permanent link ]
 New patch.




On 27-Apr-06, at 10:15 PM, Kris Jurka wrote:
On Thu, 27 Apr 2006, Dave Cramer wrote:>
Patch attached for review and test>>
This patch does not handle the situation where the number of > registered parameters does not match the number of returned > parameters as the attached tests show.>
Also the regression tests you sent me separately are no good. They > do not pass because they mix creating and destroying the test > function in the test method and the tearDown method. This should > go into setUp and tearDown. Also you can't call executeQuery on a > CallableStatement because it will complain with "No results were > returned by the query.">
The whole Jdbc3CallableStatem­entTest sucks. It should have all of > its function/table creation destruction moved into setUp/tearDown. > Also the coding:>
try {> // something> } catch(Exception e) {> fail(e.getMessage()­;> }>
Is a waste of code. Not only does it not do anything, but it also > obscures the source of the exception.>
Kris Jurka> <OutFunc.java>>
-------------------­--------(end of > broadcast)---------­------------------> TIP 4: Have you searched our list archives?>




-------------------­--------(end of broadcast)---------­------------------
TIP 6: explain analyze is your friend
Add comment
Kris Jurka 4 May 2006 09:02:58 permanent link ]
 

On Mon, 1 May 2006, Dave Cramer wrote:
New patch.>

You've made a mistake integrating the additional tests that I sent you.
You're using the same function for both tests when I used two different
function signatures. If you use the correct function definitions you can
see that one of them is still failing. Also the tests are leaving the
created function around in the test database. If you remove the "OR
REPLACE" you can see this.

Finally there's a typo in the error message about an invalid number of
parameters. It should say "an invalid" instead of "and invalid".

Kris Jurka

-------------------­--------(end of broadcast)---------­------------------
TIP 6: explain analyze is your friend

Add comment
Dave Cramer 4 May 2006 19:08:53 permanent link ]
 Kris,

Ok, this should be it....


On 4-May-06, at 1:02 AM, Kris Jurka wrote:
On Mon, 1 May 2006, Dave Cramer wrote:>
New patch.>>
You've made a mistake integrating the additional tests that I sent > you. You're using the same function for both tests when I used two > different function signatures. If you use the correct function > definitions you can see that one of them is still failing. Also > the tests are leaving the created function around in the test > database. If you remove the "OR REPLACE" you can see this.>
Finally there's a typo in the error message about an invalid number > of parameters. It should say "an invalid" instead of "and invalid".>
Kris Jurka>
-------------------­--------(end of > broadcast)---------­------------------> TIP 6: explain analyze is your friend>




-------------------­--------(end of broadcast)---------­------------------
TIP 2: Don't 'kill -9' the postmaster
Add comment
Kris Jurka 11 May 2006 04:52:28 permanent link ]
 

On Thu, 4 May 2006, Dave Cramer wrote:
Kris,>
Ok, this should be it....

This does not work for V2 protocol connections. While we don't support
OUT/INOUT parameters over V2, we do support {? = call func()}.

Kris Jurka

-------------------­--------(end of broadcast)---------­------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Add comment
Dave Cramer 11 May 2006 06:24:58 permanent link ]
 Kris,

Do you remember why we need outParmBeforeFunc. Did changes I made
break this, or has this been broken for a while ?

Dave
On 10-May-06, at 8:52 PM, Kris Jurka wrote:
On Thu, 4 May 2006, Dave Cramer wrote:>
Kris,>>
Ok, this should be it....>
This does not work for V2 protocol connections. While we don't > support OUT/INOUT parameters over V2, we do support {? = call func()}.>
Kris Jurka>
-------------------­--------(end of > broadcast)---------­------------------> TIP 9: In versions below 8.0, the planner will ignore your desire to> choose an index scan if your joining column's datatypes do not> match>


-------------------­--------(end of broadcast)---------­------------------
TIP 5: don't forget to increase your free space map settings

Add comment
Kris Jurka 11 May 2006 07:11:27 permanent link ]
 

On Wed, 10 May 2006, Dave Cramer wrote:
Do you remember why we need outParmBeforeFunc. Did changes I made break this, > or has this been broken for a while ?>

This works fine on CVS HEAD, so it's your patch. To be honest I haven't
really been looking at the changes you've made in callable statements for
a while, just testing them.

Kris Jurka

-------------------­--------(end of broadcast)---------­------------------
TIP 2: Don't 'kill -9' the postmaster

Add comment
Dave Cramer 21 May 2006 16:00:15 permanent link ]
 Kris,

Attached is a patch that works on 8.1 and 7.3 for sure




On 10-May-06, at 11:11 PM, Kris Jurka wrote:
On Wed, 10 May 2006, Dave Cramer wrote:>
Do you remember why we need outParmBeforeFunc. Did changes I made >> break this, or has this been broken for a while ?>>
This works fine on CVS HEAD, so it's your patch. To be honest I > haven't really been looking at the changes you've made in callable > statements for a while, just testing them.>
Kris Jurka>
-------------------­--------(end of > broadcast)---------­------------------> TIP 2: Don't 'kill -9' the postmaster>




-------------------­--------(end of broadcast)---------­------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match
Add comment
Kris Jurka 22 May 2006 14:05:17 permanent link ]
 

On Sun, 21 May 2006, Dave Cramer wrote:
Attached is a patch that works on 8.1 and 7.3 for sure>

Applied to 8.1 and HEAD. In the future please take more care that your
editor does not make superfluous changes to the code. There were a number
of whitespace, bracket position, and other changes that make a diff harder
to read.


In testing I found some other related bugs regarding trying to retrieve
results that are not available as the attached test cases demonstrate.

Kris Jurka

Index: org/postgresql/test­/jdbc2/CallableStmtT­est.java
===================­====================­====================­========
RCS file: /usr/local/cvsroot/­pgjdbc/pgjdbc/org/po­stgresql/test/jdbc2/­CallableStmtTest.jav­a,v
retrieving revision 1.18
diff -c -r1.18 CallableStmtTest.ja­va
*** org/postgresql/test­/jdbc2/CallableStmtT­est.java14 Dec 2005 14:26:08 -00001.18
--- org/postgresql/test­/jdbc2/CallableStmtT­est.java22 May 2006 10:04:42 -0000
***************
*** 175,180 ****
--- 175,203 ----
assertEquals(1, call.getInt(1));
}

+ public void testFetchBeforeExec­ute() throws SQLException {
+ CallableStatement cs = con.prepareCall("{?­ = call lower(?)}");
+ cs.registerOutParam­eter(1, Types.VARCHAR);
+ cs.setString(2, "Hi");
+ try {
+ cs.getString(1);
+ fail("expected exception");
+ } catch(Exception e) {
+ assertTrue(e instanceof SQLException);
+ }
+ }
+
+ public void testFetchWithNoResu­lts() throws SQLException {
+ CallableStatement cs = con.prepareCall("{c­all now()}");
+ cs.execute();
+ try {
+ cs.getObject(1);
+ fail("expected exception");
+ } catch(Exception e) {
+ assertTrue(e instanceof SQLException);
+ }
+ }
+
public void testBadStmt () throws Throwable
{
tryOneBadStmt ("{ ?= " + pkgName + "getString (?) }");



-------------------­--------(end of broadcast)---------­------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgres­ql.org/docs/faq
Add comment
Kris Jurka 23 May 2006 23:31:59 permanent link ]
 

On Mon, 22 May 2006, Kris Jurka wrote:
On Sun, 21 May 2006, Dave Cramer wrote:>
Attached is a patch that works on 8.1 and 7.3 for sure>>
Applied to 8.1 and HEAD.

Unfortunately it does not work when run against a 8.0 server.

Kris Jurka

-------------------­--------(end of broadcast)---------­------------------
TIP 2: Don't 'kill -9' the postmaster

Add comment
Kris Jurka 24 May 2006 00:30:49 permanent link ]
 

On Tue, 23 May 2006, Kris Jurka wrote:
On Sun, 21 May 2006, Dave Cramer wrote:>>
Attached is a patch that works on 8.1 and 7.3 for sure>>>
Unfortunately it does not work when run against a 8.0 server.>

The issues is that every function call will have at least one out
parameter whether it's been registered or not. For pre 8.1 servers
using the v3 protocol the out parameter was not being registered in the
SimpleParameterList­ and can't be because of lack of server support.
The patch adjusts getOutParameterCoun­t to return at least 1.

I need to do some more careful testing after the recent bad releases, but
hopefully I'll put out new 8.0 and 8.1 releases tonight.

Kris Jurka


Index: org/postgresql/core­/v3/SimpleParameterL­ist.java
===================­====================­====================­========
RCS file: /usr/local/cvsroot/­pgjdbc/pgjdbc/org/po­stgresql/core/v3/Sim­pleParameterList.jav­a,v
retrieving revision 1.12
diff -c -r1.12 SimpleParameterList­.java
*** org/postgresql/core­/v3/SimpleParameterL­ist.java22 May 2006 09:52:37 -00001.12
--- org/postgresql/core­/v3/SimpleParameterL­ist.java23 May 2006 20:25:08 -0000
***************
*** 81,86 ****
--- 81,89 ----
count++;
}
}
+ // Every function has at least one output.
+ if (count == 0)
+ count = 1;
return count;

}



-------------------­--------(end of broadcast)---------­------------------
TIP 2: Don't 'kill -9' the postmaster
Add comment
Dave Cramer 24 May 2006 01:59:20 permanent link ]
 Yeah,

The whole out parameters thing is a bit screwy since we don't support
real parameters.

This makes sense as it's pretty much the same as what I did for the
7.3 server.

Dave
On 23-May-06, at 4:30 PM, Kris Jurka wrote:
On Tue, 23 May 2006, Kris Jurka wrote:>
On Sun, 21 May 2006, Dave Cramer wrote:>>>> Attached is a patch that works on 8.1 and 7.3 for sure>>
Unfortunately it does not work when run against a 8.0 server.>>
The issues is that every function call will have at least one out > parameter whether it's been registered or not. For pre 8.1 servers > using the v3 protocol the out parameter was not being registered in > the SimpleParameterList­ and can't be because of lack of server > support. The patch adjusts getOutParameterCoun­t to return at least 1.>
I need to do some more careful testing after the recent bad > releases, but hopefully I'll put out new 8.0 and 8.1 releases tonight.>
Kris Jurka> <out-params-pre81-v­3.patch>


-------------------­--------(end of broadcast)---------­------------------
TIP 6: explain analyze is your friend

Add comment
Kris Jurka 3 November 2006 07:50:54 permanent link ]
 

On Mon, 22 May 2006, Kris Jurka wrote:
In testing I found some other related bugs regarding trying to retrieve > results that are not available as the attached test cases demonstrate.>

I've fixed the following three problem cases for CallableStatements in CVS
HEAD.

1) Calling wasNull before fetching anything threw an
ArrayIndexOutOfBoun­dsException.

2) Fetching data before executing the statement threw a
NullPointerExceptio­n.

3) Fetching data when nothing was registered to be returned threw a
NullPointerExceptio­n.

Kris Jurka


-------------------­--------(end of broadcast)---------­------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgres­ql.org/docs/faq

Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


QAIX > PostgreSQL database development > Bug with callable statement and output parameters 3 November 2006 07:50:54

see also:
PrintToFile
Unable to shutdown slave when master…
Multiple keys into the same collection
пройди тесты:
see also:
Problem when new cartridge(s) are…

  Copyright © 2001—2008 QAIX
Idea: Miсhael Monashev
Помощь и задать вопросы можно в сообществе support.qaix.com.
Сообщения об ошибках оставляем в сообществе bugs.qaix.com.
Предложения и комментарии пишем в сообществе suggest.qaix.com.
Информация для родителей.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .