diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-12-19 16:10:51 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-12-21 08:26:15 +0100 |
commit | d425658bd9fd8e315e4931afb544bc845da0360e (patch) | |
tree | a35679686a7df2a504b9088ba6807b60c52067fc /connectivity | |
parent | 526387b96e9bc2c04b0dc26744bf6b88ea7c0521 (diff) |
pass OSQLParseNode around by unique_ptr
Change-Id: I8ffb9e04614472c3645d24bebdc88f91059d12ad
Reviewed-on: https://gerrit.libreoffice.org/65436
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/source/commontools/ParameterSubstitution.cxx | 5 | ||||
-rw-r--r-- | connectivity/source/commontools/predicateinput.cxx | 22 | ||||
-rw-r--r-- | connectivity/source/drivers/ado/APreparedStatement.cxx | 5 | ||||
-rw-r--r-- | connectivity/source/drivers/file/FStatement.cxx | 2 | ||||
-rw-r--r-- | connectivity/source/drivers/macab/MacabStatement.cxx | 2 | ||||
-rw-r--r-- | connectivity/source/drivers/mork/MStatement.cxx | 2 | ||||
-rw-r--r-- | connectivity/source/parse/sqlbison.y | 8 | ||||
-rw-r--r-- | connectivity/source/parse/sqlnode.cxx | 5 |
8 files changed, 23 insertions, 28 deletions
diff --git a/connectivity/source/commontools/ParameterSubstitution.cxx b/connectivity/source/commontools/ParameterSubstitution.cxx index dfec360b23e5..a8efa6c6a694 100644 --- a/connectivity/source/commontools/ParameterSubstitution.cxx +++ b/connectivity/source/commontools/ParameterSubstitution.cxx @@ -83,12 +83,11 @@ namespace connectivity OSQLParser aParser( m_xContext ); OUString sErrorMessage; OUString sNewSql; - OSQLParseNode* pNode = aParser.parseTree(sErrorMessage,_sText); + std::unique_ptr<OSQLParseNode> pNode = aParser.parseTree(sErrorMessage,_sText); if(pNode) { // special handling for parameters - OSQLParseNode::substituteParameterNames(pNode); + OSQLParseNode::substituteParameterNames(pNode.get()); pNode->parseNodeToStr( sNewSql, xConnection ); - delete pNode; sRet = sNewSql; } } diff --git a/connectivity/source/commontools/predicateinput.cxx b/connectivity/source/commontools/predicateinput.cxx index fbc9c0bbb40e..b7a08ef57309 100644 --- a/connectivity/source/commontools/predicateinput.cxx +++ b/connectivity/source/commontools/predicateinput.cxx @@ -123,9 +123,9 @@ namespace dbtools } - OSQLParseNode* OPredicateInputController::implPredicateTree(OUString& _rErrorMessage, const OUString& _rStatement, const Reference< XPropertySet > & _rxField) const + std::unique_ptr<OSQLParseNode> OPredicateInputController::implPredicateTree(OUString& _rErrorMessage, const OUString& _rStatement, const Reference< XPropertySet > & _rxField) const { - OSQLParseNode* pReturn = const_cast< OSQLParser& >( m_aParser ).predicateTree( _rErrorMessage, _rStatement, m_xFormatter, _rxField ); + std::unique_ptr<OSQLParseNode> pReturn = const_cast< OSQLParser& >( m_aParser ).predicateTree( _rErrorMessage, _rStatement, m_xFormatter, _rxField ); if ( !pReturn ) { // is it a text field ? sal_Int32 nType = DataType::OTHER; @@ -242,7 +242,7 @@ namespace dbtools // parse the string OUString sError; OUString sTransformedText( _rPredicateValue ); - OSQLParseNode* pParseNode = implPredicateTree( sError, sTransformedText, _rxField ); + std::unique_ptr<OSQLParseNode> pParseNode = implPredicateTree( sError, sTransformedText, _rxField ); if ( _pErrorMessage ) *_pErrorMessage = sError; if ( pParseNode ) @@ -258,7 +258,6 @@ namespace dbtools rParseContext.getPreferredLocale(), static_cast<sal_Char>(nDecSeparator), &rParseContext ); _rPredicateValue = sTransformedText; - delete pParseNode; bSuccess = true; } @@ -279,9 +278,9 @@ namespace dbtools // (dbaccess/source/ui/dlg/paramdialog.cxx). I do not fully understand this ..... OUString sError; - OSQLParseNode* pParseNode = implPredicateTree( sError, _rPredicateValue, _rxField ); + std::unique_ptr<OSQLParseNode> pParseNode = implPredicateTree( sError, _rPredicateValue, _rxField ); - implParseNode(pParseNode, true) >>= sReturn; + implParseNode(std::move(pParseNode), true) >>= sReturn; } return sReturn; @@ -325,10 +324,10 @@ namespace dbtools pColumn->setFunction(true); pColumn->setRealName(sField); - OSQLParseNode* pParseNode = implPredicateTree( sError, _rPredicateValue, xColumn ); + std::unique_ptr<OSQLParseNode> pParseNode = implPredicateTree( sError, _rPredicateValue, xColumn ); if(pParseNode) { - implParseNode(pParseNode, true) >>= sReturn; + implParseNode(std::move(pParseNode), true) >>= sReturn; } return sReturn; } @@ -344,22 +343,21 @@ namespace dbtools // (dbaccess/source/ui/dlg/paramdialog.cxx). I do not fully understand this ..... OUString sError; - OSQLParseNode* pParseNode = implPredicateTree( sError, _rPredicateValue, _rxField ); + std::unique_ptr<OSQLParseNode> pParseNode = implPredicateTree( sError, _rPredicateValue, _rxField ); - return implParseNode(pParseNode, false); + return implParseNode(std::move(pParseNode), false); } return Any(); } - Any OPredicateInputController::implParseNode(OSQLParseNode* pParseNode, bool _bForStatementUse) const + Any OPredicateInputController::implParseNode(std::unique_ptr<OSQLParseNode> pParseNode, bool _bForStatementUse) const { if ( ! pParseNode ) return Any(); else { OUString sReturn; - std::shared_ptr<OSQLParseNode> xTakeOwnership(pParseNode); OSQLParseNode* pOdbcSpec = pParseNode->getByRule( OSQLParseNode::odbc_fct_spec ); if ( pOdbcSpec ) { diff --git a/connectivity/source/drivers/ado/APreparedStatement.cxx b/connectivity/source/drivers/ado/APreparedStatement.cxx index 9544bde9bfab..95ce16c347fb 100644 --- a/connectivity/source/drivers/ado/APreparedStatement.cxx +++ b/connectivity/source/drivers/ado/APreparedStatement.cxx @@ -61,15 +61,14 @@ OPreparedStatement::OPreparedStatement( OConnection* _pConnection, const OUStrin OSQLParser aParser(comphelper::getComponentContext(_pConnection->getDriver()->getORB())); OUString sErrorMessage; OUString sNewSql; - OSQLParseNode* pNode = aParser.parseTree(sErrorMessage,sql); + std::unique_ptr<OSQLParseNode> pNode = aParser.parseTree(sErrorMessage,sql); if(pNode) { // special handling for parameters // we recursive replace all occurrences of ? in the statement and // replace them with name like "parame" */ sal_Int32 nParameterCount = 0; - replaceParameterNodeName(pNode,"parame",nParameterCount); + replaceParameterNodeName(pNode.get(), "parame", nParameterCount); pNode->parseNodeToStr( sNewSql, _pConnection ); - delete pNode; } else sNewSql = sql; diff --git a/connectivity/source/drivers/file/FStatement.cxx b/connectivity/source/drivers/file/FStatement.cxx index d99e3808f37b..ec74025fb945 100644 --- a/connectivity/source/drivers/file/FStatement.cxx +++ b/connectivity/source/drivers/file/FStatement.cxx @@ -367,7 +367,7 @@ void OStatement_Base::setOrderbyColumn( OSQLParseNode const * pColumnRef, void OStatement_Base::construct(const OUString& sql) { OUString aErr; - m_pParseTree = m_aParser.parseTree(aErr,sql); + m_pParseTree = m_aParser.parseTree(aErr,sql).release(); if(!m_pParseTree) throw SQLException(aErr,*this,OUString(),0,Any()); diff --git a/connectivity/source/drivers/macab/MacabStatement.cxx b/connectivity/source/drivers/macab/MacabStatement.cxx index 55d91567330e..a418b85c2d94 100644 --- a/connectivity/source/drivers/macab/MacabStatement.cxx +++ b/connectivity/source/drivers/macab/MacabStatement.cxx @@ -403,7 +403,7 @@ Reference< XResultSet > SAL_CALL MacabCommonStatement::executeQuery( Reference< XResultSet > xRS = pResult; OUString aErr; - m_pParseTree = m_aParser.parseTree(aErr, sql); + m_pParseTree = m_aParser.parseTree(aErr, sql).release(); if (m_pParseTree == nullptr) throw SQLException(aErr, *this, aErr, 0, Any()); diff --git a/connectivity/source/drivers/mork/MStatement.cxx b/connectivity/source/drivers/mork/MStatement.cxx index 813508f25994..5ae4a49952df 100644 --- a/connectivity/source/drivers/mork/MStatement.cxx +++ b/connectivity/source/drivers/mork/MStatement.cxx @@ -115,7 +115,7 @@ OCommonStatement::StatementType OCommonStatement::parseSql( const OUString& sql { OUString aErr; - m_pParseTree.reset( m_aParser.parseTree(aErr,sql) ); + m_pParseTree = m_aParser.parseTree(aErr,sql); if(m_pParseTree) { diff --git a/connectivity/source/parse/sqlbison.y b/connectivity/source/parse/sqlbison.y index a93f3401cabc..013073b882d5 100644 --- a/connectivity/source/parse/sqlbison.y +++ b/connectivity/source/parse/sqlbison.y @@ -4494,10 +4494,10 @@ void setParser(OSQLParser* _pParser) xxx_pGLOBAL_SQLPARSER = _pParser; } -void OSQLParser::setParseTree(OSQLParseNode * pNewParseTree) +void OSQLParser::setParseTree(OSQLParseNode* pNewParseTree) { ::osl::MutexGuard aGuard(getMutex()); - m_pParseTree = pNewParseTree; + m_pParseTree.reset(pNewParseTree); } @@ -4561,7 +4561,7 @@ static OUString delComment( const OUString& rQuery ) return aBuf.makeStringAndClear(); } -OSQLParseNode* OSQLParser::parseTree(OUString& rErrorMessage, +std::unique_ptr<OSQLParseNode> OSQLParser::parseTree(OUString& rErrorMessage, const OUString& rStatement, bool bInternational) { @@ -4609,7 +4609,7 @@ OSQLParseNode* OSQLParser::parseTree(OUString& rErrorMessage, SAL_WARN_IF(!m_pParseTree, "connectivity.parse", "OSQLParser: Parser did not create ParseTree"); - return m_pParseTree; + return std::move(m_pParseTree); } } diff --git a/connectivity/source/parse/sqlnode.cxx b/connectivity/source/parse/sqlnode.cxx index f9acc655347f..b4890a25b46d 100644 --- a/connectivity/source/parse/sqlnode.cxx +++ b/connectivity/source/parse/sqlnode.cxx @@ -1159,7 +1159,7 @@ OUString OSQLParser::stringToDouble(const OUString& _rValue,sal_Int16 _nScale) } -OSQLParseNode* OSQLParser::predicateTree(OUString& rErrorMessage, const OUString& rStatement, +std::unique_ptr<OSQLParseNode> OSQLParser::predicateTree(OUString& rErrorMessage, const OUString& rStatement, const Reference< css::util::XNumberFormatter > & xFormatter, const Reference< XPropertySet > & xField, bool bUseRealName) @@ -1309,14 +1309,13 @@ OSQLParseNode* OSQLParser::predicateTree(OUString& rErrorMessage, const OUString // Instead, the parse method sets the member pParseTree and simply returns that OSL_ENSURE(m_pParseTree != nullptr,"OSQLParser: Parser did not return a ParseTree!"); - return m_pParseTree; + return std::move(m_pParseTree); } } OSQLParser::OSQLParser(const css::uno::Reference< css::uno::XComponentContext >& rxContext, const IParseContext* _pContext) :m_pContext(_pContext) - ,m_pParseTree(nullptr) ,m_pData( new OSQLParser_Data ) ,m_nFormatKey(0) ,m_nDateFormatKey(0) |