pgpool2.git / summary / log / commit / refs

commit    0c93c0044ea4b2f94207a2fc2c108785b5350ca2
Author:   Tatsuo Ishii <ishii at sraoss.co.jp>
Date:     Fri Nov 13 23:35:38 2009 +0000

    Fix some query rewriting cases.


pool_timestamp.c | 23 ++++++++++++++++++----- test/timestamp/expected/insert.out | 6 +++--- test/timestamp/expected/misc.out | 4 ++-- test/timestamp/expected/update.out | 6 +++--- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/pool_timestamp.c b/pool_timestamp.c index 35bec6aae..1ffbe80e4 100644 --- a/pool_timestamp.c +++ b/pool_timestamp.c @@ -26,6 +26,7 @@ #include "pool.h" #include "pool_timestamp.h" #include "parser/parsenodes.h" +#include "parser/gramparse.h" #include "parser/pool_memory.h" #define Assert(x) @@ -154,7 +155,7 @@ isStringConst(Node *node, const char *str) a_const = (A_Const *) node; val = a_const->val; - if (val.type == T_String && strcmp(str, val.val.str) == 0) + if (val.type == T_String && val.val.str && strcmp(str, val.val.str) == 0) return true; return false; @@ -210,10 +211,12 @@ rewrite_timestamp_walker(Node *node, void *context) if (list_length(fcall->funcname) == 1 && strcmp("now", strVal(linitial(fcall->funcname))) == 0) { - extern List *SystemFuncName(char *name); + TypeCast *tc = makeNode(TypeCast); + tc->arg = makeTsExpr(ctx); + tc->typename = SystemTypeName("text"); fcall->funcname = SystemFuncName("timestamptz"); - fcall->args = list_make1(makeTsExpr(ctx)); + fcall->args = list_make1(tc); ctx->rewrite = true; } } @@ -626,6 +629,17 @@ rewrite_timestamp(POOL_CONNECTION_POOL *backend, Node *node, /* save to portal */ portal->num_tsparams = list_length(ctx.params); + + /* add param type */ + if (IsA(node, PrepareStmt)) + { + int i; + PrepareStmt *p_stmt = (PrepareStmt *) node; + + for (i = ctx.num_params; i <= portal->num_tsparams; i++) + p_stmt->argtypes = + lappend(p_stmt->argtypes, SystemTypeName("timestamptz")); + } } else { @@ -672,8 +686,7 @@ bind_rewrite_timestamp(POOL_CONNECTION_POOL *backend, Portal *portal, ts_len = strlen(ts); *len += (strlen(ts) + sizeof(int32)) * portal->num_tsparams; - /*sendlen = htonl(*len + 4);*/ - new_msg = copy_to = (char *) malloc(*len); /* XXX how to free */ + new_msg = copy_to = (char *) malloc(*len); copy_from = orig_msg; /* portal_name */ diff --git a/test/timestamp/expected/insert.out b/test/timestamp/expected/insert.out index 6c54a3852..a14368931 100644 --- a/test/timestamp/expected/insert.out +++ b/test/timestamp/expected/insert.out @@ -1,8 +1,8 @@ INSERT INTO "rel1" VALUES (DEFAULT,'2009-01-01 23:59:59.123456+09',DEFAULT,'2009-01-01 23:59:59.123456+09') INSERT INTO rel2 DEFAULT VALUES INSERT INTO rel2(c1) VALUES(1) -INSERT INTO "rel1" VALUES (1,"timestamptz"('2009-01-01 23:59:59.123456+09'),2,'2009-01-01 23:59:59.123456+09'::text::date) -INSERT INTO "rel1" VALUES (3,"timestamptz"('2009-01-01 23:59:59.123456+09'),4,'2009-01-01 23:59:59.123456+09'::text::timetz) +INSERT INTO "rel1" VALUES (1,"timestamptz"('2009-01-01 23:59:59.123456+09'::text),2,'2009-01-01 23:59:59.123456+09'::text::date) +INSERT INTO "rel1" VALUES (3,"timestamptz"('2009-01-01 23:59:59.123456+09'::text),4,'2009-01-01 23:59:59.123456+09'::text::timetz) INSERT INTO "rel1" VALUES (5,'2009-01-01 23:59:59.123456+09'::text::timestamptz(0),6,'2009-01-01 23:59:59.123456+09'::text::timetz(0)) INSERT INTO "rel1" VALUES (7,'2009-01-01 23:59:59.123456+09'::text::timestamp,8,'2009-01-01 23:59:59.123456+09'::text::time) INSERT INTO "rel1" VALUES (9,'2009-01-01 23:59:59.123456+09'::text::timestamp(0),10,'2009-01-01 23:59:59.123456+09'::text::time(0)) @@ -12,4 +12,4 @@ INSERT INTO "rel1"("c2", "c1", "c4") VALUES ('2000-1-1',1,'2009-01-01 23:59:59.1 INSERT INTO "rel1"("c2", "c1", "c4") VALUES ('2009-01-01 23:59:59.123456+09',2,'2009-01-01 23:59:59.123456+09') INSERT INTO "rel1"("c2", "c1", "c4") VALUES ('2009-01-01 23:59:59.123456+09',3,'2009-01-01 23:59:59.123456+09'), ('2009-01-01 23:59:59.123456+09',4,'2009-01-01 23:59:59.123456+09'), ('2009-1-1',5,'2009-01-01 23:59:59.123456+09') INSERT INTO rel1(c1, c2, c4) VALUES(1, '2009-1-1', '2009-2-2') -PREPARE "q" (int4) AS INSERT INTO "rel1"("c3", "c2", "c4") VALUES ($1,$2,$3) +PREPARE "q" (int4,timestamptz,timestamptz) AS INSERT INTO "rel1"("c3", "c2", "c4") VALUES ($1,$2,$3) diff --git a/test/timestamp/expected/misc.out b/test/timestamp/expected/misc.out index 98285e9f4..e1f9bf82b 100644 --- a/test/timestamp/expected/misc.out +++ b/test/timestamp/expected/misc.out @@ -1,3 +1,3 @@ DELETE FROM "rel1" WHERE ("c1"='2009-01-01 23:59:59.123456+09'::text::date ) -PREPARE "q" ("date") AS DELETE FROM "rel1" WHERE ( ("c1"=$1 ) AND ("c3"=$2::text::date )) -EXECUTE "q" ("timestamptz"('2009-01-01 23:59:59.123456+09')) +PREPARE "q" ("date",timestamptz) AS DELETE FROM "rel1" WHERE ( ("c1"=$1 ) AND ("c3"=$2::text::date )) +EXECUTE "q" ("timestamptz"('2009-01-01 23:59:59.123456+09'::text)) diff --git a/test/timestamp/expected/update.out b/test/timestamp/expected/update.out index 7d965501e..4d0011d59 100644 --- a/test/timestamp/expected/update.out +++ b/test/timestamp/expected/update.out @@ -1,6 +1,6 @@ UPDATE "rel1" SET "c1" = DEFAULT, "c2" = '2009-01-01 23:59:59.123456+09' UPDATE rel2 SET c1 = DEFAULT, c2 = DEFAULT -UPDATE "rel1" SET "c1" = "timestamptz"('2009-01-01 23:59:59.123456+09'), "c2" = '2009-01-01 23:59:59.123456+09'::text::date -UPDATE "rel1" SET "c3" = "timestamptz"('2009-01-01 23:59:59.123456+09'), "c4" = '2009-01-01 23:59:59.123456+09'::text::timetz +UPDATE "rel1" SET "c1" = "timestamptz"('2009-01-01 23:59:59.123456+09'::text), "c2" = '2009-01-01 23:59:59.123456+09'::text::date +UPDATE "rel1" SET "c3" = "timestamptz"('2009-01-01 23:59:59.123456+09'::text), "c4" = '2009-01-01 23:59:59.123456+09'::text::timetz UPDATE "rel1" SET "c1" = '2009-01-01 23:59:59.123456+09'::text::timestamp, "c2" = '2009-01-01 23:59:59.123456+09'::text::time -PREPARE "q" (int4) AS UPDATE "rel1" SET "c1" = $1, "c2" = $2::text::date +PREPARE "q" (int4,timestamptz) AS UPDATE "rel1" SET "c1" = $1, "c2" = $2::text::date [parent: ff39a5f03151]