[Libreoffice-commits] .: 10 commits - connectivity/inc connectivity/source dbaccess/source

Lionel Elie Mamane lmamane at kemper.freedesktop.org
Sun Oct 30 04:43:05 PDT 2011


 connectivity/inc/connectivity/sqlnode.hxx             |   34 -
 connectivity/source/parse/sqlbison.y                  |    8 
 connectivity/source/parse/sqlflex.l                   |    8 
 dbaccess/source/ui/querydesign/QueryDesignView.cxx    |  391 ++++++++++++++++--
 dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx |  157 +++----
 5 files changed, 467 insertions(+), 131 deletions(-)

New commits:
commit be1bc3c80a684e68743a020f64c2e665c11ea635
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Sat Oct 29 07:55:06 2011 +0200

    wrong logic in comment

diff --git a/connectivity/inc/connectivity/sqlnode.hxx b/connectivity/inc/connectivity/sqlnode.hxx
index 0abfdb2..9329702 100644
--- a/connectivity/inc/connectivity/sqlnode.hxx
+++ b/connectivity/inc/connectivity/sqlnode.hxx
@@ -315,7 +315,7 @@ namespace connectivity
 
                 Currently, there's only one condition how this method can fail: If it contains a nested
                 query which causes a cycle. E.g., consider a statement <code>SELECT * from "foo"</code>,
-                where <code>bar </code> is a query defined as <code>SELECT * FROM "bar"</code>, where
+                where <code>foo</code> is a query defined as <code>SELECT * FROM "bar"</code>, where
                 <code>bar</code> is defined as <code>SELECT * FROM "foo"</code>. This statement obviously
                 cannot be parsed to an executable statement.
 
commit 2cd03f687f349c6f0352eac72b2dec327d64d800
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Sat Oct 29 07:54:41 2011 +0200

    Typo/spelling in comment

