[Libreoffice-commits] core.git: 7 commits - connectivity/Library_firebird_sdbc.mk connectivity/source

Andrzej J.R. Hunt andrzej at ahunt.org
Wed Aug 21 03:33:04 PDT 2013


 connectivity/Library_firebird_sdbc.mk                     |    1 
 connectivity/source/drivers/firebird/DatabaseMetaData.cxx |   81 ++++----------
 connectivity/source/drivers/firebird/Keys.cxx             |   56 +++++++++
 connectivity/source/drivers/firebird/Keys.hxx             |   41 +++++++
 connectivity/source/drivers/firebird/Table.cxx            |   17 --
 connectivity/source/drivers/firebird/Util.cxx             |    8 -
 connectivity/source/drivers/firebird/Util.hxx             |    2 
 7 files changed, 133 insertions(+), 73 deletions(-)

New commits:
commit dd3a05c0ea59c0d0f14a1b446c8031348fbec195
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Wed Aug 21 11:25:55 2013 +0100

    Fix -Wmaybe-uninitialized. (firebird-sdbc)
    
    Change-Id: Icf72838624927482f52cbc1626b785c4fd6765ea

diff --git a/connectivity/source/drivers/firebird/Table.cxx b/connectivity/source/drivers/firebird/Table.cxx
index 8114d08..abc57af 100644
--- a/connectivity/source/drivers/firebird/Table.cxx
+++ b/connectivity/source/drivers/firebird/Table.cxx
@@ -128,7 +128,7 @@ void SAL_CALL Table::alterColumnByName(const OUString& rColName,
 
     if (bIsNullableChanged)
     {
-        sal_Int32 nNullabble;
+        sal_Int32 nNullabble = 0;
         rDescriptor->getPropertyValue("IsNullable") >>= nNullabble;
 
         if (nNullabble != ColumnValue::NULLABLE_UNKNOWN)
commit e43f05f5b1a88d1b1fae0743a17e85c5ecd4fc52
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Wed Aug 21 08:54:44 2013 +0100

    Simplify some sql statements with multiple conditions. (firebird-sdbc)
    
    By prepending a "WHERE (0=1)" we can avoid having to detect when
    we specifically need to add "OR"s, and vice-versa for "AND", simplifying
    the code.
    
    Change-Id: Idde5c0691788051f87eb1e868bf6b74a8ae72da3

diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
index 2aa1bc8..215d84f 100644
--- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
+++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
@@ -1136,33 +1136,27 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns(
         "relfields.RDB$NULL_FLAG "      // 9
         "FROM RDB$RELATION_FIELDS relfields "
         "JOIN RDB$FIELDS fields "
-        "on (fields.RDB$FIELD_NAME = relfields.RDB$FIELD_SOURCE) ");
+        "on (fields.RDB$FIELD_NAME = relfields.RDB$FIELD_SOURCE) "
+        "WHERE (1 = 1) ");
 
-    if (!tableNamePattern.isEmpty() && !columnNamePattern.isEmpty())
-    {
-        queryBuf.append("WHERE ");
-    }
     if (!tableNamePattern.isEmpty())
     {
         OUString sAppend;
         if (tableNamePattern.match("%"))
-            sAppend = "relfields.RDB$RELATION_NAME LIKE '%' ";
+            sAppend = "AND relfields.RDB$RELATION_NAME LIKE '%' ";
         else
-            sAppend = "relfields.RDB$RELATION_NAME = '%' ";
+            sAppend = "AND relfields.RDB$RELATION_NAME = '%' ";
 
         queryBuf.append(sAppend.replaceAll("%", tableNamePattern));
     }
 
     if (!columnNamePattern.isEmpty())
     {
-        if (!tableNamePattern.isEmpty())
-            queryBuf.append("AND ");
-
         OUString sAppend;
         if (columnNamePattern.match("%"))
-            sAppend = "relfields.RDB$FIELD_NAME LIKE '%' ";
+            sAppend = "AND relfields.RDB$FIELD_NAME LIKE '%' ";
         else
-            sAppend = "relfields.RDB$FIELD_NAME = '%' ";
+            sAppend = "AND relfields.RDB$FIELD_NAME = '%' ";
 
         queryBuf.append(sAppend.replaceAll("%", columnNamePattern));
     }
@@ -1339,21 +1333,19 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables(
     }
     else
     {
+        queryBuf.append("( (0 = 1) ");
         for (int i = 0; i < types.getLength(); i++)
         {
-            if (i)
-                queryBuf.append("OR ");
-
             if (types[i] == "SYSTEM TABLE")
-                queryBuf.append("(RDB$SYSTEM_FLAG = 1 AND RDB$VIEW_BLR IS NULL) ");
+                queryBuf.append("OR (RDB$SYSTEM_FLAG = 1 AND RDB$VIEW_BLR IS NULL) ");
             else if (types[i] == "TABLE")
-                queryBuf.append("(RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0 AND RDB$VIEW_BLR IS NULL) ");
+                queryBuf.append("OR (RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0 AND RDB$VIEW_BLR IS NULL) ");
             else if (types[i] == "VIEW")
-                queryBuf.append("(RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0 AND RDB$VIEW_BLR IS NOT NULL) ");
+                queryBuf.append("OR (RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0 AND RDB$VIEW_BLR IS NOT NULL) ");
             else
                 throw SQLException(); // TODO: implement other types, see above.
-
         }
+        queryBuf.append(") ");
     }
 
     if (!tableNamePattern.isEmpty())
@@ -1367,8 +1359,6 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables(
         queryBuf.append(sAppend.replaceAll(wld, tableNamePattern));
     }
 
-
-
     queryBuf.append(" ORDER BY RDB$RELATION_TYPE, RDB$RELATION_NAME");
 
     OUString query = queryBuf.makeStringAndClear();
commit 7358cf00822a916b1690ffd86822a28d3996e288
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Wed Aug 21 08:30:41 2013 +0100

    Add custom wrapper for OKeysHelper.firebird. (firebird-sdbc)
    
    Keys are handled as a constraint in firebird so need different handling
    when dropping to other dbs.
    
    Change-Id: Ifc4929a1ee7477260b9a279487d44edbb525a17a

diff --git a/connectivity/Library_firebird_sdbc.mk b/connectivity/Library_firebird_sdbc.mk
index 1f78608..2391349 100644
--- a/connectivity/Library_firebird_sdbc.mk
+++ b/connectivity/Library_firebird_sdbc.mk
@@ -43,6 +43,7 @@ $(eval $(call gb_Library_add_exception_objects,firebird_sdbc,\
     connectivity/source/drivers/firebird/Connection \
     connectivity/source/drivers/firebird/DatabaseMetaData \
     connectivity/source/drivers/firebird/Driver \
+    connectivity/source/drivers/firebird/Keys \
     connectivity/source/drivers/firebird/PreparedStatement \
     connectivity/source/drivers/firebird/ResultSet \
     connectivity/source/drivers/firebird/ResultSetMetaData \
diff --git a/connectivity/source/drivers/firebird/Keys.cxx b/connectivity/source/drivers/firebird/Keys.cxx
new file mode 100644
index 0000000..c187491
--- /dev/null
+++ b/connectivity/source/drivers/firebird/Keys.cxx
@@ -0,0 +1,56 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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 "Keys.hxx"
+#include "Table.hxx"
+
+#include <connectivity/dbtools.hxx>
+
+using namespace ::connectivity;
+using namespace ::connectivity::firebird;
+
+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 TStringVector& rNames):
+    OKeysHelper(pTable,
+                rMutex,
+                rNames),
+    m_pTable(pTable)
+{
+}
+
+//----- XDrop ----------------------------------------------------------------
+void Keys::dropObject(sal_Int32 nPosition, const OUString sName)
+{
+    Reference< XConnection> xConnection = m_pTable->getConnection();
+
+    if (!m_pTable->isNew())
+    {
+        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: */
\ No newline at end of file
diff --git a/connectivity/source/drivers/firebird/Keys.hxx b/connectivity/source/drivers/firebird/Keys.hxx
new file mode 100644
index 0000000..a99edbd
--- /dev/null
+++ b/connectivity/source/drivers/firebird/Keys.hxx
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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/.
+ */
+
+#ifndef CONNECTIVITY_FIREBIRD_KEYS_HXX
+#define CONNECTIVITY_FIREBIRD_KEYS_HXX
+
+#include <connectivity/TKeys.hxx>
+
+namespace connectivity
+{
+
+    namespace firebird
+    {
+
+        class Table;
+
+        class Keys: public ::connectivity::OKeysHelper
+        {
+        private:
+            Table* m_pTable;
+
+        public:
+            Keys(Table* pTable,
+                 ::osl::Mutex& rMutex,
+                 const ::connectivity::TStringVector& rNames);
+
+        // OKeysHelper / XDrop
+        void dropObject(sal_Int32 nPosition, const ::rtl::OUString sName);
+
+        };
+    }
+}
+#endif // CONNECTIVITY_FIREBIRD_KEYS_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
diff --git a/connectivity/source/drivers/firebird/Table.cxx b/connectivity/source/drivers/firebird/Table.cxx
index 9b76d2a..8114d08 100644
--- a/connectivity/source/drivers/firebird/Table.cxx
+++ b/connectivity/source/drivers/firebird/Table.cxx
@@ -8,12 +8,12 @@
  */
 
 #include "Columns.hxx"
+#include "Keys.hxx"
 #include "Table.hxx"
 
 #include <comphelper/sequence.hxx>
 #include <connectivity/dbtools.hxx>
 #include <connectivity/TIndexes.hxx>
-#include <connectivity/TKeys.hxx>
 
 #include <com/sun/star/sdbc/ColumnValue.hpp>
 
@@ -70,11 +70,9 @@ OCollection* Table::createColumns(const TStringVector& rNames)
 
 OCollection* Table::createKeys(const TStringVector& rNames)
 {
-    // TODO: maybe add a wrapper here in case we the OKeysHelper isn't
-    // fully FB compatible.
-    return new OKeysHelper(this,
-                           m_rMutex,
-                           rNames);
+    return new Keys(this,
+                    m_rMutex,
+                    rNames);
 }
 
 OCollection* Table::createIndexes(const TStringVector& rNames)
commit a22f4351cc5db1be2278813aef78a7920452d2fe
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Wed Aug 21 08:29:34 2013 +0100

    Sanitize primary key names too. (firebird-sdbc)
    
    Change-Id: I28b195280a02883c3bf597f4ded470ced0b74f14

diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
index 9e04116..2aa1bc8 100644
--- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
+++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
@@ -1534,14 +1534,14 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getPrimaryKeys(
         // 3. Table Name
         if (xRs->getRow() == 1) // Table name doesn't change, so only retrieve once
         {
-            aCurrentRow[3] = new ORowSetValueDecorator(xRow->getString(1));
+            aCurrentRow[3] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(1)));
         }
         // 4. Column Name
-        aCurrentRow[4] = new ORowSetValueDecorator(xRow->getString(2));
+        aCurrentRow[4] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(2)));
         // 5. KEY_SEQ (which key in the sequence)
         aCurrentRow[5] = new ORowSetValueDecorator(xRow->getShort(3));
         // 6. Primary Key Name
-        aCurrentRow[6] = new ORowSetValueDecorator(xRow->getString(4));
+        aCurrentRow[6] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(4)));
 
         aResults.push_back(aCurrentRow);
     }
