[Libreoffice-commits] core.git: dbaccess/source mysqlc/source

Julien Nabet serval2412 at yahoo.fr
Sun Sep 24 06:26:27 UTC 2017


 dbaccess/source/ui/dlg/directsql.cxx |   98 ++++++++++++++++++++++-------------
 dbaccess/source/ui/inc/directsql.hxx |    3 +
 mysqlc/source/mysqlc_statement.cxx   |    6 --
 3 files changed, 68 insertions(+), 39 deletions(-)

New commits:
commit 444730a67dbd2ad6cebe666b2cd23c67d5c668f2
Author: Julien Nabet <serval2412 at yahoo.fr>
Date:   Sat Sep 23 13:26:58 2017 +0200

    tdf#103685: "Commands out of sync" when connecting to MySQL using direct
    
    Thanks to Lionel for his great help
    
    Change-Id: Ifcc1d72cca29c031f31da203cd1e3302ea0ea3e3
    Reviewed-on: https://gerrit.libreoffice.org/42688
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Lionel Elie Mamane <lionel at mamane.lu>

diff --git a/dbaccess/source/ui/dlg/directsql.cxx b/dbaccess/source/ui/dlg/directsql.cxx
index 220687e2ff6b..5b109fedf23e 100644
--- a/dbaccess/source/ui/dlg/directsql.cxx
+++ b/dbaccess/source/ui/dlg/directsql.cxx
@@ -29,6 +29,7 @@
 #include <rtl/strbuf.hxx>
 #include <com/sun/star/sdbc/SQLException.hpp>
 #include <com/sun/star/sdbc/XRow.hpp>
