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