diff --git a/connectivity/inc/connectivity/sqlnode.hxx b/connectivity/inc/connectivity/sqlnode.hxx
index 4fd6714..0abfdb2 100644
--- a/connectivity/inc/connectivity/sqlnode.hxx
+++ b/connectivity/inc/connectivity/sqlnode.hxx
@@ -289,7 +289,7 @@ namespace connectivity
         /** parses the node to a string which can be passed to a driver's connection for execution
 
             Any particles of the parse tree which represent application-level features - such
-            as queries appearing in the FROM part - are subsituted, so that the resulting statement can
+            as queries appearing in the FROM part - are substituted, so that the resulting statement can
             be executed at an SDBC-level connection.
 
             @param  _out_rString
commit 1f805926d825e06c859ad79954c4bc27a4467f85
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Sun Oct 30 12:35:22 2011 +0100

    fillFunctionInfo now also guesses the type of non-function call expressions

diff --git a/dbaccess/source/ui/querydesign/QueryDesignView.cxx b/dbaccess/source/ui/querydesign/QueryDesignView.cxx
index 44c2503..2b0fd2c 100644
--- a/dbaccess/source/ui/querydesign/QueryDesignView.cxx
+++ b/dbaccess/source/ui/querydesign/QueryDesignView.cxx
@@ -3204,40 +3204,385 @@ bool OQueryDesignView::initByParseIterator( ::dbtools::SQLExceptionInfo* _pError
     }
     return eErrorCode == eOk;
 }
+
+// Utility function for fillFunctionInfo
+namespace {
+    sal_Int32 char_datatype(const::connectivity::OSQLParseNode* pDataType, const unsigned int offset) {
+        int cnt = pDataType->count() - offset;
+        if ( cnt < 0 )
+        {
+            OSL_FAIL("internal error in decoding character datatype specification");
+            return DataType::VARCHAR;
+        }
+        else if ( cnt == 0 )
+        {
+            if ( offset == 0 )
+            {
+                // The datatype is the node itself
+                if ( SQL_ISTOKENOR2 (pDataType, CHARACTER, CHAR) )
+                    return DataType::CHAR;
+                else if ( SQL_ISTOKEN (pDataType, VARCHAR) )
+                    return DataType::VARCHAR;
+                else if ( SQL_ISTOKEN (pDataType, CLOB) )
+                    return DataType::CLOB;
+                else
+                {
+                    OSL_FAIL("unknown/unexpected token in decoding character datatype specification");
+                    return DataType::VARCHAR;
+                }
+            }
+            else
+            {
+                // No child left to read!
+                OSL_FAIL("incomplete datatype in decoding character datatype specification");
+                return DataType::VARCHAR;
+            }
+        }
+
+        if ( SQL_ISTOKEN(pDataType->getChild(offset), NATIONAL) )
+            return char_datatype(pDataType, offset+1);
+        else if ( SQL_ISTOKENOR3(pDataType->getChild(offset), CHARACTER, CHAR, NCHAR) )
+        {
+            if ( cnt > 2 && SQL_ISTOKEN(pDataType->getChild(offset+1), LARGE) && SQL_ISTOKEN(pDataType->getChild(offset+2), OBJECT) )
+                return DataType::CLOB;
+            else if ( cnt > 1 && SQL_ISTOKEN(pDataType->getChild(offset+1), VARYING) )
+                return DataType::VARCHAR;
+            else
+                return DataType::CHAR;
+        }
+        else if ( SQL_ISTOKEN (pDataType->getChild(offset), VARCHAR) )
+            return DataType::VARCHAR;
+        else if ( SQL_ISTOKENOR2 (pDataType->getChild(offset), CLOB, NCLOB) )
+            return DataType::CLOB;
+
+        OSL_FAIL("unrecognised character datatype");
+        return DataType::VARCHAR;
+    }
+}
+
 //------------------------------------------------------------------------------
+// Try to guess the type of an expression in simple cases.
+// Originally meant to be called only on a function call (hence the misnomer),
+// but now tries to do the best it can also in other cases.
+// Don't completely rely on fillFunctionInfo,
+// it won't look at the function's arguments to find the return type
+// (in particular, in the case of general_set_fct,
+//  the return type is the type of the argument;
+//  if that is (as is typical) a column reference,
+//  it is the type of the column).
+// TODO: There is similar "guess the expression's type" code in several places:
+//       SelectionBrowseBox.cxx: OSelectionBrowseBox::saveField
+//       QueryDesignView.cxx: InstallFields, GetOrderCriteria, GetGroupCriteria
+//       If possible, they should be factorised into this function
+//       (which should then be renamed...)
+
 void OQueryDesignView::fillFunctionInfo(  const ::connectivity::OSQLParseNode* pNode
                                         ,const ::rtl::OUString& sFunctionTerm
                                         ,OTableFieldDescRef& aInfo)
 {
-    // get the type out of the funtion name
+    // get the type of the expression, as far as easily possible
     OQueryController& rController = static_cast<OQueryController&>(getController());
     sal_Int32 nDataType = DataType::DOUBLE;
     ::rtl::OUString sFieldName = sFunctionTerm;
-    const OSQLParseNode* pFunctionName;
-    // Fix fdo#38286 : crash when constant in the query
-    // TODO : is it possible to have a child or children in the pNode ?
-    // if not this part could be simplified
-    if (pNode->count()) 
-    {
-        pFunctionName = pNode->getChild(0);
-    }
-    else
-    {
-        pFunctionName = pNode;
-    }
-    if ( !SQL_ISPUNCTUATION(pFunctionName,"{") )
-    {
-        if ( SQL_ISRULEOR2(pNode,length_exp,char_value_fct) )
-            pFunctionName = pFunctionName->getChild(0);
+    switch(pNode->getNodeType())
+    {
+    case SQL_NODE_CONCAT:
+    case SQL_NODE_STRING:
+        nDataType = DataType::VARCHAR;
+        break;
+    case SQL_NODE_INTNUM:
+        nDataType = DataType::INTEGER;
+        break;
+    case SQL_NODE_APPROXNUM:
+        nDataType = DataType::DOUBLE;
+        break;
+    case SQL_NODE_DATE:
+    case SQL_NODE_ACCESS_DATE:
+        nDataType = DataType::TIMESTAMP;
+        break;
+    case SQL_NODE_COMPARISON:
+    case SQL_NODE_EQUAL:
+    case SQL_NODE_LESS:
+    case SQL_NODE_GREAT:
+    case SQL_NODE_LESSEQ:
+    case SQL_NODE_GREATEQ:
+    case SQL_NODE_NOTEQUAL:
+        nDataType = DataType::BOOLEAN;
+        break;
+    case SQL_NODE_NAME:
+    case SQL_NODE_LISTRULE:
+    case SQL_NODE_COMMALISTRULE:
+    case SQL_NODE_KEYWORD:
+    case SQL_NODE_AMMSC: //??
+    case SQL_NODE_PUNCTUATION:
+        OSL_FAIL("Unexpected SQL Node Type");
+        break;
+    case SQL_NODE_RULE:
+        switch(pNode->getKnownRuleID())
+        {
+        case OSQLParseNode::select_statement:
+        case OSQLParseNode::table_exp:
+        case OSQLParseNode::table_ref_commalist:
+        case OSQLParseNode::table_ref:
+        case OSQLParseNode::catalog_name:
+        case OSQLParseNode::schema_name:
+        case OSQLParseNode::table_name:
+        case OSQLParseNode::opt_column_commalist:
+        case OSQLParseNode::column_commalist:
+        case OSQLParseNode::column_ref_commalist:
+        case OSQLParseNode::column_ref:
+        case OSQLParseNode::opt_order_by_clause:
+        case OSQLParseNode::ordering_spec_commalist:
+        case OSQLParseNode::ordering_spec:
+        case OSQLParseNode::opt_asc_desc:
+        case OSQLParseNode::where_clause:
+        case OSQLParseNode::opt_where_clause:
+        case OSQLParseNode::opt_escape:
+        case OSQLParseNode::scalar_exp_commalist:
+        case OSQLParseNode::scalar_exp: // Seems to never be generated?
+        case OSQLParseNode::parameter_ref:
+        case OSQLParseNode::parameter:
+        case OSQLParseNode::range_variable:
+        case OSQLParseNode::delete_statement_positioned:
+        case OSQLParseNode::delete_statement_searched:
+        case OSQLParseNode::update_statement_positioned:
+        case OSQLParseNode::update_statement_searched:
+        case OSQLParseNode::assignment_commalist:
+        case OSQLParseNode::assignment:
+        case OSQLParseNode::insert_statement:
+        case OSQLParseNode::insert_atom_commalist:
+        case OSQLParseNode::insert_atom:
+        case OSQLParseNode::from_clause:
+        case OSQLParseNode::qualified_join:
+        case OSQLParseNode::cross_union:
+        case OSQLParseNode::select_sublist:
+        case OSQLParseNode::join_type:
+        case OSQLParseNode::named_columns_join:
+        case OSQLParseNode::joined_table:
+        case OSQLParseNode::sql_not:
+        case OSQLParseNode::manipulative_statement:
+        case OSQLParseNode::value_exp_commalist:
+        case OSQLParseNode::union_statement:
+        case OSQLParseNode::outer_join_type:
+        case OSQLParseNode::selection:
+        case OSQLParseNode::base_table_def:
+        case OSQLParseNode::base_table_element_commalist:
+        case OSQLParseNode::data_type:
+        case OSQLParseNode::column_def:
+        case OSQLParseNode::table_node:
+        case OSQLParseNode::as:  // Seems to never be generated?
+        case OSQLParseNode::op_column_commalist:
+        case OSQLParseNode::table_primary_as_range_column:
+        case OSQLParseNode::character_string_type:
+            OSL_FAIL("Unexpected SQL RuleID");
+            break;
+        case OSQLParseNode::column:
+        case OSQLParseNode::column_val:
+            OSL_FAIL("Cannot guess column type");
+            break;
+        case OSQLParseNode::values_or_query_spec:
+            OSL_FAIL("Cannot guess VALUES type");
+            break;
+        case OSQLParseNode::derived_column:
+            OSL_FAIL("Cannot guess computed column type");
+            break;
+        case OSQLParseNode::subquery:
+            OSL_FAIL("Cannot guess subquery return type");
+            break;
+        case OSQLParseNode::search_condition:
+        case OSQLParseNode::comparison_predicate:
+        case OSQLParseNode::between_predicate:
+        case OSQLParseNode::like_predicate:
+        case OSQLParseNode::test_for_null:
+        case OSQLParseNode::predicate_check: // Seems to never be generated?
+        case OSQLParseNode::boolean_term:
+        case OSQLParseNode::boolean_primary:
+        case OSQLParseNode::in_predicate:
+        case OSQLParseNode::existence_test:
+        case OSQLParseNode::unique_test:
+        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:
+        case OSQLParseNode::between_predicate_part_2:
+            nDataType = DataType::BOOLEAN;
+            break;
+        case OSQLParseNode::num_value_exp:
+        case OSQLParseNode::extract_exp:
+        case OSQLParseNode::term:
+        case OSQLParseNode::factor:
+            // Might by an integer or a float; take the most generic
+            nDataType = DataType::DOUBLE;
+            break;
+        case OSQLParseNode::value_exp_primary:
+        case OSQLParseNode::value_exp:
+        case OSQLParseNode::odbc_call_spec:
+            // Really, we don't know. Let the default.
+            break;
+        case OSQLParseNode::position_exp:
+        case OSQLParseNode::length_exp:
+            nDataType = DataType::INTEGER;
+            break;
+        case OSQLParseNode::char_value_exp:
+        case OSQLParseNode::char_value_fct:
+        case OSQLParseNode::fold:
+        case OSQLParseNode::char_substring_fct:
+        case OSQLParseNode::char_factor:
+        case OSQLParseNode::concatenation:
+            nDataType = DataType::VARCHAR;
+            break;
+        case OSQLParseNode::datetime_primary:
+            nDataType = DataType::TIMESTAMP;
+            break;
+        case OSQLParseNode::bit_value_fct:
+            nDataType = DataType::BINARY;
+            break;
+        case OSQLParseNode::general_set_fct: // May depend on argument; ignore that for now
+        case OSQLParseNode::set_fct_spec:
+        {
+            if (pNode->count() == 0)
+            {
+                // This is not a function call, no sense to continue with a function return type lookup
+                OSL_FAIL("Got leaf SQL node where non-leaf expected");
+                break;
+            }
+            const OSQLParseNode* pFunctionName = pNode->getChild(0);
+            if ( SQL_ISPUNCTUATION(pFunctionName,"{") )
+            {
+                if ( pNode->count() == 3 )
+                    return fillFunctionInfo( pNode->getChild(1), sFunctionTerm, aInfo );
+                else
+                    OSL_FAIL("ODBC escape not in recognised form");
+                break;
+            }
+            else
+            {
+                if ( SQL_ISRULEOR2(pNode,length_exp,char_value_fct) )
+                    pFunctionName = pFunctionName->getChild(0);
 
-        ::rtl::OUString sFunctionName = pFunctionName->getTokenValue();
-        if ( !sFunctionName.getLength() )
-            sFunctionName = ::rtl::OStringToOUString(OSQLParser::TokenIDToStr(pFunctionName->getTokenID()),RTL_TEXTENCODING_UTF8);
+                ::rtl::OUString sFunctionName = pFunctionName->getTokenValue();
+                if ( !sFunctionName.getLength() )
+                    sFunctionName = ::rtl::OStringToOUString(OSQLParser::TokenIDToStr(pFunctionName->getTokenID()),RTL_TEXTENCODING_UTF8);
 
-        nDataType = OSQLParser::getFunctionReturnType(
-                            sFunctionName
-                            ,&rController.getParser().getContext());
+                nDataType = OSQLParser::getFunctionReturnType(
+                    sFunctionName
+                    ,&rController.getParser().getContext());
+            }
+            break;
+        }
+        case OSQLParseNode::odbc_fct_spec:
+        {
+            if (pNode->count() != 2)
+            {
+                OSL_FAIL("interior of ODBC escape not in recognised shape");
+                break;
+            }
+
+            const OSQLParseNode* const pEscapeType = pNode->getChild(0);
+            if (SQL_ISTOKEN(pEscapeType, TS))
+                nDataType = DataType::TIMESTAMP;
+            else if (SQL_ISTOKEN(pEscapeType, D))
+                nDataType = DataType::DATE;
+            else if (SQL_ISTOKEN(pEscapeType, T))
+                nDataType = DataType::TIME;
+            else if (SQL_ISTOKEN(pEscapeType, FN))
+                return fillFunctionInfo( pNode->getChild(1), sFunctionTerm, aInfo );
+            else
+                OSL_FAIL("Unknown ODBC escape");
+            break;
+        }
+        case OSQLParseNode::cast_spec:
+        {
+            if ( pNode->count() != 6 || !SQL_ISTOKEN(pNode->getChild(3), AS) )
+            {
+                OSL_FAIL("CAST not in recognised shape");
+                break;
+            }
+            const OSQLParseNode *pCastTarget = pNode->getChild(4);
+            if ( SQL_ISTOKENOR2(pCastTarget, INTEGER, INT) )
+                nDataType = DataType::INTEGER;
+            else if ( SQL_ISTOKEN(pCastTarget, SMALLINT) )
+                nDataType = DataType::SMALLINT;
+            else if ( SQL_ISTOKEN(pCastTarget, BIGINT) )
+                nDataType = DataType::BIGINT;
+            else if ( SQL_ISTOKEN(pCastTarget, FLOAT) )
+                nDataType = DataType::FLOAT;
+            else if ( SQL_ISTOKEN(pCastTarget, REAL) )
+                nDataType = DataType::REAL;
+           else if ( SQL_ISTOKEN(pCastTarget, DOUBLE) )
+                nDataType = DataType::DOUBLE;
+            else if ( SQL_ISTOKEN(pCastTarget, BOOLEAN) )
+                nDataType = DataType::BOOLEAN;
+            else if ( SQL_ISTOKEN(pCastTarget, DATE) )
+                nDataType = DataType::DATE;
+            else if ( pCastTarget->count() > 0 )
+            {
+                const OSQLParseNode *pDataType = pCastTarget->getChild(0);
+                while (pDataType->count() > 0)
+                {
+                    pCastTarget = pDataType;
+                    pDataType = pDataType->getChild(0);
+                }
+                if ( SQL_ISTOKEN (pDataType, TIME) )
+                    nDataType = DataType::TIME;
+                else if ( SQL_ISTOKEN (pDataType, TIMESTAMP) )
+                    nDataType = DataType::TIMESTAMP;
+                else if ( SQL_ISTOKENOR3 (pDataType, CHARACTER, CHAR, NCHAR) )
+                    nDataType = char_datatype(pCastTarget, 0);
+                else if ( SQL_ISTOKEN (pDataType, VARCHAR) )
+                    nDataType = DataType::VARCHAR;
+                else if ( SQL_ISTOKEN (pDataType, CLOB) )
+                    nDataType = DataType::CLOB;
+                else if ( SQL_ISTOKEN (pDataType, NATIONAL) )
+                    nDataType = char_datatype(pCastTarget, 1);
+                else if ( SQL_ISTOKEN (pDataType, BINARY) )
+                {
+                    if ( pCastTarget->count() > 2 && SQL_ISTOKEN(pCastTarget->getChild(1), LARGE) && SQL_ISTOKEN(pCastTarget->getChild(2), OBJECT) )
+                        nDataType = DataType::BLOB;
+                    else if ( pCastTarget->count() > 1 && SQL_ISTOKEN(pCastTarget->getChild(1), VARYING) )
+                        nDataType = DataType::VARBINARY;
+                    else
+                        nDataType = DataType::BINARY;
+                }
+                else if ( SQL_ISTOKEN (pDataType, VARBINARY) )
+                    nDataType = DataType::VARBINARY;
+                else if ( SQL_ISTOKEN (pDataType, BLOB) )
+                    nDataType = DataType::BLOB;
+                else if ( SQL_ISTOKEN (pDataType, NUMERIC) )
+                    nDataType = DataType::NUMERIC;
+                else if ( SQL_ISTOKENOR2 (pDataType, DECIMAL, DEC) )
+                    nDataType = DataType::DECIMAL;
+                else if ( SQL_ISTOKEN (pDataType, FLOAT) )
+                    nDataType = DataType::FLOAT;
+                else if ( SQL_ISTOKEN (pDataType, DOUBLE) )
+                    nDataType = DataType::DOUBLE;
+                else if ( SQL_ISTOKEN (pDataType, TIME) )
+                    nDataType = DataType::TIME;
+                else if ( SQL_ISTOKEN (pDataType, TIMESTAMP) )
+                    nDataType = DataType::TIMESTAMP;
+                else if ( SQL_ISTOKEN (pDataType, INTERVAL) )
+                    // Not in DataType published constant (because not in JDBC...)
+                    nDataType = DataType::VARCHAR;
+                else
+                    OSL_FAIL("Failed to decode CAST target");
+            }
+            else
+                OSL_FAIL("Could not decipher CAST target");
+            break;
+        }
+        default:
+            OSL_FAIL("Unknown SQL RuleID");
+            break;
+        }
+        break;
+    default:
+        OSL_FAIL("Unknown SQL Node Type");
+        break;
     }
+
     aInfo->SetDataType(nDataType);
     aInfo->SetFieldType(TAB_NORMAL_FIELD);
     aInfo->SetField(sFieldName);
diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
index df55d49..1b2328d 100644
--- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
+++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
@@ -882,16 +882,7 @@ sal_Bool OSelectionBrowseBox::saveField(const String& _sFieldName,OTableFieldDes
                     if ( SQL_ISRULE(pColumnRef,set_fct_spec) )
                         aSelEntry->SetFunctionType(/*FKT_NUMERIC | */FKT_OTHER);
                     else
