44#include <rtl/ustrbuf.hxx>
46#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
47#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
48#include <com/sun/star/sdbc/SQLException.hpp>
49#include <com/sun/star/sdbc/XRow.hpp>
50#include <com/sun/star/sdbc/ColumnValue.hpp>
65using com::sun::star::uno::Any;
66using com::sun::star::uno::UNO_QUERY;
68using com::sun::star::uno::RuntimeException;
70using com::sun::star::sdbc::XRow;
71using com::sun::star::sdbc::XStatement;
72using com::sun::star::sdbc::XResultSet;
73using com::sun::star::sdbc::XDatabaseMetaData;
74using com::sun::star::sdbc::SQLException;
110 const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
111 const css::uno::Reference< css::sdbc::XConnection > & origin,
115 :
Container( refMutex, origin, pSettings,
"COLUMN" ),
116 m_schemaName(
std::move( schemaName )),
124 ReflectionBase *pBase,
const css::uno::Reference< css::sdbc::XRow > &xRow )
177 static const int DATA_TYPE = 5;
178 static const int TYPE_NAME = 6;
180 static const int DECIMAL_DIGITS = 9;
181 static const int IS_NULLABLE = 11;
182 static const int DESCRIPTION = 12;
186 OUString
typeName = xRow->getString( TYPE_NAME );
192 st.
TYPE,
Any( xRow->getInt( DATA_TYPE ) ) );
201 st.
SCALE,
Any( xRow->getInt( DECIMAL_DIGITS ) ) );
287 osl::MutexGuard guard(
m_xMutex->GetMutex() );
327 catch ( css::sdbc::SQLException & e )
330 throw css::lang::WrappedTargetRuntimeException( e.Message,
338 std::u16string_view schemaName,
342 const css::uno::Reference< css::beans::XPropertySet > & past,
343 const css::uno::Reference< css::beans::XPropertySet > & future)
369 OUStringBuffer buf( 128 );
370 if( ! pastColumnName.getLength())
373 buf.append(
"ALTER TABLE" );
375 buf.append(
"ADD COLUMN" );
377 buf.append( futureTypeName );
382 if( pastTypeName != futureTypeName )
385 "Can't modify column types, drop the column and create a new one" );
388 if( pastColumnName != futureColumnName )
390 buf.append(
"ALTER TABLE" );
392 buf.append(
"RENAME COLUMN" );
402 if( futureDefaultValue != pastDefaultValue )
405 buf.append(
"ALTER TABLE" );
407 buf.append(
"ALTER COLUMN" );
412 buf.append(
"SET DEFAULT " + futureDefaultValue );
419 if( futureNullable != pastNullable )
422 buf.append(
"ALTER TABLE" );
424 buf.append(
"ALTER COLUMN" );
426 if( futureNullable == css::sdbc::ColumnValue::NO_NULLS )
432 buf.append(
"DROP" );
434 buf.append(
" NOT NULL" );
446 if( futureComment != pastComment )
449 buf.append(
"COMMENT ON COLUMN" );
459 const css::uno::Reference< css::beans::XPropertySet >& future )
461 osl::MutexGuard guard(
m_xMutex->GetMutex() );
464 past->setPropertyValue( st.
IS_NULLABLE,
Any( css::sdbc::ColumnValue::NULLABLE ) );
495 osl::MutexGuard guard(
m_xMutex->GetMutex() );
498 throw css::lang::IndexOutOfBoundsException(
499 "COLUMNS: Index out of range (allowed 0 to "
500 + OUString::number(
m_values.size() -1)
501 +
", got " + OUString::number(
index ) +
")",
511 OUStringBuffer
update( 128 );
512 update.append(
"ALTER TABLE ONLY");
514 update.append(
"DROP COLUMN" );
518 stmt->executeUpdate(
update.makeStringAndClear() );
530 const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
531 const css::uno::Reference< css::sdbc::XConnection > & origin,
533 const OUString &schemaName,
538 refMutex, origin, pSettings, schemaName,
tableName );
539 (*ppColumns)->refresh();
546 const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
547 const css::uno::Reference< css::sdbc::XConnection > & origin,
549 :
Container( refMutex, origin, pSettings,
"COLUMN-DESCRIPTOR" )
ColumnDescriptors(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::XNameAccess > create(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &origin, ConnectionSettings *pSettings, const OUString &schemaName, const OUString &tableName, rtl::Reference< Columns > *pColumns)
virtual void SAL_CALL dropByIndex(sal_Int32 index) override
virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL createDataDescriptor() override
Columns(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &origin, ConnectionSettings *pSettings, OUString schemaName, OUString tableName)
virtual void SAL_CALL appendByDescriptor(const css::uno::Reference< css::beans::XPropertySet > &descriptor) override
virtual ~Columns() override
virtual void SAL_CALL refresh() override
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
void setPropertyValue_NoBroadcast_public(const OUString &name, const css::uno::Any &value)
void executeUpdate(const OUString &sql)
#define SAL_INFO(area, stream)
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)
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
void bufferQuoteConstant(OUStringBuffer &buf, std::u16string_view value, ConnectionSettings *settings)
void bufferQuoteQualifiedIdentifier(OUStringBuffer &buf, std::u16string_view schema, std::u16string_view table, ConnectionSettings *settings)
sal_Int32 extractIntProperty(const Reference< XPropertySet > &descriptor, const OUString &name)
static Any isAutoIncrement(std::u16string_view defaultValue)
std::unordered_map< OUString, sal_Int32 > String2IntMap
OUString sqltype2string(const Reference< XPropertySet > &desc)
OUString extractStringProperty(const Reference< XPropertySet > &descriptor, const OUString &name)
void bufferQuoteIdentifier(OUStringBuffer &buf, std::u16string_view toQuote, ConnectionSettings *settings)
OUString columnMetaData2SDBCX(ReflectionBase *pBase, const css::uno::Reference< css::sdbc::XRow > &xRow)
void alterColumnByDescriptor(std::u16string_view schemaName, std::u16string_view tableName, ConnectionSettings *settings, const Reference< XStatement > &stmt, const css::uno::Reference< css::beans::XPropertySet > &past, const css::uno::Reference< css::beans::XPropertySet > &future)
static Any isCurrency(std::u16string_view typeName)
constexpr sal_Int32 DEFAULT_VALUE
std::map< OUString, rtl::Reference< Entity > > map
OUString IS_AUTO_INCREMENT