Permalink
Browse files

Fix some query rewriting cases.

  • Loading branch information...
1 parent 245afe8 commit 5bac118a8fc3c57430226eb63ba7deab17005b26 t-ishii committed Nov 13, 2009
Showing with 27 additions and 14 deletions.
  1. +19 −6 pool_timestamp.c
  2. +3 −3 test/timestamp/expected/insert.out
  3. +2 −2 test/timestamp/expected/misc.out
  4. +3 −3 test/timestamp/expected/update.out
View
25 pool_timestamp.c
@@ -1,6 +1,6 @@
/* -*-pgsql-c-*- */
/*
- * $Header: /cvsroot/pgpool/pgpool-II/pool_timestamp.c,v 1.2 2009/11/11 01:53:31 t-ishii Exp $
+ * $Header: /cvsroot/pgpool/pgpool-II/pool_timestamp.c,v 1.3 2009/11/13 23:35:38 t-ishii Exp $
*
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
@@ -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 */
View
6 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)
View
4 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))
View
6 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

0 comments on commit 5bac118

Please sign in to comment.