summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2013-07-31 17:22:43 +0200
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2013-07-31 19:04:23 +0200
commit43095140eb162dad953919facc636a19c24c8cc0 (patch)
tree5e8af364aecb14050e3ac5eea180091f0b10a33f /connectivity
parent608dec14f1fd7b46b294da9341a6da6a24caef91 (diff)
Cut identifier to correct length (firebird-sdbc).
Currently firebird returns table and column identifiers as being 93 chars long (rather than 31 as per spec), this leads to problems with ALTER and DROP commands which are unable to deal with the incorrect length. For now we simply discard the extra characters (which are blank characters). (SELECT and similar commands have been able to deal with the overlength identifiers previously, which is why this hack wasn't required beforehand.) Change-Id: Ib6c984b5fc72dc4e326b3f8d36f6cbc4a3c9086a
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/drivers/firebird/DatabaseMetaData.cxx18
-rw-r--r--connectivity/source/drivers/firebird/ResultSetMetaData.cxx4
-rw-r--r--connectivity/source/drivers/firebird/Util.cxx6
-rw-r--r--connectivity/source/drivers/firebird/Util.hxx8
4 files changed, 29 insertions, 7 deletions
diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
index 943bb8273629..452f72d5f19a 100644
--- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
+++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
@@ -1067,11 +1067,13 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges(
// 3. TABLE_NAME
{
OUString sTableName = xRow->getString(1);
+ sanitizeIdentifier(sTableName);
aCurrentRow.push_back(new ORowSetValueDecorator(sTableName));
}
// 3. COLUMN_NAME
{
OUString sColumnName = xRow->getString(6);
+ sanitizeIdentifier(sColumnName);
aCurrentRow.push_back(new ORowSetValueDecorator(sColumnName));
}
// 4. GRANTOR
@@ -1180,13 +1182,15 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns(
{
// 3. TABLE_NAME
{
- OUString aTableName = xRow->getString(1);
- aCurrentRow[3] = new ORowSetValueDecorator(aTableName);
+ OUString sTableName = xRow->getString(1);
+ sanitizeIdentifier(sTableName);
+ aCurrentRow[3] = new ORowSetValueDecorator(sTableName);
}
// 4. Column Name
{
- OUString aColumnName = xRow->getString(2);
- aCurrentRow[4] = new ORowSetValueDecorator(aColumnName);
+ OUString sColumnName = xRow->getString(2);
+ sanitizeIdentifier(sColumnName);
+ aCurrentRow[4] = new ORowSetValueDecorator(sColumnName);
}
// 5. Datatype
@@ -1348,7 +1352,8 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables(
{
ODatabaseMetaDataResultSet::ORow aCurrentRow(3);
- OUString aTableName = xRow->getString(1);
+ OUString sTableName = xRow->getString(1);
+ sanitizeIdentifier(sTableName);
sal_Int16 systemFlag = xRow->getShort(2);
sal_Int16 tableType = xRow->getShort(3);
uno::Reference< XBlob > xBlob = xRow->getBlob(4);
@@ -1383,7 +1388,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables(
// TABLE_CAT (catalog) may be null -- thus we omit it.
// TABLE_SCHEM (schema) may be null -- thus we omit it.
// TABLE_NAME
- aCurrentRow.push_back(new ORowSetValueDecorator(aTableName));
+ aCurrentRow.push_back(new ORowSetValueDecorator(sTableName));
// TABLE_TYPE
aCurrentRow.push_back(new ORowSetValueDecorator(aTableType));
// REMARKS
@@ -1599,6 +1604,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges(
// 3. TABLE_NAME
{
OUString sTableName = xRow->getString(1);
+ sanitizeIdentifier(sTableName);
aCurrentRow.push_back(new ORowSetValueDecorator(sTableName));
}
// 4. GRANTOR
diff --git a/connectivity/source/drivers/firebird/ResultSetMetaData.cxx b/connectivity/source/drivers/firebird/ResultSetMetaData.cxx
index 9bcc6b3592d1..31110fc17e86 100644
--- a/connectivity/source/drivers/firebird/ResultSetMetaData.cxx
+++ b/connectivity/source/drivers/firebird/ResultSetMetaData.cxx
@@ -85,9 +85,11 @@ OUString SAL_CALL OResultSetMetaData::getColumnName(sal_Int32 column)
throw(SQLException, RuntimeException)
{
verifyValidColumn(column);
- return OUString(m_pSqlda->sqlvar[column-1].sqlname,
+ OUString sRet(m_pSqlda->sqlvar[column-1].sqlname,
m_pSqlda->sqlvar[column-1].sqlname_length,
RTL_TEXTENCODING_UTF8);
+ sanitizeIdentifier(sRet);
+ return sRet;
}
OUString SAL_CALL OResultSetMetaData::getTableName(sal_Int32 column)
diff --git a/connectivity/source/drivers/firebird/Util.cxx b/connectivity/source/drivers/firebird/Util.cxx
index f8259de7e954..90c74fc9d0b7 100644
--- a/connectivity/source/drivers/firebird/Util.cxx
+++ b/connectivity/source/drivers/firebird/Util.cxx
@@ -19,6 +19,12 @@ using namespace ::com::sun::star;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::uno;
+void firebird::sanitizeIdentifier(OUString& rIdentifier)
+{
+ if (rIdentifier.getLength() > 31)
+ rIdentifier = rIdentifier.copy(0, 31);
+}
+
void firebird::evaluateStatusVector(ISC_STATUS_ARRAY& aStatusVector,
const OUString& aCause,
const uno::Reference< XInterface >& _rxContext)
diff --git a/connectivity/source/drivers/firebird/Util.hxx b/connectivity/source/drivers/firebird/Util.hxx
index 664a17d008c3..fcd34bffd641 100644
--- a/connectivity/source/drivers/firebird/Util.hxx
+++ b/connectivity/source/drivers/firebird/Util.hxx
@@ -23,6 +23,14 @@ namespace connectivity
{
/**
+ * Make sure an identifier is safe to use within the databse. Currently
+ * firebird seems to return identifiers with 93 character (instead of
+ * 31). Use this to avoid issues when using the identifier in other
+ * sql queries.
+ */
+ void sanitizeIdentifier(::rtl::OUString& rIdentifier);
+
+ /**
* Evaluate a firebird status vector and throw exceptions as necessary.
* The content of the status vector is included in the thrown exception.
*/