Kaydet (Commit) c69436f7 authored tarafından Marcos Paulo de Souza's avatar Marcos Paulo de Souza Kaydeden (comit) Olivier Hallot

fdo#57950: Remove some chained appends in connectivity and..

... remove some RTL* macros.

Change-Id: I919d17e14334c9220b47775355512df8dfa00bca
Reviewed-on: https://gerrit.libreoffice.org/1768Reviewed-by: 's avatarOlivier Hallot <olivier.hallot@alta.org.br>
Tested-by: 's avatarOlivier Hallot <olivier.hallot@alta.org.br>
üst d00bc092
...@@ -98,7 +98,6 @@ using com::sun::star::sdbc::XDatabaseMetaData; ...@@ -98,7 +98,6 @@ using com::sun::star::sdbc::XDatabaseMetaData;
namespace pq_sdbc_driver namespace pq_sdbc_driver
{ {
#define ASCII_STR(x) OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
Keys::Keys( Keys::Keys(
const ::rtl::Reference< RefCountedMutex > & refMutex, const ::rtl::Reference< RefCountedMutex > & refMutex,
...@@ -127,58 +126,17 @@ static sal_Int32 string2keytype( const rtl::OUString &type ) ...@@ -127,58 +126,17 @@ static sal_Int32 string2keytype( const rtl::OUString &type )
static sal_Int32 string2keyrule( const rtl::OUString & rule ) static sal_Int32 string2keyrule( const rtl::OUString & rule )
{ {
sal_Int32 ret = com::sun::star::sdbc::KeyRule::NO_ACTION; sal_Int32 ret = com::sun::star::sdbc::KeyRule::NO_ACTION;
if( rule.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "r" ) ) == 0 ) if( rule == "r" )
ret = com::sun::star::sdbc::KeyRule::RESTRICT; ret = com::sun::star::sdbc::KeyRule::RESTRICT;
else if( rule.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "c" ) ) == 0 ) else if( rule == "c" )
ret = com::sun::star::sdbc::KeyRule::CASCADE; ret = com::sun::star::sdbc::KeyRule::CASCADE;
else if( rule.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "n" ) ) == 0 ) else if( rule == "n" )
ret = com::sun::star::sdbc::KeyRule::SET_NULL; ret = com::sun::star::sdbc::KeyRule::SET_NULL;
else if( rule.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "d" ) ) == 0 ) else if( rule == "d" )
ret = com::sun::star::sdbc::KeyRule::SET_DEFAULT; ret = com::sun::star::sdbc::KeyRule::SET_DEFAULT;
return ret; return ret;
} }
// static void fillAttnum2attnameMap(
// Int2StringMap &map,
// const Reference< com::sun::star::sdbc::XConnection > &conn,
// const rtl::OUString &schema,
// const rtl::OUString &table )
// {
// Reference< XPreparedStatement > prep = conn->prepareStatement(
// ASCII_STR( "SELECT attname,attnum "
// "FROM pg_attribute "
// "INNER JOIN pg_class ON attrelid = pg_class.oid "
// "INNER JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid "
// "WHERE relname=? AND nspname=?" ) );
// Reference< XParameters > paras( prep, UNO_QUERY );
// paras->setString( 1 , table );
// paras->setString( 2 , schema );
// Reference< XResultSet > rs = prep->executeQuery();
// Reference< XRow > xRow( rs , UNO_QUERY );
// while( rs->next() )
// {
// map[ xRow->getInt(2) ] = xRow->getString(1);
// }
// }
// static Sequence< rtl::OUString > resolveColumnNames(
// const Int2StringMap &map, const rtl::OUString &array )
// {
// Sequence< sal_Int32 > intArray = string2intarray( array );
// Sequence< ::rtl::OUString > ret( intArray.getLength() );
// for( int i = 0; i < intArray.getLength() ; i ++ )
// {
// Int2StringMap::const_iterator ii = map.find( intArray[i] );
// if( ii != map.end() )
// ret[i] = ii->second;
// }
// return ret;
// }
void Keys::refresh() void Keys::refresh()
throw (::com::sun::star::uno::RuntimeException) throw (::com::sun::star::uno::RuntimeException)
{ {
...@@ -186,12 +144,10 @@ void Keys::refresh() ...@@ -186,12 +144,10 @@ void Keys::refresh()
{ {
if( isLog( m_pSettings, LogLevel::INFO ) ) if( isLog( m_pSettings, LogLevel::INFO ) )
{ {
rtl::OStringBuffer buf; OString buf( "sdbcx.Keys get refreshed for table " +
buf.append( "sdbcx.Keys get refreshed for table " ); OUStringToOString( m_schemaName, m_pSettings->encoding ) +
buf.append( OUStringToOString( m_schemaName, m_pSettings->encoding ) ); "." + OUStringToOString( m_tableName,m_pSettings->encoding ));
buf.append( "." ); log( m_pSettings, LogLevel::INFO, buf.getStr() );
buf.append( OUStringToOString( m_tableName,m_pSettings->encoding ) );
log( m_pSettings, LogLevel::INFO, buf.makeStringAndClear().getStr() );
} }
osl::MutexGuard guard( m_refMutex->mutex ); osl::MutexGuard guard( m_refMutex->mutex );
...@@ -201,7 +157,6 @@ void Keys::refresh() ...@@ -201,7 +157,6 @@ void Keys::refresh()
fillAttnum2attnameMap( mainMap, m_origin, m_schemaName, m_tableName ); fillAttnum2attnameMap( mainMap, m_origin, m_schemaName, m_tableName );
Reference< XPreparedStatement > stmt = m_origin->prepareStatement( Reference< XPreparedStatement > stmt = m_origin->prepareStatement(
ASCII_STR(
"SELECT conname, " // 1 "SELECT conname, " // 1
"contype, " // 2 "contype, " // 2
"confupdtype, " // 3 "confupdtype, " // 3
...@@ -214,7 +169,7 @@ void Keys::refresh() ...@@ -214,7 +169,7 @@ void Keys::refresh()
"INNER JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid " "INNER JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid "
"LEFT JOIN pg_class AS class2 ON confrelid = class2.oid " "LEFT JOIN pg_class AS class2 ON confrelid = class2.oid "
"LEFT JOIN pg_namespace AS nmsp2 ON class2.relnamespace=nmsp2.oid " "LEFT JOIN pg_namespace AS nmsp2 ON class2.relnamespace=nmsp2.oid "
"WHERE pg_class.relname = ? AND pg_namespace.nspname = ?" ) ); "WHERE pg_class.relname = ? AND pg_namespace.nspname = ?" );
Reference< XParameters > paras( stmt, UNO_QUERY ); Reference< XParameters > paras( stmt, UNO_QUERY );
paras->setString( 1 , m_tableName ); paras->setString( 1 , m_tableName );
...@@ -250,9 +205,7 @@ void Keys::refresh() ...@@ -250,9 +205,7 @@ void Keys::refresh()
if( com::sun::star::sdbcx::KeyType::FOREIGN == keyType ) if( com::sun::star::sdbcx::KeyType::FOREIGN == keyType )
{ {
OUStringBuffer buf( 128 ); OUStringBuffer buf( 128 );
buf.append( xRow->getString( 6 ) ); buf.append( xRow->getString( 6 ) + "." + xRow->getString( 5 ) );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "." ) );
buf.append( xRow->getString( 5 ) );
pKey->setPropertyValue_NoBroadcast_public( pKey->setPropertyValue_NoBroadcast_public(
st.REFERENCED_TABLE, makeAny( buf.makeStringAndClear() ) ); st.REFERENCED_TABLE, makeAny( buf.makeStringAndClear() ) );
...@@ -295,9 +248,9 @@ void Keys::appendByDescriptor( ...@@ -295,9 +248,9 @@ void Keys::appendByDescriptor(
osl::MutexGuard guard( m_refMutex->mutex ); osl::MutexGuard guard( m_refMutex->mutex );
OUStringBuffer buf( 128 ); OUStringBuffer buf( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE " ) ); buf.append( "ALTER TABLE " );
bufferQuoteQualifiedIdentifier( buf, m_schemaName, m_tableName, m_pSettings ); bufferQuoteQualifiedIdentifier( buf, m_schemaName, m_tableName, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " ADD " ) ); buf.append( " ADD " );
bufferKey2TableConstraint( buf, descriptor, m_pSettings ); bufferKey2TableConstraint( buf, descriptor, m_pSettings );
Reference< XStatement > stmt = Reference< XStatement > stmt =
...@@ -315,11 +268,8 @@ void Keys::dropByIndex( sal_Int32 index ) ...@@ -315,11 +268,8 @@ void Keys::dropByIndex( sal_Int32 index )
if( index < 0 || index >= m_values.getLength() ) if( index < 0 || index >= m_values.getLength() )
{ {
OUStringBuffer buf( 128 ); OUStringBuffer buf( 128 );
buf.appendAscii( "TABLES: Index out of range (allowed 0 to " ); buf.append( "TABLES: Index out of range (allowed 0 to " + OUString::number(m_values.getLength() -1) +
buf.append( (sal_Int32)(m_values.getLength() -1) ); ", got " + OUString::number( index ) + ")" );
buf.appendAscii( ", got " );
buf.append( index );
buf.appendAscii( ")" );
throw com::sun::star::lang::IndexOutOfBoundsException( throw com::sun::star::lang::IndexOutOfBoundsException(
buf.makeStringAndClear(), *this ); buf.makeStringAndClear(), *this );
} }
...@@ -329,9 +279,9 @@ void Keys::dropByIndex( sal_Int32 index ) ...@@ -329,9 +279,9 @@ void Keys::dropByIndex( sal_Int32 index )
m_values[index] >>= set; m_values[index] >>= set;
OUStringBuffer buf( 128 ); OUStringBuffer buf( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE " ) ); buf.append( "ALTER TABLE " );
bufferQuoteQualifiedIdentifier( buf, m_schemaName, m_tableName, m_pSettings ); bufferQuoteQualifiedIdentifier( buf, m_schemaName, m_tableName, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " DROP CONSTRAINT " ) ); buf.append( " DROP CONSTRAINT " );
bufferQuoteIdentifier( buf, extractStringProperty( set , getStatics().NAME ), m_pSettings ); bufferQuoteIdentifier( buf, extractStringProperty( set , getStatics().NAME ), m_pSettings );
m_origin->createStatement()->executeUpdate( buf.makeStringAndClear() ); m_origin->createStatement()->executeUpdate( buf.makeStringAndClear() );
......
...@@ -77,10 +77,6 @@ ...@@ -77,10 +77,6 @@
using osl::MutexGuard; using osl::MutexGuard;
using osl::Mutex; using osl::Mutex;
using rtl::OUString;
using rtl::OUStringBuffer;
using rtl::OUStringToOString;
using com::sun::star::container::XNameAccess; using com::sun::star::container::XNameAccess;
using com::sun::star::container::XIndexAccess; using com::sun::star::container::XIndexAccess;
using com::sun::star::container::ElementExistException; using com::sun::star::container::ElementExistException;
...@@ -227,9 +223,9 @@ void Table::rename( const ::rtl::OUString& newName ) ...@@ -227,9 +223,9 @@ void Table::rename( const ::rtl::OUString& newName )
try try
{ {
OUStringBuffer buf(128); OUStringBuffer buf(128);
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) ); buf.append( "ALTER TABLE" );
bufferQuoteQualifiedIdentifier(buf, schema, oldName, m_pSettings ); bufferQuoteQualifiedIdentifier(buf, schema, oldName, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("SET SCHEMA" ) ); buf.append( "SET SCHEMA" );
bufferQuoteIdentifier( buf, newSchemaName, m_pSettings ); bufferQuoteIdentifier( buf, newSchemaName, m_pSettings );
Reference< XStatement > statement = m_conn->createStatement(); Reference< XStatement > statement = m_conn->createStatement();
statement->executeUpdate( buf.makeStringAndClear() ); statement->executeUpdate( buf.makeStringAndClear() );
...@@ -239,9 +235,8 @@ void Table::rename( const ::rtl::OUString& newName ) ...@@ -239,9 +235,8 @@ void Table::rename( const ::rtl::OUString& newName )
} }
catch( com::sun::star::sdbc::SQLException &e ) catch( com::sun::star::sdbc::SQLException &e )
{ {
OUStringBuffer buf( e.Message ); OUString buf( e.Message + "(NOTE: Only postgresql server >= V8.1 support changing a table's schema)" );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "(NOTE: Only postgresql server >= V8.1 support changing a table's schema)" ) ); e.Message = buf;
e.Message = buf.makeStringAndClear();
throw; throw;
} }
...@@ -249,9 +244,9 @@ void Table::rename( const ::rtl::OUString& newName ) ...@@ -249,9 +244,9 @@ void Table::rename( const ::rtl::OUString& newName )
if( ! newTableName.equals( oldName ) ) // might also be just the change of a schema name if( ! newTableName.equals( oldName ) ) // might also be just the change of a schema name
{ {
OUStringBuffer buf(128); OUStringBuffer buf(128);
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) ); buf.append( "ALTER TABLE" );
bufferQuoteQualifiedIdentifier(buf, schema, oldName, m_pSettings ); bufferQuoteQualifiedIdentifier(buf, schema, oldName, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("RENAME TO" ) ); buf.append( "RENAME TO" );
bufferQuoteIdentifier( buf, newTableName, m_pSettings ); bufferQuoteIdentifier( buf, newTableName, m_pSettings );
Reference< XStatement > statement = m_conn->createStatement(); Reference< XStatement > statement = m_conn->createStatement();
statement->executeUpdate( buf.makeStringAndClear() ); statement->executeUpdate( buf.makeStringAndClear() );
......
...@@ -72,10 +72,6 @@ ...@@ -72,10 +72,6 @@
using osl::MutexGuard; using osl::MutexGuard;
using rtl::OUString;
using rtl::OUStringBuffer;
using rtl::OUStringToOString;
using com::sun::star::beans::XPropertySet; using com::sun::star::beans::XPropertySet;
using com::sun::star::uno::Any; using com::sun::star::uno::Any;
...@@ -93,7 +89,6 @@ using com::sun::star::container::XEnumeration; ...@@ -93,7 +89,6 @@ using com::sun::star::container::XEnumeration;
using com::sun::star::lang::WrappedTargetException; using com::sun::star::lang::WrappedTargetException;
using com::sun::star::sdbc::XRow; using com::sun::star::sdbc::XRow;
// using com::sun::star::sdbc::DataType;
using com::sun::star::sdbc::XCloseable; using com::sun::star::sdbc::XCloseable;
using com::sun::star::sdbc::XStatement; using com::sun::star::sdbc::XStatement;
using com::sun::star::sdbc::XResultSet; using com::sun::star::sdbc::XResultSet;
...@@ -103,7 +98,6 @@ using com::sun::star::sdbc::XDatabaseMetaData; ...@@ -103,7 +98,6 @@ using com::sun::star::sdbc::XDatabaseMetaData;
using com::sun::star::sdbcx::XColumnsSupplier; using com::sun::star::sdbcx::XColumnsSupplier;
using com::sun::star::sdbcx::XKeysSupplier; using com::sun::star::sdbcx::XKeysSupplier;
using com::sun::star::sdbcx::XViewsSupplier; using com::sun::star::sdbcx::XViewsSupplier;
// using com::sun::star::sdbcx::Privilege;
namespace pq_sdbc_driver namespace pq_sdbc_driver
{ {
...@@ -173,7 +167,7 @@ void Tables::refresh() ...@@ -173,7 +167,7 @@ void Tables::refresh()
m_values.realloc( tableIndex ); m_values.realloc( tableIndex );
m_values[currentTableIndex] = makeAny( prop ); m_values[currentTableIndex] = makeAny( prop );
OUStringBuffer buf( name.getLength() + schema.getLength() + 1); OUStringBuffer buf( name.getLength() + schema.getLength() + 1);
buf.append( schema ).appendAscii( "." ).append( name ); buf.append( schema + "." + name );
map[ buf.makeStringAndClear() ] = currentTableIndex; map[ buf.makeStringAndClear() ] = currentTableIndex;
} }
} }
...@@ -208,7 +202,7 @@ static void appendColumnList( ...@@ -208,7 +202,7 @@ static void appendColumnList(
} }
else else
{ {
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) ); buf.append( ", " );
} }
Reference< XPropertySet > column( xEnum->nextElement(), UNO_QUERY ); Reference< XPropertySet > column( xEnum->nextElement(), UNO_QUERY );
OUString name = extractStringProperty( column, st.NAME ); OUString name = extractStringProperty( column, st.NAME );
...@@ -225,12 +219,12 @@ static void appendColumnList( ...@@ -225,12 +219,12 @@ static void appendColumnList(
column->getPropertyValue( st.TYPE ) >>= dataType; column->getPropertyValue( st.TYPE ) >>= dataType;
if( com::sun::star::sdbc::DataType::INTEGER == dataType ) if( com::sun::star::sdbc::DataType::INTEGER == dataType )
{ {
buf.appendAscii( " serial "); buf.append( " serial ");
isNullable = sal_False; isNullable = sal_False;
} }
else if( com::sun::star::sdbc::DataType::BIGINT == dataType ) else if( com::sun::star::sdbc::DataType::BIGINT == dataType )
{ {
buf.appendAscii( " serial8 " ); buf.append( " serial8 " );
isNullable = sal_False; isNullable = sal_False;
} }
else else
...@@ -246,9 +240,7 @@ static void appendColumnList( ...@@ -246,9 +240,7 @@ static void appendColumnList(
} }
if( ! isNullable ) if( ! isNullable )
// buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " NULL " ) ); buf.append( " NOT NULL " );
// else
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " NOT NULL " ) );
} }
} }
...@@ -266,7 +258,7 @@ static void appendKeyList( ...@@ -266,7 +258,7 @@ static void appendKeyList(
Reference< XEnumeration > xEnum = keys->createEnumeration(); Reference< XEnumeration > xEnum = keys->createEnumeration();
while( xEnum.is() && xEnum->hasMoreElements() ) while( xEnum.is() && xEnum->hasMoreElements() )
{ {
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) ); buf.append( ", " );
Reference< XPropertySet > key( xEnum->nextElement(), UNO_QUERY ); Reference< XPropertySet > key( xEnum->nextElement(), UNO_QUERY );
bufferKey2TableConstraint( buf, key, settings ); bufferKey2TableConstraint( buf, key, settings );
} }
...@@ -292,9 +284,9 @@ void Tables::appendByDescriptor( ...@@ -292,9 +284,9 @@ void Tables::appendByDescriptor(
TransactionGuard transaction( stmt ); TransactionGuard transaction( stmt );
OUStringBuffer buf( 128 ); OUStringBuffer buf( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("CREATE TABLE" ) ); buf.append( "CREATE TABLE" );
bufferQuoteQualifiedIdentifier( buf, schema, name , m_pSettings); bufferQuoteQualifiedIdentifier( buf, schema, name , m_pSettings);
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "(" ) ); buf.append( "(" );
// columns // columns
Reference< XColumnsSupplier > supplier( descriptor, UNO_QUERY ); Reference< XColumnsSupplier > supplier( descriptor, UNO_QUERY );
...@@ -302,7 +294,7 @@ void Tables::appendByDescriptor( ...@@ -302,7 +294,7 @@ void Tables::appendByDescriptor(
appendKeyList( buf, Reference< XKeysSupplier >( descriptor, UNO_QUERY ), m_pSettings ); appendKeyList( buf, Reference< XKeysSupplier >( descriptor, UNO_QUERY ), m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ") " ) ); buf.append( ") " );
// execute the creation ! // execute the creation !
transaction.executeUpdate( buf.makeStringAndClear() ); transaction.executeUpdate( buf.makeStringAndClear() );
...@@ -311,9 +303,9 @@ void Tables::appendByDescriptor( ...@@ -311,9 +303,9 @@ void Tables::appendByDescriptor(
if( description.getLength() ) if( description.getLength() )
{ {
buf = OUStringBuffer( 128 ); buf = OUStringBuffer( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "COMMENT ON TABLE" ) ); buf.append( "COMMENT ON TABLE" );
bufferQuoteQualifiedIdentifier( buf, schema, name, m_pSettings ); bufferQuoteQualifiedIdentifier( buf, schema, name, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "IS " ) ); buf.append( "IS " );
bufferQuoteConstant( buf, description, m_pSettings); bufferQuoteConstant( buf, description, m_pSettings);
transaction.executeUpdate( buf.makeStringAndClear() ); transaction.executeUpdate( buf.makeStringAndClear() );
...@@ -335,10 +327,10 @@ void Tables::appendByDescriptor( ...@@ -335,10 +327,10 @@ void Tables::appendByDescriptor(
if( description.getLength() ) if( description.getLength() )
{ {
buf = OUStringBuffer( 128 ); buf = OUStringBuffer( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "COMMENT ON COLUMN " ) ); buf.append( "COMMENT ON COLUMN " );
bufferQuoteQualifiedIdentifier( bufferQuoteQualifiedIdentifier(
buf, schema, name, extractStringProperty( column, st.NAME ), m_pSettings ); buf, schema, name, extractStringProperty( column, st.NAME ), m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "IS " ) ); buf.append( "IS " );
bufferQuoteConstant( buf, description, m_pSettings ); bufferQuoteConstant( buf, description, m_pSettings );
transaction.executeUpdate( buf.makeStringAndClear() ); transaction.executeUpdate( buf.makeStringAndClear() );
} }
...@@ -352,39 +344,8 @@ void Tables::appendByDescriptor( ...@@ -352,39 +344,8 @@ void Tables::appendByDescriptor(
// TODO: cheaper recalculate // TODO: cheaper recalculate
// Container::append( concatQualified( schema, name ), descriptor ); // maintain the lists // Container::append( concatQualified( schema, name ), descriptor ); // maintain the lists
refresh(); refresh();
// increase the vector
// sal_Int32 index = m_values.getLength();
// m_values.realloc( index + 1 );
// Table * pTable =
// new Table( m_refMutex, m_origin, m_pSettings, false /*modifiable*/ );
// Reference< com::sun::star::beans::XPropertySet > prop = pTable;
// copyProperties( pTable, descriptor );
// m_values[index] = makeAny( prop );
// OUStringBuffer buf( name.getLength() + 1 + schema.getLength() );
// buf.append( schema ).appendAscii( "." ).append( name );
// m_name2index[ buf.makeStringAndClear() ] = index;
} }
// void Tables::dropByName( const ::rtl::OUString& elementName )
// throw (::com::sun::star::sdbc::SQLException,
// ::com::sun::star::container::NoSuchElementException,
// ::com::sun::star::uno::RuntimeException)
// {
// String2IntMap::const_iterator ii = m_name2index.find( elementName );
// if( ii == m_name2index.end() )
// {
// OUStringBuffer buf( 128 );
// buf.appendAscii( "Table " );
// buf.append( elementName );
// buf.appendAscii( " is unknown, so it can't be dropped" );
// throw com::sun::star::container::NoSuchElementException(
// buf.makeStringAndClear(), *this );
// }
// dropByIndex( ii->second );
// }
void Tables::dropByIndex( sal_Int32 index ) void Tables::dropByIndex( sal_Int32 index )
throw (::com::sun::star::sdbc::SQLException, throw (::com::sun::star::sdbc::SQLException,
::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IndexOutOfBoundsException,
...@@ -394,13 +355,9 @@ void Tables::dropByIndex( sal_Int32 index ) ...@@ -394,13 +355,9 @@ void Tables::dropByIndex( sal_Int32 index )
if( index < 0 || index >= m_values.getLength() ) if( index < 0 || index >= m_values.getLength() )
{ {
OUStringBuffer buf( 128 ); OUStringBuffer buf( 128 );
buf.appendAscii( "TABLES: Index out of range (allowed 0 to " ); buf.append( "TABLES: Index out of range (allowed 0 to " + OUString::number(m_values.getLength() -1) +
buf.append( (sal_Int32) (m_values.getLength() -1) ); ", got " + OUString::number( index ) + ")" );
buf.appendAscii( ", got " ); throw com::sun::star::lang::IndexOutOfBoundsException( buf.makeStringAndClear(), *this );
buf.append( index );
buf.appendAscii( ")" );
throw com::sun::star::lang::IndexOutOfBoundsException(
buf.makeStringAndClear(), *this );
} }
Reference< XPropertySet > set; Reference< XPropertySet > set;
...@@ -416,11 +373,11 @@ void Tables::dropByIndex( sal_Int32 index ) ...@@ -416,11 +373,11 @@ void Tables::dropByIndex( sal_Int32 index )
else else
{ {
OUStringBuffer update( 128 ); OUStringBuffer update( 128 );
update.appendAscii( RTL_CONSTASCII_STRINGPARAM( "DROP " ) ); update.append( "DROP " );
if( extractStringProperty( set, st.TYPE ).equals( st.VIEW ) ) if( extractStringProperty( set, st.TYPE ).equals( st.VIEW ) )
update.appendAscii( RTL_CONSTASCII_STRINGPARAM( "VIEW " ) ); update.append( "VIEW " );
else else
update.appendAscii( RTL_CONSTASCII_STRINGPARAM( "TABLE " ) ); update.append( "TABLE " );
bufferQuoteQualifiedIdentifier( update, schema, name, m_pSettings ); bufferQuoteQualifiedIdentifier( update, schema, name, m_pSettings );
Reference< XStatement > stmt = m_origin->createStatement( ); Reference< XStatement > stmt = m_origin->createStatement( );
DisposeGuard dispGuard( stmt ); DisposeGuard dispGuard( stmt );
......
...@@ -72,9 +72,6 @@ ...@@ -72,9 +72,6 @@
using osl::MutexGuard; using osl::MutexGuard;
using osl::Mutex; using osl::Mutex;
using rtl::OUString;
using rtl::OUStringBuffer;
using com::sun::star::container::XNameAccess; using com::sun::star::container::XNameAccess;
using com::sun::star::container::XIndexAccess; using com::sun::star::container::XIndexAccess;
using com::sun::star::container::ElementExistException; using com::sun::star::container::ElementExistException;
...@@ -109,8 +106,6 @@ using com::sun::star::sdbc::SQLException; ...@@ -109,8 +106,6 @@ using com::sun::star::sdbc::SQLException;
namespace pq_sdbc_driver namespace pq_sdbc_driver
{ {
#define ASCII_STR(x) OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
User::User( const ::rtl::Reference< RefCountedMutex > & refMutex, User::User( const ::rtl::Reference< RefCountedMutex > & refMutex,
const Reference< com::sun::star::sdbc::XConnection > & connection, const Reference< com::sun::star::sdbc::XConnection > & connection,
ConnectionSettings *pSettings ) ConnectionSettings *pSettings )
...@@ -173,9 +168,9 @@ void User::changePassword( ...@@ -173,9 +168,9 @@ void User::changePassword(
{ {
(void) oldPassword; (void) oldPassword;
rtl::OUStringBuffer buf(128); rtl::OUStringBuffer buf(128);
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER USER " ) ); buf.append( "ALTER USER " );
bufferQuoteIdentifier( buf, extractStringProperty( this, getStatics().NAME ), m_pSettings ); bufferQuoteIdentifier( buf, extractStringProperty( this, getStatics().NAME ), m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " PASSWORD " ) ); buf.append( " PASSWORD " );
bufferQuoteConstant( buf, newPassword, m_pSettings ); bufferQuoteConstant( buf, newPassword, m_pSettings );
Reference< XStatement > stmt = m_conn->createStatement(); Reference< XStatement > stmt = m_conn->createStatement();
DisposeGuard guard( stmt ); DisposeGuard guard( stmt );
...@@ -192,13 +187,9 @@ sal_Int32 User::getPrivileges( const ::rtl::OUString& objName, sal_Int32 objType ...@@ -192,13 +187,9 @@ sal_Int32 User::getPrivileges( const ::rtl::OUString& objName, sal_Int32 objType
rtl::OUString user = extractStringProperty( this, st.NAME ); rtl::OUString user = extractStringProperty( this, st.NAME );
rtl::OUStringBuffer buf( 128 ); rtl::OUStringBuffer buf( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("User::getPrivileges[") ); buf.append( "User::getPrivileges[" + extractStringProperty( this, st.NAME ) +
buf.append( extractStringProperty( this, st.NAME ) ); "] got called for " + objName + "(type=" +
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "] got called for " ) ); OUString::number(objType) + ")");
buf.append( objName );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "(type=" ) );
buf.append( objType );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ")" ) );
log( m_pSettings, LogLevel::INFO, buf.makeStringAndClear() ); log( m_pSettings, LogLevel::INFO, buf.makeStringAndClear() );
} }
// all privileges // all privileges
...@@ -217,18 +208,16 @@ void User::grantPrivileges( const ::rtl::OUString& objName, sal_Int32 objType, s ...@@ -217,18 +208,16 @@ void User::grantPrivileges( const ::rtl::OUString& objName, sal_Int32 objType, s
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
{ {
(void) objName; (void) objType; (void) objPrivileges; (void) objName; (void) objType; (void) objPrivileges;
throw com::sun::star::sdbc::SQLException( throw com::sun::star::sdbc::SQLException("pq_driver: privilege change not implemented yet",
ASCII_STR( "pq_driver: privilege change not implemented yet" ), *this, OUString(), 1, Any() );
*this, OUString(), 1, Any() );
} }
void User::revokePrivileges( const ::rtl::OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) void User::revokePrivileges( const ::rtl::OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges )
throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
{ {
(void) objName; (void) objType; (void) objPrivileges; (void) objName; (void) objType; (void) objPrivileges;
throw com::sun::star::sdbc::SQLException( throw com::sun::star::sdbc::SQLException("pq_driver: privilege change not implemented yet",
ASCII_STR( "pq_driver: privilege change not implemented yet" ), *this, OUString(), 1, Any() );
*this, OUString(), 1, Any() );
} }
//______________________________________________________________________________________ //______________________________________________________________________________________
......
...@@ -96,7 +96,6 @@ using com::sun::star::sdbc::XDatabaseMetaData; ...@@ -96,7 +96,6 @@ using com::sun::star::sdbc::XDatabaseMetaData;
namespace pq_sdbc_driver namespace pq_sdbc_driver
{ {
#define ASCII_STR(x) OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
Users::Users( Users::Users(
const ::rtl::Reference< RefCountedMutex > & refMutex, const ::rtl::Reference< RefCountedMutex > & refMutex,
const ::com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > & origin, const ::com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > & origin,
...@@ -117,8 +116,7 @@ void Users::refresh() ...@@ -117,8 +116,7 @@ void Users::refresh()
Reference< XStatement > stmt = m_origin->createStatement(); Reference< XStatement > stmt = m_origin->createStatement();
Reference< XResultSet > rs = Reference< XResultSet > rs = stmt->executeQuery( "SELECT usename FROM pg_shadow" );
stmt->executeQuery( ASCII_STR( "SELECT usename FROM pg_shadow" ) );
Reference< XRow > xRow( rs , UNO_QUERY ); Reference< XRow > xRow( rs , UNO_QUERY );
...@@ -164,9 +162,9 @@ void Users::appendByDescriptor( ...@@ -164,9 +162,9 @@ void Users::appendByDescriptor(
osl::MutexGuard guard( m_refMutex->mutex ); osl::MutexGuard guard( m_refMutex->mutex );
OUStringBuffer update( 128 ); OUStringBuffer update( 128 );
update.appendAscii( RTL_CONSTASCII_STRINGPARAM( "CREATE USER " ) ); update.append( "CREATE USER " );
bufferQuoteIdentifier( update, extractStringProperty( descriptor, getStatics().NAME ), m_pSettings ); bufferQuoteIdentifier( update, extractStringProperty( descriptor, getStatics().NAME ), m_pSettings );
update.appendAscii( RTL_CONSTASCII_STRINGPARAM( " PASSWORD " ) ); update.append( " PASSWORD " );
bufferQuoteConstant( update, extractStringProperty( descriptor, getStatics().PASSWORD ), m_pSettings ); bufferQuoteConstant( update, extractStringProperty( descriptor, getStatics().PASSWORD ), m_pSettings );
Reference< XStatement > stmt = m_origin->createStatement( ); Reference< XStatement > stmt = m_origin->createStatement( );
......
...@@ -73,10 +73,6 @@ ...@@ -73,10 +73,6 @@
using osl::MutexGuard; using osl::MutexGuard;
using osl::Mutex; using osl::Mutex;
using rtl::OUString;
using rtl::OUStringBuffer;
using rtl::OUStringToOString;
using com::sun::star::container::XNameAccess; using com::sun::star::container::XNameAccess;
using com::sun::star::container::XIndexAccess; using com::sun::star::container::XIndexAccess;
using com::sun::star::container::ElementExistException; using com::sun::star::container::ElementExistException;
...@@ -110,7 +106,6 @@ using com::sun::star::sdbc::SQLException; ...@@ -110,7 +106,6 @@ using com::sun::star::sdbc::SQLException;
namespace pq_sdbc_driver namespace pq_sdbc_driver
{ {
#define ASCII_STR(x) OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
View::View( const ::rtl::Reference< RefCountedMutex > & refMutex, View::View( const ::rtl::Reference< RefCountedMutex > & refMutex,
const Reference< com::sun::star::sdbc::XConnection > & connection, const Reference< com::sun::star::sdbc::XConnection > & connection,
...@@ -167,9 +162,9 @@ void View::rename( const ::rtl::OUString& newName ) ...@@ -167,9 +162,9 @@ void View::rename( const ::rtl::OUString& newName )
try try
{ {
OUStringBuffer buf(128); OUStringBuffer buf(128);
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) ); buf.append( "ALTER TABLE" );
bufferQuoteQualifiedIdentifier(buf, schema, oldName, m_pSettings ); bufferQuoteQualifiedIdentifier(buf, schema, oldName, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("SET SCHEMA" ) ); buf.append( "SET SCHEMA" );
bufferQuoteIdentifier( buf, newSchemaName, m_pSettings ); bufferQuoteIdentifier( buf, newSchemaName, m_pSettings );
Reference< XStatement > statement = m_conn->createStatement(); Reference< XStatement > statement = m_conn->createStatement();
statement->executeUpdate( buf.makeStringAndClear() ); statement->executeUpdate( buf.makeStringAndClear() );
...@@ -179,9 +174,8 @@ void View::rename( const ::rtl::OUString& newName ) ...@@ -179,9 +174,8 @@ void View::rename( const ::rtl::OUString& newName )
} }
catch( com::sun::star::sdbc::SQLException &e ) catch( com::sun::star::sdbc::SQLException &e )
{ {
OUStringBuffer buf( e.Message ); OUString buf( e.Message + "(NOTE: Only postgresql server >= V8.1 support changing a table's schema)" );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "(NOTE: Only postgresql server >= V8.1 support changing a table's schema)" ) ); e.Message = buf;
e.Message = buf.makeStringAndClear();
throw; throw;
} }
...@@ -189,9 +183,9 @@ void View::rename( const ::rtl::OUString& newName ) ...@@ -189,9 +183,9 @@ void View::rename( const ::rtl::OUString& newName )
if( ! oldName.equals( newTableName ) ) if( ! oldName.equals( newTableName ) )
{ {
OUStringBuffer buf(128); OUStringBuffer buf(128);
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) ); buf.appendAscii( "ALTER TABLE" );
bufferQuoteQualifiedIdentifier( buf, schema, oldName, m_pSettings ); bufferQuoteQualifiedIdentifier( buf, schema, oldName, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("RENAME TO" ) ); buf.appendAscii( "RENAME TO" );
bufferQuoteIdentifier( buf, newTableName, m_pSettings ); bufferQuoteIdentifier( buf, newTableName, m_pSettings );
Reference< XStatement > statement = m_conn->createStatement(); Reference< XStatement > statement = m_conn->createStatement();
statement->executeUpdate( buf.makeStringAndClear() ); statement->executeUpdate( buf.makeStringAndClear() );
......
...@@ -99,7 +99,6 @@ using com::sun::star::sdbc::XDatabaseMetaData; ...@@ -99,7 +99,6 @@ using com::sun::star::sdbc::XDatabaseMetaData;
namespace pq_sdbc_driver namespace pq_sdbc_driver
{ {
#define ASCII_STR(x) OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
Views::Views( Views::Views(
const ::rtl::Reference< RefCountedMutex > & refMutex, const ::rtl::Reference< RefCountedMutex > & refMutex,
const ::com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > & origin, const ::com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > & origin,
...@@ -120,16 +119,15 @@ void Views::refresh() ...@@ -120,16 +119,15 @@ void Views::refresh()
Reference< XStatement > stmt = m_origin->createStatement(); Reference< XStatement > stmt = m_origin->createStatement();
Reference< XResultSet > rs = stmt->executeQuery( Reference< XResultSet > rs = stmt->executeQuery("SELECT "
ASCII_STR( "SELECT " "DISTINCT ON( pg_namespace.nspname, relname) " // needed because of duplicates
"DISTINCT ON( pg_namespace.nspname, relname) " // needed because of duplicates "pg_namespace.nspname," // 1
"pg_namespace.nspname," // 1 "relname," // 2
"relname," // 2 "pg_get_viewdef(ev_class) " // 3
"pg_get_viewdef(ev_class) " // 3 "FROM pg_namespace, pg_class, pg_rewrite "
"FROM pg_namespace, pg_class, pg_rewrite " "WHERE pg_namespace.oid = relnamespace "
"WHERE pg_namespace.oid = relnamespace " "AND pg_class.oid = ev_class "
"AND pg_class.oid = ev_class " "AND relkind=\'v\'" );
"AND relkind='v'" ) );
Reference< XRow > xRow( rs , UNO_QUERY ); Reference< XRow > xRow( rs , UNO_QUERY );
...@@ -157,7 +155,7 @@ void Views::refresh() ...@@ -157,7 +155,7 @@ void Views::refresh()
m_values.realloc( viewIndex ); m_values.realloc( viewIndex );
m_values[currentViewIndex] = makeAny( prop ); m_values[currentViewIndex] = makeAny( prop );
OUStringBuffer buf( table.getLength() + schema.getLength() + 1); OUStringBuffer buf( table.getLength() + schema.getLength() + 1);
buf.append( schema ).appendAscii( "." ).append( table ); buf.append( schema + "." + table );
map[ buf.makeStringAndClear() ] = currentViewIndex; map[ buf.makeStringAndClear() ] = currentViewIndex;
} }
} }
...@@ -189,10 +187,9 @@ void Views::appendByDescriptor( ...@@ -189,10 +187,9 @@ void Views::appendByDescriptor(
OUStringBuffer buf( 128 ); OUStringBuffer buf( 128 );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "CREATE VIEW " ) ); buf.append( "CREATE VIEW ");
bufferQuoteQualifiedIdentifier( buf, schema, name, m_pSettings ); bufferQuoteQualifiedIdentifier( buf, schema, name, m_pSettings );
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " AS " ) ); buf.append(" AS " + command );
buf.append( command );
stmt->executeUpdate( buf.makeStringAndClear() ); stmt->executeUpdate( buf.makeStringAndClear() );
...@@ -202,18 +199,6 @@ void Views::appendByDescriptor( ...@@ -202,18 +199,6 @@ void Views::appendByDescriptor(
{ {
m_pSettings->pTablesImpl->refresh(); m_pSettings->pTablesImpl->refresh();
} }
// increase the vector
// sal_Int32 index = m_values.getLength();
// m_values.realloc( index + 1 );
// View * pView =
// new View( m_refMutex, m_origin, m_pSettings, false /*modifiable*/ );
// Reference< com::sun::star::beans::XPropertySet > prop = pTable;
// copyProperties( pTable, descriptor );
// m_values[index] = makeAny( prop );
// OUStringBuffer buf( name.getLength() + 1 + schema.getLength() );
// buf.append( schema ).appendAscii( "." ).append( name );
// m_name2index[ buf.makeStringAndClear() ] = index;
} }
void Views::dropByName( const ::rtl::OUString& elementName ) void Views::dropByName( const ::rtl::OUString& elementName )
...@@ -225,9 +210,7 @@ void Views::dropByName( const ::rtl::OUString& elementName ) ...@@ -225,9 +210,7 @@ void Views::dropByName( const ::rtl::OUString& elementName )
if( ii == m_name2index.end() ) if( ii == m_name2index.end() )
{ {
OUStringBuffer buf( 128 ); OUStringBuffer buf( 128 );
buf.appendAscii( "View " ); buf.append( "View " + elementName + " is unknown, so it can't be dropped" );
buf.append( elementName );
buf.appendAscii( " is unknown, so it can't be dropped" );
throw com::sun::star::container::NoSuchElementException( throw com::sun::star::container::NoSuchElementException(
buf.makeStringAndClear(), *this ); buf.makeStringAndClear(), *this );
} }
...@@ -239,17 +222,12 @@ void Views::dropByIndex( sal_Int32 index ) ...@@ -239,17 +222,12 @@ void Views::dropByIndex( sal_Int32 index )
::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IndexOutOfBoundsException,
::com::sun::star::uno::RuntimeException) ::com::sun::star::uno::RuntimeException)
{ {
// throw SQLException(
// ASCII_STR( "view deletion not supported" ), *this, OUString(), 1, Any() );
osl::MutexGuard guard( m_refMutex->mutex ); osl::MutexGuard guard( m_refMutex->mutex );
if( index < 0 || index >= m_values.getLength() ) if( index < 0 || index >= m_values.getLength() )
{ {
OUStringBuffer buf( 128 ); OUStringBuffer buf( 128 );
buf.appendAscii( "VIEWS: Index out of range (allowed 0 to " ); buf.append( "VIEWS: Index out of range (allowed 0 to " + OUString::number(m_values.getLength() -1) +
buf.append( (sal_Int32) (m_values.getLength() -1) ); ", got " + OUString::number( index ) + ")");
buf.appendAscii( ", got " );
buf.append( index );
buf.appendAscii( ")" );
throw com::sun::star::lang::IndexOutOfBoundsException( throw com::sun::star::lang::IndexOutOfBoundsException(
buf.makeStringAndClear(), *this ); buf.makeStringAndClear(), *this );
} }
...@@ -262,8 +240,7 @@ void Views::dropByIndex( sal_Int32 index ) ...@@ -262,8 +240,7 @@ void Views::dropByIndex( sal_Int32 index )
set->getPropertyValue( st.NAME ) >>= name; set->getPropertyValue( st.NAME ) >>= name;
OUStringBuffer update( 128 ); OUStringBuffer update( 128 );
update.appendAscii( "DROP VIEW \"" ).append( schema ).appendAscii( "\".\"" ); update.append( "DROP VIEW \"" + schema + "\".\"" + name + "\"" );
update.append( name ).appendAscii( "\"" );
Reference< XStatement > stmt = m_origin->createStatement( ); Reference< XStatement > stmt = m_origin->createStatement( );
......
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