-                    {
-                        if ( SQL_ISRULEOR2(pColumnRef,num_value_exp,term) || SQL_ISRULE(pColumnRef,factor) )
-                            aSelEntry->SetDataType(DataType::DOUBLE);
-                        else if ( SQL_ISRULE(pColumnRef,value_exp) )
-                            aSelEntry->SetDataType(DataType::TIMESTAMP);
-                        else
-                            aSelEntry->SetDataType(DataType::VARCHAR);
-
                         aSelEntry->SetFunctionType(FKT_NUMERIC | FKT_OTHER);
-                    }
                 }
 
                 aSelEntry->SetAlias(::rtl::OUString());
commit 70511e6e1596f98cf908938373b6bfc7f6370248
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Sun Oct 30 12:33:29 2011 +0100

    Errors in comments

diff --git a/connectivity/source/parse/sqlbison.y b/connectivity/source/parse/sqlbison.y
index 455084b..8ac72ac 100755
--- a/connectivity/source/parse/sqlbison.y
+++ b/connectivity/source/parse/sqlbison.y
@@ -4733,7 +4733,7 @@ OSQLParseNode* OSQLParser::parseTree(::rtl::OUString& rErrorMessage,
 //-----------------------------------------------------------------------------
 sal_uInt32 OSQLParser::StrToRuleID(const ::rtl::OString & rValue)
 {
-	// Search for the given name in yysvar and return the index
+	// Search for the given name in yytname and return the index
 	// (or UNKNOWN_RULE, if not found)
 	static sal_uInt32 nLen = SAL_N_ELEMENTS(yytname);
 	for (sal_uInt32 i = YYTRANSLATE(SQL_TOKEN_INVALIDSYMBOL); i < (nLen-1); i++)
diff --git a/connectivity/source/parse/sqlflex.l b/connectivity/source/parse/sqlflex.l
index d5166c7..d5b2f14 100755
--- a/connectivity/source/parse/sqlflex.l
+++ b/connectivity/source/parse/sqlflex.l
@@ -598,7 +598,7 @@ sal_Int32 mapEnumToToken(IParseContext::InternationalKeyCode _eKeyCode )
 }
 /*
  * Read SQL Name literal
- * Valid Names or internatioanl keywords:
+ * Valid Names or international keywords:
  *	As we have international keywords, we test first on them  
  */
 sal_Int32 gatherName(const sal_Char* text)
commit 74816f998b5d947edaba21102d6b0de28016aec7
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Sun Oct 30 12:32:08 2011 +0100

    translate comments

diff --git a/connectivity/source/parse/sqlbison.y b/connectivity/source/parse/sqlbison.y
index e83a122..455084b 100755
--- a/connectivity/source/parse/sqlbison.y
+++ b/connectivity/source/parse/sqlbison.y
@@ -4733,8 +4733,8 @@ OSQLParseNode* OSQLParser::parseTree(::rtl::OUString& rErrorMessage,
 //-----------------------------------------------------------------------------
 sal_uInt32 OSQLParser::StrToRuleID(const ::rtl::OString & rValue)
 {
-	// In yysvar nach dem angegebenen Namen suchen, den Index zurueckliefern
-	// (oder 0, wenn nicht gefunden)
+	// Search for the given name in yysvar and return the index
+	// (or UNKNOWN_RULE, if not found)
 	static sal_uInt32 nLen = SAL_N_ELEMENTS(yytname);
 	for (sal_uInt32 i = YYTRANSLATE(SQL_TOKEN_INVALIDSYMBOL); i < (nLen-1); i++)
 	{
@@ -4742,7 +4742,7 @@ sal_uInt32 OSQLParser::StrToRuleID(const ::rtl::OString & rValue)
 			return i;
 	}
 
-	// Nicht gefunden
+	// Not found
 	return OParseNode::UNKNOWN_RULE;
 }
 
commit 338ea7617f33d975cc35f44030f522ec5d77adfb
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Sun Oct 30 11:40:22 2011 +0100

    Return proper UNKNOWN_RULE instead of 0 for unknown rule
    
    also make unknown rule -1 to better separate it
    Before, an unknown rule actually went to 0 == OSQLParser::select_statement

diff --git a/connectivity/inc/connectivity/sqlnode.hxx b/connectivity/inc/connectivity/sqlnode.hxx
index 69eeaba..4fd6714 100644
--- a/connectivity/inc/connectivity/sqlnode.hxx
+++ b/connectivity/inc/connectivity/sqlnode.hxx
@@ -239,7 +239,7 @@ namespace connectivity
             between_predicate_part_2,
             cast_spec,
             rule_count,             // last value
-            UNKNOWN_RULE            // ID indicating that a node is no rule with a matching Rule-enum value (see getKnownRuleID)
+            UNKNOWN_RULE = -1       // ID indicating that a node is no rule with a matching Rule-enum value (see getKnownRuleID)
         };
 
         // must be ascii encoding for the value
diff --git a/connectivity/source/parse/sqlbison.y b/connectivity/source/parse/sqlbison.y
index d559c29..e83a122 100755
--- a/connectivity/source/parse/sqlbison.y
+++ b/connectivity/source/parse/sqlbison.y
@@ -4743,7 +4743,7 @@ sal_uInt32 OSQLParser::StrToRuleID(const ::rtl::OString & rValue)
 	}
 
 	// Nicht gefunden
