Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support for bool columns

  • Loading branch information...
commit 2592e4b3cb69040c3d0238d2ff927b40773748a6 1 parent 358fd3d
@cyga authored
Showing with 83 additions and 37 deletions.
  1. +74 −33 src/www_fdw.c
  2. +9 −4 test/test-default-xml.sh
View
107 src/www_fdw.c
@@ -393,43 +393,84 @@ www_param(Node *node, TupleDesc tupdesc)
if (node == NULL)
return NULL;
-/* TODO add support for bool operators, they look like:
- * col=false
+ if (
+ /* col=false
+ :qual (
+ {BOOLEXPR
+ :boolop not
+ :args (
+ {VAR
+ :varno 1
+ :varattno 2
+ :vartype 16
+ :vartypmod -1
+ :varcollid 0
+ :varlevelsup 0
+ :varnoold 1
+ :varoattno 2
+ :location 33
+ }
+ )
+ :location -1
+ }
+ )
+ */
+ IsA(node, BoolExpr)
+ ) {
+ BoolExpr *op = (BoolExpr*)node;
+ if(
+ NOT_EXPR == op->boolop
+ &&
+ 1 == list_length(op->args)
+ ) {
+ Node *arg = list_nth(op->args, 0);
+ if( IsA(arg, Var) ) {
+ char *key;
+ StringInfoData buf;
+ Index varattno = ((Var *) arg)->varattno;
+ Assert(0 < varattno && varattno <= tupdesc->natts);
+ key = NameStr(tupdesc->attrs[varattno - 1]->attname);
+
+ initStringInfo(&buf);
+ appendStringInfo(&buf, "%s=%s", percent_encode((unsigned char *) key, -1),
+ percent_encode((unsigned char*)"false", -1));
+ return buf.data;
+ }
+ else {
+ ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("NOT operator with not a var detected")));
+ }
+ }
+ }
+ else if (
+ /* col=true
:qual (
- {BOOLEXPR
- :boolop not
- :args (
- {VAR
- :varno 1
- :varattno 2
- :vartype 16
- :vartypmod -1
- :varcollid 0
- :varlevelsup 0
- :varnoold 1
- :varoattno 2
- :location 33
- }
- )
- :location -1
- }
- )
- * col=true
- :qual (
- {VAR
- :varno 1
- :varattno 2
- :vartype 16
- :vartypmod -1
- :varcollid 0
- :varlevelsup 0
- :varnoold 1
- :varoattno 2
+ {VAR
+ :varno 1
+ :varattno 2
+ :vartype 16
+ :vartypmod -1
+ :varcollid 0
+ :varlevelsup 0
+ :varnoold 1
+ :varoattno 2
:location 33
}
)
- */
- if (IsA(node, OpExpr))
+ */
+ IsA(node, Var)
+ ) {
+ char *key;
+ StringInfoData buf;
+ Index varattno = ((Var *) node)->varattno;
+ Assert(0 < varattno && varattno <= tupdesc->natts);
+ key = NameStr(tupdesc->attrs[varattno - 1]->attname);
+
+ initStringInfo(&buf);
+ appendStringInfo(&buf, "%s=%s", percent_encode((unsigned char *) key, -1),
+ percent_encode((unsigned char*)"true", -1));
+ return buf.data;
+ }
+ else if (IsA(node, OpExpr))
{
OpExpr *op = (OpExpr *) node;
Node *left, *right, *tmp;
View
13 test/test-default-xml.sh
@@ -75,10 +75,15 @@ sql="select id from www_fdw_test where id=12 limit 1"
r=`$psql -tA -c"$sql"`
test "$r" $'12' "$sql"
-# TODO not implemented yet
-# sql="select b from www_fdw_test where b=true limit 1"
-# r=`$psql -tA -c"$sql"`
-# test "$r" $'true' "$sql"
+sql="select b from www_fdw_test where b=true limit 1"
+r=`$psql -tA -c"$sql"`
+test "$r" $'t' "$sql"
+
+# server doesn't really filter
+# we check ability to parse tree strucure in psql
+sql="select b from www_fdw_test where b=false limit 1"
+r=`$psql -tA -c"$sql"`
+test "$r" $'t' "$sql"
sql="select d from www_fdw_test where d='2012-11-20' limit 1"
r=`$psql -tA -c"$sql"`
Please sign in to comment.
Something went wrong with that request. Please try again.