connectivity/source/drivers/mysqlc/mysqlc_catalog.hxx |    2 
 connectivity/source/drivers/mysqlc/mysqlc_tables.cxx  |   54 ++++++++++++------
 connectivity/source/drivers/mysqlc/mysqlc_tables.hxx  |    9 ++-
 connectivity/source/drivers/mysqlc/mysqlc_views.cxx   |    9 +++
 4 files changed, 54 insertions(+), 20 deletions(-)

New commits:
commit eb69767d7c1bb8e6e780fd9503f08c9d7f5ecb45
Author:     Julien Nabet <serval2...@yahoo.fr>
AuthorDate: Tue Jan 25 19:22:42 2022 +0100
Commit:     Julien Nabet <serval2...@yahoo.fr>
CommitDate: Tue Jan 25 21:07:26 2022 +0100

    Mysql/MariaDB: after creating a view then refresh, make it appear as a view
    
    For this, I took example on hsqldb part this time (instead of Firebird 
which is uncomplete).
    
    Also, deleting a brand new created table works now.
    
    Of course, there are still pb with schema containing special characters 
like "`"
    
    Change-Id: I4849f412ed5b3c2f35fbb4caaf06577828cc255a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128943
    Tested-by: Jenkins
    Reviewed-by: Julien Nabet <serval2...@yahoo.fr>

diff --git a/connectivity/source/drivers/mysqlc/mysqlc_catalog.hxx 
b/connectivity/source/drivers/mysqlc/mysqlc_catalog.hxx
index 288367f38e33..1bea18c7667b 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_catalog.hxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_catalog.hxx
@@ -29,6 +29,8 @@ public:
 
     // IRefreshableUsers
     virtual void refreshUsers() override;
+
+    sdbcx::OCollection* getPrivateTables() const { return m_pTables.get(); }
 };
 
 } // namespace connectivity::mysqlc
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_tables.cxx 
b/connectivity/source/drivers/mysqlc/mysqlc_tables.cxx
index eb3995160422..ee82134086e9 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_tables.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_tables.cxx
@@ -153,28 +153,48 @@ css::uno::Reference<css::beans::XPropertySet> 
connectivity::mysqlc::Tables::crea
 }
 
 //----- XAppend ---------------------------------------------------------------
-connectivity::sdbcx::ObjectType connectivity::mysqlc::Tables::appendObject(
-    const OUString& /* rName */, const 
css::uno::Reference<css::beans::XPropertySet>& rDescriptor)
+void connectivity::mysqlc::Tables::createTable(
+    const css::uno::Reference<css::beans::XPropertySet>& descriptor)
 {
-    OUString sSql(
-        ::dbtools::createSqlCreateTableStatement(rDescriptor, 
m_xMetaData->getConnection()));
-    OUString sCatalog, sSchema, sComposedName, sTable;
-    const css::uno::Reference<css::sdbc::XConnection>& xConnection = 
m_xMetaData->getConnection();
-
-    ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
+    const css::uno::Reference<css::sdbc::XConnection> xConnection = 
m_xMetaData->getConnection();
+    OUString aSql = ::dbtools::createSqlCreateTableStatement(descriptor, 
xConnection);
 
-    
rDescriptor->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)) 
>>= sCatalog;
-    
rDescriptor->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) 
>>= sSchema;
-    rDescriptor->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) 
>>= sTable;
+    css::uno::Reference<css::sdbc::XStatement> xStmt = 
xConnection->createStatement();
+    if (xStmt.is())
+    {
+        xStmt->execute(aSql);
+        ::comphelper::disposeComponent(xStmt);
+    }
+}
 
