diff options
author | Julien Nabet <serval2412@yahoo.fr> | 2020-10-31 17:00:25 +0100 |
---|---|---|
committer | Julien Nabet <serval2412@yahoo.fr> | 2020-11-05 19:59:22 +0100 |
commit | 101647617f38a40dabbe9fb66b71ee9b2db5f2ae (patch) | |
tree | 526c43913dc847b233074b9135e1eff4a2bfc85f /connectivity | |
parent | e49e10f8fecac4b65f913c1bab9f2e3e9ba154ad (diff) |
tdf#121553: Firebird, fix datatypes management
+manual merge with:
https://cgit.freedesktop.org/libreoffice/core/commit/?id=42899e8b4e1dfc872924f3488ff6e2070c93c06e
In Firebird, BLOB and CLOB are both "BLOB" types but can be distinguished with SUB_TYPE
- BINARY for BLOB
- TEXT for CLOB ("C" = "Character" -> Text)
To deal with this, the enum "BlobSubtype" has been created in connectivity/source/drivers/firebird/Util.hxx
it contains:
- Blob = 0
- Clob = 1
but also
- Image = -9546
This last one is to deal with LONGVARBINARY which doesn't exist in Firebird
It has been added with:
see https://cgit.freedesktop.org/libreoffice/core/commit/?id=0217031a98508731f15df9d361a6e5b584db5716)
When creating a table, Tables::createStandardColumnPart was adding SUB_TYPE part in request part but only when creating table
not when altering table.
So let's deal with subtypes in the 2 mappings:
- ODatabaseMetaData::getTypeInfo from DatabaseMetaData.cxx
- ColumnTypeInfo::getColumnTypeName from Utils.cxx
and let's remove the SUB_TYPE wrong management part from Tables::createStandardColumnPart
Also, BINARY and VARBINARY were wrongly mapped since they should be respectively:
- CHAR CHARACTER SET OCTETS
- VARCHAR CHARACTER SET OCTETS
It also showed that DataType::VARBINARY was missing in ColumnTypeInfo::getColumnTypeName() change from my previous commit
see: https://cgit.freedesktop.org/libreoffice/core/commit/?id=5b33b1a6b0f251202e89cef436efd4719c3fc0c4
Change-Id: I5589fd4f781671076f534865cfe9d30943738fd2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105107
(cherry picked from commit aba06f2c3a39f33007a8f4e6e234254f42e01f0d)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105050
Reviewed-by: Lionel Mamane <lionel@mamane.lu>
Tested-by: Jenkins
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/source/drivers/firebird/DatabaseMetaData.cxx | 15 | ||||
-rw-r--r-- | connectivity/source/drivers/firebird/Tables.cxx | 18 | ||||
-rw-r--r-- | connectivity/source/drivers/firebird/Util.cxx | 14 |
3 files changed, 21 insertions, 26 deletions
diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx index 3823e7874f34..7e6f957d2b1f 100644 --- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx +++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx @@ -862,9 +862,11 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale tmp.push_back(aRow); - // Binary (CHAR) - // It is distinguished from Text type by its character set - aRow[1] = new ORowSetValueDecorator(OUString("CHAR")); + // Binary (CHAR); we use the Firebird synonym CHARACTER + // to fool LO into seeing it as different types. + // It is distinguished from Text type by its character set OCTETS; + // that will be added by Tables::createStandardColumnPart + aRow[1] = new ORowSetValueDecorator(OUString("CHARACTER")); aRow[2] = new ORowSetValueDecorator(DataType::BINARY); aRow[3] = new ORowSetValueDecorator(sal_Int16(32765)); // Prevision = max length aRow[6] = new ORowSetValueDecorator(OUString("length")); // Create Params @@ -875,7 +877,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() tmp.push_back(aRow); // Varbinary (VARCHAR) - aRow[1] = new ORowSetValueDecorator(OUString("VARCHAR")); + aRow[1] = new ORowSetValueDecorator(OUString("CHARACTER VARYING")); aRow[2] = new ORowSetValueDecorator(DataType::VARBINARY); aRow[3] = new ORowSetValueDecorator(sal_Int16(32765)); // Prevision = max length aRow[6] = new ORowSetValueDecorator(OUString("length")); // Create Params @@ -883,7 +885,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() sal_Int16(ColumnSearch::NONE)); // Searchable // Clob (SQL_BLOB) - aRow[1] = new ORowSetValueDecorator(OUString("BLOB")); // BLOB, with subtype 1 + aRow[1] = new ORowSetValueDecorator(OUString("BLOB SUB_TYPE TEXT")); // BLOB, with subtype 1 aRow[2] = new ORowSetValueDecorator(DataType::CLOB); aRow[3] = new ORowSetValueDecorator(sal_Int32(2147483647)); // Precision = max length aRow[6] = new ORowSetValueDecorator(); // Create Params @@ -896,6 +898,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() // Longvarbinary (SQL_BLOB) // Distinguished from simple blob with a user-defined subtype. + aRow[1] = new ORowSetValueDecorator(OUString("BLOB SUB_TYPE " + OUString::number(static_cast<short>(BlobSubtype::Image))) ); // BLOB, with subtype 0 aRow[2] = new ORowSetValueDecorator(DataType::LONGVARBINARY); tmp.push_back(aRow); @@ -1002,7 +1005,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() tmp.push_back(aRow); // SQL_BLOB - aRow[1] = new ORowSetValueDecorator(OUString("BLOB")); + aRow[1] = new ORowSetValueDecorator(OUString("BLOB SUB_TYPE BINARY")); aRow[2] = new ORowSetValueDecorator(DataType::BLOB); aRow[3] = new ORowSetValueDecorator(sal_Int32(0)); // Prevision = max length aRow[6] = new ORowSetValueDecorator(); // Create Params diff --git a/connectivity/source/drivers/firebird/Tables.cxx b/connectivity/source/drivers/firebird/Tables.cxx index 34907418abf8..5acb391caeb5 100644 --- a/connectivity/source/drivers/firebird/Tables.cxx +++ b/connectivity/source/drivers/firebird/Tables.cxx @@ -93,9 +93,8 @@ OUString Tables::createStandardColumnPart(const Reference< XPropertySet >& xColP aSql.append(" "); aSql.append(dbtools::createStandardTypePart(xColProp, _xConnection)); - - // Add character set for BINARY (fix) type: - // BINARY is distinguished from other CHAR types by its character set. + // Add character set for (VAR)BINARY (fix) types: + // (VAR) BINARY is distinguished from other CHAR types by its character set. // Octets is a special character set for binary data. if ( xPropInfo.is() && xPropInfo->hasPropertyByName(rPropMap.getNameByIndex( PROPERTY_ID_TYPE)) ) @@ -108,19 +107,6 @@ OUString Tables::createStandardColumnPart(const Reference< XPropertySet >& xColP aSql.append(" "); aSql.append("CHARACTER SET OCTETS"); } - else if(aType == DataType::CLOB) - { - // CLOB is a special type of blob in Firebird context. - // Subtype number 1 always refers to CLOB - aSql.append(" "); - aSql.append("SUB_TYPE 1"); - } - else if(aType == DataType::LONGVARBINARY) - { - aSql.append(" "); - aSql.append("SUB_TYPE "); - aSql.append(OUString::number(static_cast<short>(BlobSubtype::Image))); - } } if ( bIsAutoIncrement && !sAutoIncrementValue.isEmpty()) diff --git a/connectivity/source/drivers/firebird/Util.cxx b/connectivity/source/drivers/firebird/Util.cxx index 7bdb12b8eb29..64e3297235ea 100644 --- a/connectivity/source/drivers/firebird/Util.cxx +++ b/connectivity/source/drivers/firebird/Util.cxx @@ -217,15 +217,21 @@ OUString firebird::ColumnTypeInfo::getColumnTypeName() const case DataType::TIMESTAMP: return "TIMESTAMP"; case DataType::BINARY: - return "BINARY"; + // in Firebird, that is the same datatype "CHAR" as DataType::CHAR, + // only with CHARACTER SET OCTETS; we use the synonym CHARACTER + // to fool LO into seeing it as different types. + return "CHARACTER"; + case DataType::VARBINARY: + // see above comment about DataType::BINARY. + return "CHARACTER VARYING"; case DataType::LONGVARBINARY: - return "LONGVARBINARY"; + return "BLOB SUB_TYPE " + OUString::number(static_cast<short>(BlobSubtype::Image)); case DataType::ARRAY: return "ARRAY"; case DataType::BLOB: - return "BLOB"; + return "BLOB SUB_TYPE BINARY"; case DataType::CLOB: - return "CLOB"; + return "BLOB SUB_TYPE TEXT"; case DataType::BOOLEAN: return "BOOLEAN"; case DataType::SQLNULL: |