21#include <com/sun/star/sdbc/ColumnValue.hpp>
22#include <com/sun/star/sdbcx/Privilege.hpp>
23#include <com/sun/star/beans/PropertyAttribute.hpp>
40 const uno::Reference< XConnection >& rConnection):
52 const uno::Reference< XConnection >& rConnection,
53 const OUString& rName,
54 const OUString& rType,
55 const OUString& rDescription):
70void Table::construct()
72 OTableHelper::construct();
77 m_nPrivileges = Privilege::DROP |
78 Privilege::REFERENCE |
88 PropertyAttribute::READONLY,
93OCollection* Table::createColumns(const ::std::vector< OUString>& rNames)
100OCollection* Table::createKeys(const ::std::vector< OUString>& rNames)
102 return new Keys(
this,
107OCollection* Table::createIndexes(const ::std::vector< OUString>& rNames)
115void SAL_CALL Table::alterColumnByName(
const OUString& rColName,
116 const uno::Reference< XPropertySet >& rDescriptor)
118 MutexGuard aGuard(m_rMutex);
119 checkDisposed(WeakComponentImplHelperBase::rBHelper.bDisposed);
121 uno::Reference< XPropertySet >
xColumn(m_xColumns->getByName(rColName), UNO_QUERY);
124 const bool bNameChanged =
xColumn->getPropertyValue(
"Name") != rDescriptor->getPropertyValue(
"Name");
126 const bool bTypeChanged =
xColumn->getPropertyValue(
"Type") != rDescriptor->getPropertyValue(
"Type");
127 const bool bTypeNameChanged =
xColumn->getPropertyValue(
"TypeName") != rDescriptor->getPropertyValue(
"TypeName");
128 const bool bPrecisionChanged =
xColumn->getPropertyValue(
"Precision") != rDescriptor->getPropertyValue(
"Precision");
129 const bool bScaleChanged =
xColumn->getPropertyValue(
"Scale") != rDescriptor->getPropertyValue(
"Scale");
130 const bool bIsNullableChanged =
xColumn->getPropertyValue(
"IsNullable") != rDescriptor->getPropertyValue(
"IsNullable");
131 const bool bIsAutoIncrementChanged =
xColumn->getPropertyValue(
"IsAutoIncrement") != rDescriptor->getPropertyValue(
"IsAutoIncrement");
135 bool bDefaultChanged =
xColumn->getPropertyValue(
"DefaultValue")
136 != rDescriptor->getPropertyValue(
"DefaultValue");
138 if (bTypeChanged || bTypeNameChanged || bPrecisionChanged || bScaleChanged)
143 OUString sSql(getAlterTableColumn(rColName) +
"TYPE " +
150 if (bIsNullableChanged)
153 rDescriptor->getPropertyValue(
"IsNullable") >>=
nNullable;
155 if (nNullable != ColumnValue::NULLABLE_UNKNOWN)
161 if (nNullable == ColumnValue::NULLABLE)
163 sSql =
"UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = NULL "
164 "WHERE RDB$FIELD_NAME = '" + rColName +
"' "
165 "AND RDB$RELATION_NAME = '" + getName() +
"'";
167 else if (nNullable == ColumnValue::NO_NULLS)
171 OUString sFillNulls(
"UPDATE \"" + getName() +
"\" SET \""
172 + rColName +
"\" = 0 "
173 "WHERE \"" + rColName +
"\" IS NULL");
176 sSql =
"UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = 1 "
177 "WHERE RDB$FIELD_NAME = '" + rColName +
"' "
178 "AND RDB$RELATION_NAME = '" + getName() +
"'";
184 SAL_WARN(
"connectivity.firebird",
"Attempting to set Nullable to NULLABLE_UNKNOWN");
188 if (bIsAutoIncrementChanged)
191 "Changing autoincrement property of existing column is not supported",
192 ::dbtools::StandardSQLState::FUNCTION_NOT_SUPPORTED,
199 OUString sNewDefault;
200 rDescriptor->getPropertyValue(
"DefaultValue") >>= sNewDefault;
203 if (sNewDefault.isEmpty())
204 sSql = getAlterTableColumn(rColName) +
"DROP DEFAULT";
206 sSql = getAlterTableColumn(rColName) +
"SET DEFAULT " + sNewDefault;
213 OUString sNewColName;
214 rDescriptor->getPropertyValue(
"Name") >>= sNewColName;
215 OUString sSql(getAlterTableColumn(rColName)
216 +
" TO \"" + sNewColName +
"\"");
222 m_xColumns->refresh();
226void SAL_CALL Table::rename(
const OUString&)
232Any SAL_CALL Table::queryInterface(
const Type& rType)
234 if (rType.getTypeName() ==
"com.sun.star.sdbcx.XRename")
237 return OTableHelper::queryInterface(rType);
240OUString Table::getAlterTableColumn(std::u16string_view rColumn)
242 return (
"ALTER TABLE \"" + getName() +
"\" ALTER COLUMN \"" + rColumn +
"\" ");
#define SAL_WARN(area, stream)
void checkDisposed(bool _bThrow)
std::vector< OIndex > Indexes
#define PROPERTY_ID_PRIVILEGES