Mysql/MariaDB: tdf#81430 make tables editable (with or without PK)
Change-Id: I7df464107e692817ef80d887a4addea618d6cc72 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128356 Tested-by: Jenkins Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
This commit is contained in:
@@ -31,12 +31,12 @@ $(eval $(call gb_Library_add_libs,mysqlc,\
|
||||
$(eval $(call gb_Library_use_sdk_api,mysqlc))
|
||||
|
||||
$(eval $(call gb_Library_use_libraries,mysqlc,\
|
||||
comphelper \
|
||||
cppu \
|
||||
dbtools \
|
||||
cppuhelper \
|
||||
dbtools \
|
||||
sal \
|
||||
salhelper \
|
||||
comphelper \
|
||||
cppuhelper \
|
||||
))
|
||||
|
||||
$(eval $(call gb_Library_add_defs,mysqlc,\
|
||||
@@ -49,17 +49,26 @@ $(eval $(call gb_Library_add_defs,mysqlc,\
|
||||
))
|
||||
|
||||
$(eval $(call gb_Library_add_exception_objects,mysqlc,\
|
||||
connectivity/source/drivers/mysqlc/mysqlc_catalog \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_column \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_columns \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_connection \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_databasemetadata \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_driver \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_general \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_indexes \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_keys \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_preparedstatement \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_resultset \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_services \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_statement \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_table \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_tables \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_types \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_user \
|
||||
connectivity/source/drivers/mysqlc/mysqlc_users \
|
||||
))
|
||||
|
||||
$(eval $(call gb_Library_set_componentfile,mysqlc,connectivity/source/drivers/mysqlc/mysqlc,services))
|
||||
|
||||
@@ -549,6 +549,11 @@ OUString SAL_CALL OTableHelper::getName()
|
||||
return sComposedName;
|
||||
}
|
||||
|
||||
OUString OTableHelper::getTableName()
|
||||
{
|
||||
return m_Name;
|
||||
}
|
||||
|
||||
std::shared_ptr<sdbcx::KeyProperties> OTableHelper::getKeyProperties(const OUString& _sName) const
|
||||
{
|
||||
std::shared_ptr<sdbcx::KeyProperties> pKeyProps;
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||
*/
|
||||
|
||||
#include "mysqlc_catalog.hxx"
|
||||
#include "mysqlc_connection.hxx"
|
||||
#include "mysqlc_databasemetadata.hxx"
|
||||
#include <com/sun/star/sdbc/SQLException.hpp>
|
||||
|
||||
#include "mysqlc_driver.hxx"
|
||||
#include "mysqlc_statement.hxx"
|
||||
@@ -27,6 +29,10 @@
|
||||
|
||||
#include <com/sun/star/beans/NamedValue.hpp>
|
||||
|
||||
#include <comphelper/processfactory.hxx>
|
||||
#include <comphelper/servicehelper.hxx>
|
||||
#include <comphelper/storagehelper.hxx>
|
||||
|
||||
#include <osl/diagnose.h>
|
||||
#include <cppuhelper/supportsservice.hxx>
|
||||
|
||||
@@ -37,6 +43,7 @@ using namespace com::sun::star::container;
|
||||
using namespace com::sun::star::lang;
|
||||
using namespace com::sun::star::beans;
|
||||
using namespace com::sun::star::sdbc;
|
||||
using namespace com::sun::star::sdbcx;
|
||||
using ::osl::MutexGuard;
|
||||
|
||||
#define MYSQLC_URI_PREFIX "sdbc:mysqlc:"
|
||||
@@ -53,6 +60,7 @@ void lcl_executeUpdate(MYSQL* pMySql, const OString& sql)
|
||||
OConnection::OConnection(MysqlCDriver& _rDriver)
|
||||
: OMetaConnection_BASE(m_aMutex)
|
||||
, m_mysql()
|
||||
, m_xCatalog(nullptr)
|
||||
, m_xMetaData(nullptr)
|
||||
, m_xDriver(&_rDriver)
|
||||
{
|
||||
@@ -489,4 +497,36 @@ OUString OConnection::transFormPreparedStatement(const OUString& _sSQL)
|
||||
return sSqlStatement;
|
||||
}
|
||||
|
||||
//----- XUnoTunnel ----------------------------------------------------------
|
||||
// virtual
|
||||
sal_Int64 SAL_CALL OConnection::getSomething(const css::uno::Sequence<sal_Int8>& rId)
|
||||
{
|
||||
return comphelper::getSomethingImpl(rId, this);
|
||||
}
|
||||
|
||||
// static
|
||||
Sequence<sal_Int8> OConnection::getUnoTunnelId()
|
||||
{
|
||||
static const comphelper::UnoIdInit implId;
|
||||
return implId.getSeq();
|
||||
}
|
||||
|
||||
Reference<XTablesSupplier> OConnection::createCatalog()
|
||||
{
|
||||
MutexGuard aGuard(m_aMutex);
|
||||
|
||||
// m_xCatalog is a weak reference. Reuse it if it still exists.
|
||||
Reference<XTablesSupplier> xCatalog = m_xCatalog;
|
||||
if (xCatalog.is())
|
||||
{
|
||||
return xCatalog;
|
||||
}
|
||||
else
|
||||
{
|
||||
xCatalog = new Catalog(this);
|
||||
m_xCatalog = xCatalog;
|
||||
return m_xCatalog;
|
||||
}
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
@@ -35,8 +35,10 @@
|
||||
#include <com/sun/star/sdbc/XWarningsSupplier.hpp>
|
||||
#include <com/sun/star/util/XStringSubstitution.hpp>
|
||||
|
||||
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
|
||||
|
||||
#include <cppuhelper/basemutex.hxx>
|
||||
#include <cppuhelper/compbase3.hxx>
|
||||
#include <cppuhelper/compbase.hxx>
|
||||
#include <cppuhelper/weakref.hxx>
|
||||
#include <rtl/string.hxx>
|
||||
#include <rtl/ref.hxx>
|
||||
@@ -61,8 +63,8 @@ using ::com::sun::star::sdbc::SQLException;
|
||||
using ::com::sun::star::sdbc::SQLWarning;
|
||||
using ::com::sun::star::uno::RuntimeException;
|
||||
|
||||
typedef ::cppu::WeakComponentImplHelper3<css::sdbc::XConnection, css::sdbc::XWarningsSupplier,
|
||||
css::lang::XServiceInfo>
|
||||
typedef ::cppu::WeakComponentImplHelper<css::sdbc::XConnection, css::sdbc::XWarningsSupplier,
|
||||
css::lang::XUnoTunnel, css::lang::XServiceInfo>
|
||||
OMetaConnection_BASE;
|
||||
|
||||
struct ConnectionSettings
|
||||
@@ -93,6 +95,7 @@ private:
|
||||
|
||||
// Data attributes
|
||||
|
||||
css::uno::WeakReference<css::sdbcx::XTablesSupplier> m_xCatalog;
|
||||
css::uno::WeakReference<css::sdbc::XDatabaseMetaData> m_xMetaData;
|
||||
|
||||
OWeakRefArray m_aStatements; // vector containing a list
|
||||
@@ -115,6 +118,12 @@ public:
|
||||
|
||||
rtl_TextEncoding getConnectionEncoding() const { return m_settings.encoding; }
|
||||
|
||||
/**
|
||||
* Create and/or connect to the sdbcx Catalog. This is completely
|
||||
* unrelated to the SQL "Catalog".
|
||||
*/
|
||||
css::uno::Reference<css::sdbcx::XTablesSupplier> createCatalog();
|
||||
|
||||
// OComponentHelper
|
||||
virtual void SAL_CALL disposing() override;
|
||||
|
||||
@@ -125,6 +134,10 @@ public:
|
||||
|
||||
virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
|
||||
|
||||
// XUnoTunnel
|
||||
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence<sal_Int8>& rId) override;
|
||||
static css::uno::Sequence<sal_Int8> getUnoTunnelId();
|
||||
|
||||
// XConnection
|
||||
css::uno::Reference<css::sdbc::XStatement> SAL_CALL createStatement() override;
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ sal_Bool SAL_CALL ODatabaseMetaData::supportsNonNullableColumns() { return true;
|
||||
|
||||
OUString SAL_CALL ODatabaseMetaData::getCatalogTerm() { return "n/a"; }
|
||||
|
||||
OUString SAL_CALL ODatabaseMetaData::getIdentifierQuoteString() { return "\""; }
|
||||
OUString SAL_CALL ODatabaseMetaData::getIdentifierQuoteString() { return "`"; }
|
||||
|
||||
OUString SAL_CALL ODatabaseMetaData::getExtraNameCharacters() { return "#@"; }
|
||||
|
||||
@@ -806,7 +806,8 @@ Reference<XResultSet> SAL_CALL ODatabaseMetaData::getTables(const Any& /*catalog
|
||||
"IF(STRCMP(TABLE_TYPE,'BASE TABLE'), TABLE_TYPE, 'TABLE') AS TABLE_TYPE, TABLE_COMMENT AS "
|
||||
"REMARKS "
|
||||
"FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema', 'mysql', "
|
||||
"'performance_schema') AND TABLE_SCHEMA LIKE '?' AND TABLE_NAME LIKE '?' "
|
||||
"'performance_schema') AND TABLE_SCHEMA LIKE '?' AND CONCAT(TABLE_SCHEMA, '.', TABLE_NAME) "
|
||||
"LIKE '?' "
|
||||
};
|
||||
|
||||
if (types.getLength() == 1)
|
||||
|
||||
@@ -177,7 +177,7 @@ public:
|
||||
css::uno::Reference<css::sdbc::XResultSet> SAL_CALL getSchemas() override;
|
||||
css::uno::Reference<css::sdbc::XResultSet> SAL_CALL getCatalogs() override;
|
||||
css::uno::Reference<css::sdbc::XResultSet> SAL_CALL getTableTypes() override;
|
||||
css::uno::Reference<css::sdbc::XResultSet>
|
||||
virtual css::uno::Reference<css::sdbc::XResultSet>
|
||||
SAL_CALL getColumns(const Any& catalog, const OUString& schemaPattern,
|
||||
const OUString& tableNamePattern,
|
||||
const OUString& columnNamePattern) override;
|
||||
|
||||
@@ -23,9 +23,11 @@ using namespace css::uno;
|
||||
using namespace css::lang;
|
||||
using namespace css::beans;
|
||||
using namespace css::sdbc;
|
||||
using namespace css::sdbcx;
|
||||
using namespace connectivity::mysqlc;
|
||||
|
||||
#include <cppuhelper/supportsservice.hxx>
|
||||
#include <comphelper/servicehelper.hxx>
|
||||
|
||||
MysqlCDriver::MysqlCDriver(const Reference<XMultiServiceFactory>& _rxFactory)
|
||||
: ODriver_BASE(m_aMutex)
|
||||
@@ -59,7 +61,7 @@ OUString MysqlCDriver::getImplementationName_Static()
|
||||
|
||||
Sequence<OUString> MysqlCDriver::getSupportedServiceNames_Static()
|
||||
{
|
||||
return { "com.sun.star.sdbc.Driver" };
|
||||
return { "com.sun.star.sdbc.Driver", "com.sun.star.sdbcx.Driver" };
|
||||
}
|
||||
|
||||
OUString SAL_CALL MysqlCDriver::getImplementationName() { return getImplementationName_Static(); }
|
||||
@@ -113,6 +115,21 @@ sal_Int32 SAL_CALL MysqlCDriver::getMajorVersion() { return MARIADBC_VERSION_MAJ
|
||||
|
||||
sal_Int32 SAL_CALL MysqlCDriver::getMinorVersion() { return MARIADBC_VERSION_MINOR; }
|
||||
|
||||
Reference<XTablesSupplier>
|
||||
SAL_CALL MysqlCDriver::getDataDefinitionByConnection(const Reference<XConnection>& rConnection)
|
||||
{
|
||||
if (OConnection* pConnection = comphelper::getFromUnoTunnel<OConnection>(rConnection))
|
||||
return pConnection->createCatalog();
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference<XTablesSupplier> SAL_CALL
|
||||
MysqlCDriver::getDataDefinitionByURL(const OUString& rURL, const Sequence<PropertyValue>& rInfo)
|
||||
{
|
||||
Reference<XConnection> xConnection = connect(rURL, rInfo);
|
||||
return getDataDefinitionByConnection(xConnection);
|
||||
}
|
||||
|
||||
namespace connectivity::mysqlc
|
||||
{
|
||||
Reference<XInterface> MysqlCDriver_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
#include <com/sun/star/sdbc/XDriver.hpp>
|
||||
#include <com/sun/star/lang/XServiceInfo.hpp>
|
||||
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
||||
|
||||
#include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
|
||||
#include <cppuhelper/compbase.hxx>
|
||||
#include <cppuhelper/compbase2.hxx>
|
||||
#include <osl/module.h>
|
||||
|
||||
@@ -38,7 +39,9 @@ using css::uno::Sequence;
|
||||
Reference<css::uno::XInterface>
|
||||
MysqlCDriver_CreateInstance(const Reference<css::lang::XMultiServiceFactory>& _rxFactory);
|
||||
|
||||
typedef ::cppu::WeakComponentImplHelper2<css::sdbc::XDriver, css::lang::XServiceInfo> ODriver_BASE;
|
||||
typedef ::cppu::WeakComponentImplHelper<css::sdbc::XDriver, css::sdbcx::XDataDefinitionSupplier,
|
||||
css::lang::XServiceInfo>
|
||||
ODriver_BASE;
|
||||
|
||||
typedef void* (*OMysqlCConnection_CreateInstanceFunction)(void* _pDriver);
|
||||
|
||||
@@ -82,6 +85,12 @@ public:
|
||||
const Reference<css::lang::XMultiServiceFactory>& getFactory() const { return m_xFactory; }
|
||||
|
||||
static rtl_TextEncoding getDefaultEncoding() { return RTL_TEXTENCODING_UTF8; }
|
||||
|
||||
// XDataDefinitionSupplier
|
||||
virtual css::uno::Reference<css::sdbcx::XTablesSupplier> SAL_CALL getDataDefinitionByConnection(
|
||||
const css::uno::Reference<css::sdbc::XConnection>& rxConnection) override;
|
||||
virtual css::uno::Reference<css::sdbcx::XTablesSupplier> SAL_CALL getDataDefinitionByURL(
|
||||
const OUString& rsURL, const css::uno::Sequence<css::beans::PropertyValue>& rInfo) override;
|
||||
};
|
||||
|
||||
} /* connectivity::mysqlc */
|
||||
|
||||
@@ -20,14 +20,12 @@ using namespace ::com::sun::star::sdbc;
|
||||
|
||||
Indexes::Indexes(Table* pTable, Mutex& rMutex, const vector<OUString>& rVector)
|
||||
: OIndexesHelper(pTable, rMutex, rVector)
|
||||
, m_pTable(pTable)
|
||||
{
|
||||
}
|
||||
/* , m_pTable(pTable) */ {}
|
||||
|
||||
// XDrop
|
||||
void Indexes::dropObject(sal_Int32 /*nPosition*/, const OUString& sIndexName)
|
||||
void Indexes::dropObject(sal_Int32 /*nPosition*/, const OUString& /* sIndexName */)
|
||||
{
|
||||
// TODO IMPLEMENT ME
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
||||
|
||||
@@ -18,7 +18,8 @@ namespace connectivity::mysqlc
|
||||
class Indexes : public ::connectivity::OIndexesHelper
|
||||
{
|
||||
private:
|
||||
Table* m_pTable;
|
||||
// TODO: useful?
|
||||
// Table* m_pTable;
|
||||
|
||||
protected:
|
||||
// XDrop
|
||||
|
||||
@@ -32,8 +32,7 @@ Keys::Keys(Table* pTable, Mutex& rMutex, const ::std::vector<OUString>& rNames)
|
||||
//----- XDrop ----------------------------------------------------------------
|
||||
void Keys::dropObject(sal_Int32 nPosition, const OUString& sName)
|
||||
{
|
||||
// TODO IMPLEMENT ME (should we just copy from Firebird LO code below?)
|
||||
/*
|
||||
// TODO: implement (should we just copy from Firebird LO code below?)
|
||||
if (m_pTable->isNew())
|
||||
return;
|
||||
|
||||
@@ -44,12 +43,11 @@ void Keys::dropObject(sal_Int32 nPosition, const OUString& sName)
|
||||
const OUString sQuote
|
||||
= m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString();
|
||||
|
||||
OUString sSql("ALTER TABLE " + quoteName(sQuote, m_pTable->getName()) + " DROP CONSTRAINT "
|
||||
+ quoteName(sQuote, sName));
|
||||
OUString sSql("ALTER TABLE " + quoteName(sQuote, m_pTable->getTableName())
|
||||
+ " DROP CONSTRAINT " + quoteName(sQuote, sName));
|
||||
|
||||
m_pTable->getConnection()->createStatement()->execute(sSql);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "mysqlc_general.hxx"
|
||||
|
||||
#include <com/sun/star/sdbc/XRow.hpp>
|
||||
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
|
||||
|
||||
using namespace connectivity::mysqlc;
|
||||
using namespace com::sun::star::uno;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <sal/log.hxx>
|
||||
#include <comphelper/sequence.hxx>
|
||||
#include <comphelper/types.hxx>
|
||||
#include <connectivity/dbtools.hxx>
|
||||
|
||||
#include <com/sun/star/sdbc/ColumnValue.hpp>
|
||||
@@ -44,8 +45,9 @@ Table::Table(Tables* pTables, Mutex& rMutex, const uno::Reference<XConnection>&
|
||||
}
|
||||
|
||||
Table::Table(Tables* pTables, Mutex& rMutex, const uno::Reference<XConnection>& rConnection,
|
||||
const OUString& rName, const OUString& rType, const OUString& rDescription)
|
||||
: OTableHelper(pTables, rConnection, true, rName, rType, rDescription, "", "")
|
||||
const OUString& rCatalog, const OUString& rSchema, const OUString& rName,
|
||||
const OUString& rType, const OUString& rDescription)
|
||||
: OTableHelper(pTables, rConnection, true, rName, rType, rDescription, rSchema, rCatalog)
|
||||
, m_rMutex(rMutex)
|
||||
, m_nPrivileges(0)
|
||||
{
|
||||
@@ -83,8 +85,8 @@ OCollection* Table::createIndexes(const ::std::vector<OUString>& rNames)
|
||||
}
|
||||
|
||||
//----- XAlterTable -----------------------------------------------------------
|
||||
void SAL_CALL Table::alterColumnByName(const OUString& /* rColName */,
|
||||
const uno::Reference<XPropertySet>& /* rDescriptor */)
|
||||
void SAL_CALL Table::alterColumnByName(const OUString& rColName,
|
||||
const uno::Reference<XPropertySet>& rDescriptor)
|
||||
{
|
||||
MutexGuard aGuard(m_rMutex);
|
||||
checkDisposed(WeakComponentImplHelperBase::rBHelper.bDisposed);
|
||||
@@ -97,43 +99,53 @@ void SAL_CALL Table::alterColumnByName(const OUString& /* rColName */,
|
||||
// sdbcx::ColumnDescriptor
|
||||
const bool bTypeChanged
|
||||
= xColumn->getPropertyValue("Type") != rDescriptor->getPropertyValue("Type");
|
||||
const bool bTypeNameChanged
|
||||
= xColumn->getPropertyValue("TypeName") != rDescriptor->getPropertyValue("TypeName");
|
||||
const bool bTypeNameChanged = !comphelper::getString(xColumn->getPropertyValue("TypeName"))
|
||||
.equalsIgnoreAsciiCase(comphelper::getString(
|
||||
rDescriptor->getPropertyValue("TypeName")));
|
||||
const bool bPrecisionChanged
|
||||
= xColumn->getPropertyValue("Precision") != rDescriptor->getPropertyValue("Precision");
|
||||
const bool bScaleChanged
|
||||
= xColumn->getPropertyValue("Scale") != rDescriptor->getPropertyValue("Scale");
|
||||
|
||||
const bool bIsNullableChanged
|
||||
= xColumn->getPropertyValue("IsNullable") != rDescriptor->getPropertyValue("IsNullable");
|
||||
|
||||
const bool bIsAutoIncrementChanged = xColumn->getPropertyValue("IsAutoIncrement")
|
||||
!= rDescriptor->getPropertyValue("IsAutoIncrement");
|
||||
|
||||
// there's also DefaultValue but not related to database directly, it seems completely internal to LO
|
||||
// so no need to test it
|
||||
// TODO: remainder -- these are all "optional" so have to detect presence and change.
|
||||
|
||||
bool bDefaultChanged = xColumn->getPropertyValue("DefaultValue")
|
||||
!= rDescriptor->getPropertyValue("DefaultValue");
|
||||
|
||||
// TODO: tests to do
|
||||
if (bTypeChanged || bTypeNameChanged || bPrecisionChanged || bScaleChanged || bIsNullableChanged
|
||||
|| bIsAutoIncrementChanged || bDefaultChanged)
|
||||
if (bTypeChanged || bTypeNameChanged || bPrecisionChanged || bScaleChanged || bIsNullableChanged
|
||||
|| bIsAutoIncrementChanged)
|
||||
{
|
||||
// If bPrecisionChanged this will only succeed if we have increased the
|
||||
// precision, otherwise an exception is thrown -- however the base
|
||||
// gui then offers to delete and recreate the column.
|
||||
OUString sSql(getAlterTableColumn(rColName) + "TYPE "
|
||||
+ ::dbtools::createStandardTypePart(rDescriptor, getConnection()));
|
||||
getConnection()->createStatement()->execute(sSql);
|
||||
OUStringBuffer sSql(300);
|
||||
sSql.append("ALTER TABLE `" + getTableName() + "` MODIFY COLUMN `" + rColName + "` "
|
||||
+ ::dbtools::createStandardTypePart(rDescriptor, getConnection()));
|
||||
|
||||
if (comphelper::getBOOL(rDescriptor->getPropertyValue("IsAutoIncrement")))
|
||||
sSql.append(" auto_increment");
|
||||
|
||||
// see ColumnValue: NO_NULLS = 0, NULLABLE = 1, NULLABLE_UNKNOWN
|
||||
// so entry required = yes corresponds to NO_NULLS = 0 and only in this case
|
||||
// NOT NULL
|
||||
if (comphelper::getINT32(rDescriptor->getPropertyValue("IsNullable")) == 0)
|
||||
sSql.append(" NOT NULL");
|
||||
|
||||
getConnection()->createStatement()->execute(sSql.makeStringAndClear());
|
||||
// TODO: could cause errors e.g. if incompatible types, deal with them here as appropriate.
|
||||
// possibly we have to wrap things in Util::evaluateStatusVector.
|
||||
}
|
||||
|
||||
// TODO: tests to do
|
||||
// TODO: quote identifiers as needed.
|
||||
if (bNameChanged)
|
||||
{
|
||||
OUString sNewColName;
|
||||
rDescriptor->getPropertyValue("Name") >>= sNewColName;
|
||||
OUString sSql(getAlterTableColumn(rColName) + " TO \"" + sNewColName + "\"");
|
||||
OUString sSql("ALTER TABLE `" + getName() + "` RENAME COLUMN `" + rColName + "` TO `"
|
||||
+ sNewColName + "`");
|
||||
|
||||
getConnection()->createStatement()->execute(sSql);
|
||||
}
|
||||
@@ -142,10 +154,13 @@ void SAL_CALL Table::alterColumnByName(const OUString& /* rColName */,
|
||||
}
|
||||
|
||||
void SAL_CALL Table::alterColumnByIndex(
|
||||
sal_Int32 /* index */, const css::uno::Reference<css::beans::XPropertySet>& /* descriptor */)
|
||||
sal_Int32 index, const css::uno::Reference<css::beans::XPropertySet>& descriptor)
|
||||
{
|
||||
MutexGuard aGuard(m_rMutex);
|
||||
// TODO: implement
|
||||
uno::Reference<XPropertySet> xColumn(m_xColumns->getByIndex(index), UNO_QUERY_THROW);
|
||||
alterColumnByName(comphelper::getString(xColumn->getPropertyValue(
|
||||
OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),
|
||||
descriptor);
|
||||
}
|
||||
|
||||
// ----- XRename --------------------------------------------------------------
|
||||
@@ -163,13 +178,4 @@ Any SAL_CALL Table::queryInterface(const Type& rType)
|
||||
return OTableHelper::queryInterface(rType);
|
||||
}
|
||||
|
||||
// ----- XTypeProvider --------------------------------------------------------
|
||||
uno::Sequence<Type> SAL_CALL Table::getTypes() { return OTableHelper::getTypes(); }
|
||||
|
||||
OUString Table::getAlterTableColumn(std::u16string_view rColumn)
|
||||
{
|
||||
// TODO: test
|
||||
return ("ALTER TABLE \"" + getName() + "\" ALTER COLUMN \"" + rColumn + "\" ");
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
||||
|
||||
@@ -29,12 +29,6 @@ private:
|
||||
::osl::Mutex& m_rMutex;
|
||||
sal_Int32 m_nPrivileges;
|
||||
|
||||
/**
|
||||
* Get the ALTER TABLE [TABLE] ALTER [COLUMN] String.
|
||||
* Includes a trailing space.
|
||||
*/
|
||||
OUString getAlterTableColumn(std::u16string_view rColumn);
|
||||
|
||||
protected:
|
||||
void construct() override;
|
||||
|
||||
@@ -42,8 +36,9 @@ public:
|
||||
Table(Tables* pTables, ::osl::Mutex& rMutex,
|
||||
const css::uno::Reference<css::sdbc::XConnection>& _xConnection);
|
||||
Table(Tables* pTables, ::osl::Mutex& rMutex,
|
||||
const css::uno::Reference<css::sdbc::XConnection>& _xConnection, const OUString& rName,
|
||||
const OUString& rType, const OUString& rDescription);
|
||||
const css::uno::Reference<css::sdbc::XConnection>& _xConnection, const OUString& rCatalog,
|
||||
const OUString& rSchema, const OUString& rName, const OUString& rType,
|
||||
const OUString& rDescription);
|
||||
|
||||
// OTableHelper
|
||||
virtual ::connectivity::sdbcx::OCollection*
|
||||
@@ -70,9 +65,6 @@ public:
|
||||
|
||||
//XInterface
|
||||
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& rType) override;
|
||||
|
||||
//XTypeProvider
|
||||
virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override;
|
||||
};
|
||||
|
||||
} // namespace connectivity::mysqlc
|
||||
|
||||
@@ -54,6 +54,8 @@ ObjectType Tables::createObject(const OUString& rName)
|
||||
throw RuntimeException();
|
||||
|
||||
ObjectType xRet(new Table(this, m_rMutex, m_xMetaData->getConnection(),
|
||||
xRow->getString(1), // Catalog
|
||||
xRow->getString(2), // Schema
|
||||
xRow->getString(3), // Name
|
||||
xRow->getString(4), // Type
|
||||
xRow->getString(5))); // Description / Remarks / Comments
|
||||
|
||||
@@ -29,7 +29,7 @@ User::User(const css::uno::Reference<css::sdbc::XConnection>& rConnection, const
|
||||
{
|
||||
}
|
||||
|
||||
void User::changePassword(const OUString&, const OUString& newPassword)
|
||||
void User::changePassword(const OUString&, const OUString& /* newPassword */)
|
||||
{
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
@@ -148,6 +148,9 @@ namespace connectivity
|
||||
// XNamed
|
||||
virtual OUString SAL_CALL getName() override;
|
||||
|
||||
// To retrieve the table name only without the schema
|
||||
OUString getTableName();
|
||||
|
||||
// helper method to get key properties
|
||||
std::shared_ptr<sdbcx::KeyProperties> getKeyProperties(const OUString& _sName) const;
|
||||
void addKey(const OUString& _sName,const std::shared_ptr<sdbcx::KeyProperties>& _aKeyProperties);
|
||||
|
||||
Reference in New Issue
Block a user