+#include <com/sun/star/sdbc/XMultipleResults.hpp>
 
 namespace dbaui
 {
@@ -183,52 +184,50 @@ namespace dbaui
         ::osl::MutexGuard aGuard(m_aMutex);
 
         OUString sStatus;
-        css::uno::Reference< css::sdbc::XResultSet > xResultSet;
+
+        // clear the output box
+        m_pOutput->SetText(OUString());
         try
         {
             // create a statement
             Reference< XStatement > xStatement = m_xConnection->createStatement();
-            OSL_ENSURE(xStatement.is(), "DirectSQLDialog::implExecuteStatement: no statement returned by the connection!");
+            css::uno::Reference< css::sdbc::XMultipleResults > xMR ( xStatement, UNO_QUERY );
 
-            // clear the output box
-            m_pOutput->SetText(OUString());
-            if (xStatement.is())
+            if (xMR.is())
             {
-                if (_rStatement.toAsciiUpperCase().startsWith("SELECT") && m_pShowOutput->IsChecked())
+                bool hasRS = xStatement->execute(_rStatement);
+                if(hasRS)
+                {
+                    css::uno::Reference< css::sdbc::XResultSet > xRS (xMR->getResultSet());
+                    if (m_pShowOutput->IsChecked())
+                        display(xRS);
+                }
+                else
+                    addOutputText(OUString::number(xMR->getUpdateCount()) + " rows updated\n");
+                while ((hasRS=xMR->getMoreResults()) || (xMR->getUpdateCount() != -1))
                 {
-                    // execute it as a query
-                    xResultSet = xStatement->executeQuery(_rStatement);
-                    // get a handle for the rows
-                    css::uno::Reference< css::sdbc::XRow > xRow( xResultSet, css::uno::UNO_QUERY );
-                    // work through each of the rows
-                    while (xResultSet->next())
+                    if(hasRS)
                     {
-                        // initialise the output line for each row
-                        OUString out("");
-                        // work along the columns until that are none left
-                        try
-                        {
-                            int i = 1;
-                            for (;;)
-                            {
-                                // be dumb, treat everything as a string
-                                out += xRow->getString(i) + ",";
-                                i++;
-                            }
-                        }
-                        // trap for when we fall off the end of the row
-                        catch (const SQLException&)
-                        {
-                        }
-                        // report the output
-                        addOutputText(out);
+                        css::uno::Reference< css::sdbc::XResultSet > xRS (xMR->getResultSet());
+                        if (m_pShowOutput->IsChecked())
+                            display(xRS);
                     }
-                } else {
-                    // execute it
-                    xStatement->execute(_rStatement);
                 }
             }
-
+            else
+            {
+                if (_rStatement.toAsciiUpperCase().startsWith("SELECT"))
+                {
+                    css::uno::Reference< css::sdbc::XResultSet > xRS = xStatement->executeQuery(_rStatement);
+                    if(m_pShowOutput->IsChecked())
+                        display(xRS);
+                }
+                else
+                {
+                    sal_Int32 resultCount = xStatement->executeUpdate(_rStatement);
+                    addOutputText(OUString::number(resultCount) + " rows updated\n");
+                }
+            }
             // successful
             sStatus = DBA_RES(STR_COMMAND_EXECUTED_SUCCESSFULLY);
 
@@ -248,6 +247,35 @@ namespace dbaui
         addStatusText(sStatus);
     }
 
+    void DirectSQLDialog::display(css::uno::Reference< css::sdbc::XResultSet > xRS)
+    {
+        // get a handle for the rows
+        css::uno::Reference< css::sdbc::XRow > xRow( xRS, css::uno::UNO_QUERY );
+        // work through each of the rows
+        while (xRS->next())
+        {
+            // initialise the output line for each row
+            OUString out("");
+            // work along the columns until that are none left
+            try
+            {
+                int i = 1;
+                for (;;)
+                {
+                    // be dumb, treat everything as a string
+                    out += xRow->getString(i) + ",";
+                    i++;
+                }
+            }
+            // trap for when we fall off the end of the row
+            catch (const SQLException&)
+            {
+            }
+            // report the output
+            addOutputText(out);
+        }
+    }
+
     void DirectSQLDialog::addStatusText(const OUString& _rMessage)
     {
         OUString sAppendMessage = OUString::number(m_nStatusCount++) + ": " + _rMessage + "\n\n";
diff --git a/dbaccess/source/ui/inc/directsql.hxx b/dbaccess/source/ui/inc/directsql.hxx
index 422ccba494ce..7a48d4d58b12 100644
--- a/dbaccess/source/ui/inc/directsql.hxx
+++ b/dbaccess/source/ui/inc/directsql.hxx
@@ -106,6 +106,9 @@ namespace dbaui
         /// adds a status text to the output list
         void addOutputText(const OUString& _rMessage);
 
+        /// displays resultset
+        void display(css::uno::Reference< css::sdbc::XResultSet > xRS);
+
 #ifdef DBG_UTIL
         const sal_Char* impl_CheckInvariants() const;
 #endif
diff --git a/mysqlc/source/mysqlc_statement.cxx b/mysqlc/source/mysqlc_statement.cxx
index 3a082004831a..96ab88de79ee 100644
--- a/mysqlc/source/mysqlc_statement.cxx
+++ b/mysqlc/source/mysqlc_statement.cxx
@@ -175,7 +175,7 @@ Reference< XConnection > SAL_CALL OCommonStatement::getConnection()
 
 sal_Int32 SAL_CALL OCommonStatement::getUpdateCount()
 {
-    return 0;
+    return cppStatement->getUpdateCount();
 }
 
 Any SAL_CALL OStatement::queryInterface(const Type & rType)
@@ -238,9 +238,7 @@ sal_Bool SAL_CALL OCommonStatement::getMoreResults()
     MutexGuard aGuard(m_aMutex);
     checkDisposed(rBHelper.bDisposed);
 
-    // if your driver supports more than only one resultset
-    // and has one more at this moment return true
-    return false;
+    return cppStatement->getMoreResults();
 }
 
 Any SAL_CALL OCommonStatement::getWarnings()


More information about the Libreoffice-commits mailing list