diff options
author | Lionel Elie Mamane <lionel@mamane.lu> | 2016-03-04 13:01:57 +0100 |
---|---|---|
committer | Lionel Elie Mamane <lionel@mamane.lu> | 2016-03-04 13:16:42 +0100 |
commit | 5cbb6631e6d4c1000bff936712b4bd4aafbe04d5 (patch) | |
tree | 957cf7f76f73a00bf2fc1abd1a138077e64b3353 /connectivity/source | |
parent | 0b0c99edbbd29a89ddc5af60f9abba141e42a4a4 (diff) |
pgsql-sdbc: factorise common code
Change-Id: Iea185bc216e92baee9f97157b8ac13a9a64f99b5
Diffstat (limited to 'connectivity/source')
-rw-r--r-- | connectivity/source/drivers/postgresql/pq_databasemetadata.cxx | 92 |
1 files changed, 38 insertions, 54 deletions
diff --git a/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx b/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx index 0d52703caead..57011f082977 100644 --- a/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx +++ b/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx @@ -1209,41 +1209,56 @@ sal_Bool DatabaseMetaData::dataDefinitionIgnoredInTransactions( ) throw (SQLExc m_refMutex, *this, statics.tablesRowNames, vec, m_pSettings->tc ); } -struct SortInternalSchemasLastAndPublicFirst +namespace { - bool operator () ( const std::vector< Any > & a, const std::vector< Any > & b ) + // sort no schema first, then "public", then normal schemas, then internal schemas + int compare_schema(const OUString &nsA, const OUString &nsB) { - OUString valueA; - OUString valueB; - a[0] >>= valueA; - b[0] >>= valueB; - bool ret = false; - if( valueA== "public" ) + if (nsA.isEmpty()) { - ret = true; + return nsB.isEmpty() ? 0 : -1; } - else if( valueB == "public" ) + else if (nsB.isEmpty()) { - ret = false; + assert(!nsA.isEmpty()); + return 1; } - else if( valueA.startsWith( "pg_" ) && - valueB.startsWith( "pg_" ) ) + else if(nsA == "public") { - ret = valueA.compareTo( valueB ) < 0; // sorts equal ! + return (nsB == "public") ? 0 : -1; } - else if( valueA.startsWith( "pg_" )) + else if(nsB == "public") { - ret = false; // sorts last ! + assert(nsA != "public"); + return 1; } - else if( valueB.startsWith( "pg_" ) ) + else if(nsA.startsWith("pg_")) { - ret = true; // sorts first ! + if(nsB.startsWith("pg_")) + return nsA.compareTo(nsB); + else + return 1; + } + else if(nsB.startsWith("pg_")) + { + return -1; } else { - ret = (valueA.compareTo( valueB ) < 0); + return nsA.compareTo(nsB); } - return ret; + } +} + +struct SortInternalSchemasLastAndPublicFirst +{ + bool operator () ( const std::vector< Any > & a, const std::vector< Any > & b ) + { + OUString valueA; + OUString valueB; + a[0] >>= valueA; + b[0] >>= valueB; + return compare_schema(valueA, valueB); } }; @@ -2171,8 +2186,8 @@ struct TypeInfoByDataTypeSorter assert(nIndex < 0); } - // sort no schema first, then "public", then normal schemas, then internal schemas - if(nsA == nsB) + const int ns_comp = compare_schema(nsA, nsB); + if(ns_comp == 0) { if(nsA.isEmpty()) { @@ -2185,40 +2200,9 @@ struct TypeInfoByDataTypeSorter } return nameA.compareTo( nameB ) < 0; } - else if (nsA.isEmpty()) - { - assert(!nsB.isEmpty()); - return true; - } - else if (nsB.isEmpty()) - { - assert(!nsA.isEmpty()); - return false; - } - else if(nsA == "public") - { - assert(nsB != "public"); - return true; - } - else if(nsB == "public") - { - assert(nsA != "public"); - return false; - } - else if(nsA.startsWith("pg_")) - { - if(nsB.startsWith("pg_")) - return nsA.compareTo(nsB) < 0; - else - return false; - } - else if(nsB.startsWith("pg_")) - { - return true; - } else { - return nsA.compareTo(nsB) < 0; + return ns_comp < 0; } } |