-	return 0;
+	return OParseNode::UNKNOWN_RULE;
 }
 
 //-----------------------------------------------------------------------------
commit 98b5910149c940a62d155014f61962ceae382911
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Sun Oct 30 11:36:24 2011 +0100

    Introduce combined 2&3 test for SQL Token

diff --git a/connectivity/inc/connectivity/sqlnode.hxx b/connectivity/inc/connectivity/sqlnode.hxx
index ddb058c..69eeaba 100644
--- a/connectivity/inc/connectivity/sqlnode.hxx
+++ b/connectivity/inc/connectivity/sqlnode.hxx
@@ -465,6 +465,8 @@ namespace connectivity
     // utilities to query for a specific rule, token or punctuation
     #define SQL_ISRULE(pParseNode, eRule)   ((pParseNode)->isRule() && (pParseNode)->getRuleID() == OSQLParser::RuleID(OSQLParseNode::eRule))
     #define SQL_ISTOKEN(pParseNode, token) ((pParseNode)->isToken() && (pParseNode)->getTokenID() == SQL_TOKEN_##token)
+    #define SQL_ISTOKENOR2(pParseNode, tok0, tok1) ((pParseNode)->isToken() &&  ( (pParseNode)->getTokenID() == SQL_TOKEN_##tok0 || (pParseNode)->getTokenID() == SQL_TOKEN_##tok1 ))
+    #define SQL_ISTOKENOR3(pParseNode, tok0, tok1, tok2) ((pParseNode)->isToken() && ( (pParseNode)->getTokenID() == SQL_TOKEN_##tok0 || (pParseNode)->getTokenID() == SQL_TOKEN_##tok1 || (pParseNode)->getTokenID() == SQL_TOKEN_##tok2 ))
     #define SQL_ISPUNCTUATION(pParseNode, aString) ((pParseNode)->getNodeType() == SQL_NODE_PUNCTUATION && !(pParseNode)->getTokenValue().compareToAscii(aString))
 }
 
