summaryrefslogtreecommitdiff
path: root/connectivity/source/parse/sqlnode.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'connectivity/source/parse/sqlnode.cxx')
-rw-r--r--connectivity/source/parse/sqlnode.cxx559
1 files changed, 273 insertions, 286 deletions
diff --git a/connectivity/source/parse/sqlnode.cxx b/connectivity/source/parse/sqlnode.cxx
index 48c55051ef6b..823813b3f0e0 100644
--- a/connectivity/source/parse/sqlnode.cxx
+++ b/connectivity/source/parse/sqlnode.cxx
@@ -50,7 +50,7 @@
#include <comphelper/numbers.hxx>
#include <connectivity/dbtools.hxx>
#include <connectivity/dbmetadata.hxx>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
#include <string.h>
#include <algorithm>
#include <functional>
@@ -59,6 +59,7 @@
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
+#include <utility>
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::util;
@@ -91,39 +92,26 @@ namespace
void replaceAndReset(connectivity::OSQLParseNode*& _pResetNode,connectivity::OSQLParseNode* _pNewNode)
{
- _pResetNode->getParent()->replace(_pResetNode, _pNewNode);
- delete _pResetNode;
+ _pResetNode->getParent()->replaceAndDelete(_pResetNode, _pNewNode);
_pResetNode = _pNewNode;
}
/** quotes a string and search for quotes inside the string and replace them with the new quote
@param rValue
The value to be quoted.
- @param rQuot
+ @param rQuote
The quote
- @param rQuotToReplace
+ @param rQuoteToReplace
The quote to replace with
@return
The quoted string.
*/
- OUString SetQuotation(std::u16string_view rValue, const OUString& rQuot, const OUString& rQuotToReplace)
+ OUString SetQuotation(const OUString& rValue, std::u16string_view rQuote, std::u16string_view rQuoteToReplace)
{
- OUString rNewValue = rQuot + rValue;
- sal_Int32 nIndex = sal_Int32(-1); // Replace quotes with double quotes or the parser gets into problems
-
- if (!rQuot.isEmpty())
- {
- do
- {
- nIndex += 2;
- nIndex = rNewValue.indexOf(rQuot,nIndex);
- if(nIndex != -1)
- rNewValue = rNewValue.replaceAt(nIndex,rQuot.getLength(),rQuotToReplace);
- } while (nIndex != -1);
- }
-
- rNewValue += rQuot;
- return rNewValue;
+ // Replace quotes with double quotes or the parser gets into problems
+ if (!rQuote.empty())
+ return rQuote + rValue.replaceAll(rQuote, rQuoteToReplace) + rQuote;
+ return rValue;
}
bool columnMatchP(const connectivity::OSQLParseNode* pSubTree, const connectivity::SQLParseNodeParameter& rParam)
@@ -147,41 +135,41 @@ namespace
{
}
- if(pSubTree->count())
+ if(!pSubTree->count())
+ return false;
+
+ const OSQLParseNode* pCol = pSubTree->getChild(pSubTree->count()-1);
+ if (SQL_ISRULE(pCol,column_val))
{
- const OSQLParseNode* pCol = pSubTree->getChild(pSubTree->count()-1);
- if (SQL_ISRULE(pCol,column_val))
- {
- assert(pCol->count() == 1);
- pCol = pCol->getChild(0);
- }
- const OSQLParseNode* pTable(nullptr);
- switch (pSubTree->count())
- {
- case 1:
- break;
- case 3:
- pTable = pSubTree->getChild(0);
- break;
- case 5:
- case 7:
- SAL_WARN("connectivity.parse", "SQL: catalog and/or schema in column_ref in predicate");
- break;
- default:
- SAL_WARN("connectivity.parse", "columnMatchP: SQL grammar changed; column_ref has " << pSubTree->count() << " children");
- assert(false);
- break;
- }
- // TODO: not all DBMS match column names case-insensitively...
- // see XDatabaseMetaData::supportsMixedCaseIdentifiers()
- // and XDatabaseMetaData::supportsMixedCaseQuotedIdentifiers()
- if ( // table name matches (or no table name)?
- ( !pTable || pTable->getTokenValue().equalsIgnoreAsciiCase(rParam.sPredicateTableAlias) )
- && // column name matches?
- pCol->getTokenValue().equalsIgnoreAsciiCase(aFieldName)
- )
- return true;
+ assert(pCol->count() == 1);
+ pCol = pCol->getChild(0);
}
+ const OSQLParseNode* pTable(nullptr);
+ switch (pSubTree->count())
+ {
+ case 1:
+ break;
+ case 3:
+ pTable = pSubTree->getChild(0);
+ break;
+ case 5:
+ case 7:
+ SAL_WARN("connectivity.parse", "SQL: catalog and/or schema in column_ref in predicate");
+ break;
+ default:
+ SAL_WARN("connectivity.parse", "columnMatchP: SQL grammar changed; column_ref has " << pSubTree->count() << " children");
+ assert(false);
+ break;
+ }
+ // TODO: not all DBMS match column names case-insensitively...
+ // see XDatabaseMetaData::supportsMixedCaseIdentifiers()
+ // and XDatabaseMetaData::supportsMixedCaseQuotedIdentifiers()
+ if ( // table name matches (or no table name)?
+ ( !pTable || pTable->getTokenValue().equalsIgnoreAsciiCase(rParam.sPredicateTableAlias) )
+ && // column name matches?
+ pCol->getTokenValue().equalsIgnoreAsciiCase(aFieldName)
+ )
+ return true;
return false;
}
}
@@ -191,7 +179,7 @@ namespace connectivity
SQLParseNodeParameter::SQLParseNodeParameter( const Reference< XConnection >& _rxConnection,
const Reference< XNumberFormatter >& _xFormatter, const Reference< XPropertySet >& _xField,
- const OUString &_sPredicateTableAlias,
+ OUString _sPredicateTableAlias,
const Locale& _rLocale, const IParseContext* _pContext,
bool _bIntl, bool _bQuote, OUString _sDecSep, bool _bPredicate, bool _bParseToSDBC )
:rLocale(_rLocale)
@@ -200,9 +188,9 @@ SQLParseNodeParameter::SQLParseNodeParameter( const Reference< XConnection >& _r
,pSubQueryHistory( std::make_shared<QueryNameSet>() )
,xFormatter(_xFormatter)
,xField(_xField)
- ,sPredicateTableAlias(_sPredicateTableAlias)
+ ,sPredicateTableAlias(std::move(_sPredicateTableAlias))
,m_rContext( _pContext ? *_pContext : OSQLParser::s_aDefaultContext )
- ,sDecSep(_sDecSep)
+ ,sDecSep(std::move(_sDecSep))
,bQuote(_bQuote)
,bInternational(_bIntl)
,bPredicate(_bPredicate)
@@ -210,14 +198,14 @@ SQLParseNodeParameter::SQLParseNodeParameter( const Reference< XConnection >& _r
{
}
-OUString OSQLParseNode::convertDateString(const SQLParseNodeParameter& rParam, const OUString& rString)
+OUString OSQLParseNode::convertDateString(const SQLParseNodeParameter& rParam, std::u16string_view rString)
{
Date aDate = DBTypeConversion::toDate(rString);
Reference< XNumberFormatsSupplier > xSupplier(rParam.xFormatter->getNumberFormatsSupplier());
Reference< XNumberFormatTypes > xTypes(xSupplier->getNumberFormats(), UNO_QUERY);
double fDate = DBTypeConversion::toDouble(aDate,DBTypeConversion::getNULLDate(xSupplier));
- sal_Int32 nKey = xTypes->getStandardIndex(rParam.rLocale) + 36; // XXX hack
+ sal_Int32 nKey = xTypes->getFormatIndex(NumberFormatIndex::DATE_SYS_DDMMYYYY, rParam.rLocale);
return rParam.xFormatter->convertNumberToString(nKey, fDate);
}
@@ -229,12 +217,12 @@ OUString OSQLParseNode::convertDateTimeString(const SQLParseNodeParameter& rPara
Reference< XNumberFormatTypes > xTypes(xSupplier->getNumberFormats(), UNO_QUERY);
double fDateTime = DBTypeConversion::toDouble(aDate,DBTypeConversion::getNULLDate(xSupplier));
- sal_Int32 nKey = xTypes->getStandardIndex(rParam.rLocale) + 51; // XXX hack
+ sal_Int32 nKey = xTypes->getFormatIndex(NumberFormatIndex::DATETIME_SYS_DDMMYYYY_HHMMSS, rParam.rLocale);
return rParam.xFormatter->convertNumberToString(nKey, fDateTime);
}
-OUString OSQLParseNode::convertTimeString(const SQLParseNodeParameter& rParam, const OUString& rString)
+OUString OSQLParseNode::convertTimeString(const SQLParseNodeParameter& rParam, std::u16string_view rString)
{
css::util::Time aTime = DBTypeConversion::toTime(rString);
Reference< XNumberFormatsSupplier > xSupplier(rParam.xFormatter->getNumberFormatsSupplier());
@@ -242,7 +230,7 @@ OUString OSQLParseNode::convertTimeString(const SQLParseNodeParameter& rParam, c
Reference< XNumberFormatTypes > xTypes(xSupplier->getNumberFormats(), UNO_QUERY);
double fTime = DBTypeConversion::toDouble(aTime);
- sal_Int32 nKey = xTypes->getStandardIndex(rParam.rLocale) + 41; // XXX hack
+ sal_Int32 nKey = xTypes->getFormatIndex(NumberFormatIndex::TIME_HHMMSS, rParam.rLocale);
return rParam.xFormatter->convertNumberToString(nKey, fTime);
}
@@ -256,7 +244,7 @@ void OSQLParseNode::parseNodeToStr(OUString& rString,
parseNodeToStr(
rString, _rxConnection, nullptr, nullptr, OUString(),
pContext ? pContext->getPreferredLocale() : OParseContext::getDefaultLocale(),
- pContext, _bIntl, _bQuote, OUString("."), false );
+ pContext, _bIntl, _bQuote, ".", false );
}
@@ -264,13 +252,13 @@ void OSQLParseNode::parseNodeToPredicateStr(OUString& rString,
const Reference< XConnection >& _rxConnection,
const Reference< XNumberFormatter > & xFormatter,
const css::lang::Locale& rIntl,
- OUString _sDec,
+ const OUString& rDec,
const IParseContext* pContext ) const
{
OSL_ENSURE(xFormatter.is(), "OSQLParseNode::parseNodeToPredicateStr:: no formatter!");
if (xFormatter.is())
- parseNodeToStr(rString, _rxConnection, xFormatter, nullptr, OUString(), rIntl, pContext, true, true, _sDec, true);
+ parseNodeToStr(rString, _rxConnection, xFormatter, nullptr, OUString(), rIntl, pContext, true, true, rDec, true);
}
@@ -280,13 +268,13 @@ void OSQLParseNode::parseNodeToPredicateStr(OUString& rString,
const Reference< XPropertySet > & _xField,
const OUString &_sPredicateTableAlias,
const css::lang::Locale& rIntl,
- OUString _sDec,
+ const OUString& rDec,
const IParseContext* pContext ) const
{
OSL_ENSURE(xFormatter.is(), "OSQLParseNode::parseNodeToPredicateStr:: no formatter!");
if (xFormatter.is())
- parseNodeToStr( rString, _rxConnection, xFormatter, _xField, _sPredicateTableAlias, rIntl, pContext, true, true, _sDec, true );
+ parseNodeToStr( rString, _rxConnection, xFormatter, _xField, _sPredicateTableAlias, rIntl, pContext, true, true, rDec, true );
}
@@ -299,7 +287,7 @@ void OSQLParseNode::parseNodeToStr(OUString& rString,
const IParseContext* pContext,
bool _bIntl,
bool _bQuote,
- OUString _sDecSep,
+ const OUString& _rDecSep,
bool _bPredicate) const
{
OSL_ENSURE( _rxConnection.is(), "OSQLParseNode::parseNodeToStr: invalid connection!" );
@@ -313,7 +301,7 @@ void OSQLParseNode::parseNodeToStr(OUString& rString,
OSQLParseNode::impl_parseNodeToString_throw( sBuffer,
SQLParseNodeParameter(
_rxConnection, xFormatter, _xField, _sPredicateTableAlias, rIntl, pContext,
- _bIntl, _bQuote, _sDecSep, _bPredicate, false
+ _bIntl, _bQuote, _rDecSep, _bPredicate, false
) );
}
catch( const SQLException& )
@@ -353,7 +341,7 @@ bool OSQLParseNode::parseNodeToExecutableStatement( OUString& _out_rString, cons
|| xMeta->getURL().startsWithIgnoreAsciiCase("sdbc:firebird:")))
{
sLimitValue = pTableExp->getChild(6)->getChild(1)->getTokenValue();
- pTableExp->removeAt(6);
+ delete pTableExp->removeAt(6);
}
_out_rString.clear();
@@ -374,7 +362,7 @@ bool OSQLParseNode::parseNodeToExecutableStatement( OUString& _out_rString, cons
{
constexpr char SELECT_KEYWORD[] = "SELECT";
sBuffer.insert(sBuffer.indexOf(SELECT_KEYWORD) + strlen(SELECT_KEYWORD),
- OUStringConcatenation(" FIRST " + sLimitValue));
+ Concat2View(" FIRST " + sLimitValue));
}
_out_rString = sBuffer.makeStringAndClear();
@@ -757,7 +745,7 @@ void OSQLParseNode::impl_parseLikeNodeToString_throw( OUStringBuffer& rString, c
{
OUString aStr = ConvertLikeToken(pParaNode, pEscNode, rParam.bInternational);
rString.append(" ");
- rString.append(SetQuotation(aStr,"\'","\'\'"));
+ rString.append(SetQuotation(aStr, u"\'", u"\'\'"));
}
else
pParaNode->impl_parseNodeToString_throw( rString, aNewParam, false );
@@ -815,7 +803,7 @@ void OSQLParser::killThousandSeparator(OSQLParseNode* pLiteral)
{
if ( pLiteral )
{
- if ( s_xLocaleData->getLocaleItem( m_pData->aLocale ).decimalSeparator.toChar() == ',' )
+ if ( s_xLocaleData.get()->get()->getLocaleItem( m_pData->aLocale ).decimalSeparator.toChar() == ',' )
{
pLiteral->m_aNodeValue = pLiteral->m_aNodeValue.replace('.', sal_Unicode());
// and replace decimal
@@ -1130,7 +1118,7 @@ OUString OSQLParser::stringToDouble(const OUString& _rValue,sal_Int16 _nScale)
OUString aValue;
if(!m_xCharClass.is())
m_xCharClass = CharacterClassification::create( m_xContext );
- if( s_xLocaleData.is() )
+ if( s_xLocaleData.get() )
{
try
{
@@ -1140,8 +1128,9 @@ OUString OSQLParser::stringToDouble(const OUString& _rValue,sal_Int16 _nScale)
aValue = OUString::number(aResult.Value);
sal_Int32 nPos = aValue.lastIndexOf('.');
if((nPos+_nScale) < aValue.getLength())
- aValue = aValue.replaceAt(nPos+_nScale,aValue.getLength()-nPos-_nScale,OUString());
- aValue = aValue.replaceAt(aValue.lastIndexOf('.'),1,s_xLocaleData->getLocaleItem(m_pData->aLocale).decimalSeparator);
+ aValue = aValue.replaceAt(nPos+_nScale,aValue.getLength()-nPos-_nScale, u"");
+ OUString sDecimalSeparator = s_xLocaleData.get()->get()->getLocaleItem(m_pData->aLocale).decimalSeparator;
+ aValue = aValue.replaceAt(aValue.lastIndexOf('.'), 1, sDecimalSeparator);
return aValue;
}
}
@@ -1153,9 +1142,9 @@ OUString OSQLParser::stringToDouble(const OUString& _rValue,sal_Int16 _nScale)
}
-::osl::Mutex& OSQLParser::getMutex()
+std::mutex& OSQLParser::getMutex()
{
- static ::osl::Mutex aMutex;
+ static std::mutex aMutex;
return aMutex;
}
@@ -1166,7 +1155,7 @@ std::unique_ptr<OSQLParseNode> OSQLParser::predicateTree(OUString& rErrorMessage
bool bUseRealName)
{
// Guard the parsing
- ::osl::MutexGuard aGuard(getMutex());
+ std::unique_lock aGuard(getMutex());
// must be reset
setParser(this);
@@ -1259,7 +1248,7 @@ std::unique_ptr<OSQLParseNode> OSQLParser::predicateTree(OUString& rErrorMessage
s_pScanner->SetRule(OSQLScanner::GetSTRINGRule());
break;
default:
- if ( s_xLocaleData->getLocaleItem( m_pData->aLocale ).decimalSeparator.toChar() == ',' )
+ if ( s_xLocaleData.get()->get()->getLocaleItem( m_pData->aLocale ).decimalSeparator.toChar() == ',' )
s_pScanner->SetRule(OSQLScanner::GetGERRule());
else
s_pScanner->SetRule(OSQLScanner::GetENGRule());
@@ -1294,7 +1283,8 @@ std::unique_ptr<OSQLParseNode> OSQLParser::predicateTree(OUString& rErrorMessage
// clear the garbage collector
(*s_pGarbageCollector)->clearAndDelete();
- m_pParseTree.release(); // because the garbage collector deleted it
+ // coverity[leaked_storage : FALSE] - because the garbage collector deleted it
+ m_pParseTree.release();
return nullptr;
}
else
@@ -1316,12 +1306,15 @@ std::unique_ptr<OSQLParseNode> OSQLParser::predicateTree(OUString& rErrorMessage
}
-OSQLParser::OSQLParser(const css::uno::Reference< css::uno::XComponentContext >& rxContext, const IParseContext* _pContext)
+OSQLParser::OSQLParser(css::uno::Reference< css::uno::XComponentContext > xContext,
+ const IParseContext* _pContext,
+ const IParseContext* _pNeutral)
:m_pContext(_pContext)
+ ,m_pNeutral(_pNeutral)
,m_pData( new OSQLParser_Data )
,m_nFormatKey(0)
,m_nDateFormatKey(0)
- ,m_xContext(rxContext)
+ ,m_xContext(std::move(xContext))
{
@@ -1333,7 +1326,7 @@ OSQLParser::OSQLParser(const css::uno::Reference< css::uno::XComponentContext >&
#endif
#endif
- ::osl::MutexGuard aGuard(getMutex());
+ std::unique_lock aGuard(getMutex());
// Do we have to initialize the data?
if (s_nRefCount == 0)
{
@@ -1341,8 +1334,8 @@ OSQLParser::OSQLParser(const css::uno::Reference< css::uno::XComponentContext >&
s_pScanner->setScanner();
s_pGarbageCollector = new OSQLParseNodesGarbageCollector();
- if(!s_xLocaleData.is())
- s_xLocaleData = LocaleData::create(m_xContext);
+ if(!s_xLocaleData.get())
+ s_xLocaleData.set(LocaleData::create(m_xContext));
// reset to UNKNOWN_RULE
static_assert(OSQLParseNode::UNKNOWN_RULE==0, "UNKNOWN_RULE must be 0 for memset to 0 to work");
@@ -1354,109 +1347,109 @@ OSQLParser::OSQLParser(const css::uno::Reference< css::uno::XComponentContext >&
OString sRuleName; // the name of the rule ("select_statement")
} aRuleDescriptions[] =
{
- { OSQLParseNode::select_statement, "select_statement" },
- { OSQLParseNode::table_exp, "table_exp" },
- { OSQLParseNode::table_ref_commalist, "table_ref_commalist" },
- { OSQLParseNode::table_ref, "table_ref" },
- { OSQLParseNode::catalog_name, "catalog_name" },
- { OSQLParseNode::schema_name, "schema_name" },
- { OSQLParseNode::table_name, "table_name" },
- { OSQLParseNode::opt_column_commalist, "opt_column_commalist" },
- { OSQLParseNode::column_commalist, "column_commalist" },
- { OSQLParseNode::column_ref_commalist, "column_ref_commalist" },
- { OSQLParseNode::column_ref, "column_ref" },
- { OSQLParseNode::opt_order_by_clause, "opt_order_by_clause" },
- { OSQLParseNode::ordering_spec_commalist, "ordering_spec_commalist" },
- { OSQLParseNode::ordering_spec, "ordering_spec" },
- { OSQLParseNode::opt_asc_desc, "opt_asc_desc" },
- { 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" },
- { OSQLParseNode::opt_escape, "opt_escape" },
- { OSQLParseNode::test_for_null, "test_for_null" },
- { OSQLParseNode::scalar_exp_commalist, "scalar_exp_commalist" },
- { OSQLParseNode::scalar_exp, "scalar_exp" },
- { OSQLParseNode::parameter_ref, "parameter_ref" },
- { OSQLParseNode::parameter, "parameter" },
- { OSQLParseNode::general_set_fct, "general_set_fct" },
- { OSQLParseNode::range_variable, "range_variable" },
- { OSQLParseNode::column, "column" },
- { OSQLParseNode::delete_statement_positioned, "delete_statement_positioned" },
- { OSQLParseNode::delete_statement_searched, "delete_statement_searched" },
- { OSQLParseNode::update_statement_positioned, "update_statement_positioned" },
- { OSQLParseNode::update_statement_searched, "update_statement_searched" },
- { OSQLParseNode::assignment_commalist, "assignment_commalist" },
- { OSQLParseNode::assignment, "assignment" },
- { OSQLParseNode::values_or_query_spec, "values_or_query_spec" },
- { OSQLParseNode::insert_statement, "insert_statement" },
- { OSQLParseNode::insert_atom_commalist, "insert_atom_commalist" },
- { OSQLParseNode::insert_atom, "insert_atom" },
- { OSQLParseNode::from_clause, "from_clause" },
- { OSQLParseNode::qualified_join, "qualified_join" },
- { OSQLParseNode::cross_union, "cross_union" },
- { OSQLParseNode::select_sublist, "select_sublist" },
- { OSQLParseNode::derived_column, "derived_column" },
- { OSQLParseNode::column_val, "column_val" },
- { OSQLParseNode::set_fct_spec, "set_fct_spec" },
- { OSQLParseNode::boolean_term, "boolean_term" },
- { OSQLParseNode::boolean_primary, "boolean_primary" },
- { OSQLParseNode::num_value_exp, "num_value_exp" },
- { OSQLParseNode::join_type, "join_type" },
- { OSQLParseNode::position_exp, "position_exp" },
- { OSQLParseNode::extract_exp, "extract_exp" },
- { OSQLParseNode::length_exp, "length_exp" },
- { OSQLParseNode::char_value_fct, "char_value_fct" },
- { OSQLParseNode::odbc_call_spec, "odbc_call_spec" },
- { OSQLParseNode::in_predicate, "in_predicate" },
- { OSQLParseNode::existence_test, "existence_test" },
- { OSQLParseNode::unique_test, "unique_test" },
- { OSQLParseNode::all_or_any_predicate, "all_or_any_predicate" },
- { OSQLParseNode::named_columns_join, "named_columns_join" },
- { OSQLParseNode::join_condition, "join_condition" },
- { OSQLParseNode::joined_table, "joined_table" },
- { OSQLParseNode::boolean_factor, "boolean_factor" },
- { OSQLParseNode::sql_not, "sql_not" },
- { OSQLParseNode::manipulative_statement, "manipulative_statement" },
- { OSQLParseNode::subquery, "subquery" },
- { OSQLParseNode::value_exp_commalist, "value_exp_commalist" },
- { OSQLParseNode::odbc_fct_spec, "odbc_fct_spec" },
- { OSQLParseNode::union_statement, "union_statement" },
- { OSQLParseNode::outer_join_type, "outer_join_type" },
- { OSQLParseNode::char_value_exp, "char_value_exp" },
- { OSQLParseNode::term, "term" },
- { OSQLParseNode::value_exp_primary, "value_exp_primary" },
- { OSQLParseNode::value_exp, "value_exp" },
- { OSQLParseNode::selection, "selection" },
- { OSQLParseNode::fold, "fold" },
- { OSQLParseNode::char_substring_fct, "char_substring_fct" },
- { OSQLParseNode::factor, "factor" },
- { OSQLParseNode::base_table_def, "base_table_def" },
- { OSQLParseNode::base_table_element_commalist, "base_table_element_commalist" },
- { OSQLParseNode::data_type, "data_type" },
- { OSQLParseNode::column_def, "column_def" },
- { OSQLParseNode::table_node, "table_node" },
- { 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" },
- { OSQLParseNode::concatenation, "concatenation" },
- { OSQLParseNode::char_factor, "char_factor" },
- { OSQLParseNode::bit_value_fct, "bit_value_fct" },
- { OSQLParseNode::comparison_predicate_part_2, "comparison_predicate_part_2" },
- { OSQLParseNode::parenthesized_boolean_value_expression, "parenthesized_boolean_value_expression" },
- { OSQLParseNode::character_string_type, "character_string_type" },
- { OSQLParseNode::other_like_predicate_part_2, "other_like_predicate_part_2" },
- { OSQLParseNode::between_predicate_part_2, "between_predicate_part_2" },
- { OSQLParseNode::null_predicate_part_2, "null_predicate_part_2" },
- { OSQLParseNode::cast_spec, "cast_spec" },
- { OSQLParseNode::window_function, "window_function" }
+ { OSQLParseNode::select_statement, "select_statement"_ostr },
+ { OSQLParseNode::table_exp, "table_exp"_ostr },
+ { OSQLParseNode::table_ref_commalist, "table_ref_commalist"_ostr },
+ { OSQLParseNode::table_ref, "table_ref"_ostr },
+ { OSQLParseNode::catalog_name, "catalog_name"_ostr },
+ { OSQLParseNode::schema_name, "schema_name"_ostr },
+ { OSQLParseNode::table_name, "table_name"_ostr },
+ { OSQLParseNode::opt_column_commalist, "opt_column_commalist"_ostr },
+ { OSQLParseNode::column_commalist, "column_commalist"_ostr },
+ { OSQLParseNode::column_ref_commalist, "column_ref_commalist"_ostr },
+ { OSQLParseNode::column_ref, "column_ref"_ostr },
+ { OSQLParseNode::opt_order_by_clause, "opt_order_by_clause"_ostr },
+ { OSQLParseNode::ordering_spec_commalist, "ordering_spec_commalist"_ostr },
+ { OSQLParseNode::ordering_spec, "ordering_spec"_ostr },
+ { OSQLParseNode::opt_asc_desc, "opt_asc_desc"_ostr },
+ { OSQLParseNode::where_clause, "where_clause"_ostr },
+ { OSQLParseNode::opt_where_clause, "opt_where_clause"_ostr },
+ { OSQLParseNode::search_condition, "search_condition"_ostr },
+ { OSQLParseNode::comparison, "comparison"_ostr },
+ { OSQLParseNode::comparison_predicate, "comparison_predicate"_ostr },
+ { OSQLParseNode::between_predicate, "between_predicate"_ostr },
+ { OSQLParseNode::like_predicate, "like_predicate"_ostr },
+ { OSQLParseNode::opt_escape, "opt_escape"_ostr },
+ { OSQLParseNode::test_for_null, "test_for_null"_ostr },
+ { OSQLParseNode::scalar_exp_commalist, "scalar_exp_commalist"_ostr },
+ { OSQLParseNode::scalar_exp, "scalar_exp"_ostr },
+ { OSQLParseNode::parameter_ref, "parameter_ref"_ostr },
+ { OSQLParseNode::parameter, "parameter"_ostr },
+ { OSQLParseNode::general_set_fct, "general_set_fct"_ostr },
+ { OSQLParseNode::range_variable, "range_variable"_ostr },
+ { OSQLParseNode::column, "column"_ostr },
+ { OSQLParseNode::delete_statement_positioned, "delete_statement_positioned"_ostr },
+ { OSQLParseNode::delete_statement_searched, "delete_statement_searched"_ostr },
+ { OSQLParseNode::update_statement_positioned, "update_statement_positioned"_ostr },
+ { OSQLParseNode::update_statement_searched, "update_statement_searched"_ostr },
+ { OSQLParseNode::assignment_commalist, "assignment_commalist"_ostr },
+ { OSQLParseNode::assignment, "assignment"_ostr },
+ { OSQLParseNode::values_or_query_spec, "values_or_query_spec"_ostr },
+ { OSQLParseNode::insert_statement, "insert_statement"_ostr },
+ { OSQLParseNode::insert_atom_commalist, "insert_atom_commalist"_ostr },
+ { OSQLParseNode::insert_atom, "insert_atom"_ostr },
+ { OSQLParseNode::from_clause, "from_clause"_ostr },
+ { OSQLParseNode::qualified_join, "qualified_join"_ostr },
+ { OSQLParseNode::cross_union, "cross_union"_ostr },
+ { OSQLParseNode::select_sublist, "select_sublist"_ostr },
+ { OSQLParseNode::derived_column, "derived_column"_ostr },
+ { OSQLParseNode::column_val, "column_val"_ostr },
+ { OSQLParseNode::set_fct_spec, "set_fct_spec"_ostr },
+ { OSQLParseNode::boolean_term, "boolean_term"_ostr },
+ { OSQLParseNode::boolean_primary, "boolean_primary"_ostr },
+ { OSQLParseNode::num_value_exp, "num_value_exp"_ostr },
+ { OSQLParseNode::join_type, "join_type"_ostr },
+ { OSQLParseNode::position_exp, "position_exp"_ostr },
+ { OSQLParseNode::extract_exp, "extract_exp"_ostr },
+ { OSQLParseNode::length_exp, "length_exp"_ostr },
+ { OSQLParseNode::char_value_fct, "char_value_fct"_ostr },
+ { OSQLParseNode::odbc_call_spec, "odbc_call_spec"_ostr },
+ { OSQLParseNode::in_predicate, "in_predicate"_ostr },
+ { OSQLParseNode::existence_test, "existence_test"_ostr },
+ { OSQLParseNode::unique_test, "unique_test"_ostr },
+ { OSQLParseNode::all_or_any_predicate, "all_or_any_predicate"_ostr },
+ { OSQLParseNode::named_columns_join, "named_columns_join"_ostr },
+ { OSQLParseNode::join_condition, "join_condition"_ostr },
+ { OSQLParseNode::joined_table, "joined_table"_ostr },
+ { OSQLParseNode::boolean_factor, "boolean_factor"_ostr },
+ { OSQLParseNode::sql_not, "sql_not"_ostr },
+ { OSQLParseNode::manipulative_statement, "manipulative_statement"_ostr },
+ { OSQLParseNode::subquery, "subquery"_ostr },
+ { OSQLParseNode::value_exp_commalist, "value_exp_commalist"_ostr },
+ { OSQLParseNode::odbc_fct_spec, "odbc_fct_spec"_ostr },
+ { OSQLParseNode::union_statement, "union_statement"_ostr },
+ { OSQLParseNode::outer_join_type, "outer_join_type"_ostr },
+ { OSQLParseNode::char_value_exp, "char_value_exp"_ostr },
+ { OSQLParseNode::term, "term"_ostr },
+ { OSQLParseNode::value_exp_primary, "value_exp_primary"_ostr },
+ { OSQLParseNode::value_exp, "value_exp"_ostr },
+ { OSQLParseNode::selection, "selection"_ostr },
+ { OSQLParseNode::fold, "fold"_ostr },
+ { OSQLParseNode::char_substring_fct, "char_substring_fct"_ostr },
+ { OSQLParseNode::factor, "factor"_ostr },
+ { OSQLParseNode::base_table_def, "base_table_def"_ostr },
+ { OSQLParseNode::base_table_element_commalist, "base_table_element_commalist"_ostr },
+ { OSQLParseNode::data_type, "data_type"_ostr },
+ { OSQLParseNode::column_def, "column_def"_ostr },
+ { OSQLParseNode::table_node, "table_node"_ostr },
+ { OSQLParseNode::as_clause, "as_clause"_ostr },
+ { OSQLParseNode::opt_as, "opt_as"_ostr },
+ { OSQLParseNode::op_column_commalist, "op_column_commalist"_ostr },
+ { OSQLParseNode::table_primary_as_range_column, "table_primary_as_range_column"_ostr },
+ { OSQLParseNode::datetime_primary, "datetime_primary"_ostr },
+ { OSQLParseNode::concatenation, "concatenation"_ostr },
+ { OSQLParseNode::char_factor, "char_factor"_ostr },
+ { OSQLParseNode::bit_value_fct, "bit_value_fct"_ostr },
+ { OSQLParseNode::comparison_predicate_part_2, "comparison_predicate_part_2"_ostr },
+ { OSQLParseNode::parenthesized_boolean_value_expression, "parenthesized_boolean_value_expression"_ostr },
+ { OSQLParseNode::character_string_type, "character_string_type"_ostr },
+ { OSQLParseNode::other_like_predicate_part_2, "other_like_predicate_part_2"_ostr },
+ { OSQLParseNode::between_predicate_part_2, "between_predicate_part_2"_ostr },
+ { OSQLParseNode::null_predicate_part_2, "null_predicate_part_2"_ostr },
+ { OSQLParseNode::cast_spec, "cast_spec"_ostr },
+ { OSQLParseNode::window_function, "window_function"_ostr }
};
- const size_t nRuleMapCount = SAL_N_ELEMENTS( aRuleDescriptions );
+ const size_t nRuleMapCount = std::size( aRuleDescriptions );
// added a new rule? Adjust this map!
// +1 for UNKNOWN_RULE
static_assert(nRuleMapCount + 1 == static_cast<size_t>(OSQLParseNode::rule_count), "must be equal");
@@ -1483,7 +1476,7 @@ OSQLParser::OSQLParser(const css::uno::Reference< css::uno::XComponentContext >&
OSQLParser::~OSQLParser()
{
- ::osl::MutexGuard aGuard(getMutex());
+ std::unique_lock aGuard(getMutex());
OSL_ENSURE(s_nRefCount > 0, "OSQLParser::~OSQLParser() : suspicious call : has a refcount of 0 !");
if (!--s_nRefCount)
{
@@ -1493,8 +1486,6 @@ OSQLParser::~OSQLParser()
delete s_pGarbageCollector;
s_pGarbageCollector = nullptr;
- // Is only set the first time, so we should delete it only when there are no more instances
- s_xLocaleData = nullptr;
RuleIDMap().swap(s_aReverseRuleIDLookup);
}
@@ -1510,7 +1501,7 @@ void OSQLParseNode::substituteParameterNames(OSQLParseNode const * _pNode)
if(SQL_ISRULE(pChildNode,parameter) && pChildNode->count() > 1)
{
OSQLParseNode* pNewNode = new OSQLParseNode("?" ,SQLNodeType::Punctuation,0);
- delete pChildNode->replace(pChildNode->getChild(0),pNewNode);
+ pChildNode->replaceAndDelete(pChildNode->getChild(0), pNewNode);
sal_Int32 nChildCount = pChildNode->count();
for(sal_Int32 j=1;j < nChildCount;++j)
delete pChildNode->removeAt(1);
@@ -1611,11 +1602,11 @@ OSQLParseNode::OSQLParseNode(std::string_view _rNewValue,
OSL_ENSURE(m_eNodeType >= SQLNodeType::Rule && m_eNodeType <= SQLNodeType::Concat,"OSQLParseNode: created with invalid NodeType");
}
-OSQLParseNode::OSQLParseNode(const OUString &_rNewValue,
+OSQLParseNode::OSQLParseNode(OUString _aNewValue,
SQLNodeType eNewNodeType,
sal_uInt32 nNewNodeID)
:m_pParent(nullptr)
- ,m_aNodeValue(_rNewValue)
+ ,m_aNodeValue(std::move(_aNewValue))
,m_eNodeType(eNewNodeType)
,m_nNodeID(nNewNodeID)
{
@@ -1685,10 +1676,9 @@ OSQLParseNode::~OSQLParseNode()
{
}
-
void OSQLParseNode::append(OSQLParseNode* pNewNode)
{
- OSL_ENSURE(pNewNode != nullptr, "OSQLParseNode: invalid NewSubTree");
+ assert(pNewNode != nullptr && "OSQLParseNode: invalid NewSubTree");
OSL_ENSURE(pNewNode->getParent() == nullptr, "OSQLParseNode: Node is not an orphan");
OSL_ENSURE(std::none_of(m_aChildren.begin(), m_aChildren.end(),
[&] (std::unique_ptr<OSQLParseNode> const & r) { return r.get() == pNewNode; }),
@@ -1703,54 +1693,53 @@ void OSQLParseNode::append(OSQLParseNode* pNewNode)
bool OSQLParseNode::addDateValue(OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const
{
// special display for date/time values
- if (SQL_ISRULE(this,set_fct_spec) && SQL_ISPUNCTUATION(m_aChildren[0],"{"))
- {
- const OSQLParseNode* pODBCNode = m_aChildren[1].get();
- const OSQLParseNode* pODBCNodeChild = pODBCNode->m_aChildren[0].get();
+ if (!SQL_ISRULE(this,set_fct_spec) || !SQL_ISPUNCTUATION(m_aChildren[0],"{"))
+ return false;
- if (pODBCNodeChild->getNodeType() == SQLNodeType::Keyword && (
- SQL_ISTOKEN(pODBCNodeChild, D) ||
- SQL_ISTOKEN(pODBCNodeChild, T) ||
- SQL_ISTOKEN(pODBCNodeChild, TS) ))
- {
- OUString suQuote("'");
- if (rParam.bPredicate)
- {
- if (rParam.aMetaData.shouldEscapeDateTime())
- {
- suQuote = "#";
- }
- }
- else
- {
- if (rParam.aMetaData.shouldEscapeDateTime())
- {
- // suQuote = "'";
- return false;
- }
- }
+ const OSQLParseNode* pODBCNode = m_aChildren[1].get();
+ const OSQLParseNode* pODBCNodeChild = pODBCNode->m_aChildren[0].get();
- if (!rString.isEmpty())
- rString.append(" ");
- rString.append(suQuote);
- const OUString sTokenValue = pODBCNode->m_aChildren[1]->getTokenValue();
- if (SQL_ISTOKEN(pODBCNodeChild, D))
- {
- rString.append(rParam.bPredicate ? convertDateString(rParam, sTokenValue) : sTokenValue);
- }
- else if (SQL_ISTOKEN(pODBCNodeChild, T))
- {
- rString.append(rParam.bPredicate ? convertTimeString(rParam, sTokenValue) : sTokenValue);
- }
- else
- {
- rString.append(rParam.bPredicate ? convertDateTimeString(rParam, sTokenValue) : sTokenValue);
- }
- rString.append(suQuote);
- return true;
- }
+ if (pODBCNodeChild->getNodeType() != SQLNodeType::Keyword || !(
+ SQL_ISTOKEN(pODBCNodeChild, D) ||
+ SQL_ISTOKEN(pODBCNodeChild, T) ||
+ SQL_ISTOKEN(pODBCNodeChild, TS) ))
+ return false;
+
+ OUString suQuote("'");
+ if (rParam.bPredicate)
+ {
+ if (rParam.aMetaData.shouldEscapeDateTime())
+ {
+ suQuote = "#";
+ }
}
- return false;
+ else
+ {
+ if (rParam.aMetaData.shouldEscapeDateTime())
+ {
+ // suQuote = "'";
+ return false;
+ }
+ }
+
+ if (!rString.isEmpty())
+ rString.append(" ");
+ rString.append(suQuote);
+ const OUString sTokenValue = pODBCNode->m_aChildren[1]->getTokenValue();
+ if (SQL_ISTOKEN(pODBCNodeChild, D))
+ {
+ rString.append(rParam.bPredicate ? convertDateString(rParam, sTokenValue) : sTokenValue);
+ }
+ else if (SQL_ISTOKEN(pODBCNodeChild, T))
+ {
+ rString.append(rParam.bPredicate ? convertTimeString(rParam, sTokenValue) : sTokenValue);
+ }
+ else
+ {
+ rString.append(rParam.bPredicate ? convertDateTimeString(rParam, sTokenValue) : sTokenValue);
+ }
+ rString.append(suQuote);
+ return true;
}
void OSQLParseNode::replaceNodeValue(const OUString& rTableAlias, const OUString& rColumnName)
@@ -1844,10 +1833,11 @@ void OSQLParseNode::disjunctiveNormalForm(OSQLParseNode*& pSearchCondition)
OSQLParseNode* pNewRight = nullptr;
// cut right from parent
- pSearchCondition->removeAt(2);
+ OSQLParseNode* pOldRight = pSearchCondition->removeAt(2);
+ assert(pOldRight == pRight);
- pNewRight = MakeANDNode(pOr->removeAt(2) ,pRight);
- pNewLeft = MakeANDNode(pOr->removeAt(sal_uInt32(0)) ,new OSQLParseNode(*pRight));
+ pNewRight = MakeANDNode(pOr->removeAt(2), pOldRight);
+ pNewLeft = MakeANDNode(pOr->removeAt(sal_uInt32(0)), new OSQLParseNode(*pOldRight));
pNewNode = MakeORNode(pNewLeft,pNewRight);
// and append new Node
replaceAndReset(pSearchCondition,pNewNode);
@@ -1863,10 +1853,11 @@ void OSQLParseNode::disjunctiveNormalForm(OSQLParseNode*& pSearchCondition)
OSQLParseNode* pNewRight = nullptr;
// cut left from parent
- pSearchCondition->removeAt(sal_uInt32(0));
+ OSQLParseNode* pOldLeft = pSearchCondition->removeAt(sal_uInt32(0));
+ assert(pOldLeft == pLeft);
- pNewRight = MakeANDNode(pLeft,pOr->removeAt(2));
- pNewLeft = MakeANDNode(new OSQLParseNode(*pLeft),pOr->removeAt(sal_uInt32(0)));
+ pNewRight = MakeANDNode(pOldLeft, pOr->removeAt(2));
+ pNewLeft = MakeANDNode(new OSQLParseNode(*pOldLeft), pOr->removeAt(sal_uInt32(0)));
pNewNode = MakeORNode(pNewLeft,pNewRight);
// and append new Node
@@ -1874,9 +1865,9 @@ void OSQLParseNode::disjunctiveNormalForm(OSQLParseNode*& pSearchCondition)
disjunctiveNormalForm(pSearchCondition);
}
else if(SQL_ISRULE(pLeft,boolean_primary) && (!SQL_ISRULE(pLeft->getChild(1),search_condition) || !SQL_ISRULE(pLeft->getChild(1),boolean_term)))
- pSearchCondition->replace(pLeft, pLeft->removeAt(1));
+ pSearchCondition->replaceAndDelete(pLeft, pLeft->removeAt(1));
else if(SQL_ISRULE(pRight,boolean_primary) && (!SQL_ISRULE(pRight->getChild(1),search_condition) || !SQL_ISRULE(pRight->getChild(1),boolean_term)))
- pSearchCondition->replace(pRight, pRight->removeAt(1));
+ pSearchCondition->replaceAndDelete(pRight, pRight->removeAt(1));
}
}
@@ -1963,8 +1954,7 @@ void OSQLParseNode::negateSearchCondition(OSQLParseNode*& pSearchCondition, bool
assert(SQL_ISTOKEN(pNot,NOT));
pNotNot = new OSQLParseNode(OUString(),SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::sql_not));
}
- pComparison->replace(pNot, pNotNot);
- delete pNot;
+ pComparison->replaceAndDelete(pNot, pNotNot);
}
else
{
@@ -1993,8 +1983,7 @@ void OSQLParseNode::negateSearchCondition(OSQLParseNode*& pSearchCondition, bool
pNewComparison = new OSQLParseNode("=",SQLNodeType::Equal,SQL_EQUAL);
break;
}
- pSearchCondition->replace(pComparison, pNewComparison);
- delete pComparison;
+ pSearchCondition->replaceAndDelete(pComparison, pNewComparison);
}
}
@@ -2016,8 +2005,7 @@ void OSQLParseNode::negateSearchCondition(OSQLParseNode*& pSearchCondition, bool
assert(SQL_ISTOKEN(pNot,NOT));
pNotNot = new OSQLParseNode(OUString(),SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::sql_not));
}
- pPart2->replace(pNot, pNotNot);
- delete pNot;
+ pPart2->replaceAndDelete(pNot, pNotNot);
}
else if(bNegate && SQL_ISRULE(pSearchCondition,like_predicate))
{
@@ -2027,8 +2015,7 @@ void OSQLParseNode::negateSearchCondition(OSQLParseNode*& pSearchCondition, bool
pNotNot = new OSQLParseNode("NOT",SQLNodeType::Keyword,SQL_TOKEN_NOT);
else
pNotNot = new OSQLParseNode(OUString(),SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::sql_not));
- pSearchCondition->getChild( 1 )->replace(pNot, pNotNot);
- delete pNot;
+ pSearchCondition->getChild( 1 )->replaceAndDelete(pNot, pNotNot);
}
}
@@ -2364,7 +2351,7 @@ void OSQLParseNode::showParseTree( OUStringBuffer& _inout_rBuffer, sal_uInt32 nL
void OSQLParseNode::insert(sal_uInt32 nPos, OSQLParseNode* pNewSubTree)
{
- OSL_ENSURE(pNewSubTree != nullptr, "OSQLParseNode: invalid NewSubTree");
+ assert(pNewSubTree != nullptr && "OSQLParseNode: invalid NewSubTree");
OSL_ENSURE(pNewSubTree->getParent() == nullptr, "OSQLParseNode: Node is not an orphan");
// Create connection to getParent
@@ -2376,7 +2363,7 @@ void OSQLParseNode::insert(sal_uInt32 nPos, OSQLParseNode* pNewSubTree)
OSQLParseNode* OSQLParseNode::removeAt(sal_uInt32 nPos)
{
- OSL_ENSURE(nPos < m_aChildren.size(),"Illegal position for removeAt");
+ assert(nPos < m_aChildren.size() && "Illegal position for removeAt");
auto aPos(m_aChildren.begin() + nPos);
auto pNode = std::move(*aPos);
@@ -2389,27 +2376,24 @@ OSQLParseNode* OSQLParseNode::removeAt(sal_uInt32 nPos)
// Replace methods
-OSQLParseNode* OSQLParseNode::replace(OSQLParseNode* pOldSubNode, OSQLParseNode* pNewSubNode )
+void OSQLParseNode::replaceAndDelete(OSQLParseNode* pOldSubNode, OSQLParseNode* pNewSubNode )
{
- OSL_ENSURE(pOldSubNode != nullptr && pNewSubNode != nullptr, "OSQLParseNode: invalid nodes");
- OSL_ENSURE(pNewSubNode->getParent() == nullptr, "OSQLParseNode: node already has getParent");
- OSL_ENSURE(std::any_of(m_aChildren.begin(), m_aChildren.end(),
- [&] (std::unique_ptr<OSQLParseNode> const & r) { return r.get() == pOldSubNode; }),
- "OSQLParseNode::Replace() Node not element of parent");
- OSL_ENSURE(std::none_of(m_aChildren.begin(), m_aChildren.end(),
- [&] (std::unique_ptr<OSQLParseNode> const & r) { return r.get() == pNewSubNode; }),
- "OSQLParseNode::Replace() Node already element of parent");
+ assert(pOldSubNode != nullptr && pNewSubNode != nullptr && "OSQLParseNode: invalid nodes");
+ assert(pOldSubNode != pNewSubNode && "OSQLParseNode: same node");
+ assert(pNewSubNode->getParent() == nullptr && "OSQLParseNode: node already has getParent");
+ assert(std::any_of(m_aChildren.begin(), m_aChildren.end(),
+ [&] (std::unique_ptr<OSQLParseNode> const & r) { return r.get() == pOldSubNode; })
+ && "OSQLParseNode::Replace() Node not element of parent");
+ assert(std::none_of(m_aChildren.begin(), m_aChildren.end(),
+ [&] (std::unique_ptr<OSQLParseNode> const & r) { return r.get() == pNewSubNode; })
+ && "OSQLParseNode::Replace() Node already element of parent");
pOldSubNode->setParent( nullptr );
pNewSubNode->setParent( this );
auto it = std::find_if(m_aChildren.begin(), m_aChildren.end(),
[&pOldSubNode](const std::unique_ptr<OSQLParseNode>& rxChild) { return rxChild.get() == pOldSubNode; });
- if (it != m_aChildren.end())
- {
- it->release();
- it->reset(pNewSubNode);
- }
- return pOldSubNode;
+ assert(it != m_aChildren.end());
+ it->reset(pNewSubNode);
}
void OSQLParseNode::parseLeaf(OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const
@@ -2429,7 +2413,7 @@ void OSQLParseNode::parseLeaf(OUStringBuffer& rString, const SQLParseNodeParamet
case SQLNodeType::String:
if (!rString.isEmpty())
rString.append(" ");
- rString.append(SetQuotation(m_aNodeValue,"\'","\'\'"));
+ rString.append(SetQuotation(m_aNodeValue, u"\'", u"\'\'"));
break;
case SQLNodeType::Name:
if (!rString.isEmpty())
@@ -2473,7 +2457,7 @@ void OSQLParseNode::parseLeaf(OUStringBuffer& rString, const SQLParseNodeParamet
case SQLNodeType::ApproxNum:
{
OUString aTmp = m_aNodeValue;
- static OUString strPoint(".");
+ static constexpr OUString strPoint(u"."_ustr);
if (rParam.bInternational && rParam.bPredicate && rParam.sDecSep != strPoint)
aTmp = aTmp.replaceAll(strPoint, rParam.sDecSep);
@@ -2511,7 +2495,7 @@ void OSQLParseNode::parseLeaf(OUStringBuffer& rString, const SQLParseNodeParamet
sal_Int32 OSQLParser::getFunctionReturnType(std::u16string_view _sFunctionName, const IParseContext* pContext)
{
- sal_Int32 nType = DataType::VARCHAR;
+ sal_Int32 nType = DataType::SQLNULL;
OString sFunctionName(OUStringToOString(_sFunctionName,RTL_TEXTENCODING_UTF8));
if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ASCII,pContext))) nType = DataType::INTEGER;
@@ -2722,15 +2706,16 @@ OSQLParseNode::Rule OSQLParseNode::getKnownRuleID() const
OUString OSQLParseNode::getTableRange(const OSQLParseNode* _pTableRef)
{
- OSL_ENSURE(_pTableRef && _pTableRef->count() > 1 && _pTableRef->getKnownRuleID() == OSQLParseNode::table_ref,"Invalid node give, only table ref is allowed!");
+ assert(_pTableRef);
+ OSL_ENSURE(_pTableRef->count() > 1 && _pTableRef->getKnownRuleID() == OSQLParseNode::table_ref,"Invalid node give, only table ref is allowed!");
const sal_uInt32 nCount = _pTableRef->count();
OUString sTableRange;
if ( nCount == 2 || (nCount == 3 && !_pTableRef->getChild(0)->isToken()) )
{
const OSQLParseNode* pNode = _pTableRef->getChild(nCount - (nCount == 2 ? 1 : 2));
- OSL_ENSURE(pNode && (pNode->getKnownRuleID() == OSQLParseNode::table_primary_as_range_column
- || pNode->getKnownRuleID() == OSQLParseNode::range_variable)
- ,"SQL grammar changed!");
+ assert(pNode);
+ OSL_ENSURE(pNode->getKnownRuleID() == OSQLParseNode::table_primary_as_range_column ||
+ pNode->getKnownRuleID() == OSQLParseNode::range_variable, "SQL grammar changed!");
if ( !pNode->isLeaf() )
sTableRange = pNode->getChild(1)->getTokenValue();
} // if ( nCount == 2 || nCount == 3 )
@@ -2748,13 +2733,13 @@ OSQLParseNodesContainer::~OSQLParseNodesContainer()
void OSQLParseNodesContainer::push_back(OSQLParseNode* _pNode)
{
- ::osl::MutexGuard aGuard(m_aMutex);
+ std::unique_lock aGuard(m_aMutex);
m_aNodes.push_back(_pNode);
}
void OSQLParseNodesContainer::erase(OSQLParseNode* _pNode)
{
- ::osl::MutexGuard aGuard(m_aMutex);
+ std::unique_lock aGuard(m_aMutex);
if ( !m_aNodes.empty() )
{
std::vector< OSQLParseNode* >::iterator aFind = std::find(m_aNodes.begin(), m_aNodes.end(),_pNode);
@@ -2765,13 +2750,13 @@ void OSQLParseNodesContainer::erase(OSQLParseNode* _pNode)
void OSQLParseNodesContainer::clear()
{
- ::osl::MutexGuard aGuard(m_aMutex);
+ std::unique_lock aGuard(m_aMutex);
m_aNodes.clear();
}
void OSQLParseNodesContainer::clearAndDelete()
{
- ::osl::MutexGuard aGuard(m_aMutex);
+ std::unique_lock aGuard(m_aMutex);
// clear the garbage collector
while ( !m_aNodes.empty() )
{
@@ -2780,7 +2765,9 @@ void OSQLParseNodesContainer::clearAndDelete()
{
pNode = pNode->getParent();
}
+ aGuard.unlock(); // can call back into this object during destruction
delete pNode;
+ aGuard.lock();
}
}
} // namespace connectivity