LCOV - code coverage report
Current view: top level - connectivity/source/drivers/postgresql - pq_xcolumns.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 162 0.0 %
Date: 2014-11-03 Functions: 0 14 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*************************************************************************
       3             :  *
       4             :  *  Effective License of whole file:
       5             :  *
       6             :  *    This library is free software; you can redistribute it and/or
       7             :  *    modify it under the terms of the GNU Lesser General Public
       8             :  *    License version 2.1, as published by the Free Software Foundation.
       9             :  *
      10             :  *    This library is distributed in the hope that it will be useful,
      11             :  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13             :  *    Lesser General Public License for more details.
      14             :  *
      15             :  *    You should have received a copy of the GNU Lesser General Public
      16             :  *    License along with this library; if not, write to the Free Software
      17             :  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      18             :  *    MA  02111-1307  USA
      19             :  *
      20             :  *  Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
      21             :  *
      22             :  *    The Contents of this file are made available subject to the terms of
      23             :  *    the GNU Lesser General Public License Version 2.1
      24             :  *
      25             :  *    Copyright: 2000 by Sun Microsystems, Inc.
      26             :  *
      27             :  *    Contributor(s): Joerg Budischewski
      28             :  *
      29             :  *  All parts contributed on or after August 2011:
      30             :  *
      31             :  *    This Source Code Form is subject to the terms of the Mozilla Public
      32             :  *    License, v. 2.0. If a copy of the MPL was not distributed with this
      33             :  *    file, You can obtain one at http://mozilla.org/MPL/2.0/.
      34             :  *
      35             :  ************************************************************************/
      36             : 
      37             : #include <rtl/ustrbuf.hxx>
      38             : #include <rtl/strbuf.hxx>
      39             : 
      40             : #include <com/sun/star/sdbc/XRow.hpp>
      41             : #include <com/sun/star/sdbc/XParameters.hpp>
      42             : #include <com/sun/star/sdbc/DataType.hpp>
      43             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      44             : 
      45             : #include <cppuhelper/implbase1.hxx>
      46             : 
      47             : #include "pq_xcolumns.hxx"
      48             : #include "pq_xcolumn.hxx"
      49             : #include "pq_statics.hxx"
      50             : #include "pq_tools.hxx"
      51             : 
      52             : using osl::MutexGuard;
      53             : 
      54             : 
      55             : using com::sun::star::beans::XPropertySet;
      56             : using com::sun::star::beans::XPropertyChangeListener;
      57             : using com::sun::star::beans::PropertyChangeEvent;
      58             : 
      59             : using com::sun::star::uno::Any;
      60             : using com::sun::star::uno::makeAny;
      61             : using com::sun::star::uno::UNO_QUERY;
      62             : using com::sun::star::uno::Type;
      63             : using com::sun::star::uno::XInterface;
      64             : using com::sun::star::uno::Reference;
      65             : using com::sun::star::uno::Sequence;
      66             : using com::sun::star::uno::RuntimeException;
      67             : 
      68             : using com::sun::star::container::NoSuchElementException;
      69             : using com::sun::star::lang::WrappedTargetException;
      70             : 
      71             : using com::sun::star::sdbc::XRow;
      72             : using com::sun::star::sdbc::XCloseable;
      73             : using com::sun::star::sdbc::XStatement;
      74             : using com::sun::star::sdbc::XResultSet;
      75             : using com::sun::star::sdbc::XParameters;
      76             : using com::sun::star::sdbc::XPreparedStatement;
      77             : using com::sun::star::sdbc::XDatabaseMetaData;
      78             : using com::sun::star::sdbc::SQLException;
      79             : 
      80             : namespace pq_sdbc_driver
      81             : {
      82             : 
      83           0 : static Any isCurrency( const OUString & typeName )
      84             : {
      85           0 :     sal_Bool b = typeName.equalsIgnoreAsciiCase("money");
      86           0 :     return Any( &b, getBooleanCppuType() );
      87             : }
      88             : 
      89             : // static sal_Bool isAutoIncrement8( const OUString & typeName )
      90             : // {
      91             : //     return typeName.equalsIgnoreAsciiCase("serial8") ||
      92             : //         typeName.equalsIgnoreAsciiCase("bigserial");
      93             : // }
      94             : 
      95           0 : static Any isAutoIncrement( const OUString & defaultValue )
      96             : {
      97           0 :     sal_Bool ret = defaultValue.startsWith( "nextval(" );
      98             : //     printf( "%s %d\n",
      99             : //             OUStringToOString(defaultValue, RTL_TEXTENCODING_ASCII_US).getStr(),
     100             : //             ret );
     101             : //     {
     102             : //     static const char  * const serials[] =
     103             : //         {
     104             : //             "serial", "serial4", "serial8", "bigserial", 0
     105             : //         };
     106             : // s    sal_Bool b = sal_False;
     107             : //     for( int i = 0; !b && serials[i] ; i ++ )
     108             : //     {
     109             : //         b = b || typeName.equalsIgnoreAsciiCaseAscii( serials[i] );
     110             : //     }
     111           0 :     return Any ( &ret, getBooleanCppuType() );
     112             : }
     113             : 
     114           0 : Columns::Columns(
     115             :         const ::rtl::Reference< RefCountedMutex > & refMutex,
     116             :         const ::com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection >  & origin,
     117             :         ConnectionSettings *pSettings,
     118             :         const OUString &schemaName,
     119             :         const OUString &tableName)
     120             :     : Container( refMutex, origin, pSettings,  "COLUMN" ),
     121             :       m_schemaName( schemaName ),
     122           0 :       m_tableName( tableName )
     123           0 : {}
     124             : 
     125           0 : Columns::~Columns()
     126           0 : {}
     127             : 
     128           0 : OUString columnMetaData2SDBCX(
     129             :     ReflectionBase *pBase, const com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > &xRow )
     130             : {
     131           0 :     Statics & st = getStatics();
     132             : 
     133             :     //  1. TABLE_CAT string => table catalog (may be NULL)
     134             :     //               => not supported
     135             :     //  2. TABLE_SCHEM string => table schema (may be NULL)
     136             :     //               => pg_namespace.nspname
     137             :     //  3. TABLE_NAME string => table name
     138             :     //               => pg_class.relname
     139             :     //  4. COLUMN_NAME string => column name
     140             :     //               => pg_attribure.attname
     141             :     //  5. DATA_TYPE short => SQL type from java.sql.Types
     142             :     //               => pg_type.typname => sdbc.DataType
     143             :     //  6. TYPE_NAME string => Data source dependent type name, for a UDT the
     144             :     //                         type name is fully qualified
     145             :     //               => pg_type.typname
     146             :     //  7. COLUMN_SIZE long => column size. For char or date types this is
     147             :     //                         the maximum number of characters, for numeric
     148             :     //                         or decimal types this is precision.
     149             :     //               => pg_type.typlen ( TODO: What is about variable size ? )
     150             :     //  8. BUFFER_LENGTH is not used.
     151             :     //               => not used
     152             :     //  9. DECIMAL_DIGITS long => the number of fractional digits
     153             :     //               => don't know ! TODO !
     154             :     //  10. NUM_PREC_RADIX long => Radix (typically either 10 or 2)
     155             :     //               => TODO ??
     156             :     //  11. NULLABLE long => is NULL allowed?
     157             :     //                      NO_NULLS - might not allow NULL values
     158             :     //                      NULABLE - definitely allows NULL values
     159             :     //                      NULLABLE_UNKNOWN - nullability unknown
     160             :     //               => pg_attribute.attnotnull
     161             :     //  12. REMARKS string => comment describing column (may be NULL )
     162             :     //               => Don't know, there does not seem to exist something like
     163             :     //                  that in postgres
     164             :     //  13. COLUMN_DEF string => default value (may be NULL)
     165             :     //               => pg_type.typdefault
     166             :     //  14. SQL_DATA_TYPE long => unused
     167             :     //               => empty
     168             :     //  15. SQL_DATETIME_SUB long => unused
     169             :     //               => empty
     170             :     //  16. CHAR_OCTET_LENGTH long => for char types the maximum number of
     171             :     //                                bytes in the column
     172             :     //               => pg_type.typlen
     173             :     //  17. ORDINAL_POSITION int => index of column in table (starting at 1)
     174             :     //                              pg_attribute.attnum
     175             :     //  18. IS_NULLABLE string => "NO" means column definitely does not allow
     176             :     //                            NULL values; "YES" means the column might
     177             :     //                            allow NULL values. An empty string means
     178             :     //                            nobody knows.
     179             :     //               => pg_attribute.attnotnull
     180             : 
     181             :     static const int COLUMN_NAME = 4;
     182             :     static const int DATA_TYPE = 5;
     183             :     static const int TYPE_NAME = 6;
     184             :     static const int COLUMN_SIZE = 7;
     185             :     static const int DECIMAL_DIGITS = 9;
     186             :     static const int IS_NULLABLE = 11;
     187             :     static const int DESCRIPTION = 12;
     188             :     static const int DEFAULT_VALUE = 13;
     189             : 
     190           0 :     OUString name = xRow->getString( COLUMN_NAME );
     191           0 :     OUString typeName  = xRow->getString( TYPE_NAME );
     192             : 
     193             :     pBase->setPropertyValue_NoBroadcast_public(
     194           0 :         st.NAME, makeAny( name ) );
     195             : 
     196             :     pBase->setPropertyValue_NoBroadcast_public(
     197           0 :         st.TYPE, makeAny( xRow->getInt( DATA_TYPE ) ) );
     198             : 
     199             :     pBase->setPropertyValue_NoBroadcast_public(
     200           0 :         st.TYPE_NAME, makeAny( typeName ) );
     201             : 
     202             :     pBase->setPropertyValue_NoBroadcast_public(
     203           0 :         st.PRECISION, makeAny( xRow->getInt( COLUMN_SIZE ) ) );
     204             : 
     205             :     pBase->setPropertyValue_NoBroadcast_public(
     206           0 :         st.SCALE, makeAny( xRow->getInt( DECIMAL_DIGITS ) ) );
     207             : 
     208             :     pBase->setPropertyValue_NoBroadcast_public(
     209           0 :         st.IS_NULLABLE, makeAny( xRow->getInt( IS_NULLABLE ) ) );
     210             : 
     211             :     pBase->setPropertyValue_NoBroadcast_public(
     212           0 :         st.DEFAULT_VALUE, makeAny( xRow->getString( DEFAULT_VALUE ) ) );
     213             : 
     214             : //     pBase->setPropertyValue_NoBroadcast_public(
     215             : //         st.DESCRIPTION, makeAny( xRow->getString( DESCRIPTION ) ) );
     216             : 
     217             : //     if( pBase->getPropertySetInfo()->hasPropertyByName( st.HELP_TEXT ) )
     218             : //         pBase->setPropertyValue_NoBroadcast_public(
     219             : //             st.HELP_TEXT, makeAny( xRow->getString( DESCRIPTION ) ) );
     220             : //     else // for key columns, etc. ...
     221             :         pBase->setPropertyValue_NoBroadcast_public(
     222           0 :             st.DESCRIPTION, makeAny( xRow->getString( DESCRIPTION ) ) );
     223             : 
     224             : 
     225             :     // maybe a better criterion than the type name can be found in future
     226             :     pBase->setPropertyValue_NoBroadcast_public(
     227           0 :         st.IS_AUTO_INCREMENT, isAutoIncrement(xRow->getString( DEFAULT_VALUE )) );
     228             : 
     229             :     pBase->setPropertyValue_NoBroadcast_public(
     230           0 :         st.IS_CURRENCY, isCurrency( typeName));
     231           0 :     return name;
     232             : }
     233             : 
     234             : 
     235             : // class CommentChanger : public cppu::WeakImplHelper1< XPropertyChangeListener >
     236             : // {
     237             : //     ::rtl::Reference< RefCountedMutex > m_refMutex;
     238             : //     ::com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > m_connection;
     239             : //     ConnectionSettings *m_pSettings;
     240             : //     OUString m_schema;
     241             : //     OUString m_table;
     242             : //     OUString m_column;
     243             : 
     244             : // public:
     245             : //     CommentChanger(
     246             : //         const ::rtl::Reference< RefCountedMutex > & refMutex,
     247             : //         const ::com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > & connection,
     248             : //         ConnectionSettings *pSettings,
     249             : //         const OUString & schema,
     250             : //         const OUString & table,
     251             : //         const OUString & column ) :
     252             : //         m_refMutex( refMutex ),
     253             : //         m_connection( connection ),
     254             : //         m_pSettings( pSettings ),
     255             : //         m_schema ( schema ),
     256             : //         m_table ( table ),
     257             : //         m_column ( column )
     258             : //     {}
     259             : 
     260             : 
     261             : //     // Methods
     262             : //     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException)
     263             : //     {
     264             : //         osl::MutexGuard guard( m_refMutex->mutex );
     265             : //         m_connection.clear();
     266             : //     }
     267             : //         // Methods
     268             : //     virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException)
     269             : //     {
     270             : //         osl::MutexGuard guard( m_refMutex->mutex );
     271             : //         OUStringBuffer buf( 128 );
     272             : //         OUString comment;
     273             : //         evt.NewValue >>= comment;
     274             : //         buf.append( "COMMENT ON COLUMN" );
     275             : //         bufferQuoteQualifiedIdentifier( buf, m_schema, m_table , m_column );
     276             : //         buf.append( "IS " );
     277             : //         bufferQuoteConstant( buf, comment,m_pSettings->encoding);
     278             : 
     279             : //         printf( "changing comment of column %s to %s\n",
     280             : //                 OUStringToOString( m_column, RTL_TEXTENCODING_ASCII_US ).getStr(),
     281             : //                 OUStringToOString( comment, RTL_TEXTENCODING_ASCII_US ).getStr() );
     282             : 
     283             : //         m_connection->createStatement()->executeUpdate( buf.makeStringAndClear() );
     284             : //     }
     285             : // };
     286             : 
     287           0 : void Columns::refresh()
     288             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     289             : {
     290             :     try
     291             :     {
     292           0 :         if( isLog( m_pSettings, LogLevel::INFO ) )
     293             :         {
     294           0 :             OStringBuffer buf;
     295           0 :             buf.append( "sdbcx.Columns get refreshed for table " );
     296           0 :             buf.append( OUStringToOString( m_schemaName, m_pSettings->encoding ) );
     297           0 :             buf.append( "." );
     298           0 :             buf.append( OUStringToOString( m_tableName, m_pSettings->encoding ) );
     299           0 :             log( m_pSettings, LogLevel::INFO, buf.makeStringAndClear().getStr() );
     300             :         }
     301           0 :         osl::MutexGuard guard( m_refMutex->mutex );
     302             : 
     303           0 :         Statics &st = getStatics();
     304           0 :         Reference< XDatabaseMetaData > meta = m_origin->getMetaData();
     305             : 
     306             :         Reference< XResultSet > rs =
     307           0 :             meta->getColumns( Any(), m_schemaName, m_tableName, st.cPERCENT );
     308             : 
     309           0 :         DisposeGuard disposeIt( rs );
     310           0 :         Reference< XRow > xRow( rs , UNO_QUERY );
     311             : 
     312           0 :         String2IntMap map;
     313             : 
     314           0 :         m_values = Sequence< com::sun::star::uno::Any > ();
     315           0 :         int columnIndex = 0;
     316           0 :         while( rs->next() )
     317             :         {
     318             :             Column * pColumn =
     319           0 :                 new Column( m_refMutex, m_origin, m_pSettings );
     320           0 :             Reference< com::sun::star::beans::XPropertySet > prop = pColumn;
     321             : 
     322           0 :             OUString name = columnMetaData2SDBCX( pColumn, xRow );
     323             : //             pColumn->addPropertyChangeListener(
     324             : //                 st.HELP_TEXT,
     325             : //                 new CommentChanger(
     326             : //                     m_refMutex,
     327             : //                     m_origin,
     328             : //                     m_pSettings,
     329             : //                     m_schemaName,
     330             : //                     m_tableName,
     331             : //                     name ) );
     332             : 
     333             :             {
     334           0 :                 const int currentColumnIndex = columnIndex++;
     335             :                 assert(currentColumnIndex  == m_values.getLength());
     336           0 :                 m_values.realloc( columnIndex );
     337           0 :                 m_values[currentColumnIndex] = makeAny( prop );
     338           0 :                 map[ name ] = currentColumnIndex;
     339             :             }
     340           0 :         }
     341           0 :         m_name2index.swap( map );
     342             :     }
     343           0 :     catch ( com::sun::star::sdbc::SQLException & e )
     344             :     {
     345           0 :         throw RuntimeException( e.Message , e.Context );
     346             :     }
     347           0 :     fire( RefreshedBroadcaster( *this ) );
     348           0 : }
     349             : 
     350             : 
     351           0 : void alterColumnByDescriptor(
     352             :     const OUString & schemaName,
     353             :     const OUString & tableName,
     354             :     ConnectionSettings *settings,
     355             :     const Reference< XStatement > &stmt,
     356             :     const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > & past,
     357             :     const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > & future)
     358             : {
     359           0 :     Statics & st  = getStatics();
     360             : 
     361             : //     if( past->getPropertyValue( st.TABLE_NAME ) != future->getPropertyValue( st.TABLE_NAME ) ||
     362             : //         past->getPropertyValue( st.SCHEMA_NAME ) != future->getPropertyValue( st.SCHEMA_NAME ))
     363             : //     {
     364             : //         OUStringBuffer buf(128);
     365             : //         buf.append( "Can't move column " );
     366             : //         buf.append( extractStringProperty( past, st.COLUMN_NAME ) );
     367             : //         buf.append( " from table " );
     368             : //         buf.append( extractStringProperty( past, st.TABLE_NAME ) );
     369             : //         buf.append( " to table " );
     370             : //         buf.append( extractStringProperty( past, st.TABLE_NAME ) );
     371             : //         throw SQLException( buf.makeStringAndClear() );
     372             : //     }
     373             : 
     374             : //     OUString tableName = extractStringProperty( past, st.TABLE_NAME );
     375             : //     OUString schemaName = extractStringProperty( past, st.SCHEMA_NAME );
     376           0 :     OUString pastColumnName = extractStringProperty( past, st.NAME );
     377           0 :     OUString futureColumnName = extractStringProperty( future, st.NAME );
     378           0 :     OUString pastTypeName = sqltype2string( past );
     379           0 :     OUString futureTypeName = sqltype2string( future );
     380             : 
     381           0 :     TransactionGuard transaction( stmt );
     382             : 
     383           0 :     OUStringBuffer buf( 128 );
     384           0 :     if( ! pastColumnName.getLength())
     385             :     {
     386             :         // create a new column
     387           0 :         buf.append( "ALTER TABLE" );
     388           0 :         bufferQuoteQualifiedIdentifier( buf, schemaName, tableName, settings );
     389           0 :         buf.append( "ADD COLUMN" );
     390           0 :         bufferQuoteIdentifier( buf, futureColumnName, settings );
     391           0 :         buf.append( futureTypeName );
     392           0 :         transaction.executeUpdate( buf.makeStringAndClear() );
     393             :     }
     394             :     else
     395             :     {
     396           0 :         if( pastTypeName != futureTypeName )
     397             :         {
     398             :             throw RuntimeException(
     399           0 :                 "Can't modify column types, drop the column and create a new one" );
     400             :         }
     401             : 
     402           0 :         if( pastColumnName != futureColumnName )
     403             :         {
     404           0 :             buf.append( "ALTER TABLE" );
     405           0 :             bufferQuoteQualifiedIdentifier( buf, schemaName, tableName, settings );
     406           0 :             buf.append( "RENAME COLUMN" );
     407           0 :             bufferQuoteIdentifier( buf, pastColumnName, settings );
     408           0 :             buf.append( "TO" );
     409           0 :             bufferQuoteIdentifier( buf, futureColumnName, settings );
     410           0 :             transaction.executeUpdate( buf.makeStringAndClear() );
     411             :         }
     412             :     }
     413             : 
     414           0 :     OUString futureDefaultValue = extractStringProperty( future, st.DEFAULT_VALUE );
     415           0 :     OUString pastDefaultValue = extractStringProperty( past, st.DEFAULT_VALUE );
     416           0 :     if( futureDefaultValue != pastDefaultValue )
     417             :     {
     418           0 :         buf = OUStringBuffer( 128 );
     419           0 :         buf.append( "ALTER TABLE" );
     420           0 :         bufferQuoteQualifiedIdentifier( buf, schemaName, tableName, settings );
     421           0 :         buf.append( "ALTER COLUMN" );
     422           0 :         bufferQuoteIdentifier( buf, futureColumnName, settings );
     423           0 :         buf.append( "SET DEFAULT " );
     424             :         // LEM TODO: check out
     425             :         // default value is not quoted, caller needs to quote himself (otherwise
     426             :         // how to pass e.g. nextval('something' ) ????
     427           0 :         buf.append( futureDefaultValue );
     428             : //        bufferQuoteConstant( buf, defaultValue, encoding );
     429           0 :         transaction.executeUpdate( buf.makeStringAndClear() );
     430             :     }
     431             : 
     432           0 :     sal_Int32 futureNullable = extractIntProperty( future, st.IS_NULLABLE );
     433           0 :     sal_Int32 pastNullable = extractIntProperty( past, st.IS_NULLABLE );
     434           0 :     if( futureNullable != pastNullable )
     435             :     {
     436           0 :         buf = OUStringBuffer( 128 );
     437           0 :         buf.append( "ALTER TABLE" );
     438           0 :         bufferQuoteQualifiedIdentifier( buf, schemaName, tableName, settings );
     439           0 :         buf.append( "ALTER COLUMN" );
     440           0 :         bufferQuoteIdentifier( buf, futureColumnName, settings );
     441           0 :         if( futureNullable == com::sun::star::sdbc::ColumnValue::NO_NULLS )
     442             :         {
     443           0 :             buf.append( "SET" );
     444             :         }
     445             :         else
     446             :         {
     447           0 :             buf.append( "DROP" );
     448             :         }
     449           0 :         buf.append( " NOT NULL" );
     450           0 :         transaction.executeUpdate( buf.makeStringAndClear() );
     451             :     }
     452             : 
     453             : //     OUString futureComment = extractStringProperty( future, st.HELP_TEXT );
     454             : //     OUString pastComment = extractStringProperty( past, st.HELP_TEXT );
     455             : //     printf( "past Comment %s, futureComment %s\n",
     456             : //             OUStringToOString( pastComment, RTL_TEXTENCODING_ASCII_US ).getStr(),
     457             : //             OUStringToOString( futureComment, RTL_TEXTENCODING_ASCII_US ).getStr() );
     458           0 :     OUString futureComment = extractStringProperty( future, st.DESCRIPTION );
     459           0 :     OUString pastComment = extractStringProperty( past, st.DESCRIPTION );
     460             : 
     461           0 :     if( futureComment != pastComment )
     462             :     {
     463           0 :         buf = OUStringBuffer( 128 );
     464           0 :         buf.append( "COMMENT ON COLUMN" );
     465           0 :         bufferQuoteQualifiedIdentifier( buf, schemaName, tableName , futureColumnName, settings );
     466           0 :         buf.append( "IS " );
     467           0 :         bufferQuoteConstant( buf, futureComment, settings );
     468           0 :         transaction.executeUpdate( buf.makeStringAndClear() );
     469             :     }
     470           0 :     transaction.commit();
     471           0 : }
     472             : 
     473           0 : void Columns::appendByDescriptor(
     474             :     const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& future )
     475             :     throw (::com::sun::star::sdbc::SQLException,
     476             :            ::com::sun::star::container::ElementExistException,
     477             :            ::com::sun::star::uno::RuntimeException, std::exception)
     478             : {
     479           0 :     osl::MutexGuard guard( m_refMutex->mutex );
     480           0 :     Statics & st = getStatics();
     481           0 :     Reference< XPropertySet > past = createDataDescriptor();
     482           0 :     past->setPropertyValue( st.IS_NULLABLE, makeAny( com::sun::star::sdbc::ColumnValue::NULLABLE ) );
     483             :     alterColumnByDescriptor(
     484           0 :         m_schemaName, m_tableName, m_pSettings, m_origin->createStatement() , past, future  );
     485             : 
     486           0 :     refresh();
     487           0 : }
     488             : 
     489             : // void Columns::dropByName( const OUString& elementName )
     490             : //     throw (::com::sun::star::sdbc::SQLException,
     491             : //            ::com::sun::star::container::NoSuchElementException,
     492             : //            ::com::sun::star::uno::RuntimeException)
     493             : // {
     494             : //     String2IntMap::const_iterator ii = m_name2index.find( elementName );
     495             : //     if( ii == m_name2index.end() )
     496             : //     {
     497             : //         OUStringBuffer buf( 128 );
     498             : //         buf.appendAscii( "Column " );
     499             : //         buf.append( elementName );
     500             : //         buf.appendAscii( " is unknown in table " );
     501             : //         buf.append( m_schemaName );
     502             : //         buf.appendAscii( "." );
     503             : //         buf.append( m_tableName );
     504             : //         buf.appendAscii( ", so it can't be dropped" );
     505             : //         throw com::sun::star::container::NoSuchElementException(
     506             : //             buf.makeStringAndClear(), *this );
     507             : //     }
     508             : //     dropByIndex( ii->second );
     509             : // }
     510             : 
     511           0 : void Columns::dropByIndex( sal_Int32 index )
     512             :     throw (::com::sun::star::sdbc::SQLException,
     513             :            ::com::sun::star::lang::IndexOutOfBoundsException,
     514             :            ::com::sun::star::uno::RuntimeException, std::exception)
     515             : {
     516           0 :     osl::MutexGuard guard( m_refMutex->mutex );
     517           0 :     if( index < 0 ||  index >= m_values.getLength() )
     518             :     {
     519           0 :         OUStringBuffer buf( 128 );
     520           0 :         buf.appendAscii( "COLUMNS: Index out of range (allowed 0 to " );
     521           0 :         buf.append((sal_Int32)(m_values.getLength() -1) );
     522           0 :         buf.appendAscii( ", got " );
     523           0 :         buf.append( index );
     524           0 :         buf.appendAscii( ")" );
     525             :         throw com::sun::star::lang::IndexOutOfBoundsException(
     526           0 :             buf.makeStringAndClear(), *this );
     527             :     }
     528             : 
     529           0 :     Reference< XPropertySet > set;
     530           0 :     m_values[index] >>= set;
     531           0 :     Statics &st = getStatics();
     532           0 :     OUString name;
     533           0 :     set->getPropertyValue( st.NAME ) >>= name;
     534             : 
     535           0 :     OUStringBuffer update( 128 );
     536           0 :     update.appendAscii( "ALTER TABLE ONLY");
     537           0 :     bufferQuoteQualifiedIdentifier( update, m_schemaName, m_tableName, m_pSettings );
     538           0 :     update.appendAscii( "DROP COLUMN" );
     539           0 :     bufferQuoteIdentifier( update, name, m_pSettings );
     540           0 :     Reference< XStatement > stmt = m_origin->createStatement( );
     541           0 :     DisposeGuard disposeIt( stmt );
     542           0 :     stmt->executeUpdate( update.makeStringAndClear() );
     543             : 
     544           0 :     Container::dropByIndex( index );
     545           0 : }
     546             : 
     547             : 
     548           0 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > Columns::createDataDescriptor()
     549             :         throw (::com::sun::star::uno::RuntimeException, std::exception)
     550             : {
     551           0 :     return new ColumnDescriptor( m_refMutex, m_origin, m_pSettings );
     552             : }
     553             : 
     554           0 : Reference< com::sun::star::container::XNameAccess > Columns::create(
     555             :     const ::rtl::Reference< RefCountedMutex > & refMutex,
     556             :     const ::com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection >  & origin,
     557             :     ConnectionSettings *pSettings,
     558             :     const OUString &schemaName,
     559             :     const OUString &tableName,
     560             :     Columns **ppColumns)
     561             : {
     562             :     *ppColumns = new Columns(
     563           0 :         refMutex, origin, pSettings, schemaName, tableName );
     564           0 :     Reference< com::sun::star::container::XNameAccess > ret = *ppColumns;
     565           0 :     (*ppColumns)->refresh();
     566             : 
     567           0 :     return ret;
     568             : }
     569             : 
     570             : 
     571             : 
     572           0 : ColumnDescriptors::ColumnDescriptors(
     573             :         const ::rtl::Reference< RefCountedMutex > & refMutex,
     574             :         const ::com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection >  & origin,
     575             :         ConnectionSettings *pSettings )
     576           0 :     : Container( refMutex, origin, pSettings,  "COLUMN-DESCRIPTOR" )
     577           0 : {}
     578             : 
     579             : 
     580           0 : Reference< ::com::sun::star::beans::XPropertySet > ColumnDescriptors::createDataDescriptor()
     581             :         throw (::com::sun::star::uno::RuntimeException, std::exception)
     582             : {
     583           0 :     return new ColumnDescriptor( m_refMutex, m_origin, m_pSettings );
     584             : }
     585             : 
     586             : }
     587             : 
     588             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10