commit e0157dfec5d0aed888fc214abc878881789511fb
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Wed Aug 21 08:24:59 2013 +0100

    Simplify/improve sanitizeIdentifier usage. (firebird-sdbc)
    
    Change-Id: Ic0f66cc68b49a2e9d9f9b8b139a479a7179cc08b

diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
index 555e0ab..9e04116 100644
--- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
+++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
@@ -1091,17 +1091,9 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges(
     while( rs->next() )
     {
         // 3. TABLE_NAME
-        {
-            OUString sTableName = xRow->getString(1);
-            sanitizeIdentifier(sTableName);
-            aCurrentRow[3] = new ORowSetValueDecorator(sTableName);
-        }
+        aCurrentRow[3] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(1)));
         // 4. COLUMN_NAME
-        {
-            OUString sColumnName = xRow->getString(6);
-            sanitizeIdentifier(sColumnName);
-            aCurrentRow[4] = new ORowSetValueDecorator(sColumnName);
-        }
+        aCurrentRow[4] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(6)));
         aCurrentRow[5] = new ORowSetValueDecorator(xRow->getString(2)); // 5. GRANTOR
         aCurrentRow[6] = new ORowSetValueDecorator(xRow->getString(3)); // 6. GRANTEE
         aCurrentRow[7] = new ORowSetValueDecorator(xRow->getString(4)); // 7. Privilege
