diff options
author | Lionel Elie Mamane <lionel@mamane.lu> | 2016-03-04 12:38:47 +0100 |
---|---|---|
committer | Lionel Elie Mamane <lionel@mamane.lu> | 2016-03-04 13:16:41 +0100 |
commit | 0b0c99edbbd29a89ddc5af60f9abba141e42a4a4 (patch) | |
tree | 36456f269b8fa70911c8e04ebe8fc4dddeb10509 /connectivity | |
parent | ac1468e2ef5de7db8ea82a66422e224af509c7e3 (diff) |
tdf#92538 pgsql-sdbc make a reasonable sorting of types
Change-Id: I74283234834b5057857620ed2466068e88628585
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/source/drivers/postgresql/pq_databasemetadata.cxx | 79 |
1 files changed, 76 insertions, 3 deletions
diff --git a/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx b/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx index fd34a1209809..0d52703caead 100644 --- a/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx +++ b/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx @@ -2142,11 +2142,84 @@ struct TypeInfoByDataTypeSorter OUString nameB; a[0 /*TYPE_NAME*/] >>= nameA; b[0 /*TYPE_NAME*/] >>= nameB; - if( nameA.startsWith( "int4" ) ) + OUString nsA, tnA, nsB, tnB; + + // parse typename into schema and typename + sal_Int32 nIndex=0; + nsA = nameA.getToken(0, '.', nIndex); + if (nIndex<0) + { + tnA = nsA; + nsA.clear(); + } + else + { + tnA = nameA.getToken(0, '.', nIndex); + assert(nIndex < 0); + } + + nIndex=0; + nsB = nameB.getToken(0, '.', nIndex); + if (nIndex<0) + { + tnB = nsB; + nsB.clear(); + } + else + { + tnB = nameB.getToken(0, '.', nIndex); + assert(nIndex < 0); + } + + // sort no schema first, then "public", then normal schemas, then internal schemas + if(nsA == nsB) + { + if(nsA.isEmpty()) + { + assert(nsB.isEmpty()); + // within each type category, sort privileged choice first + if( tnA == "int4" || tnA == "varchar" || tnA == "char" || tnA == "text") + return true; + if( tnB == "int4" || tnB == "varchar" || tnB == "char" || tnB == "text") + return false; + } + return nameA.compareTo( nameB ) < 0; + } + else if (nsA.isEmpty()) + { + assert(!nsB.isEmpty()); return true; - if( nameB.startsWith( "int4" ) ) + } + 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; - return nameA.compareTo( nameB ) < 0; + } + 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 valueA.toInt32() < valueB.toInt32(); |