commit 2053a71686b3a3266de2ec0199896a120874396d
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Sun Oct 30 07:02:13 2011 +0100

    8.5 is not an integer, but an approxnum

diff --git a/connectivity/source/parse/sqlflex.l b/connectivity/source/parse/sqlflex.l
index 45485fd..d5166c7 100755
--- a/connectivity/source/parse/sqlflex.l
+++ b/connectivity/source/parse/sqlflex.l
@@ -435,10 +435,10 @@ ZONE				{SQL_NEW_KEYWORD(SQL_TOKEN_ZONE);  }
 
 <SQL>[A-Za-z\200-\277\300-\337\340-\357\360-\367\370-\373\374-\375][A-Za-z\200-\277\300-\337\340-\357\360-\367\370-\373\374-\375_0-9]*		{return gatherName( SQLyytext);}
 
-<SQL>([0-9]+) | 
-<SQL>([0-9]+"."[0-9]*) | 
-<SQL>("."[0-9]*)					{SQL_NEW_INTNUM; }
+<SQL>([0-9]+)					{SQL_NEW_INTNUM; }
 
+<SQL>("."[0-9]*) |
+<SQL>([0-9]+"."[0-9]*) | 
 <SQL>[0-9]+[eE][+-]?[0-9]+   |
 <SQL>[0-9]+"."[0-9]*[eE][+-]?[0-9]+ |
 <SQL>"."[0-9]*[eE][+-]?[0-9]+		{SQL_NEW_APPROXNUM;  }