@@ -1195,18 +1187,9 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns(
     while( rs->next() )
     {
         // 3. TABLE_NAME
-        {
-            OUString sTableName = xRow->getString(1);
-            sanitizeIdentifier(sTableName);
-            aCurrentRow[3] = new ORowSetValueDecorator(sTableName);
-        }
+        aCurrentRow[3] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(1)));
         // 4. Column Name
-        {
-            OUString sColumnName = xRow->getString(2);
-            sanitizeIdentifier(sColumnName);
-            aCurrentRow[4] = new ORowSetValueDecorator(sColumnName);
-        }
-
+        aCurrentRow[4] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(2)));
         // 5. Datatype
         short aType = getFBTypeFromBlrType(xRow->getShort(6));
         aCurrentRow[5] = new ORowSetValueDecorator(getColumnTypeFromFBType(aType));
@@ -1402,11 +1385,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables(
     while( rs->next() )
     {
         // 3. TABLE_NAME
-        {
-            OUString sTableName = xRow->getString(1);
-            sanitizeIdentifier(sTableName);
-            aCurrentRow[3] = new ORowSetValueDecorator(sTableName);
-        }
+        aCurrentRow[3] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(1)));
         // 4. TABLE_TYPE
         {
             // TODO: check this as the docs are a bit unclear.
@@ -1655,11 +1634,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges(
     while( rs->next() )
     {
         // 3. TABLE_NAME
-        {
-            OUString sTableName = xRow->getString(1);
-            sanitizeIdentifier(sTableName);
-            aRow[3] = new ORowSetValueDecorator(sTableName);
-        }
+        aRow[3] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(1)));
         aRow[4] = new ORowSetValueDecorator(xRow->getString(2)); // 4. GRANTOR
         aRow[5] = new ORowSetValueDecorator(xRow->getString(3)); // 5. GRANTEE
         aRow[6] = new ORowSetValueDecorator(xRow->getString(4)); // 6. Privilege
diff --git a/connectivity/source/drivers/firebird/Util.cxx b/connectivity/source/drivers/firebird/Util.cxx
index bdf673e..47661db 100644
--- a/connectivity/source/drivers/firebird/Util.cxx
+++ b/connectivity/source/drivers/firebird/Util.cxx
@@ -19,12 +19,12 @@ using namespace ::com::sun::star;
 using namespace ::com::sun::star::sdbc;
 using namespace ::com::sun::star::uno;
 
-OUString& firebird::sanitizeIdentifier(OUString& rIdentifier)
+OUString firebird::sanitizeIdentifier(const OUString& rIdentifier)
 {
-    rIdentifier = rIdentifier.trim();
-    assert(rIdentifier.getLength() <= 31); // Firebird identifiers cannot be longer than this.
+    OUString sRet = rIdentifier.trim();
+    assert(sRet.getLength() <= 31); // Firebird identifiers cannot be longer than this.
 
-    return rIdentifier;
+    return sRet;
 }
 
 void firebird::evaluateStatusVector(ISC_STATUS_ARRAY& aStatusVector,
diff --git a/connectivity/source/drivers/firebird/Util.hxx b/connectivity/source/drivers/firebird/Util.hxx
index 589337f..3a992a8 100644
--- a/connectivity/source/drivers/firebird/Util.hxx
+++ b/connectivity/source/drivers/firebird/Util.hxx
@@ -31,7 +31,7 @@ namespace connectivity
          * for such shorter strings, however any trailing padding makes the gui
          * editing of such names harder, hence we remove all trailing whitespace.
          */
-        ::rtl::OUString& sanitizeIdentifier(::rtl::OUString& rIdentifier);
+        ::rtl::OUString sanitizeIdentifier(const ::rtl::OUString& rIdentifier);
 
         /**
          * Evaluate a firebird status vector and throw exceptions as necessary.
commit 36f23dd846d0cf03f9c816ae296ab2ce7aff3a00
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Wed Aug 21 07:44:19 2013 +0100

    Remove unnecessary commit (firebird-sdbc).
    
    Null flag has to be manually retrieved and isn't actually DDL.
    
    Change-Id: I4ea88dcda1e4e0a2ae034572fb483415c7a5736d

diff --git a/connectivity/source/drivers/firebird/Table.cxx b/connectivity/source/drivers/firebird/Table.cxx
index 2b30057..9b76d2a 100644
--- a/connectivity/source/drivers/firebird/Table.cxx
+++ b/connectivity/source/drivers/firebird/Table.cxx
@@ -159,11 +159,6 @@ void SAL_CALL Table::alterColumnByName(const OUString& rColName,
                        "AND RDB$RELATION_NAME = '" + getName() + "'";
             }
             getConnection()->createStatement()->execute(sSql);
-
-            // This is in essence a DDL statement which requires a commit
-            // to become visible in practice.
-            getConnection()->commit();
-            // TODO: confirm, do we really need this.
         }
         else
         {
commit 1c3f2bff496a1bcef37df717a0f808e2375ccc85
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Wed Aug 21 07:24:40 2013 +0100

    Retrieve nullable from correct table. (firebird-sdbc)
    
    Change-Id: Iaa84c26bb87ea834297e67af7a3e0ac20efba574

diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
index 6aac8e7..555e0ab 100644
--- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
+++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
@@ -1137,7 +1137,11 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns(
         "fields.RDB$FIELD_TYPE, "       // 6
         "fields.RDB$FIELD_LENGTH, "     // 7
         "fields.RDB$FIELD_PRECISION, "  // 8
-        "fields.RDB$NULL_FLAG "         // 9
+        // Specifically use relfields null flag -- the one in fields is used
+        // for domains, whether a specific field is nullable is set in relfields,
+        // this is also the one we manually fiddle when changin NULL/NOT NULL
+        // (see Table.cxx)
+        "relfields.RDB$NULL_FLAG "      // 9
         "FROM RDB$RELATION_FIELDS relfields "
         "JOIN RDB$FIELDS fields "
         "on (fields.RDB$FIELD_NAME = relfields.RDB$FIELD_SOURCE) ");


More information about the Libreoffice-commits mailing list