diff options
author | Prashant <lprashant.94@gmail.com> | 2016-05-17 17:04:40 +0000 |
---|---|---|
committer | jan iversen <jani@documentfoundation.org> | 2016-06-23 10:14:55 +0000 |
commit | d43f4390e006716ca538ad92d09bd012179efd66 (patch) | |
tree | d60b61f01af19294495e17333526baf3e233813f /connectivity | |
parent | 9e28b2f9ac3f205db223352cb88eb3546a8e1c0e (diff) |
tdf#67302 Resolving tablesSupplier name clash for postgresql
Change-Id: Ic9bedc678699e136c09a51575f1d27131c5ffd29
Reviewed-on: https://gerrit.libreoffice.org/25069
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: jan iversen <jani@documentfoundation.org>
Diffstat (limited to 'connectivity')
8 files changed, 34 insertions, 10 deletions
diff --git a/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx b/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx index c2e64df1efcc..cec6070a767a 100644 --- a/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx +++ b/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx @@ -212,7 +212,9 @@ void ResultSetMetaData::checkTable() { const OUString name (getTableName ( 1 )); const OUString schema (getSchemaName( 1 )); - const OUString composedName( schema.isEmpty() ? name : (schema + "." + name) ); + const OUString EscapedName (name.replaceAll("\"","\"\"" )); + const OUString EscapedSchema ( schema.replaceAll("\"","\"\"")); + const OUString composedName( schema.isEmpty() ? name : ("\"" + EscapedSchema + "\".\"" + EscapedName + "\"") ); tables->getByName( composedName ) >>= m_table; } } diff --git a/connectivity/source/drivers/postgresql/pq_tools.cxx b/connectivity/source/drivers/postgresql/pq_tools.cxx index 4e6df8b0fdf2..0312dde08488 100644 --- a/connectivity/source/drivers/postgresql/pq_tools.cxx +++ b/connectivity/source/drivers/postgresql/pq_tools.cxx @@ -463,6 +463,21 @@ void splitSQL( const OString & sql, OStringVector &vec ) } +void splitDoubleQuoteEscapedIdentifiers( const OUString & source, OUString *first, OUString *second) +{ + OStringVector vec; + int a = source.indexOf("\".\""); + OString tempstring = OUStringToOString(source , RTL_TEXTENCODING_UTF8); + if(a > 0) + { + //remove start and end double quote as well as escaped double quotes + *first =OStringToOUString(OString(&tempstring.getStr()[1],a-2) , RTL_TEXTENCODING_UTF8); + *first=first->replaceAll("\"\"","\""); + *second =OStringToOUString(OString(&tempstring.getStr()[a+2],source.getLength()-a-2) , RTL_TEXTENCODING_UTF8); + *second=second->replaceAll("\"\"","\""); + } +} + void tokenizeSQL( const OString & sql, OStringVector &vec ) { int length = sql.getLength(); diff --git a/connectivity/source/drivers/postgresql/pq_tools.hxx b/connectivity/source/drivers/postgresql/pq_tools.hxx index 6ab147c76d39..8c17c287f368 100644 --- a/connectivity/source/drivers/postgresql/pq_tools.hxx +++ b/connectivity/source/drivers/postgresql/pq_tools.hxx @@ -111,6 +111,7 @@ OUString array2String( const css::uno::Sequence< css::uno::Any > &seq ); css::uno::Reference< css::sdbc::XConnection > extractConnectionFromStatement( const css::uno::Reference< css::uno::XInterface > & stmt ); +void splitDoubleQuoteEscapedIdentifiers( const OUString & source, OUString *first, OUString *second); void splitConcatenatedIdentifier( const OUString & source, OUString *first, OUString *second); diff --git a/connectivity/source/drivers/postgresql/pq_xtable.cxx b/connectivity/source/drivers/postgresql/pq_xtable.cxx index 4b8d4518c1f4..8e0ae92164f0 100644 --- a/connectivity/source/drivers/postgresql/pq_xtable.cxx +++ b/connectivity/source/drivers/postgresql/pq_xtable.cxx @@ -154,12 +154,13 @@ void Table::rename( const OUString& newName ) OUString newTableName; OUString newSchemaName; + //changing schema + dot + table-name to "schema"."table-name" // OOo2.0 passes schema + dot + new-table-name while // OO1.1.x passes new Name without schema // in case name contains a dot, it is interpreted as schema.tablename - if( newName.indexOf( '.' ) >= 0 ) + if( newName.indexOf( "\".\"" ) >= 0 ) { - splitConcatenatedIdentifier( newName, &newSchemaName, &newTableName ); + splitDoubleQuoteEscapedIdentifiers( newName, &newSchemaName, &newTableName ); } else { diff --git a/connectivity/source/drivers/postgresql/pq_xtables.cxx b/connectivity/source/drivers/postgresql/pq_xtables.cxx index 97a9b7f2b4a6..9ec5c02a0598 100644 --- a/connectivity/source/drivers/postgresql/pq_xtables.cxx +++ b/connectivity/source/drivers/postgresql/pq_xtables.cxx @@ -133,8 +133,10 @@ void Tables::refresh() { m_values.push_back( makeAny( prop ) ); - OUStringBuffer buf( name.getLength() + schema.getLength() + 1); - buf.append( schema + "." + name ); + OUString EscapedName = /* ::dbtools::composeTableNameForSelect(); */ name.replaceAll("\"","\"\""); + OUString EscapedSchema = schema.replaceAll("\"","\"\""); + OUStringBuffer buf( EscapedName.getLength() + EscapedSchema.getLength() + 1); + buf.append("\"" + EscapedSchema + "\".\"" + EscapedName + "\""); map[ buf.makeStringAndClear() ] = tableIndex; ++tableIndex; } diff --git a/connectivity/source/drivers/postgresql/pq_xtables.hxx b/connectivity/source/drivers/postgresql/pq_xtables.hxx index d46ec043dea2..17bb5fac374a 100644 --- a/connectivity/source/drivers/postgresql/pq_xtables.hxx +++ b/connectivity/source/drivers/postgresql/pq_xtables.hxx @@ -38,7 +38,7 @@ #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XTABLES_HXX #include "pq_xcontainer.hxx" - +#include "connectivity/dbtools.hxx" namespace pq_sdbc_driver { diff --git a/connectivity/source/drivers/postgresql/pq_xview.cxx b/connectivity/source/drivers/postgresql/pq_xview.cxx index c42f533a410f..2ed4ece90a82 100644 --- a/connectivity/source/drivers/postgresql/pq_xview.cxx +++ b/connectivity/source/drivers/postgresql/pq_xview.cxx @@ -102,12 +102,13 @@ void View::rename( const OUString& newName ) OUString newTableName; OUString newSchemaName; + //changing schema + dot + table-name to "schema"."table-name" // OOo2.0 passes schema + dot + new-table-name while // OO1.1.x passes new Name without schema // in case name contains a dot, it is interpreted as schema.tablename - if( newName.indexOf( '.' ) >= 0 ) + if( newName.indexOf( "\".\"" ) >= 0 ) { - splitConcatenatedIdentifier( newName, &newSchemaName, &newTableName ); + splitDoubleQuoteEscapedIdentifiers( newName, &newSchemaName, &newTableName ); } else { diff --git a/connectivity/source/drivers/postgresql/pq_xviews.cxx b/connectivity/source/drivers/postgresql/pq_xviews.cxx index 4948907c1311..2e97f17afd5d 100644 --- a/connectivity/source/drivers/postgresql/pq_xviews.cxx +++ b/connectivity/source/drivers/postgresql/pq_xviews.cxx @@ -114,8 +114,10 @@ void Views::refresh() { m_values.push_back( makeAny( prop ) ); - OUStringBuffer buf( table.getLength() + schema.getLength() + 1); - buf.append( schema + "." + table ); + OUString EscapedTable = table.replaceAll("\"","\"\""); + OUString EscapedSchema = schema.replaceAll("\"","\"\""); + OUStringBuffer buf( EscapedTable.getLength() + EscapedSchema.getLength() + 1); + buf.append("\"" + EscapedSchema + "\".\"" + EscapedTable + "\""); map[ buf.makeStringAndClear() ] = viewIndex; ++viewIndex; } |