connectivity/inc/connectivity/sqlnode.hxx | 11 +- connectivity/source/parse/sqlbison.y | 13 ++ connectivity/source/parse/sqlnode.cxx | 31 ++++-- dbaccess/source/ui/dlg/sqlmessage.cxx | 11 ++ dbaccess/source/ui/inc/sqlmessage.hxx | 12 ++ dbaccess/source/ui/querydesign/QueryDesignView.cxx | 8 + dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx | 89 ++++++++++-------- dbaccess/source/ui/querydesign/SelectionBrowseBox.hxx | 2 sal/inc/sal/log-areas.dox | 1 9 files changed, 123 insertions(+), 55 deletions(-)
New commits: commit d931b994a4bd2f8fe72f351a7d628a44a35f4abe Author: Lionel Elie Mamane <lio...@mamane.lu> Date: Wed Jan 23 16:17:39 2013 +0100 show errors as errors, not warning Change-Id: I32e514fbfbd323b688b25b9e2165d0c76e3c4db5 diff --git a/dbaccess/source/ui/dlg/sqlmessage.cxx b/dbaccess/source/ui/dlg/sqlmessage.cxx index 9c3ecc8..c46035c 100644 --- a/dbaccess/source/ui/dlg/sqlmessage.cxx +++ b/dbaccess/source/ui/dlg/sqlmessage.cxx @@ -751,7 +751,16 @@ IMPL_LINK( OSQLMessageBox, ButtonClickHdl, Button *, /*pButton*/ ) //================================================================== OSQLWarningBox::OSQLWarningBox( Window* _pParent, const OUString& _rMessage, WinBits _nStyle, const ::dbtools::SQLExceptionInfo* _pAdditionalErrorInfo ) - :OSQLMessageBox( _pParent, String( ModuleRes( STR_STAT_WARNING ) ), _rMessage, _nStyle, OSQLMessageBox::Warning, _pAdditionalErrorInfo ) + :OSQLMessageBox( _pParent, String( ModuleRes( STR_EXCEPTION_WARNING ) ), _rMessage, _nStyle, OSQLMessageBox::Warning, _pAdditionalErrorInfo ) +{ +} + +//================================================================== +// OSQLErrorBox +//================================================================== +OSQLErrorBox::OSQLErrorBox( Window* _pParent, const OUString& _rMessage, WinBits _nStyle, + const ::dbtools::SQLExceptionInfo* _pAdditionalErrorInfo ) + :OSQLMessageBox( _pParent, String( ModuleRes( STR_EXCEPTION_ERROR ) ), _rMessage, _nStyle, OSQLMessageBox::Error, _pAdditionalErrorInfo ) { } diff --git a/dbaccess/source/ui/inc/sqlmessage.hxx b/dbaccess/source/ui/inc/sqlmessage.hxx index da36617..76d896f 100644 --- a/dbaccess/source/ui/inc/sqlmessage.hxx +++ b/dbaccess/source/ui/inc/sqlmessage.hxx @@ -119,6 +119,18 @@ public: const ::dbtools::SQLExceptionInfo* _pAdditionalErrorInfo = NULL ); }; +//================================================================== +// OSQLErrorBox +//================================================================== +class OSQLErrorBox : public OSQLMessageBox +{ +public: + OSQLErrorBox( Window* _pParent, + const OUString& _rMessage, + WinBits _nStyle = WB_OK | WB_DEF_OK, + const ::dbtools::SQLExceptionInfo* _pAdditionalErrorInfo = NULL ); +}; + //......................................................................... } // namespace dbaui //......................................................................... diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx index 8897a5d..342a341 100644 --- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx +++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx @@ -633,7 +633,7 @@ sal_Bool OSelectionBrowseBox::fillColumnRef(const ::rtl::OUString& _sColumnName, { String sErrorMsg(ModuleRes(RID_STR_FIELD_DOESNT_EXIST)); sErrorMsg.SearchAndReplaceAscii("$name$",_sColumnName); - OSQLWarningBox( this, sErrorMsg ).Execute(); + OSQLErrorBox( this, sErrorMsg ).Execute(); bError = sal_True; } else @@ -739,7 +739,8 @@ sal_Bool OSelectionBrowseBox::saveField(String& _sFieldName ,OTableFieldDescRef& // something different which we have to check String sErrorMessage( ModuleRes( STR_QRY_COLUMN_NOT_FOUND ) ); sErrorMessage.SearchAndReplaceAscii("$name$",_sFieldName); - OSQLWarningBox( this, sErrorMessage ).Execute(); + OSQLErrorBox( this, sErrorMessage ).Execute(); + return sal_True; } @@ -895,7 +896,7 @@ sal_Bool OSelectionBrowseBox::saveField(String& _sFieldName ,OTableFieldDescRef& { // the field could not be inserted String sErrorMessage( ModuleRes( RID_STR_FIELD_DOESNT_EXIST ) ); sErrorMessage.SearchAndReplaceAscii("$name$",aSelEntry->GetField()); - OSQLWarningBox( this, sErrorMessage ).Execute(); + OSQLErrorBox( this, sErrorMessage ).Execute(); bError = sal_True; } } commit f1bde8cb0e00770e4f9a2e1cd2458906a7ec8a63 Author: Lionel Elie Mamane <lio...@mamane.lu> Date: Wed Jan 23 15:36:35 2013 +0100 fix handling of subqueries in query design - don't remove parentheses around subqueries (without the parentheses, it is not valid SQL) * when saving a Field (name value) typed by the user interactively * when parsing SQL and constructing the initial Query Design view - automatically add the necessary parentheses when a SELECT statement is entered as column name Also: In code saving a Field (name value) typed by the user interactively, factorise some common code Assorted minor fixes (typos in comments, etc) Change-Id: I3843258323c903cba23238b0730ec4eb5875f792 diff --git a/dbaccess/source/ui/querydesign/QueryDesignView.cxx b/dbaccess/source/ui/querydesign/QueryDesignView.cxx index 8cc532f..fe780c9 100644 --- a/dbaccess/source/ui/querydesign/QueryDesignView.cxx +++ b/dbaccess/source/ui/querydesign/QueryDesignView.cxx @@ -2202,7 +2202,8 @@ namespace pColumnRef = pColumnRef->getChild(0); OTableFieldDescRef aInfo = new OTableFieldDesc(); - if ( pColumnRef->count() == 3 && + if ( pColumnRef->getKnownRuleID() != OSQLParseNode::subquery && + pColumnRef->count() == 3 && SQL_ISPUNCTUATION(pColumnRef->getChild(0),"(") && SQL_ISPUNCTUATION(pColumnRef->getChild(2),")") ) diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx index c0532dc..8897a5d 100644 --- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx +++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx @@ -649,7 +649,7 @@ sal_Bool OSelectionBrowseBox::fillColumnRef(const ::rtl::OUString& _sColumnName, return bError; } // ----------------------------------------------------------------------------- -sal_Bool OSelectionBrowseBox::saveField(const String& _sFieldName,OTableFieldDescRef& _pEntry,sal_Bool& _bListAction) +sal_Bool OSelectionBrowseBox::saveField(String& _sFieldName ,OTableFieldDescRef& _pEntry, sal_Bool& _bListAction) { sal_Bool bError = sal_False; @@ -680,50 +680,63 @@ sal_Bool OSelectionBrowseBox::saveField(const String& _sFieldName,OTableFieldDes // we have to look which entries we should quote const ::rtl::OUString sFieldAlias = _pEntry->GetFieldAlias(); - size_t nPass = 4; ::connectivity::OSQLParser& rParser( rController.getParser() ); + { + // automatically add parentheses around subqueries + OSQLParseNode *pParseNode = NULL; + OUString devnull; + pParseNode = rParser.parseTree( devnull, _sFieldName, true ); + if (pParseNode == NULL) + pParseNode = rParser.parseTree( devnull, _sFieldName, false ); + if (pParseNode != NULL && SQL_ISRULE(pParseNode, select_statement)) + _sFieldName = ::rtl::OUString("(") + _sFieldName + ")"; + } + OSQLParseNode* pParseNode = NULL; - // 4 passes in trying to interprete the field name - // - don't quote the field name, parse internationally - // - don't quote the field name, parse en-US - // - quote the field name, parse internationally - // - quote the field name, parse en-US - do - { - bool bQuote = ( nPass <= 2 ); - bool bInternational = ( nPass % 2 ) == 0; - - ::rtl::OUString sSql; - if ( bQuote ) - sSql += ::dbtools::quoteName( xMetaData->getIdentifierQuoteString(), _sFieldName ); - else - sSql += _sFieldName; + { + // 4 passes in trying to interprete the field name + // - don't quote the field name, parse internationally + // - don't quote the field name, parse en-US + // - quote the field name, parse internationally + // - quote the field name, parse en-US + size_t nPass = 4; + ::rtl::OUString sQuotedFullFieldName(::dbtools::quoteName( xMetaData->getIdentifierQuoteString(), _sFieldName )); + ::rtl::OUString sFullFieldName(_sFieldName); if ( _pEntry->isAggreateFunction() ) { OSL_ENSURE(!_pEntry->GetFunction().isEmpty(),"Functionname darf hier nicht leer sein! ;-("); - ::rtl::OUStringBuffer aTmpStr2( _pEntry->GetFunction()); - aTmpStr2.appendAscii("("); - aTmpStr2.append(sSql); - aTmpStr2.appendAscii(")"); - sSql = aTmpStr2.makeStringAndClear(); + sQuotedFullFieldName = _pEntry->GetFunction() + "(" + sQuotedFullFieldName + ")"; + sFullFieldName = _pEntry->GetFunction() + "(" + sFullFieldName + ")"; } - sSql = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT ")) + sSql; - if ( !sFieldAlias.isEmpty() ) - { // always quote the alias name there canbe no function in it - sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ")); - sSql += ::dbtools::quoteName( xMetaData->getIdentifierQuoteString(), sFieldAlias ); - } - sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" FROM x")); + do + { + bool bQuote = ( nPass <= 2 ); + bool bInternational = ( nPass % 2 ) == 0; - pParseNode = rParser.parseTree( sErrorMsg, sSql, bInternational ); + ::rtl::OUString sSql; + if ( bQuote ) + sSql += sQuotedFullFieldName; + else + sSql += sFullFieldName; + + sSql = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT ")) + sSql; + if ( !sFieldAlias.isEmpty() ) + { // always quote the alias name: there cannot be a function in it + sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ")); + sSql += ::dbtools::quoteName( xMetaData->getIdentifierQuoteString(), sFieldAlias ); + } + sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" FROM x")); + + pParseNode = rParser.parseTree( sErrorMsg, sSql, bInternational ); + } + while ( ( pParseNode == NULL ) && ( --nPass > 0 ) ); } - while ( ( pParseNode == NULL ) && ( --nPass > 0 ) ); if ( pParseNode == NULL ) { - // something different which we have to check (may be a select statement) + // something different which we have to check String sErrorMessage( ModuleRes( STR_QRY_COLUMN_NOT_FOUND ) ); sErrorMessage.SearchAndReplaceAscii("$name$",_sFieldName); OSQLWarningBox( this, sErrorMessage ).Execute(); @@ -737,8 +750,8 @@ sal_Bool OSelectionBrowseBox::saveField(const String& _sFieldName,OTableFieldDes { _pEntry->SetField(_sFieldName); clearEntryFunctionField(_sFieldName,_pEntry,_bListAction,_pEntry->GetColumnId()); - } // travel through the select column parse node - else + } + else // travel through the select column parse node { ::comphelper::UStringMixEqual bCase(xMetaData->supportsMixedCaseQuotedIdentifiers()); @@ -777,6 +790,7 @@ sal_Bool OSelectionBrowseBox::saveField(const String& _sFieldName,OTableFieldDes ::connectivity::OSQLParseNode* pColumnRef = pChild->getChild(0); if ( + pColumnRef->getKnownRuleID() != OSQLParseNode::subquery && pColumnRef->count() == 3 && SQL_ISPUNCTUATION(pColumnRef->getChild(0),"(") && SQL_ISPUNCTUATION(pColumnRef->getChild(2),")") diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.hxx b/dbaccess/source/ui/querydesign/SelectionBrowseBox.hxx index b3b2c98..55bf270 100644 --- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.hxx +++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.hxx @@ -246,7 +246,7 @@ namespace dbaui @return <TRUE/> if an error occurred otherwise <FALSE/> */ - sal_Bool saveField(const String& _sFieldName,OTableFieldDescRef& _pEntry,sal_Bool& _bListAction); + sal_Bool saveField(String& _sFieldName, OTableFieldDescRef& _pEntry, sal_Bool& _bListAction); /** sets the table window at the _pEntry @param _pEntry commit 5214bda61e413b5b2907bcffbbf0211c254b878f Author: Lionel Elie Mamane <lio...@mamane.lu> Date: Wed Jan 23 15:30:33 2013 +0100 SQL parser: no "as" rule anymore; now as_clause and opt_as Change-Id: Ib0c7151b311029318c213abb86e6541e3b27d040 diff --git a/connectivity/inc/connectivity/sqlnode.hxx b/connectivity/inc/connectivity/sqlnode.hxx index 4082375..a74c8ab 100644 --- a/connectivity/inc/connectivity/sqlnode.hxx +++ b/connectivity/inc/connectivity/sqlnode.hxx @@ -219,7 +219,8 @@ namespace connectivity data_type, column_def, table_node, - as, + as_clause, + opt_as, op_column_commalist, table_primary_as_range_column, datetime_primary, diff --git a/connectivity/source/parse/sqlnode.cxx b/connectivity/source/parse/sqlnode.cxx index ca2281a..5ab87fa 100644 --- a/connectivity/source/parse/sqlnode.cxx +++ b/connectivity/source/parse/sqlnode.cxx @@ -392,9 +392,19 @@ void OSQLParseNode::impl_parseNodeToString_throw(::rtl::OUStringBuffer& rString, bHandled = impl_parseTableNameNodeToString_throw( rString, rParam ); break; - case as: - if ( rParam.aMetaData.generateASBeforeCorrelationName() ) - rString.append(::rtl::OUString(" AS")); + case as_clause: + assert(nCount == 0 || nCount == 2); + if (nCount == 2) + { + if ( rParam.aMetaData.generateASBeforeCorrelationName() ) + rString.append(::rtl::OUString(" AS ")); + m_aChildren[1]->impl_parseNodeToString_throw( rString, rParam ); + } + bHandled = true; + break; + + case opt_as: + assert(nCount == 0); bHandled = true; break; @@ -1386,7 +1396,8 @@ OSQLParser::OSQLParser(const ::com::sun::star::uno::Reference< ::com::sun::star: { OSQLParseNode::data_type, "data_type" }, { OSQLParseNode::column_def, "column_def" }, { OSQLParseNode::table_node, "table_node" }, - { OSQLParseNode::as, "as" }, + { OSQLParseNode::as_clause, "as_clause" }, + { OSQLParseNode::opt_as, "opt_as" }, { OSQLParseNode::op_column_commalist, "op_column_commalist" }, { OSQLParseNode::table_primary_as_range_column, "table_primary_as_range_column" }, { OSQLParseNode::datetime_primary, "datetime_primary" }, diff --git a/dbaccess/source/ui/querydesign/QueryDesignView.cxx b/dbaccess/source/ui/querydesign/QueryDesignView.cxx index 1cf9b47..8cc532f 100644 --- a/dbaccess/source/ui/querydesign/QueryDesignView.cxx +++ b/dbaccess/source/ui/querydesign/QueryDesignView.cxx @@ -3388,7 +3388,8 @@ void OQueryDesignView::fillFunctionInfo( const ::connectivity::OSQLParseNode* p case OSQLParseNode::data_type: case OSQLParseNode::column_def: case OSQLParseNode::table_node: - case OSQLParseNode::as: // Seems to never be generated? + case OSQLParseNode::as_clause: + case OSQLParseNode::opt_as: case OSQLParseNode::op_column_commalist: case OSQLParseNode::table_primary_as_range_column: case OSQLParseNode::character_string_type: commit ce59b1b3978cc148090385e086c8d48d742801d0 Author: Lionel Elie Mamane <lio...@mamane.lu> Date: Wed Jan 23 15:21:33 2013 +0100 ISO8859-1 -> UTF8 in comment Change-Id: I8a67235e5110618f45fe9d9467bbb7ff90c7c712 diff --git a/dbaccess/source/ui/querydesign/QueryDesignView.cxx b/dbaccess/source/ui/querydesign/QueryDesignView.cxx index 5507634..1cf9b47 100644 --- a/dbaccess/source/ui/querydesign/QueryDesignView.cxx +++ b/dbaccess/source/ui/querydesign/QueryDesignView.cxx @@ -2168,7 +2168,7 @@ namespace return eNoSelectStatement; ::connectivity::OSQLParseNode* pParseTree = pNode->getChild(2); // selection - sal_Bool bFirstField = sal_True; // bei der Initialisierung mu� auf alle Faelle das erste Feld neu aktiviert werden + sal_Bool bFirstField = sal_True; // bei der Initialisierung muà auf alle Faelle das erste Feld neu aktiviert werden SqlParseError eErrorCode = eOk; commit 09109f3dcde24fcd13426ce5b77bb40032f58947 Author: Lionel Elie Mamane <lio...@mamane.lu> Date: Wed Jan 23 15:20:24 2013 +0100 OSQLParser::RuleIDToRule should not silently change s_aReverseRuleIDLookup Change-Id: I2b408a23162b1200bbcd530be7acb42435388b04 diff --git a/connectivity/source/parse/sqlbison.y b/connectivity/source/parse/sqlbison.y index 96d0782..a0f7d43 100644 --- a/connectivity/source/parse/sqlbison.y +++ b/connectivity/source/parse/sqlbison.y @@ -4772,7 +4772,18 @@ sal_uInt32 OSQLParser::StrToRuleID(const ::rtl::OString & rValue) //----------------------------------------------------------------------------- OSQLParseNode::Rule OSQLParser::RuleIDToRule( sal_uInt32 _nRule ) { - return s_aReverseRuleIDLookup[ _nRule ]; + OSQLParser::RuleIDMap::const_iterator i (s_aReverseRuleIDLookup.find(_nRule)); + if (i == s_aReverseRuleIDLookup.end()) + { + SAL_WARN("connectivity.parse", + "connectivity::OSQLParser::RuleIDToRule cannot reverse-lookup rule. " + "Reverse mapping incomplete? " + "_nRule='" << _nRule << "' " + "yytname[_nRule]='" << yytname[_nRule] << "'"); + return OSQLParseNode::UNKNOWN_RULE; + } + else + return i->second; } //----------------------------------------------------------------------------- diff --git a/sal/inc/sal/log-areas.dox b/sal/inc/sal/log-areas.dox index 5232778..eeb1d60 100644 --- a/sal/inc/sal/log-areas.dox +++ b/sal/inc/sal/log-areas.dox @@ -37,6 +37,7 @@ certain functionality. @section connectivity @li @c connectivity.mork +@li @c connectivity.parse @section cui commit 22fef9910ecfcbbd7bd4c4c8268be2c4b4a5a96a Author: Lionel Elie Mamane <lio...@mamane.lu> Date: Wed Jan 23 15:19:07 2013 +0100 Make UNKNOWN_RULE the default value of connectivity::OSQLParseNode::Rule Change-Id: I4e56da8820d5c92d3b6e2ff2c749bdc0cef46d73 diff --git a/connectivity/inc/connectivity/sqlnode.hxx b/connectivity/inc/connectivity/sqlnode.hxx index e21e06e..4082375 100644 --- a/connectivity/inc/connectivity/sqlnode.hxx +++ b/connectivity/inc/connectivity/sqlnode.hxx @@ -130,7 +130,10 @@ namespace connectivity public: enum Rule { - select_statement = 0, + UNKNOWN_RULE = 0, // ID indicating that a node is no rule with a matching Rule-enum value (see getKnownRuleID) + // we make sure it is 0 so that it is the default-constructor value of this enum + // and std::map<foo,Rule>::operator[](bar) default-inserts UNKNOWN_RULE rather than select_statement (!) + select_statement, table_exp, table_ref_commalist, table_ref, @@ -229,8 +232,7 @@ namespace connectivity other_like_predicate_part_2, between_predicate_part_2, cast_spec, - rule_count, // last value - UNKNOWN_RULE = -1 // ID indicating that a node is no rule with a matching Rule-enum value (see getKnownRuleID) + rule_count // last value }; // must be ascii encoding for the value diff --git a/connectivity/source/parse/sqlnode.cxx b/connectivity/source/parse/sqlnode.cxx index ae9f3f1f..ca2281a 100644 --- a/connectivity/source/parse/sqlnode.cxx +++ b/connectivity/source/parse/sqlnode.cxx @@ -59,6 +59,7 @@ #include <tools/diagnose_ex.h> #include <string.h> #include <boost/bind.hpp> +#include <boost/static_assert.hpp> #include <algorithm> #include <functional> #include <rtl/logfile.hxx> @@ -1289,8 +1290,9 @@ OSQLParser::OSQLParser(const ::com::sun::star::uno::Reference< ::com::sun::star: if(!s_xLocaleData.is()) s_xLocaleData = LocaleData::create(m_xContext); - // reset to 0 - memset(OSQLParser::s_nRuleIDs,0,sizeof(OSQLParser::s_nRuleIDs[0]) * (OSQLParseNode::rule_count+1)); + // reset to UNKNOWN_RULE + BOOST_STATIC_ASSERT(OSQLParseNode::UNKNOWN_RULE==0); + memset(OSQLParser::s_nRuleIDs,0,sizeof(OSQLParser::s_nRuleIDs)); struct { @@ -1398,8 +1400,10 @@ OSQLParser::OSQLParser(const ::com::sun::star::uno::Reference< ::com::sun::star: { OSQLParseNode::between_predicate_part_2, "between_predicate_part_2" }, { OSQLParseNode::cast_spec, "cast_spec" } }; - size_t nRuleMapCount = sizeof( aRuleDescriptions ) / sizeof( aRuleDescriptions[0] ); - OSL_ENSURE( nRuleMapCount == size_t( OSQLParseNode::rule_count ), "OSQLParser::OSQLParser: added a new rule? Adjust this map!" ); + const size_t nRuleMapCount = sizeof( aRuleDescriptions ) / sizeof( aRuleDescriptions[0] ); + // added a new rule? Adjust this map! + // +1 for UNKNOWN_RULE + BOOST_STATIC_ASSERT( nRuleMapCount + 1 == static_cast<size_t>(OSQLParseNode::rule_count) ); for ( size_t mapEntry = 0; mapEntry < nRuleMapCount; ++mapEntry ) {
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits