tdf#121553: Firebird, fix datatypes management
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
Reviewed-by: Lionel Mamane <lionel@mamane.lu>
Tested-by: Jenkins
This commit is contained in:
@@ -863,7 +863,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo()
|
||||
|
||||
// Binary (CHAR)
|
||||
// It is distinguished from Text type by its character set
|
||||
aRow[1] = new ORowSetValueDecorator(OUString("CHAR"));
|
||||
aRow[1] = new ORowSetValueDecorator(OUString("CHAR CHARACTER SET OCTETS"));
|
||||
aRow[2] = new ORowSetValueDecorator(DataType::BINARY);
|
||||
aRow[3] = new ORowSetValueDecorator(sal_Int16(32765)); // Prevision = max length
|
||||
aRow[6] = new ORowSetValueDecorator(OUString("length")); // Create Params
|
||||
@@ -874,7 +874,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("VARCHAR CHARACTER SET OCTETS"));
|
||||
aRow[2] = new ORowSetValueDecorator(DataType::VARBINARY);
|
||||
aRow[3] = new ORowSetValueDecorator(sal_Int16(32765)); // Prevision = max length
|
||||
aRow[6] = new ORowSetValueDecorator(OUString("length")); // Create Params
|
||||
@@ -882,7 +882,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
|
||||
@@ -895,6 +895,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);
|
||||
|
||||
@@ -1001,7 +1002,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
|
||||
|
||||
@@ -94,35 +94,6 @@ OUString Tables::createStandardColumnPart(const Reference< XPropertySet >& xColP
|
||||
|
||||
aSql.append(dbtools::createStandardTypePart(xColProp, _xConnection));
|
||||
|
||||
// Add character set for BINARY (fix) type:
|
||||
// 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)) )
|
||||
{
|
||||
sal_Int32 aType = 0;
|
||||
xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_TYPE))
|
||||
>>= aType;
|
||||
if(aType == DataType::BINARY || aType == DataType::VARBINARY)
|
||||
{
|
||||
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())
|
||||
{
|
||||
aSql.append(" ");
|
||||
|
||||
@@ -217,15 +217,17 @@ OUString firebird::ColumnTypeInfo::getColumnTypeName() const
|
||||
case DataType::TIMESTAMP:
|
||||
return "TIMESTAMP";
|
||||
case DataType::BINARY:
|
||||
return "BINARY";
|
||||
return "CHAR CHARACTER SET OCTETS";
|
||||
case DataType::VARBINARY:
|
||||
return "VARCHAR CHARACTER SET OCTETS";
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user