[Libreoffice-commits] core.git: connectivity/source
Andrzej J.R. Hunt
andrzej at ahunt.org
Thu Aug 15 02:05:49 PDT 2013
connectivity/source/drivers/firebird/Table.cxx | 47 ++++++++++++++++++++-----
connectivity/source/drivers/firebird/Table.hxx | 6 +++
2 files changed, 44 insertions(+), 9 deletions(-)
New commits:
commit d3a002af12af0f4460ab2e3c5f957c69c096e3c2
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date: Thu Aug 15 09:16:36 2013 +0100
Implement altering of default value.
Change-Id: I531fbbc1e07bc686bf76103ccf7a5e1c47a72cf1
diff --git a/connectivity/source/drivers/firebird/Table.cxx b/connectivity/source/drivers/firebird/Table.cxx
index 1d96cd2..38b0bcb 100644
--- a/connectivity/source/drivers/firebird/Table.cxx
+++ b/connectivity/source/drivers/firebird/Table.cxx
@@ -83,20 +83,44 @@ void SAL_CALL Table::alterColumnByName(const OUString& rColName,
// sdbcx::Descriptor
bool bNameChanged = xColumn->getPropertyValue("Name") != rDescriptor->getPropertyValue("Name");
// sdbcx::ColumnDescriptor
-// bool bTypeChanged = xColumn->getPropertyValue("Type") != rDescriptor->getPropertyValue("Type");
-// bool bTypeNameChanged = xColumn->getPropertyValue("TypeName") != rDescriptor->getPropertyValue("TypeName");
-// bool bPrecisionChanged = xColumn->getPropertyValue("Precision") != rDescriptor->getPropertyValue("Precision");
-// bool bScaleChanged = xColumn->getPropertyValue("Scale") != rDescriptor->getPropertyValue("Scale");
-// bool bIsNullableChanged = xColumn->getPropertyValue("IsNullable") != rDescriptor->getPropertyValue("IsNullable");
-// bool bIsAutoIncrementChanged = xColumn->getPropertyValue("IsAutoIncrement") != rDescriptor->getPropertyValue("IsAutoIncrement");
- // TODO: remainder
+ bool bTypeChanged = xColumn->getPropertyValue("Type") != rDescriptor->getPropertyValue("Type");
+ bool bTypeNameChanged = xColumn->getPropertyValue("TypeName") != rDescriptor->getPropertyValue("TypeName");
+ bool bPrecisionChanged = xColumn->getPropertyValue("Precision") != rDescriptor->getPropertyValue("Precision");
+ bool bScaleChanged = xColumn->getPropertyValue("Scale") != rDescriptor->getPropertyValue("Scale");
+ bool bIsNullableChanged = xColumn->getPropertyValue("IsNullable") != rDescriptor->getPropertyValue("IsNullable");
+ bool bIsAutoIncrementChanged = xColumn->getPropertyValue("IsAutoIncrement") != rDescriptor->getPropertyValue("IsAutoIncrement");
+ // TODO: remainder -- these are all "optional" so have to detect presence and change.
+
+ bool bDefaultChanged = xColumn->getPropertyValue("DefaultValue")
+ != rDescriptor->getPropertyValue("DefaultValue");
if (bNameChanged)
{
OUString sNewTableName;
rDescriptor->getPropertyValue("Name") >>= sNewTableName;
- OUString sSql("ALTER TABLE \"" + getName() + "\" ALTER COLUMN \""
- + rColName + "\" TO \"" + sNewTableName + "\"");
+ OUString sSql(getAlterTableColumn(rColName)
+ + " TO \"" + sNewTableName + "\"");
+
+ getConnection()->createStatement()->execute(sSql);
+ }
+
+ if (bTypeChanged || bTypeNameChanged || bPrecisionChanged || bScaleChanged
+ || bIsNullableChanged || bIsAutoIncrementChanged)
+ {
+ // TODO: changeType
+ }
+
+ if (bDefaultChanged)
+ {
+ OUString sOldDefault, sNewDefault;
+ xColumn->getPropertyValue("DefaultValue") >>= sOldDefault;
+ rDescriptor->getPropertyValue("DefaultValue") >>= sNewDefault;
+
+ OUString sSql;
+ if (sNewDefault.isEmpty())
+ sSql = getAlterTableColumn(rColName) + "DROP DEFAULT";
+ else
+ sSql = getAlterTableColumn(rColName) + "SET DEFAULT " + sNewDefault;
getConnection()->createStatement()->execute(sSql);
}
@@ -140,4 +164,9 @@ uno::Sequence< Type > SAL_CALL Table::getTypes()
return OTableHelper::getTypes();
}
+
+OUString Table::getAlterTableColumn(const OUString& rColumn)
+{
+ return ("ALTER TABLE \"" + getName() + "\" ALTER COLUMN \"" + rColumn + "\" ");
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
diff --git a/connectivity/source/drivers/firebird/Table.hxx b/connectivity/source/drivers/firebird/Table.hxx
index 6ee5e36..ff9d183 100644
--- a/connectivity/source/drivers/firebird/Table.hxx
+++ b/connectivity/source/drivers/firebird/Table.hxx
@@ -28,6 +28,12 @@ namespace connectivity
private:
::osl::Mutex& m_rMutex;
+ /**
+ * Get the ALTER TABLE [TABLE] ALTER [COLUMN] String.
+ * Includes a trailing space.
+ */
+ ::rtl::OUString getAlterTableColumn(const ::rtl::OUString& rColumn);
+
public:
Table(Tables* pTables,
::osl::Mutex& rMutex,
More information about the Libreoffice-commits
mailing list