commit fbf27dc44ceb4dbeb7a5b320e8d2f65cd72dd985
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Sat Oct 29 09:07:09 2011 +0200

    Reorganise code for more clarity; no behaviour change

diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
index 35654a8..df55d49 100644
--- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
+++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
@@ -803,105 +803,103 @@ sal_Bool OSelectionBrowseBox::saveField(const String& _sFieldName,OTableFieldDes
                 // and the function is different to count
                 clearEntryFunctionField(_sFieldName,aSelEntry,_bListAction,nColumnId);
             }
-            else
+            // do we have a aggregate function and only a function?
+            else if ( SQL_ISRULE(pColumnRef,general_set_fct) )
             {
-                // first check if we have a aggregate function and only a function
-                if ( SQL_ISRULE(pColumnRef,general_set_fct) )
+                String sLocalizedFunctionName;
+                if ( GetFunctionName(pColumnRef->getChild(0)->getTokenID(),sLocalizedFunctionName) )
                 {
-                    String sLocalizedFunctionName;
-                    if ( GetFunctionName(pColumnRef->getChild(0)->getTokenID(),sLocalizedFunctionName) )
+                    String sOldLocalizedFunctionName = aSelEntry->GetFunction();
+                    aSelEntry->SetFunction(sLocalizedFunctionName);
+                    sal_uInt32 nFunCount = pColumnRef->count() - 1;
+                    sal_Int32 nFunctionType = FKT_AGGREGATE;
+                    sal_Bool bQuote = sal_False;
+                    // may be there exists only one parameter which is a column, fill all information into our fields
+                    if ( nFunCount == 4 && SQL_ISRULE(pColumnRef->getChild(3),column_ref) )
+                        bError = fillColumnRef( pColumnRef->getChild(3), xConnection, aSelEntry, _bListAction );
+                    else if ( nFunCount == 3 ) // we have a COUNT(*) here, so take the first table
+                        bError = fillColumnRef( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("*")), ::rtl::OUString(), xMetaData, aSelEntry, _bListAction );
+                    else
                     {
-                        String sOldLocalizedFunctionName = aSelEntry->GetFunction();
-                        aSelEntry->SetFunction(sLocalizedFunctionName);
-                        sal_uInt32 nFunCount = pColumnRef->count() - 1;
-                        sal_Int32 nFunctionType = FKT_AGGREGATE;
-                        sal_Bool bQuote = sal_False;
-                        // may be there exists only one parameter which is a column, fill all information into our fields
-                        if ( nFunCount == 4 && SQL_ISRULE(pColumnRef->getChild(3),column_ref) )
-                            bError = fillColumnRef( pColumnRef->getChild(3), xConnection, aSelEntry, _bListAction );
-                        else if ( nFunCount == 3 ) // we have a COUNT(*) here, so take the first table
-                            bError = fillColumnRef( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("*")), ::rtl::OUString(), xMetaData, aSelEntry, _bListAction );
-                        else
-                        {
-                            nFunctionType |= FKT_NUMERIC;
-                            bQuote = sal_True;
-                            aSelEntry->SetDataType(DataType::DOUBLE);
-                            aSelEntry->SetFieldType(TAB_NORMAL_FIELD);
-                        }
+                        nFunctionType |= FKT_NUMERIC;
+                        bQuote = sal_True;
+                        aSelEntry->SetDataType(DataType::DOUBLE);
+                        aSelEntry->SetFieldType(TAB_NORMAL_FIELD);
+                    }
 
-                        // now parse the parameters
-                        ::rtl::OUString sParameters;
-                        for(sal_uInt32 function = 2; function < nFunCount; ++function) // we only want to parse the parameters of the function
-                            pColumnRef->getChild(function)->parseNodeToStr( sParameters, xConnection, &rParser.getContext(), sal_True, bQuote );
+                    // now parse the parameters
+                    ::rtl::OUString sParameters;
+                    for(sal_uInt32 function = 2; function < nFunCount; ++function) // we only want to parse the parameters of the function
+                        pColumnRef->getChild(function)->parseNodeToStr( sParameters, xConnection, &rParser.getContext(), sal_True, bQuote );
 
