pgpool2.git / summary / log / commit / refs
commit 3c55eeeb482b903bbc3fc8825cd99349dee7b123
Author: Yugo Nagata <nagata@sraoss.co.jp>
Commit: Muhammad Usama <m.usama@gmail.com>
Date: Mon Mar 24 06:05:10 2014 +0000
Fix backend error of prepared statement including now() via JDBC in replication mode
With JDBC, when a prepared statement is executed more than PreparedThreshold times,
the statement is named, and pgpool rewrites now() to parameter in replication mode.
Hence, rewritten query has additonal parameter, so Bind message also should inclued
additional parameter format codes. However, when the number of original parameter was
one, pgpool didn't handle this. This caused a error like "incorrect binary data format
in bind parameter 2" on backend.
src/rewrite/pool_timestamp.c | 35 +++++++++++++++++++++++++++--------
1 file changed, 27 insertions(+), 8 deletions(-)
diff --git a/src/rewrite/pool_timestamp.c b/src/rewrite/pool_timestamp.c
index 8a3cf1b78..f1e81041c 100644
--- a/src/rewrite/pool_timestamp.c
+++ b/src/rewrite/pool_timestamp.c
@@ -750,7 +750,8 @@ bind_rewrite_timestamp(POOL_CONNECTION_POOL *backend,
int32 tmp4;
int i,
ts_len,
- copy_len;
+ copy_len,
+ num_org_params;
const char *copy_from;
char *ts,
*copy_to,
@@ -773,8 +774,11 @@ bind_rewrite_timestamp(POOL_CONNECTION_POOL *backend,
ts_len = strlen(ts);
- *len += (strlen(ts) + sizeof(int32)) * message->num_tsparams;
- new_msg = copy_to = (char *) malloc(*len + message->num_tsparams * sizeof(int16));
+ /* enlarge length for timestamp parameters */
+ *len += (ts_len + sizeof(int32)) * message->num_tsparams;
+ /* allocate extra memory for parameter formats */
+ num_org_params = message->query_context->num_original_params;
+ new_msg = copy_to = (char *) malloc(*len + sizeof(int16) * (message->num_tsparams + num_org_params));
copy_from = orig_msg;
/* portal_name */
@@ -792,12 +796,20 @@ bind_rewrite_timestamp(POOL_CONNECTION_POOL *backend,
copy_len = sizeof(int16);
tmp2 = num_formats = ntohs(tmp2);
- if (num_formats > 1)
+ if (num_formats >= 1)
{
- /* enlarge message length */
+ /* one means the specified format code is applied all original parameters */
+ if (num_formats == 1)
+ {
+ *len += (num_org_params - 1) * sizeof(int16);
+ tmp2 += num_org_params - 1;
+ }
+
+ /* enlarge message length for timestamp parameter's formats */
*len += message->num_tsparams * sizeof(int16);
tmp2 += message->num_tsparams;
}
+
tmp2 = htons(tmp2);
memcpy(copy_to, &tmp2, copy_len); /* copy number of format codes */
copy_to += copy_len; copy_from += copy_len;
@@ -807,10 +819,17 @@ bind_rewrite_timestamp(POOL_CONNECTION_POOL *backend,
memcpy(copy_to, copy_from, copy_len); /* copy format codes */
copy_to += copy_len; copy_from += copy_len;
- if (num_formats > 1)
+ if (num_formats >= 1)
{
- /* set format codes to zero(text) */
- memset(copy_to, 0, message->num_tsparams * 2);
+ /* copy the specified format code as numbers of original parameters */
+ if (num_formats == 1)
+ {
+ memcpy(copy_to, copy_from, (num_org_params - 1) * sizeof(int16));
+ copy_to += (num_org_params - 1) * sizeof(int16);
+ }
+
+ /* set additional format codes to zero(text) */
+ memset(copy_to, 0, message->num_tsparams * sizeof(int16));
copy_to += sizeof(int16) * message->num_tsparams;
}
[parent: 3d80e6ddff79]