Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot use queryRows with prepared statement within a transaction #41

Open
janossuranyi opened this issue Dec 4, 2016 · 2 comments
Open

Comments

@janossuranyi
Copy link

Example:

    public void runTest() {
        final CountDownLatch trigger = new CountDownLatch(1);
        final String currentDate = new SimpleDateFormat("YYYY-MM-dd").format(new Date());
        out.println("currentDate: " + currentDate);
        db.begin().flatMap(tx -> tx.queryRows("select 1::int4 where current_date = $1", currentDate)
                .map(rs -> {

                    final int r = rs.getInt(0);
                    tx.commit();

                    return r;
                })
        ).doOnTerminate(() -> trigger.countDown())
                .subscribe(out::println, Throwable::printStackTrace);

        try {
            trigger.await();
        } catch (InterruptedException ie) {
        }

        try {
            Thread.sleep(1000);
        } catch (InterruptedException ie) {
        }

        System.exit(0);

    }

Throws an exception:

com.github.pgasync.SqlException: ERROR: SQLSTATE=42P02, MESSAGE=there is no parameter $1
at com.github.pgasync.impl.netty.NettyPgProtocolStream.toSqlException(NettyPgProtocolStream.java:223)
at com.github.pgasync.impl.netty.NettyPgProtocolStream.access$300(NettyPgProtocolStream.java:46)
at com.github.pgasync.impl.netty.NettyPgProtocolStream$1.onNext(NettyPgProtocolStream.java:197)
at com.github.pgasync.impl.netty.NettyPgProtocolStream$5.channelRead(NettyPgProtocolStream.java:304)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:334)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:326)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:334)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:326)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:280)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:396)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:248)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:334)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:326)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1320)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:334)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:905)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:123)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:563)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:504)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:418)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:390)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:145)
at java.lang.Thread.run(Thread.java:745)

@cretz
Copy link
Contributor

cretz commented Dec 7, 2016

This was probably the same issue as #34 and handled in #35

@arrow00710
Copy link

It is simple error, there are code on PgConnectionPool.ReleasingTransaction.queryRows();
{code:java}
@OverRide
public Observable queryRows(String sql, Object... params) {
if (released.get()) {
return Observable.error(new SqlException("Transaction is already completed"));
}
return transaction.queryRows(sql)
.doOnError(exception -> releaseConnection());
}
{code}
should:
return transaction.queryRows(sql, params)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants