Kaydet (Commit) d43f4390 authored tarafından Prashant's avatar Prashant Kaydeden (comit) jan iversen

tdf#67302 Resolving tablesSupplier name clash for postgresql

Change-Id: Ic9bedc678699e136c09a51575f1d27131c5ffd29
Reviewed-on: https://gerrit.libreoffice.org/25069Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarjan iversen <jani@documentfoundation.org>
üst 9e28b2f9
......@@ -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;
}
}
......
......@@ -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();
......
......@@ -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);
......
......@@ -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
{
......
......@@ -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;
}
......
......@@ -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
{
......
......@@ -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
{
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment