connectivity/Library_mysqlc.mk                        |   12 +--
 connectivity/source/drivers/mysqlc/mysqlc_catalog.cxx |   63 +++++++++++++++
 connectivity/source/drivers/mysqlc/mysqlc_catalog.hxx |   36 +++++++++
 connectivity/source/drivers/mysqlc/mysqlc_indexes.cxx |   33 ++++++++
 connectivity/source/drivers/mysqlc/mysqlc_indexes.hxx |   33 ++++++++
 connectivity/source/drivers/mysqlc/mysqlc_keys.cxx    |   55 +++++++++++++
 connectivity/source/drivers/mysqlc/mysqlc_keys.hxx    |   31 +++++++
 connectivity/source/drivers/mysqlc/mysqlc_user.cxx    |   55 +++++++++++++
 connectivity/source/drivers/mysqlc/mysqlc_user.hxx    |   45 +++++++++++
 connectivity/source/drivers/mysqlc/mysqlc_users.cxx   |   71 ++++++++++++++++++
 connectivity/source/drivers/mysqlc/mysqlc_users.hxx   |   47 +++++++++++
 11 files changed, 475 insertions(+), 6 deletions(-)

New commits:
commit 8dd86eb5602bed539da5ffb584e09847dbde4d60
Author:     Julien Nabet <serval2...@yahoo.fr>
AuthorDate: Sat Jan 8 22:16:11 2022 +0100
Commit:     Julien Nabet <serval2...@yahoo.fr>
CommitDate: Tue Jan 11 20:53:43 2022 +0100

    Mysql/MariaDB: add catalog+indexes+keys+user(s) skeleton part
    
    + sort objects in Library_mysqlc.mk
    
    Change-Id: Ide8ea46424b034c109670ee5514b0afebfa376aa
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128176
    Tested-by: Jenkins
    Reviewed-by: Julien Nabet <serval2...@yahoo.fr>

diff --git a/connectivity/Library_mysqlc.mk b/connectivity/Library_mysqlc.mk
index 9cbab05bd7a7..fa760adefebe 100644
--- a/connectivity/Library_mysqlc.mk
+++ b/connectivity/Library_mysqlc.mk
@@ -49,17 +49,17 @@ $(eval $(call gb_Library_add_defs,mysqlc,\
 ))
 
 $(eval $(call gb_Library_add_exception_objects,mysqlc,\
-       connectivity/source/drivers/mysqlc/mysqlc_driver \
-       connectivity/source/drivers/mysqlc/mysqlc_services \
        connectivity/source/drivers/mysqlc/mysqlc_connection \
-       connectivity/source/drivers/mysqlc/mysqlc_resultset \
+       connectivity/source/drivers/mysqlc/mysqlc_databasemetadata \
+       connectivity/source/drivers/mysqlc/mysqlc_driver \
+       connectivity/source/drivers/mysqlc/mysqlc_general \
        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_preparedstatement \
-       connectivity/source/drivers/mysqlc/mysqlc_databasemetadata \
        connectivity/source/drivers/mysqlc/mysqlc_types \
-       connectivity/source/drivers/mysqlc/mysqlc_general \
 ))
 
 $(eval $(call 
gb_Library_set_componentfile,mysqlc,connectivity/source/drivers/mysqlc/mysqlc,services))
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_catalog.cxx 
b/connectivity/source/drivers/mysqlc/mysqlc_catalog.cxx
new file mode 100644
index 000000000000..e9b7569fb1aa
--- /dev/null
+++ b/connectivity/source/drivers/mysqlc/mysqlc_catalog.cxx
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "mysqlc_catalog.hxx"
+#include "mysqlc_tables.hxx"
+#include "mysqlc_users.hxx"
+
+#include <com/sun/star/sdbc/XRow.hpp>
+
+using namespace ::connectivity::mysqlc;
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::sdbc;
+using namespace ::com::sun::star::uno;
+
+Catalog::Catalog(const uno::Reference<XConnection>& rConnection)
+    : OCatalog(rConnection)
+    , m_xConnection(rConnection)
+{
+}
+
+//----- OCatalog -------------------------------------------------------------
+void Catalog::refreshTables()
+{
+    uno::Reference<XResultSet> xTables = m_xMetaData->getTables(Any(), "%", 
"%", {});
+
+    if (!xTables.is())
+        return;
+
+    ::std::vector<OUString> aTableNames;
+
+    fillNames(xTables, aTableNames);
+
+    if (!m_pTables)
+        m_pTables.reset(new Tables(m_xConnection->getMetaData(), *this, 
m_aMutex, aTableNames));
+    else
+        m_pTables->reFill(aTableNames);
+}
+
+void Catalog::refreshViews()
+{
+    // TODO: implement me.
+    // Sets m_pViews (OCatalog)
+}
+
+//----- IRefreshableGroups ---------------------------------------------------
+void Catalog::refreshGroups()
+{
+    // TODO: implement me
+}
+
+//----- IRefreshableUsers ----------------------------------------------------
+void Catalog::refreshUsers()
+{
+    // TODO: implement me
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_catalog.hxx 
b/connectivity/source/drivers/mysqlc/mysqlc_catalog.hxx
new file mode 100644
index 000000000000..288367f38e33
--- /dev/null
+++ b/connectivity/source/drivers/mysqlc/mysqlc_catalog.hxx
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <sdbcx/VCatalog.hxx>
+
+namespace connectivity::mysqlc
+{
+class Catalog : public ::connectivity::sdbcx::OCatalog
+{
+    css::uno::Reference<css::sdbc::XConnection> m_xConnection;
+
+public:
+    explicit Catalog(const css::uno::Reference<css::sdbc::XConnection>& 
rConnection);
+
+    // OCatalog
+    virtual void refreshTables() override;
+    virtual void refreshViews() override;
+
+    // IRefreshableGroups
+    virtual void refreshGroups() override;
+
+    // IRefreshableUsers
+    virtual void refreshUsers() override;
+};
+
+} // namespace connectivity::mysqlc
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_indexes.cxx 
b/connectivity/source/drivers/mysqlc/mysqlc_indexes.cxx
new file mode 100644
index 000000000000..ef31e2f723fd
--- /dev/null
+++ b/connectivity/source/drivers/mysqlc/mysqlc_indexes.cxx
@@ -0,0 +1,33 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "mysqlc_indexes.hxx"
+
+using namespace ::connectivity;
+using namespace ::connectivity::mysqlc;
+
+using namespace ::osl;
+using namespace ::std;
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::sdbc;
+
+Indexes::Indexes(Table* pTable, Mutex& rMutex, const vector<OUString>& rVector)
+    : OIndexesHelper(pTable, rMutex, rVector)
+    , m_pTable(pTable)
+{
+}
+
+// XDrop
+void Indexes::dropObject(sal_Int32 /*nPosition*/, const OUString& sIndexName)
+{
+    // TODO IMPLEMENT ME
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_indexes.hxx 
b/connectivity/source/drivers/mysqlc/mysqlc_indexes.hxx
new file mode 100644
index 000000000000..c450c7bc2785
--- /dev/null
+++ b/connectivity/source/drivers/mysqlc/mysqlc_indexes.hxx
@@ -0,0 +1,33 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include "mysqlc_table.hxx"
+
+#include <connectivity/TIndexes.hxx>
+
+namespace connectivity::mysqlc
+{
+class Indexes : public ::connectivity::OIndexesHelper
+{
+private:
+    Table* m_pTable;
+
+protected:
+    // XDrop
+    void dropObject(sal_Int32 nPosition, const OUString& sIndexName);
+
+public:
+    Indexes(Table* pTable, ::osl::Mutex& rMutex, const std::vector<OUString>& 
rVector);
+};
+
+} // namespace connectivity::mysqlc
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_keys.cxx 
b/connectivity/source/drivers/mysqlc/mysqlc_keys.cxx
new file mode 100644
index 000000000000..4a65a377a7ce
--- /dev/null
+++ b/connectivity/source/drivers/mysqlc/mysqlc_keys.cxx
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "mysqlc_keys.hxx"
+#include "mysqlc_table.hxx"
+
+#include <connectivity/dbtools.hxx>
+
+using namespace ::connectivity;
+using namespace ::connectivity::mysqlc;
+
+using namespace ::dbtools;
+using namespace ::osl;
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::sdbc;
+using namespace ::com::sun::star::uno;
+
+Keys::Keys(Table* pTable, Mutex& rMutex, const ::std::vector<OUString>& rNames)
+    : OKeysHelper(pTable, rMutex, rNames)
+    , m_pTable(pTable)
+{
+}
+
+//----- XDrop ----------------------------------------------------------------
+void Keys::dropObject(sal_Int32 nPosition, const OUString& sName)
+{
+    // TODO IMPLEMENT ME (should we just copy from Firebird LO code below?)
+    /*
+    if (m_pTable->isNew())
+        return;
+
+    uno::Reference<XPropertySet> xKey(getObject(nPosition), UNO_QUERY);
+
+    if (xKey.is())
+    {
+        const OUString sQuote
+            = 
m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString();
+
+        OUString sSql("ALTER TABLE " + quoteName(sQuote, m_pTable->getName()) 
+ " 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: */
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_keys.hxx 
b/connectivity/source/drivers/mysqlc/mysqlc_keys.hxx
new file mode 100644
index 000000000000..b967b9387792
--- /dev/null
+++ b/connectivity/source/drivers/mysqlc/mysqlc_keys.hxx
@@ -0,0 +1,31 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <connectivity/TKeys.hxx>
+
+namespace connectivity::mysqlc
+{
+class Table;
+
+class Keys : public ::connectivity::OKeysHelper
+{
+private:
+    Table* m_pTable;
+
+public:
+    Keys(Table* pTable, ::osl::Mutex& rMutex, const ::std::vector<OUString>& 
rNames);
+
+    // OKeysHelper / XDrop
+    void dropObject(sal_Int32 nPosition, const OUString& sName) override;
+};
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_user.cxx 
b/connectivity/source/drivers/mysqlc/mysqlc_user.cxx
new file mode 100644
index 000000000000..4afe9cf76a75
--- /dev/null
+++ b/connectivity/source/drivers/mysqlc/mysqlc_user.cxx
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "mysqlc_user.hxx"
+
+using namespace ::connectivity;
+using namespace ::connectivity::mysqlc;
+using namespace ::connectivity::sdbcx;
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::sdbc;
+
+User::User(const css::uno::Reference<css::sdbc::XConnection>& rConnection)
+    : OUser(true) // Case Sensitive
+    , m_xConnection(rConnection)
+{
+}
+
+User::User(const css::uno::Reference<css::sdbc::XConnection>& rConnection, 
const OUString& rName)
+    : OUser(rName,
+            true) // Case Sensitive
+    , m_xConnection(rConnection)
+{
+}
+
+void User::changePassword(const OUString&, const OUString& newPassword)
+{
+    // TODO: implement
+}
+
+sal_Int32 User::getPrivileges(const OUString&, sal_Int32)
+{
+    // TODO: implement.
+    return 0;
+}
+
+sal_Int32 User::getGrantablePrivileges(const OUString&, sal_Int32)
+{
+    // TODO: implement.
+    return 0;
+}
+
+//----- IRefreshableGroups ----------------------------------------------------
+void User::refreshGroups()
+{
+    // TODO: implement.
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_user.hxx 
b/connectivity/source/drivers/mysqlc/mysqlc_user.hxx
new file mode 100644
index 000000000000..e9e37e3fac47
--- /dev/null
+++ b/connectivity/source/drivers/mysqlc/mysqlc_user.hxx
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <sdbcx/VUser.hxx>
+#include <com/sun/star/sdbc/XConnection.hpp>
+
+namespace connectivity::mysqlc
+{
+/**
+* This implements com.sun.star.sdbcx.Container.
+*/
+class User : public ::connectivity::sdbcx::OUser
+{
+    css::uno::Reference<css::sdbc::XConnection> m_xConnection;
+
+public:
+    /**
+    * Create a "new" descriptor, which isn't yet in the database.
+    */
+    User(const css::uno::Reference<css::sdbc::XConnection>& rConnection);
+    /**
+    * For a user that already exists in the db.
+    */
+    User(const css::uno::Reference<css::sdbc::XConnection>& rConnection, const 
OUString& rName);
+
+    // XAuthorizable
+    virtual void SAL_CALL changePassword(const OUString&, const OUString& 
newPassword) override;
+    virtual sal_Int32 SAL_CALL getPrivileges(const OUString&, sal_Int32) 
override;
+    virtual sal_Int32 SAL_CALL getGrantablePrivileges(const OUString&, 
sal_Int32) override;
+
+    // IRefreshableGroups::
+    virtual void refreshGroups() override;
+};
+
+} // namespace connectivity::mysqlc
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_users.cxx 
b/connectivity/source/drivers/mysqlc/mysqlc_users.cxx
new file mode 100644
index 000000000000..41fce5c395cd
--- /dev/null
+++ b/connectivity/source/drivers/mysqlc/mysqlc_users.cxx
@@ -0,0 +1,71 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "mysqlc_user.hxx"
+#include "mysqlc_users.hxx"
+
+using namespace ::connectivity;
+using namespace ::connectivity::mysqlc;
+using namespace ::connectivity::sdbcx;
+using namespace ::cppu;
+using namespace ::osl;
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::sdbc;
+using namespace ::com::sun::star::uno;
+
+Users::Users(const uno::Reference<XDatabaseMetaData>& rMetaData, OWeakObject& 
rParent,
+             Mutex& rMutex, ::std::vector<OUString> const& rNames)
+    : OCollection(rParent, true, rMutex, rNames)
+    , m_xMetaData(rMetaData)
+{
+}
+
+//----- OCollection -----------------------------------------------------------
+void Users::impl_refresh()
+{
+    // TODO: IMPLEMENT ME
+}
+
+ObjectType Users::createObject(const OUString& rName)
+{
+    return new User(m_xMetaData->getConnection(), rName);
+}
+
+uno::Reference<XPropertySet> Users::createDescriptor()
+{
+    // There is some internal magic so that the same class can be used as 
either
+    // a descriptor or as a normal user. See VUser.cxx for the details. In our
+    // case we just need to ensure we use the correct constructor.
+    return new User(m_xMetaData->getConnection());
+}
+
+//----- XAppend ---------------------------------------------------------------
+ObjectType Users::appendObject(const OUString& rName, const 
uno::Reference<XPropertySet>&)
+{
+    // TODO: set sSql as appropriate
+    m_xMetaData->getConnection()->createStatement()->execute(OUString());
+
+    return createObject(rName);
+}
+
+//----- XDrop -----------------------------------------------------------------
+void Users::dropObject(sal_Int32 nPosition, const OUString&)
+{
+    uno::Reference<XPropertySet> xUser(getObject(nPosition));
+
+    if (!ODescriptor::isNew(xUser))
+    {
+        // TODO: drop me
+    }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_users.hxx 
b/connectivity/source/drivers/mysqlc/mysqlc_users.hxx
new file mode 100644
index 000000000000..15b5cf6b43f7
--- /dev/null
+++ b/connectivity/source/drivers/mysqlc/mysqlc_users.hxx
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <connectivity/sdbcx/VCollection.hxx>
+#include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
+
+namespace connectivity::mysqlc
+{
+/**
+* This implements com.sun.star.sdbcx.Container.
+*/
+class Users : public ::connectivity::sdbcx::OCollection
+{
+    css::uno::Reference<css::sdbc::XDatabaseMetaData> m_xMetaData;
+
+protected:
+    // OCollection
+    virtual void impl_refresh() override;
+    virtual ::connectivity::sdbcx::ObjectType createObject(const OUString& 
rName) override;
+    virtual css::uno::Reference<css::beans::XPropertySet> createDescriptor() 
override;
+    virtual ::connectivity::sdbcx::ObjectType
+    appendObject(const OUString& rName,
+                 const css::uno::Reference<css::beans::XPropertySet>& 
rDescriptor) override;
+
+public:
+    Users(const css::uno::Reference<css::sdbc::XDatabaseMetaData>& rMetaData,
+          ::cppu::OWeakObject& rParent, ::osl::Mutex& rMutex,
+          ::std::vector<OUString> const& rNames);
+
+    // TODO: we should also implement XDataDescriptorFactory, XRefreshable,
+    // XAppend,  etc., but all are optional.
+
+    // XDrop
+    virtual void dropObject(sal_Int32 nPosition, const OUString& rName) 
override;
+};
+
+} // namespace connectivity::mysqlc
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to