24#include <osl/diagnose.h>
26#include <rtl/ustring.hxx>
28#include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
29#include <com/sun/star/sdbc/ResultSetType.hpp>
30#include <com/sun/star/sdbc/FetchDirection.hpp>
31#include <com/sun/star/lang/DisposedException.hpp>
38#include <sqlbison.hxx>
62EBookQuery * createTest( std::u16string_view aColumnName,
64 std::u16string_view aMatch )
70 eTest, sMatch.getStr() );
78 , m_xResultSet(nullptr)
81 , m_aSQLIterator( _pConnection, _pConnection->createCatalog()->getTables(), m_aParser )
82 , m_pParseTree(nullptr)
87 , m_nResultSetType(ResultSetType::FORWARD_ONLY)
88 , m_nFetchDirection(FetchDirection::FORWARD)
89 , m_nResultSetConcurrency(ResultSetConcurrency::UPDATABLE)
90 , m_bEscapeProcessing(true)
178 OCommonStatement_IBase::disposing();
183 Any aRet = OCommonStatement_IBase::queryInterface(rType);
185 aRet = ::comphelper::OPropertyContainer::queryInterface(rType);
195 return ::comphelper::concatSequences(
aTypes.getTypes(),OCommonStatement_IBase::getTypes());
210 ::osl::MutexGuard aGuard(
m_aMutex );
221 OUString sColumnName;
222 switch ( _rColumnRef.
count() )
229 && ( pColVal->
count() == 1 )
244 if ( !sColumnName.getLength() )
245 m_xConnection->throwGenericSQLException( STR_QUERY_TOO_COMPLEX, *
this );
261 for (
size_t i=0;
i<pOrderList->
count(); ++
i )
264 if ( !pOrderBy || !
SQL_ISRULE( pOrderBy, ordering_spec ) )
269 ( pColumnRef !=
nullptr )
270 && ( pAscDesc !=
nullptr )
276 "ordering_spec structure error" );
280 m_xConnection->throwGenericSQLException( STR_SORT_BY_COL_ONLY, *
this );
286 _out_rSort.push_back(
FieldSort( nField, bAscending ) );
298 if( parseTree->
count() == 3 &&
306 else if( (
SQL_ISRULE( parseTree, search_condition ) ||
308 parseTree->
count() == 3 )
312 "unexpected search_condition structure" );
324 else if(
SQL_ISRULE( parseTree, comparison_predicate ) )
347 m_xConnection->throwGenericSQLException( STR_QUERY_TOO_COMPLEX, *
this );
354 m_xConnection->throwGenericSQLException( STR_OPERATOR_TOO_COMPLEX, *
this );
365 return ( nLHS == nRHS ) ? createTrue() :
nullptr;
370 OUString aMatchString;
382 else if(
SQL_ISRULE( parseTree, like_predicate ) )
388 m_xConnection->throwGenericSQLException(STR_QUERY_INVALID_LIKE_COLUMN,*
this);
402 "connectivity.evoab2",
403 "analyseSQL : pAtom->count() = " << pAtom->
count());
404 m_xConnection->throwGenericSQLException(STR_QUERY_INVALID_LIKE_STRING,*
this);
412 if( aMatchString == OUStringChar(
WILDCARD) )
418 else if( aMatchString.indexOf(
WILDCARD ) == -1 )
420 SAL_INFO(
"connectivity.evoab2",
"Plain contains '" << aMatchString <<
"'" );
422 if( pResult && bNotLike )
428 m_xConnection->throwGenericSQLException(STR_QUERY_NOT_LIKE_TOO_COMPLEX,*
this);
430 else if( aMatchString.indexOf (
WILDCARD ) == aMatchString.lastIndexOf (
WILDCARD ) )
432 if ( aMatchString.startsWith(OUStringChar(
WILDCARD)) )
433 pResult = createTest(
435 else if ( aMatchString.indexOf (
WILDCARD ) == aMatchString.getLength() - 1 )
436 pResult = createTest( aColumnName,
E_BOOK_QUERY_BEGINS_WITH, aMatchString.subView( 0, aMatchString.getLength() - 1 ) );
438 m_xConnection->throwGenericSQLException(STR_QUERY_LIKE_WILDCARD,*
this);
440 else if( aMatchString.getLength() >= 3 &&
441 aMatchString.startsWith(OUStringChar(
WILDCARD)) &&
442 aMatchString.indexOf (
WILDCARD, 1) == aMatchString.getLength() - 1 ) {
444 pResult = createTest( aColumnName,
E_BOOK_QUERY_CONTAINS, aMatchString.subView (1, aMatchString.getLength() - 2) );
447 m_xConnection->throwGenericSQLException(STR_QUERY_LIKE_WILDCARD_MANY,*
this);
466 aCatalog,aSchema, aTableName,
nullptr );
474 if( !aTableName.getLength() )
478 OSL_FAIL(
"odd table layout" );
481 OSL_FAIL(
"unusual table layout" );
488 SAL_INFO(
"connectivity.evoab2",
"parsing " <<
sql );
501 if ( pOrderByClause )
503 #if OSL_DEBUG_LEVEL > 1
506 SAL_INFO(
"connectivity.evoab2",
"found order-by tree:\n" << sTreeDebug );
513 if ( pWhereClause &&
SQL_ISRULE( pWhereClause, where_clause ) )
515 #if OSL_DEBUG_LEVEL > 1
518 SAL_INFO(
"connectivity.evoab2",
"found where tree:\n" << sTreeDebug );
524 pQuery = createTrue();
531 _out_rQueryData.
setQuery( createTrue() );
538 ::osl::MutexGuard aGuard(
m_aMutex );
548 ::osl::MutexGuard aGuard(
m_aMutex );
552 return Any(SQLWarning());
558 ::osl::MutexGuard aGuard(
m_aMutex );
567 return new ::cppu::OPropertyArrayHelper( aProps );
578 OCommonStatement_IBase::acquire();
583 OCommonStatement_IBase::release();
592#if OSL_DEBUG_LEVEL > 1
594 g_message(
"Parsed SQL to sexpr '%s'\n", pSexpr );
598 if ( !
aData.getQuery() )
599 m_xConnection->throwGenericSQLException( STR_QUERY_TOO_COMPLEX, *
this );
603 if ( !
aData.xSelectColumns.is() )
604 m_xConnection->throwGenericSQLException( STR_QUERY_TOO_COMPLEX, *
this );
614 pResult->construct( _rQueryData );
624 SAL_INFO(
"connectivity.evoab2",
"OCommonStatement::impl_executeQuery_throw " << _rSql );
626#if OSL_DEBUG_LEVEL > 1
627 g_message(
"Parse SQL '%s'\n",
637 return ::cppu::OPropertySetHelper::createPropertySetInfo(
getInfoHelper() );
655 ::osl::MutexGuard aGuard(
m_aMutex );
665 ::osl::MutexGuard aGuard(
m_aMutex );
674 ::osl::MutexGuard aGuard(
m_aMutex );
EAPI_EXTERN EBookQuery *(* e_book_query_not)(EBookQuery *q, gboolean unref)
EAPI_EXTERN EContactField(* e_contact_field_id)(const char *field_name)
EAPI_EXTERN EBookQuery *(* e_book_query_field_test)(EContactField field, EBookQueryTest test, const char *value)
@ E_BOOK_QUERY_BEGINS_WITH
EAPI_EXTERN EBookQuery *(* e_book_query_from_string)(const char *query_string)
EAPI_EXTERN EBookQuery *(* e_book_query_and)(int nqs, EBookQuery **qs, gboolean unref)
EAPI_EXTERN char *(* e_book_query_to_string)(EBookQuery *q)
EAPI_EXTERN EBookQuery *(* e_book_query_or)(int nqs, EBookQuery **qs, gboolean unref)
::cppu::IPropertyArrayHelper * getArrayHelper()
void describeProperties(css::uno::Sequence< css::beans::Property > &_rProps) const
void registerProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void *_pPointerToMember, const css::uno::Type &_rMemberType)
@ ordering_spec_commalist
void showParseTree(OUString &rString) const
static OUString getTableRange(const OSQLParseNode *_pTableRef)
return a table range when it exists.
static bool getTableComponents(const OSQLParseNode *_pTableNode, css::uno::Any &_rCatalog, OUString &_rSchema, OUString &_rTable, const css::uno::Reference< css::sdbc::XDatabaseMetaData > &_xMetaData)
const OUString & getTokenValue() const
OSQLParseNode * getChild(sal_uInt32 nPos) const
OSQLParseNode * getByRule(OSQLParseNode::Rule eRule) const
SQLNodeType getNodeType() const
const ::rtl::Reference< OSQLColumns > & getSelectColumns() const
void setParseTree(const OSQLParseNode *pNewParseTree)
const OSQLParseNode * getOrderTree() const
const OSQLParseNode * getParseTree() const
static bool isTableNode(const OSQLParseNode *_pTableNode)
OSQLStatementType getStatementType() const
void traverseAll()
traverses the complete statement tree, and fills all our data with the information obatined during tr...
const OSQLParseNode * getWhereTree() const
std::unique_ptr< OSQLParseNode > parseTree(OUString &rErrorMessage, const OUString &rStatement, bool bInternational=false)
void orderByAnalysis(const OSQLParseNode *_pOrderByClause, SortDescriptor &_out_rSort)
connectivity::OSQLParseTreeIterator m_aSQLIterator
QueryData impl_getEBookQuery_throw(const OUString &_rSql)
will return the EBookQuery representing the statement WHERE condition, or throw
virtual void SAL_CALL acquire() noexcept override
sal_Int32 m_nMaxFieldSize
css::uno::Reference< css::sdbc::XConnection > impl_getConnection()
virtual ~OCommonStatement() override
virtual css::uno::Any SAL_CALL getWarnings() override
OUString impl_getColumnRefColumnName_throw(const ::connectivity::OSQLParseNode &_rColumnRef)
css::uno::WeakReference< css::sdbc::XResultSet > m_xResultSet
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
rtl::Reference< OEvoabConnection > m_xConnection
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual void SAL_CALL disposing() override
sal_Int32 m_nQueryTimeOut
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
virtual void SAL_CALL close() override
void parseSql(const OUString &sql, QueryData &_out_rQueryData)
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
sal_Int32 m_nResultSetConcurrency
virtual void SAL_CALL release() noexcept override
virtual void SAL_CALL clearWarnings() override
EBookQuery * whereAnalysis(const OSQLParseNode *parseTree)
sal_Int32 m_nResultSetType
OUString getTableName() const
OCommonStatement(OEvoabConnection *_pConnection)
connectivity::OSQLParser m_aParser
connectivity::OSQLParseNode * m_pParseTree
sal_Int32 m_nFetchDirection
css::uno::Reference< css::sdbc::XResultSet > impl_executeQuery_throw(const OUString &_rSql)
virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection() override
virtual sal_Int32 SAL_CALL executeUpdate(const OUString &sql) override
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery(const OUString &sql) override
mutable::osl::Mutex m_aMutex
#define ENSURE_OR_THROW(c, m)
#define SAL_INFO(area, stream)
constexpr OUStringLiteral aData
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
::cppu::WeakComponentImplHelper< css::sdbc::XWarningsSupplier, css::sdbc::XCloseable > OCommonStatement_IBase
IMPLEMENT_SERVICE_INFO(OStatement, "com.sun.star.comp.sdbcx.evoab.OStatement", "com.sun.star.sdbc.Statement")
std::vector< FieldSort > SortDescriptor
guint findEvoabField(std::u16string_view aColName)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(OHsqlConnection, OHsqlConnection_BASE, OConnectionWrapper)
void checkDisposed(bool _bThrow)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
Reference< XConnection > m_xConnection
#define PROPERTY_ID_RESULTSETTYPE
#define PROPERTY_ID_QUERYTIMEOUT
#define PROPERTY_ID_CURSORNAME
#define PROPERTY_ID_RESULTSETCONCURRENCY
#define PROPERTY_ID_MAXFIELDSIZE
#define PROPERTY_ID_FETCHSIZE
#define PROPERTY_ID_MAXROWS
#define PROPERTY_ID_ESCAPEPROCESSING
#define PROPERTY_ID_FETCHDIRECTION
#define SQL_ISRULE(pParseNode, eRule)
#define SQL_ISPUNCTUATION(pParseNode, aString)
#define SQL_ISTOKEN(pParseNode, token)
SortDescriptor aSortOrder
QueryFilterType eFilterType
void setQuery(EBookQuery *pQuery)