-                        aSelEntry->SetFunctionType(nFunctionType);
-                        aSelEntry->SetField(sParameters);
-                        if ( aSelEntry->IsGroupBy() )
-                        {
-                            sOldLocalizedFunctionName = m_aFunctionStrings.GetToken(m_aFunctionStrings.GetTokenCount()-1);
-                            aSelEntry->SetGroupBy(sal_False);
-                        }
-
-                        // append undo action
-                        notifyFunctionFieldChanged(sOldLocalizedFunctionName,sLocalizedFunctionName,_bListAction, nColumnId);
+                    aSelEntry->SetFunctionType(nFunctionType);
+                    aSelEntry->SetField(sParameters);
+                    if ( aSelEntry->IsGroupBy() )
+                    {
+                        sOldLocalizedFunctionName = m_aFunctionStrings.GetToken(m_aFunctionStrings.GetTokenCount()-1);
+                        aSelEntry->SetGroupBy(sal_False);
                     }
-                    else
-                        OSL_FAIL("Unsupported function inserted!");
 
+                    // append undo action
+                    notifyFunctionFieldChanged(sOldLocalizedFunctionName,sLocalizedFunctionName,_bListAction, nColumnId);
                 }
                 else
+                    OSL_FAIL("Unsupported function inserted!");
+
+            }
+            else
+            {
+                // so we first clear the function field
+                clearEntryFunctionField(_sFieldName,aSelEntry,_bListAction,nColumnId);
+                ::rtl::OUString sFunction;
+                pColumnRef->parseNodeToStr( sFunction,
+                                            xConnection,
+                                            &rController.getParser().getContext(),
+                                            sal_True,
+                                            sal_True); // quote is to true because we need quoted elements inside the function
+
+                getDesignView()->fillFunctionInfo(pColumnRef,sFunction,aSelEntry);
+
+                if( SQL_ISRULEOR2(pColumnRef,position_exp,extract_exp) ||
+                    SQL_ISRULEOR2(pColumnRef,fold,char_substring_fct)  ||
+                    SQL_ISRULEOR2(pColumnRef,length_exp,char_value_fct) )
+                    // a calculation has been found ( can be calc and function )
                 {
-                    // so we first clear the function field
-                    clearEntryFunctionField(_sFieldName,aSelEntry,_bListAction,nColumnId);
-                    ::rtl::OUString sFunction;
-                    pColumnRef->parseNodeToStr( sFunction,
-                                                xConnection,
-                                                &rController.getParser().getContext(),
-                                                sal_True,
-                                                sal_True); // quote is to true because we need quoted elements inside the function
-
-                    getDesignView()->fillFunctionInfo(pColumnRef,sFunction,aSelEntry);
-
-                    if( SQL_ISRULEOR2(pColumnRef,position_exp,extract_exp) ||
-                        SQL_ISRULEOR2(pColumnRef,fold,char_substring_fct)  ||
-                        SQL_ISRULEOR2(pColumnRef,length_exp,char_value_fct) )
-                            // a calculation has been found ( can be calc and function )
-                    {
-                        // now parse the whole statement
-                        sal_uInt32 nFunCount = pColumnRef->count();
-                        ::rtl::OUString sParameters;
-                        for(sal_uInt32 function = 0; function < nFunCount; ++function)
-                            pColumnRef->getChild(function)->parseNodeToStr( sParameters, xConnection, &rParser.getContext(), sal_True, sal_True );
-
-                        sOldAlias = aSelEntry->GetAlias();
-                        sal_Int32 nNewFunctionType = aSelEntry->GetFunctionType() | FKT_NUMERIC | FKT_OTHER;
-                        aSelEntry->SetFunctionType(nNewFunctionType);
-                        aSelEntry->SetField(sParameters);
-                    }
+                    // now parse the whole statement
+                    sal_uInt32 nFunCount = pColumnRef->count();
+                    ::rtl::OUString sParameters;
+                    for(sal_uInt32 function = 0; function < nFunCount; ++function)
+                        pColumnRef->getChild(function)->parseNodeToStr( sParameters, xConnection, &rParser.getContext(), sal_True, sal_True );
+
+                    sOldAlias = aSelEntry->GetAlias();
+                    sal_Int32 nNewFunctionType = aSelEntry->GetFunctionType() | FKT_NUMERIC | FKT_OTHER;
+                    aSelEntry->SetFunctionType(nNewFunctionType);
+                    aSelEntry->SetField(sParameters);
+                }
+                else
+                {
+                    aSelEntry->SetFieldAlias(sColumnAlias);
+                    if ( SQL_ISRULE(pColumnRef,set_fct_spec) )
+                        aSelEntry->SetFunctionType(/*FKT_NUMERIC | */FKT_OTHER);
                     else
                     {
-                        aSelEntry->SetFieldAlias(sColumnAlias);
-                        if ( SQL_ISRULE(pColumnRef,set_fct_spec) )
-                            aSelEntry->SetFunctionType(/*FKT_NUMERIC | */FKT_OTHER);
+                        if ( SQL_ISRULEOR2(pColumnRef,num_value_exp,term) || SQL_ISRULE(pColumnRef,factor) )
+                            aSelEntry->SetDataType(DataType::DOUBLE);
+                        else if ( SQL_ISRULE(pColumnRef,value_exp) )
+                            aSelEntry->SetDataType(DataType::TIMESTAMP);
                         else
-                        {
-                            if ( SQL_ISRULEOR2(pColumnRef,num_value_exp,term) || SQL_ISRULE(pColumnRef,factor) )
-                                aSelEntry->SetDataType(DataType::DOUBLE);
-                            else if ( SQL_ISRULE(pColumnRef,value_exp) )
-                                aSelEntry->SetDataType(DataType::TIMESTAMP);
-                            else
-                                aSelEntry->SetDataType(DataType::VARCHAR);
-                            aSelEntry->SetFunctionType(FKT_NUMERIC | FKT_OTHER);
-                        }
-                    }
+                            aSelEntry->SetDataType(DataType::VARCHAR);
 
-                    aSelEntry->SetAlias(::rtl::OUString());
-                    notifyTableFieldChanged(sOldAlias,aSelEntry->GetAlias(),_bListAction, nColumnId);
+                        aSelEntry->SetFunctionType(FKT_NUMERIC | FKT_OTHER);
+                    }
                 }
 
