Bugzilla – Attachment 124855 Details for
Bug 67302
TablesSupplier name clash when dots in schema/table name
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Attaching changes made in some file for escaped schema name and table name. Tell me I am going in right direction.
postgre.patch (text/plain), 7.44 KB, created by
Prashant
on 2016-05-05 07:20:00 UTC
(
hide
)
Description:
Attaching changes made in some file for escaped schema name and table name. Tell me I am going in right direction.
Filename:
MIME Type:
Creator:
Prashant
Created:
2016-05-05 07:20:00 UTC
Size:
7.44 KB
patch
obsolete
>diff --git a/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx b/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx >index 2fab50b..401bf8e 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_statement.cxx b/connectivity/source/drivers/postgresql/pq_statement.cxx >index 28c4c46..516ddf5 100644 >--- a/connectivity/source/drivers/postgresql/pq_statement.cxx >+++ b/connectivity/source/drivers/postgresql/pq_statement.cxx >@@ -586,7 +586,7 @@ bool executePostgresCommand( const OString & cmd, struct CommandData *data ) > } > else if( sourceTable.getLength() > 0) > { >- splitConcatenatedIdentifier( sourceTable, &schema, &table ); >+ splitDoubleQuoteEscapedIdentifiers( sourceTable, &schema, &table ); > } > > sal_Int32 returnedRows = PQntuples( result ); >@@ -700,7 +700,7 @@ Reference< XResultSet > getGeneratedValuesFromLastInsert( > Reference< XResultSet > ret; > OUString query; > OUString schemaName, tableName; >- splitConcatenatedIdentifier( >+ splitDoubleQuoteEscapedIdentifiers( > lastTableInserted, &schemaName, &tableName ); > > if( nLastOid && lastTableInserted.getLength() ) >diff --git a/connectivity/source/drivers/postgresql/pq_tools.cxx b/connectivity/source/drivers/postgresql/pq_tools.cxx >index c55834d..eb060b0 100644 >--- a/connectivity/source/drivers/postgresql/pq_tools.cxx >+++ b/connectivity/source/drivers/postgresql/pq_tools.cxx >@@ -460,6 +460,21 @@ void splitSQL( const OString & sql, OStringVector &vec ) > > } > >+void splitDoubleQuoteEscapedIdentifiers( const OUString & source, OUString *first, OUString *second) >+{ >+ OStringVector vec; >+ OString tempstring = OUStringToOString(source , RTL_TEXTENCODING_UTF8); >+ int a = source.indexOf("\".\""); >+ 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->replaceAll("\"\"","\""); >+ *second = OStringToOUString(OString(&tempstring.getStr()[a+2],source.getLength()-a-2) , RTL_TEXTENCODING_UTF8); >+ 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 076f80b..16296f9 100644 >--- a/connectivity/source/drivers/postgresql/pq_tools.hxx >+++ b/connectivity/source/drivers/postgresql/pq_tools.hxx >@@ -111,6 +111,7 @@ OUString array2String( const com::sun::star::uno::Sequence< com::sun::star::uno: > com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > extractConnectionFromStatement( > const com::sun::star::uno::Reference< com::sun::star::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 7a14cbf..f9f57c2 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 b824ddd..41e4fbc 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 = 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_xview.cxx b/connectivity/source/drivers/postgresql/pq_xview.cxx >index a2c6d16..814dfd5 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 4df8cda..167a4bf 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; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 67302
: 124855