Skip to content

Commit

Permalink
support for bool columns
Browse files Browse the repository at this point in the history
  • Loading branch information
cyga committed Dec 2, 2012
1 parent 358fd3d commit 2592e4b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 37 deletions.
107 changes: 74 additions & 33 deletions src/www_fdw.c
Expand Up @@ -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;
Expand Down
13 changes: 9 additions & 4 deletions test/test-default-xml.sh
Expand Up @@ -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"`
Expand Down

0 comments on commit 2592e4b

Please sign in to comment.