-    sComposedName = ::dbtools::composeTableName(m_xMetaData, sCatalog, 
sSchema, sTable, true,
-                                                
::dbtools::EComposeRule::InTableDefinitions);
-    if (sComposedName.isEmpty())
-        ::dbtools::throwFunctionSequenceException(xConnection);
+// XAppend
+connectivity::sdbcx::ObjectType connectivity::mysqlc::Tables::appendObject(
+    const OUString& _rForName, const 
css::uno::Reference<css::beans::XPropertySet>& descriptor)
+{
+    createTable(descriptor);
+    return createObject(_rForName);
+}
 
-    m_xMetaData->getConnection()->createStatement()->execute(sSql);
+void connectivity::mysqlc::Tables::appendNew(const OUString& _rsNewTable)
+{
+    insertElement(_rsNewTable, nullptr);
+
+    // notify our container listeners
+    css::container::ContainerEvent aEvent(static_cast<XContainer*>(this),
+                                          css::uno::makeAny(_rsNewTable), 
css::uno::Any(),
+                                          css::uno::Any());
+    comphelper::OInterfaceIteratorHelper3 aListenerLoop(m_aContainerListeners);
+    while (aListenerLoop.hasMoreElements())
+        aListenerLoop.next()->elementInserted(aEvent);
+}
 
-    return createObject(sComposedName);
+OUString
+connectivity::mysqlc::Tables::getNameForObject(const 
connectivity::sdbcx::ObjectType& _xObject)
+{
+    OSL_ENSURE(_xObject.is(), "OTables::getNameForObject: Object is NULL!");
+    return ::dbtools::composeTableName(m_xMetaData, _xObject,
+                                       
::dbtools::EComposeRule::InDataManipulation, false)
+        .replaceAll(u"`", u"̀ `");
 }
 
 //----- XDrop -----------------------------------------------------------------
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_tables.hxx 
b/connectivity/source/drivers/mysqlc/mysqlc_tables.hxx
index 42723659d91c..2ee2ab9b96da 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_tables.hxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_tables.hxx
@@ -36,6 +36,11 @@ protected:
     appendObject(const OUString& rName,
                  const css::uno::Reference<css::beans::XPropertySet>& 
rDescriptor) override;
 
+    void createTable(const css::uno::Reference<css::beans::XPropertySet>& 
descriptor);
+    virtual OUString getNameForObject(const sdbcx::ObjectType& _xObject) 
override;
+    // XDrop
+    virtual void dropObject(sal_Int32 nPosition, const OUString& rName) 
override;
+
 public:
     Tables(const css::uno::Reference<css::sdbc::XDatabaseMetaData>& rMetaData,
            ::cppu::OWeakObject& rParent, ::osl::Mutex& rMutex,
@@ -45,11 +50,9 @@ public:
     {
     }
 
+    void appendNew(const OUString& _rsNewTable);
     // TODO: should we also implement XDataDescriptorFactory, XRefreshable,
     // XAppend,  etc. ?
-
-    // XDrop
-    virtual void dropObject(sal_Int32 nPosition, const OUString& rName) 
override;
 };
 
 } // namespace connectivity::mysqlc
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_views.cxx 
b/connectivity/source/drivers/mysqlc/mysqlc_views.cxx
index a75a25317f8d..f1b7eb3895be 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_views.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_views.cxx
@@ -17,6 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include "mysqlc_tables.hxx"
 #include "mysqlc_views.hxx"
 #include "mysqlc_view.hxx"
 #include "mysqlc_catalog.hxx"
@@ -111,6 +112,14 @@ void connectivity::mysqlc::Views::createView(
         ::comphelper::disposeComponent(xStmt);
     }
     //  TODO find a way to refresh view to make the new one appear right away
+    connectivity::mysqlc::Tables* pTables = 
static_cast<connectivity::mysqlc::Tables*>(
+        
static_cast<connectivity::mysqlc::Catalog&>(m_rParent).getPrivateTables());
+    if (pTables)
+    {
+        OUString sName = ::dbtools::composeTableName(
+            m_xMetaData, descriptor, 
::dbtools::EComposeRule::InDataManipulation, false);
+        pTables->appendNew(sName);
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to