+                aSelEntry->SetAlias(::rtl::OUString());
+                notifyTableFieldChanged(sOldAlias,aSelEntry->GetAlias(),_bListAction, nColumnId);
             }
+
             if ( i > 0 && !InsertField(aSelEntry,BROWSER_INVALIDID,sal_True,sal_False).is() ) // may we have to append more than one field
-            { // the field could not be isnerted
+            { // the field could not be inserted
                 String sErrorMessage( ModuleRes( RID_STR_FIELD_DOESNT_EXIST ) );
                 sErrorMessage.SearchAndReplaceAscii("$name$",aSelEntry->GetField());
                 OSQLWarningBox( this, sErrorMessage ).Execute();
commit d8e643124e77f166dc44100e0123747ae1097e3d
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Sat Oct 29 08:03:28 2011 +0200

    overhaul / enhance / translate / ... comments

diff --git a/connectivity/inc/connectivity/sqlnode.hxx b/connectivity/inc/connectivity/sqlnode.hxx
index 5b010bc..ddb058c 100644
--- a/connectivity/inc/connectivity/sqlnode.hxx
+++ b/connectivity/inc/connectivity/sqlnode.hxx
@@ -333,7 +333,7 @@ namespace connectivity
                             sal_Bool _bIntl = sal_False,
                             sal_Bool _bQuote= sal_True) const;
 
-        // quoted und internationalisert
+        // quoted and internationalised
         void parseNodeToPredicateStr(::rtl::OUString& rString,
                                      const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,
                                      const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter,
@@ -352,14 +352,14 @@ namespace connectivity
         OSQLParseNode* getByRule(OSQLParseNode::Rule eRule) const;
 
 #if OSL_DEBUG_LEVEL > 0
-            // shows the ParseTree with tabs and linefeeds
+        // shows the ParseTree with tabs and linefeeds
         void showParseTree( ::rtl::OUString& rString ) const;
         void showParseTree( ::rtl::OUStringBuffer& _inout_rBuf, sal_uInt32 nLevel ) const;
 #endif
 
         SQLNodeType getNodeType() const {return m_eNodeType;};
 
-            // RuleId returns the RuleID of the node's rule (only if IsRule())
+        // RuleId returns the RuleID of the node's rule (only if IsRule())
         sal_uInt32 getRuleID() const {return m_nNodeID;}
 
         /** returns the ID of the rule represented by the node
@@ -392,17 +392,17 @@ namespace connectivity
         // e.q. (a or b) and (c or d) <=> a and c or a and d or b and c or b and d
         static void disjunctiveNormalForm(OSQLParseNode*& pSearchCondition);
 
-        //   Simplies logic expressions
-        // a * a        = a
-        // a + a        = a
-        // a * ( a + b) = a
-        // a + a * b    = a
+        //   Simplifies logic expressions
+        // a and a        = a
+        // a or a         = a
+        // a and ( a + b) = a
+        // a or a and b   = a
         static void absorptions(OSQLParseNode*& pSearchCondition);
 
-        // erase not nessary braces
+        // erase unnecessary braces
         static void eraseBraces(OSQLParseNode*& pSearchCondition);
 
-        // makes the logic formula a little more smaller
+        // makes the logic formula a little smaller
         static void compress(OSQLParseNode*& pSearchCondition);
         // return the catalog, schema and tablename form this node
         // _pTableNode must be a rule of that above or a SQL_TOKEN_NAME
@@ -412,7 +412,7 @@ namespace connectivity
                                             ::rtl::OUString &_rTable
                                             ,const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& _xMetaData);
 
-        // susbtitute all occurrences of :var or [name] into the dynamic parameter ?
+        // substitute all occurrences of :var or [name] into the dynamic parameter ?
         // _pNode will be modified if parameters exists
         static void substituteParameterNames(OSQLParseNode* _pNode);
 
@@ -421,7 +421,7 @@ namespace connectivity
         static ::rtl::OUString getTableRange(const OSQLParseNode* _pTableRef);
 
     protected:
-        // ParseNodeToStr konkateniert alle Token (leaves) des ParseNodes
+        // ParseNodeToStr concatenates all Tokens (leaves) of the ParseNodes.
         void parseNodeToStr(::rtl::OUString& rString,
                             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,
                             const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter,
@@ -462,7 +462,7 @@ namespace connectivity
         return m_aChildren.at(nPos);
     }
 
-    // Utility-Methoden zum Abfragen auf bestimmte Rules, Token oder Punctuation:
+    // utilities to query for a specific rule, token or punctuation
     #define SQL_ISRULE(pParseNode, eRule)   ((pParseNode)->isRule() && (pParseNode)->getRuleID() == OSQLParser::RuleID(OSQLParseNode::eRule))
     #define SQL_ISTOKEN(pParseNode, token) ((pParseNode)->isToken() && (pParseNode)->getTokenID() == SQL_TOKEN_##token)
     #define SQL_ISPUNCTUATION(pParseNode, aString) ((pParseNode)->getNodeType() == SQL_NODE_PUNCTUATION && !(pParseNode)->getTokenValue().compareToAscii(aString))


More information about the Libreoffice-commits mailing list