43#include <rtl/ustrbuf.hxx>
44#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
45#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
46#include <com/sun/star/sdbc/SQLException.hpp>
47#include <com/sun/star/sdbc/XRow.hpp>
48#include <com/sun/star/sdbc/XParameters.hpp>
49#include <com/sun/star/sdbc/KeyRule.hpp>
50#include <com/sun/star/sdbcx/KeyType.hpp>
63using css::beans::XPropertySet;
65using com::sun::star::uno::Any;
66using com::sun::star::uno::UNO_QUERY;
70using com::sun::star::sdbc::XRow;
71using com::sun::star::sdbc::XStatement;
72using com::sun::star::sdbc::XResultSet;
73using com::sun::star::sdbc::XParameters;
74using com::sun::star::sdbc::XPreparedStatement;
80 const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
81 const css::uno::Reference< css::sdbc::XConnection > & origin,
86 m_schemaName(
std::move( schemaName )),
95 sal_Int32 ret = css::sdbcx::KeyType::UNIQUE;
97 ret = css::sdbcx::KeyType::PRIMARY;
98 else if (
type ==
u"f" )
99 ret = css::sdbcx::KeyType::FOREIGN;
105 sal_Int32 ret = css::sdbc::KeyRule::NO_ACTION;
107 ret = css::sdbc::KeyRule::RESTRICT;
108 else if( rule ==
u"c" )
109 ret = css::sdbc::KeyRule::CASCADE;
110 else if( rule ==
u"n" )
111 ret = css::sdbc::KeyRule::SET_NULL;
112 else if( rule ==
u"d" )
113 ret = css::sdbc::KeyRule::SET_DEFAULT;
123 osl::MutexGuard guard(
m_xMutex->GetMutex() );
138 "FROM pg_constraint INNER JOIN pg_class ON conrelid = pg_class.oid "
139 "INNER JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid "
140 "LEFT JOIN pg_class AS class2 ON confrelid = class2.oid "
141 "LEFT JOIN pg_namespace AS nmsp2 ON class2.relnamespace=nmsp2.oid "
142 "WHERE pg_class.relname = ? AND pg_namespace.nspname = ?" );
160 pKey->setPropertyValue_NoBroadcast_public(
161 st.
NAME,
Any( xRow->getString( 1 ) ) );
163 pKey->setPropertyValue_NoBroadcast_public( st.
TYPE,
Any( keyType ) );
164 pKey->setPropertyValue_NoBroadcast_public(
166 pKey->setPropertyValue_NoBroadcast_public(
168 pKey->setPropertyValue_NoBroadcast_public(
175 if( css::sdbcx::KeyType::FOREIGN == keyType )
177 OUString buf = xRow->getString( 6 ) +
"." + xRow->getString( 5 );
178 pKey->setPropertyValue_NoBroadcast_public(
183 pKey->setPropertyValue_NoBroadcast_public(
193 map[ xRow->getString( 1 ) ] = keyIndex;
200 catch ( css::sdbc::SQLException & e )
203 throw css::lang::WrappedTargetRuntimeException( e.Message,
212 const css::uno::Reference< css::beans::XPropertySet >& descriptor )
214 osl::MutexGuard guard(
m_xMutex->GetMutex() );
216 OUStringBuffer buf( 128 );
217 buf.append(
"ALTER TABLE " );
219 buf.append(
" ADD " );
224 stmt->executeUpdate( buf.makeStringAndClear() );
230 osl::MutexGuard guard(
m_xMutex->GetMutex() );
233 throw css::lang::IndexOutOfBoundsException(
234 "TABLES: Index out of range (allowed 0 to " + OUString::number(
m_values.size() -1)
235 +
", got " + OUString::number(
index ) +
")",
243 OUStringBuffer buf( 128 );
244 buf.append(
"ALTER TABLE " );
246 buf.append(
" DROP CONSTRAINT " );
248 m_origin->createStatement()->executeUpdate( buf.makeStringAndClear() );
261 const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
262 const css::uno::Reference< css::sdbc::XConnection > & origin,
264 const OUString & schemaName,
274 const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
275 const css::uno::Reference< css::sdbc::XConnection > & origin,
281 const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
282 const css::uno::Reference< css::sdbc::XConnection > & origin,
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
virtual void SAL_CALL dropByIndex(sal_Int32 index) override
std::vector< css::uno::Any > m_values
KeyDescriptors(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &origin, ConnectionSettings *pSettings)
virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL createDataDescriptor() override
static css::uno::Reference< css::container::XIndexAccess > create(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &origin, ConnectionSettings *pSettings)
virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL createDataDescriptor() override
Keys(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &origin, ConnectionSettings *pSettings, OUString schemaName, OUString tableName)
virtual void SAL_CALL refresh() override
virtual void SAL_CALL dropByIndex(sal_Int32 index) override
virtual void SAL_CALL appendByDescriptor(const css::uno::Reference< css::beans::XPropertySet > &descriptor) override
static css::uno::Reference< css::container::XIndexAccess > create(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &origin, ConnectionSettings *pSettings, const OUString &schemaName, const OUString &tableName)
#define SAL_INFO(area, stream)
void set(css::uno::UnoInterfaceReference const &value)
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)
css::uno::Sequence< sal_Int32 > string2intarray(const OUString &str)
std::unordered_map< OUString, sal_Int32 > String2IntMap
OUString extractStringProperty(const Reference< XPropertySet > &descriptor, const OUString &name)
Sequence< OUString > convertMappedIntArray2StringArray(const Int2StringMap &map, const Sequence< sal_Int32 > &intArray)
void bufferQuoteIdentifier(OUStringBuffer &buf, std::u16string_view toQuote, ConnectionSettings *settings)
static sal_Int32 string2keyrule(std::u16string_view rule)
static sal_Int32 string2keytype(std::u16string_view type)
std::unordered_map< sal_Int32, OUString > Int2StringMap
void bufferKey2TableConstraint(OUStringBuffer &buf, const Reference< XPropertySet > &key, ConnectionSettings *settings)
void fillAttnum2attnameMap(Int2StringMap &map, const Reference< css::sdbc::XConnection > &conn, const OUString &schema, const OUString &table)
std::map< OUString, rtl::Reference< Entity > > map
OUString PRIVATE_FOREIGN_COLUMNS
OUString REFERENCED_TABLE