postgres-async-driver
postgres-async-driver copied to clipboard
cannot use queryRows with prepared statement within a transaction
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)
This was probably the same issue as #34 and handled in #35
It is simple error, there are code on PgConnectionPool.ReleasingTransaction.queryRows(); {code:java} @Override public Observable<Row> 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)