summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLionel Elie Mamane <lionel@mamane.lu>2013-12-07 20:39:33 +0100
committerCaolán McNamara <caolanm@redhat.com>2013-12-09 19:52:22 +0000
commit962cdfb1370b983fbc7f463edfab1dad53b5a8e7 (patch)
tree2f48b8599e719243fe046dfefd31c1e96eefc22b
parent62b6a778ea2a2b5b4f164db284c5a2910586bfb7 (diff)
fdo#72267 boolean_test is subsumed by general case "foo IS [NOT] bar"
Change-Id: Ie9666b1c8878dd26593629b4b64d74b7448f98c1 Reviewed-on: https://gerrit.libreoffice.org/6974 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--connectivity/source/parse/sqlbison.y44
-rw-r--r--connectivity/source/parse/sqlnode.cxx45
-rw-r--r--dbaccess/source/ui/querydesign/QueryDesignView.cxx2
-rw-r--r--include/connectivity/sqlnode.hxx2
4 files changed, 52 insertions, 41 deletions
diff --git a/connectivity/source/parse/sqlbison.y b/connectivity/source/parse/sqlbison.y
index 8ff9b0c84faa..6e7b973985cc 100644
--- a/connectivity/source/parse/sqlbison.y
+++ b/connectivity/source/parse/sqlbison.y
@@ -222,7 +222,7 @@ using namespace connectivity;
%type <pParseNode> non_join_query_term non_join_query_primary simple_table
%type <pParseNode> table_value_const_list row_value_constructor row_value_const_list row_value_constructor_elem
%type <pParseNode> qualified_join value_exp query_term join_type outer_join_type join_condition boolean_term
-%type <pParseNode> boolean_factor truth_value boolean_test boolean_primary named_columns_join join_spec
+%type <pParseNode> boolean_factor boolean_primary named_columns_join join_spec
%type <pParseNode> cast_operand cast_target factor datetime_value_exp /*interval_value_exp*/ datetime_term datetime_factor
%type <pParseNode> datetime_primary datetime_value_fct time_zone time_zone_specifier /*interval_term*/ interval_qualifier
%type <pParseNode> start_field non_second_datetime_field end_field single_datetime_field extract_field datetime_field time_zone_field
@@ -1081,12 +1081,6 @@ opt_having_clause:
;
/* search conditions */
-truth_value:
- SQL_TOKEN_TRUE
- | SQL_TOKEN_FALSE
- | SQL_TOKEN_UNKNOWN
- | SQL_TOKEN_NULL
- ;
boolean_primary:
predicate
| '(' search_condition ')'
@@ -1130,20 +1124,9 @@ parenthesized_boolean_value_expression:
$$->append(newNode(")", SQL_NODE_PUNCTUATION));
}
;
-boolean_test:
- boolean_primary
- | boolean_primary SQL_TOKEN_IS sql_not truth_value
- {
- $$ = SQL_NEW_RULE;
- $$->append($1);
- $$->append($2);
- $$->append($3);
- $$->append($4);
- }
- ;
boolean_factor:
- boolean_test
- | SQL_TOKEN_NOT boolean_test
+ boolean_primary
+ | SQL_TOKEN_NOT boolean_primary
{ // boolean_factor: rule 1
$$ = SQL_NEW_RULE;
$$->append($1);
@@ -1171,12 +1154,12 @@ search_condition:
}
;
predicate:
- comparison_predicate
+ comparison_predicate %dprec 2
| between_predicate
| all_or_any_predicate
| existence_test
| unique_test
- | test_for_null
+ | test_for_null %dprec 1
| in_predicate
| like_predicate
;
@@ -1384,13 +1367,20 @@ opt_escape:
;
null_predicate_part_2:
- SQL_TOKEN_IS sql_not SQL_TOKEN_NULL
- {
+ SQL_TOKEN_IS sql_not SQL_TOKEN_NULL
+ {
$$ = SQL_NEW_RULE; // test_for_null: rule 1
$$->append($1);
$$->append($2);
$$->append($3);
- }
+ }
+ | SQL_TOKEN_IS sql_not SQL_TOKEN_UNKNOWN
+ {
+ $$ = SQL_NEW_RULE; // test_for_null: rule 1
+ $$->append($1);
+ $$->append($2);
+ $$->append($3);
+ }
;
test_for_null:
row_value_constructor null_predicate_part_2
@@ -3959,11 +3949,11 @@ when_operand_list:
;
when_operand:
row_value_constructor_elem
- | comparison_predicate_part_2
+ | comparison_predicate_part_2 %dprec 2
| between_predicate_part_2
| in_predicate_part_2
| character_like_predicate_part_2
- | null_predicate_part_2
+ | null_predicate_part_2 %dprec 1
;
searched_when_clause_list:
searched_when_clause
diff --git a/connectivity/source/parse/sqlnode.cxx b/connectivity/source/parse/sqlnode.cxx
index e818d3e87c28..35440180a84d 100644
--- a/connectivity/source/parse/sqlnode.cxx
+++ b/connectivity/source/parse/sqlnode.cxx
@@ -620,7 +620,6 @@ void OSQLParseNode::impl_parseNodeToString_throw(OUStringBuffer& rString, const
case unique_test:
case all_or_any_predicate:
case join_condition:
- case boolean_test:
case comparison_predicate_part_2:
case parenthesized_boolean_value_expression:
case other_like_predicate_part_2:
@@ -1385,6 +1384,7 @@ OSQLParser::OSQLParser(const ::com::sun::star::uno::Reference< ::com::sun::star:
{ OSQLParseNode::where_clause, "where_clause" },
{ OSQLParseNode::opt_where_clause, "opt_where_clause" },
{ OSQLParseNode::search_condition, "search_condition" },
+ { OSQLParseNode::comparison, "comparison" },
{ OSQLParseNode::comparison_predicate, "comparison_predicate" },
{ OSQLParseNode::between_predicate, "between_predicate" },
{ OSQLParseNode::like_predicate, "like_predicate" },
@@ -1432,7 +1432,6 @@ OSQLParser::OSQLParser(const ::com::sun::star::uno::Reference< ::com::sun::star:
{ OSQLParseNode::joined_table, "joined_table" },
{ OSQLParseNode::boolean_factor, "boolean_factor" },
{ OSQLParseNode::sql_not, "sql_not" },
- { OSQLParseNode::boolean_test, "boolean_test" },
{ OSQLParseNode::manipulative_statement, "manipulative_statement" },
{ OSQLParseNode::subquery, "subquery" },
{ OSQLParseNode::value_exp_commalist, "value_exp_commalist" },
@@ -1967,7 +1966,7 @@ void OSQLParseNode::negateSearchCondition(OSQLParseNode*& pSearchCondition, sal_
negateSearchCondition(pLeft,bNegate);
negateSearchCondition(pRight,bNegate);
}
- // SQL_TOKEN_NOT ( boolean_test )
+ // SQL_TOKEN_NOT ( boolean_primary )
else if (SQL_ISRULE(pSearchCondition,boolean_factor))
{
OSQLParseNode *pNot = pSearchCondition->removeAt((sal_uInt32)0);
@@ -1983,10 +1982,31 @@ void OSQLParseNode::negateSearchCondition(OSQLParseNode*& pSearchCondition, sal_
// row_value_constructor comparison any_all_some subquery
else if(bNegate && (SQL_ISRULE(pSearchCondition,comparison_predicate) || SQL_ISRULE(pSearchCondition,all_or_any_predicate)))
{
+ assert(pSearchCondition->count() == 3);
OSQLParseNode* pComparison = pSearchCondition->getChild(1);
OSQLParseNode* pNewComparison = NULL;
- switch(pComparison->getNodeType())
+ if(SQL_ISRULE(pComparison, comparison))
{
+ assert(pComparison->count() == 2 ||
+ pComparison->count() == 4);
+ assert(SQL_ISTOKEN(pComparison->getChild(0), IS));
+
+ OSQLParseNode* pNot = pComparison->getChild(1);
+ OSQLParseNode* pNotNot = NULL;
+ if(pNot->isRule()) // no NOT token (empty rule)
+ pNotNot = new OSQLParseNode(OUString("NOT"),SQL_NODE_KEYWORD,SQL_TOKEN_NOT);
+ else
+ {
+ assert(SQL_ISTOKEN(pNot,NOT));
+ pNotNot = new OSQLParseNode(OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::sql_not));
+ }
+ pComparison->replace(pNot, pNotNot);
+ delete pNot;
+ }
+ else
+ {
+ switch(pComparison->getNodeType())
+ {
case SQL_NODE_EQUAL:
pNewComparison = new OSQLParseNode(OUString("<>"),SQL_NODE_NOTEQUAL,SQL_NOTEQUAL);
break;
@@ -2008,29 +2028,30 @@ void OSQLParseNode::negateSearchCondition(OSQLParseNode*& pSearchCondition, sal_
default:
SAL_WARN( "connectivity.parse", "OSQLParseNode::negateSearchCondition: unexpected node type!" );
break;
+ }
}
pSearchCondition->replace(pComparison, pNewComparison);
delete pComparison;
}
- else if(bNegate && (SQL_ISRULE(pSearchCondition,test_for_null) || SQL_ISRULE(pSearchCondition,in_predicate) ||
- SQL_ISRULE(pSearchCondition,between_predicate) || SQL_ISRULE(pSearchCondition,boolean_test) ))
+ else if(bNegate && (SQL_ISRULE(pSearchCondition,test_for_null) ||
+ SQL_ISRULE(pSearchCondition,in_predicate) ||
+ SQL_ISRULE(pSearchCondition,between_predicate) ))
{
- OSQLParseNode* pPart2 = pSearchCondition;
- if ( !SQL_ISRULE(pSearchCondition,boolean_test) )
- pPart2 = pSearchCondition->getChild(1);
+ OSQLParseNode* pPart2 = pSearchCondition->getChild(1);
sal_uInt32 nNotPos = 0;
if ( SQL_ISRULE( pSearchCondition, test_for_null ) )
nNotPos = 1;
- else if ( SQL_ISRULE( pSearchCondition, boolean_test ) )
- nNotPos = 2;
OSQLParseNode* pNot = pPart2->getChild(nNotPos);
OSQLParseNode* pNotNot = NULL;
- if(pNot->isRule())
+ if(pNot->isRule()) // no NOT token (empty rule)
pNotNot = new OSQLParseNode(OUString("NOT"),SQL_NODE_KEYWORD,SQL_TOKEN_NOT);
else
+ {
+ assert(SQL_ISTOKEN(pNot,NOT));
pNotNot = new OSQLParseNode(OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::sql_not));
+ }
pPart2->replace(pNot, pNotNot);
delete pNot;
}
diff --git a/dbaccess/source/ui/querydesign/QueryDesignView.cxx b/dbaccess/source/ui/querydesign/QueryDesignView.cxx
index 678bd44314c6..fcf8732a4cb2 100644
--- a/dbaccess/source/ui/querydesign/QueryDesignView.cxx
+++ b/dbaccess/source/ui/querydesign/QueryDesignView.cxx
@@ -3345,6 +3345,7 @@ void OQueryDesignView::fillFunctionInfo( const ::connectivity::OSQLParseNode* p
case OSQLParseNode::op_column_commalist:
case OSQLParseNode::table_primary_as_range_column:
case OSQLParseNode::character_string_type:
+ case OSQLParseNode::comparison:
OSL_FAIL("Unexpected SQL RuleID");
break;
case OSQLParseNode::column:
@@ -3373,7 +3374,6 @@ void OQueryDesignView::fillFunctionInfo( const ::connectivity::OSQLParseNode* p
case OSQLParseNode::all_or_any_predicate:
case OSQLParseNode::join_condition:
case OSQLParseNode::boolean_factor:
- case OSQLParseNode::boolean_test:
case OSQLParseNode::comparison_predicate_part_2:
case OSQLParseNode::parenthesized_boolean_value_expression:
case OSQLParseNode::other_like_predicate_part_2:
diff --git a/include/connectivity/sqlnode.hxx b/include/connectivity/sqlnode.hxx
index cc9a26acf715..d1c4cf759b26 100644
--- a/include/connectivity/sqlnode.hxx
+++ b/include/connectivity/sqlnode.hxx
@@ -149,6 +149,7 @@ namespace connectivity
where_clause,
opt_where_clause,
search_condition,
+ comparison,
comparison_predicate,
between_predicate,
like_predicate,
@@ -196,7 +197,6 @@ namespace connectivity
joined_table,
boolean_factor,
sql_not,
- boolean_test,
manipulative_statement,
subquery,
value_exp_commalist,