26#include <core_resource.hxx>
31#include <osl/diagnose.h>
33#include <com/sun/star/sdbc/XConnection.hpp>
34#include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
35#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
36#include <com/sun/star/sdb/SQLContext.hpp>
42#include <com/sun/star/beans/PropertyAttribute.hpp>
43#include <com/sun/star/lang/XMultiServiceFactory.hpp>
57using namespace ::
cppu;
66 ,
const Reference< XConnection >& _rxConn
67 ,
const Reference< XComponentContext >& _xORB)
71 ,m_xCommandDefinition(_rxCommandDefinition)
73 ,m_pWarnings( nullptr )
85 ::comphelper::copyProperties(_rxCommandDefinition,
this);
96 OSL_ENSURE(
m_xConnection.is(),
"OQuery::OQuery : invalid connection !");
106 return css::uno::Sequence<sal_Int8>();
111 return ::comphelper::concatSequences(
113 ODataSettings::getTypes( ),
114 OContentHelper::getTypes( )
122 OSL_PRECOND( getColumnCount() == 0,
"OQuery::rebuildColumns: column container should be empty!" );
127 m_pColumnMediator =
nullptr;
129 Reference<XColumnsSupplier> xColSup(m_xCommandDefinition,UNO_QUERY);
130 Reference< XNameAccess > xColumnDefinitions;
133 xColumnDefinitions = xColSup->getColumns();
134 if ( xColumnDefinitions.is() )
140 SharedUNOComponent< XSingleSelectQueryComposer, DisposableComponent > xComposer(
143 Reference< XNameAccess > xColumns;
144 Reference< XIndexAccess > xColumnsIndexed;
147 xComposer->setQuery( m_sCommand );
148 Reference< XColumnsSupplier > xCols( xComposer, UNO_QUERY_THROW );
149 xColumns.set( xCols->getColumns(), UNO_SET_THROW );
150 xColumnsIndexed.set( xColumns, UNO_QUERY_THROW );
152 catch(
const SQLException& ) { }
154 SharedUNOComponent< XPreparedStatement, DisposableComponent > xPreparedStatement;
155 if ( !xColumns.is() || ( xColumnsIndexed->getCount() == 0 ) )
157 xPreparedStatement.set(
m_xConnection->prepareStatement( m_sCommand ), UNO_QUERY_THROW );
158 Reference< XResultSetMetaDataSupplier > xResMetaDataSup( xPreparedStatement, UNO_QUERY_THROW );
159 Reference< XResultSetMetaData > xResultSetMeta( xResMetaDataSup->getMetaData() );
160 if ( !xResultSetMeta.is() )
162 OUString sError(
DBA_RES( RID_STR_STATEMENT_WITHOUT_RESULT_SET ) );
163 ::dbtools::throwSQLException( sError, StandardSQLState::GENERAL_ERROR, *
this );
166 Reference< XDatabaseMetaData > xDBMeta(
m_xConnection->getMetaData(), UNO_SET_THROW );
170 aParseColumns, xDBMeta->supportsMixedCaseQuotedIdentifiers(), *
this,
m_aMutex ).release();
171 if ( !xColumns.is() )
175 const Sequence<OUString>
aColNames = xColumns->getElementNames();
176 for (
const OUString& rName :
aColNames )
178 Reference<XPropertySet> xSource(xColumns->getByName( rName ),UNO_QUERY);
179 OUString sLabel = rName;
180 if ( xColumnDefinitions.is() && xColumnDefinitions->hasByName(rName) )
182 Reference<XPropertySet> xCommandColumn(xColumnDefinitions->getByName( rName ),UNO_QUERY);
186 pColumn->setParent( *
this );
188 implAppendColumn( rName, pColumn.get() );
189 Reference< XPropertySet > xDest( *pColumn, UNO_QUERY_THROW );
190 if ( m_pColumnMediator.is() )
191 m_pColumnMediator->notifyElementCreated( rName, xDest );
194 catch(
const SQLContext& e )
197 m_pWarnings->appendWarning( e );
199 catch(
const SQLWarning& e )
202 m_pWarnings->appendWarning( e );
204 catch(
const SQLException& e )
207 m_pWarnings->appendWarning( e );
218 return "com.sun.star.sdb.dbaccess.OQuery";
223 for (
const OUString& s : aSupported)
224 if (s == _rServiceName)
237 sal_Int32 nOwnHandle = -1;
241 OSL_ENSURE(_rSource.Source.get() == Reference< XInterface >(
m_xCommandDefinition, UNO_QUERY).get(),
242 "OQuery::propertyChange : where did this call come from ?");
252 nOwnHandle = aOwnProp.Handle;
260 OSL_FAIL(
"OQuery::propertyChange : my CommandDefinition has more properties than I do !");
264 fire(&nOwnHandle, &_rSource.NewValue, &_rSource.OldValue, 1,
false);
271 OSL_ENSURE(_rSource.Source.get() == Reference< XInterface >(
m_xCommandDefinition, UNO_QUERY).get(),
272 "OQuery::disposing : where did this call come from ?");
301 OUString sAggPropName;
303 if (
getInfoHelper().fillPropertyMembersByHandle(&sAggPropName,&nAttr,_nHandle) &&
330 Sequence< Property > aProps;
333 return new ::cppu::OPropertyArrayHelper(aProps);
345 OSL_ENSURE(xRename.is(),
"No XRename interface!");
378 return "application/vnd.org.openoffice.DatabaseQuery";
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)
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
static ::rtl::Reference< OSQLColumns > createColumnsForResultSet(const css::uno::Reference< css::sdbc::XResultSetMetaData > &_rxResMetaData, const css::uno::Reference< css::sdbc::XDatabaseMetaData > &_rxDBMetaData, const css::uno::Reference< css::container::XNameAccess > &i_xQueryColumns)
mutable::osl::Mutex m_aMutex
virtual css::beans::Property SAL_CALL getPropertyByName(const ::rtl::OUString &rPropertyName)=0
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
css::uno::Sequence< css::beans::PropertyValue > m_aLayoutInformation
OUString m_sUpdateSchemaName
OUString m_sUpdateTableName
OUString m_sUpdateCatalogName
void registerPropertiesFor(ODataSettings_Base *_pItem)
register the properties from the param given.
static std::unique_ptr< OPrivateColumns > createWithIntrinsicNames(const ::rtl::Reference< ::connectivity::OSQLColumns > &_rColumns, bool _bCase, ::cppu::OWeakObject &_rParent, ::osl::Mutex &_rMutex)
creates a columns instance as above, but taking the names from the columns itself
a column of a Query, with additional information obtained from parsing the query statement
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
void setColumnsOutOfDate(bool _bOutOfDate=true)
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent &evt) override
::dbtools::WarningsContainer * m_pWarnings
virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL createDataDescriptor() override
AggregateAction m_eDoingCurrently
void registerProperties()
css::uno::Reference< css::beans::XPropertySetInfo > m_xCommandPropInfo
virtual OUString determineContentType() const override
::cppu::IPropertyArrayHelper * getArrayHelper()
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
virtual void SAL_CALL disposing() override
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
OQuery(const css::uno::Reference< css::beans::XPropertySet > &_rxCommandDefinition, const css::uno::Reference< css::sdbc::XConnection > &_rxConn, const css::uno::Reference< css::uno::XComponentContext > &_xORB)
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual ~OQuery() override
virtual void SAL_CALL rename(const OUString &newName) override
css::uno::Reference< css::sdbc::XConnection > m_xConnection
virtual rtl::Reference< OColumn > createColumn(const OUString &_rName) const override
creates an OColumn object which should represent the column with a given name
css::uno::Reference< css::beans::XPropertySet > m_xCommandDefinition
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
Reference< XSingleServiceFactory > xFactory
OUString newName(std::u16string_view aNewPrefix, std::u16string_view aOldPrefix, std::u16string_view old_Name)
std::shared_ptr< T > make_shared(Args &&... args)
Reference< XConnection > m_xConnection
const Color aColNames[SC_RANGECOLORS]
#define PROPERTY_ID_ESCAPE_PROCESSING
#define PROPERTY_ID_UPDATE_CATALOGNAME
#define PROPERTY_ID_UPDATE_SCHEMANAME
#define PROPERTY_ID_COMMAND
#define PROPERTY_ID_UPDATE_TABLENAME
#define PROPERTY_ID_LAYOUTINFORMATION
constexpr OUStringLiteral PROPERTY_COMMAND(u"Command")
constexpr OUStringLiteral PROPERTY_UPDATE_TABLENAME(u"UpdateTableName")
constexpr OUStringLiteral PROPERTY_LABEL(u"Label")
constexpr OUStringLiteral PROPERTY_UPDATE_SCHEMANAME(u"UpdateSchemaName")
constexpr OUStringLiteral SERVICE_NAME_SINGLESELECTQUERYCOMPOSER
constexpr OUStringLiteral SERVICE_SDB_QUERY
constexpr OUStringLiteral PROPERTY_ESCAPE_PROCESSING(u"EscapeProcessing")
constexpr OUStringLiteral SERVICE_SDB_DATASETTINGS
constexpr OUStringLiteral PROPERTY_NAME(u"Name")
constexpr OUStringLiteral PROPERTY_UPDATE_CATALOGNAME(u"UpdateCatalogName")
constexpr OUStringLiteral PROPERTY_LAYOUTINFORMATION(u"LayoutInformation")
#define IMPLEMENT_FORWARD_XINTERFACE3(classname, refcountbase, baseclass2, baseclass3)