38#include <rtl/ustrbuf.hxx>
39#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
40#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
41#include <com/sun/star/sdbc/SQLException.hpp>
42#include <com/sun/star/sdbc/XRow.hpp>
56using com::sun::star::uno::Any;
57using com::sun::star::uno::UNO_QUERY;
60using com::sun::star::container::NoSuchElementException;
62using com::sun::star::sdbc::XRow;
63using com::sun::star::sdbc::XStatement;
64using com::sun::star::sdbc::XResultSet;
70 const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
71 const css::uno::Reference< css::sdbc::XConnection > & origin,
83 osl::MutexGuard guard(
m_xMutex->GetMutex() );
89 "DISTINCT ON( pg_namespace.nspname, relname) "
90 "pg_namespace.nspname,"
92 "pg_get_viewdef(ev_class) "
93 "FROM pg_namespace, pg_class, pg_rewrite "
94 "WHERE pg_namespace.oid = relnamespace "
95 "AND pg_class.oid = ev_class "
96 "AND relkind=\'v\'" );
102 sal_Int32 viewIndex = 0;
106 OUString
table, schema, command;
107 schema = xRow->getString( 1 );
108 table = xRow->getString( 2 );
109 command = xRow->getString( 3 );
114 pView->setPropertyValue_NoBroadcast_public(st.
NAME ,
Any(
table) );
115 pView->setPropertyValue_NoBroadcast_public(st.
SCHEMA_NAME,
Any(schema) );
116 pView->setPropertyValue_NoBroadcast_public(st.
COMMAND,
Any(command) );
120 map[ schema +
"." +
table ] = viewIndex;
126 catch ( css::sdbc::SQLException & e )
129 throw css::lang::WrappedTargetRuntimeException( e.Message,
137 const css::uno::Reference< css::beans::XPropertySet >& descriptor )
139 osl::MutexGuard guard(
m_xMutex->GetMutex() );
142 OUString
name,schema,command;
143 descriptor->getPropertyValue( st.
SCHEMA_NAME ) >>= schema;
144 descriptor->getPropertyValue( st.
NAME ) >>=
name;
145 descriptor->getPropertyValue( st.
COMMAND ) >>= command;
149 OUStringBuffer buf( 128 );
151 buf.append(
"CREATE VIEW ");
153 buf.append(
" AS " + command );
155 stmt->executeUpdate( buf.makeStringAndClear() );
167 String2IntMap::const_iterator ii =
m_name2index.find( elementName );
170 throw css::container::NoSuchElementException(
171 "View " + elementName +
" is unknown, so it can't be dropped", *
this );
178 osl::MutexGuard guard(
m_xMutex->GetMutex() );
181 throw css::lang::IndexOutOfBoundsException(
182 "VIEWS: Index out of range (allowed 0 to " + OUString::number(
m_values.size() -1)
183 +
", got " + OUString::number(
index ) +
")",
190 OUString
name,schema;
196 stmt->executeUpdate(
"DROP VIEW \"" + schema +
"\".\"" +
name +
"\"" );
206 const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
207 const css::uno::Reference< css::sdbc::XConnection > & origin,
211 *ppViews =
new Views( refMutex, origin, pSettings );
212 (*ppViews)->refresh();
ConnectionSettings * m_pSettings
void fire(const EventBroadcastHelper &helper)
css::uno::Reference< css::sdbc::XConnection > m_origin
::rtl::Reference< comphelper::RefCountedMutex > m_xMutex
String2IntMap m_name2index
std::vector< css::uno::Any > m_values
virtual ~Views() override
virtual void SAL_CALL appendByDescriptor(const css::uno::Reference< css::beans::XPropertySet > &descriptor) override
virtual void SAL_CALL dropByName(const OUString &elementName) override
virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL createDataDescriptor() override
virtual void SAL_CALL dropByIndex(sal_Int32 index) override
Views(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &origin, ConnectionSettings *pSettings)
virtual void SAL_CALL refresh() override
static css::uno::Reference< css::container::XNameAccess > create(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &origin, ConnectionSettings *pSettings, rtl::Reference< Views > *ppViews)
void set(css::uno::UnoInterfaceReference const &value)
class SAL_NO_VTABLE XPropertySet
Any SAL_CALL getCaughtException()
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
void bufferQuoteQualifiedIdentifier(OUStringBuffer &buf, std::u16string_view schema, std::u16string_view table, ConnectionSettings *settings)
std::unordered_map< OUString, sal_Int32 > String2IntMap
void disposeNoThrow(const css::uno::Reference< css::uno::XInterface > &r)
std::map< OUString, rtl::Reference< Entity > > map
css::uno::Reference< css::container::XNameAccess > tables
rtl::Reference< Tables > pTablesImpl