Tag: oo_pqsdbc_01 User: jbu Date: 06/05/01 12:19:11 Modified: /dba/connectivity/source/drivers/postgresql/ makefile.mk, pq_databasemetadata.cxx, pq_resultset.cxx, pq_resultset.hxx, pq_resultsetmetadata.cxx, pq_resultsetmetadata.hxx, pq_tools.cxx, pq_tools.hxx, pq_updateableresultset.cxx, pq_xtable.cxx, pq_xtables.cxx, pq_xview.cxx, pq_xviews.cxx
Log: changes for 0.7.1/domain type support/type content recognition/view deletion-rename support File Changes: Directory: /dba/connectivity/source/drivers/postgresql/ ======================================================= File [changed]: makefile.mk Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/makefile.mk?r1=1.1.2.7&r2=1.1.2.8 Delta lines: +3 -3 ------------------- --- makefile.mk 22 Jan 2006 15:14:26 -0000 1.1.2.7 +++ makefile.mk 1 May 2006 19:19:05 -0000 1.1.2.8 @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.1.2.7 $ +# $Revision: 1.1.2.8 $ # -# last change: $Author: jbu $ $Date: 2006/01/22 15:14:26 $ +# last change: $Author: jbu $ $Date: 2006/05/01 19:19:05 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -79,7 +79,7 @@ PQ_SDBC_MAJOR=0 PQ_SDBC_MINOR=7 -PQ_SDBC_MICRO=0 +PQ_SDBC_MICRO=1 CFLAGS+=-I$(SOLARINCDIR)$/postgresql \ -DPOSTGRESQL_MAJOR=$(POSTGRESQL_MAJOR) \ File [changed]: pq_databasemetadata.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx?r1=1.1.2.8&r2=1.1.2.9 Delta lines: +177 -34 ---------------------- --- pq_databasemetadata.cxx 22 Jan 2006 15:14:27 -0000 1.1.2.8 +++ pq_databasemetadata.cxx 1 May 2006 19:19:05 -0000 1.1.2.9 @@ -2,9 +2,9 @@ * * $RCSfile: pq_databasemetadata.cxx,v $ * - * $Revision: 1.1.2.8 $ + * $Revision: 1.1.2.9 $ * - * last change: $Author: jbu $ $Date: 2006/01/22 15:14:27 $ + * last change: $Author: jbu $ $Date: 2006/05/01 19:19:05 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -912,6 +912,45 @@ Sequence< Sequence< Any > > ( &vec[0],vec.size() ), m_pSettings->tc ); } +struct SortInternalSchemasLastAndPublicFirst +{ + bool operator () ( const Sequence< Any > & a, const Sequence< Any > & b ) + { + OUString valueA; + OUString valueB; + a[0] >>= valueA; + b[0] >>= valueB; + bool ret = false; + if( valueA.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "public" ) ) == 0 ) + { + ret = true; + } + else if( valueB.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "public" ) ) == 0 ) + { + ret = false; + } + else if( valueA.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "pg_" ) ) && + valueB.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "pg_" ) ) ) + { + ret = valueA.compareTo( valueB ) < 0; // sorts equal ! + } + else if( valueA.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "pg_" ) )) + { + ret = false; // sorts last ! + } + else if( valueB.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "pg_" ) ) ) + { + ret = true; // sorts dorst ! + + } + else + { + ret = (valueA.compareTo( valueB ) < 0); + } + return ret; + } +}; + ::com::sun::star::uno::Reference< XResultSet > DatabaseMetaData::getSchemas( ) throw (SQLException, RuntimeException) { @@ -935,6 +974,10 @@ row[0] <<= xRow->getString(1); vec.push_back( row ); } + + // sort public first, sort internal schemas last, sort rest in alphabetic order + std::sort( vec.begin(), vec.end(), SortInternalSchemasLastAndPublicFirst() ); + Reference< XCloseable > closeable( statement, UNO_QUERY ); if( closeable.is() ) closeable->close(); @@ -965,7 +1008,7 @@ /** returns the constant from sdbc.DataType */ -static sal_Int32 typeNameToDataType( const OUString &typeName, const OUString &typtype ) +sal_Int32 typeNameToDataType( const OUString &typeName, const OUString &typtype ) { // sal_Int32 ret = com::sun::star::sdbc::DataType::DISTINCT; // map all unknown types to memo (longvarchar). This allows to show them in @@ -996,7 +1039,7 @@ } else if( 0 == typtype.compareToAscii( "d" ) ) { - ret = com::sun::star::sdbc::DataType::DISTINCT; + ret = com::sun::star::sdbc::DataType::LONGVARCHAR; } return ret; } @@ -1042,6 +1085,75 @@ } } +struct DatabaseTypeDescription +{ + DatabaseTypeDescription() + {} + DatabaseTypeDescription( const OUString &name, const OUString & type ) : + typeName( name ), + typeType( type ) + {} + DatabaseTypeDescription( const DatabaseTypeDescription &source ) : + typeName( source.typeName ), + typeType( source.typeType ) + {} + DatabaseTypeDescription & operator = ( const DatabaseTypeDescription & source ) + { + typeName = source.typeName; + typeType = source.typeType; + return *this; + } + OUString typeName; + OUString typeType; +}; + +typedef std::hash_map +< + sal_Int32, + DatabaseTypeDescription, + ::std::hash< sal_Int32 >, + ::std::equal_to< sal_Int32 >, + Allocator< ::std::pair< sal_Int32, DatabaseTypeDescription > > +> Oid2DatabaseTypeDescriptionMap; + +static void columnMetaData2DatabaseTypeDescription( + Oid2DatabaseTypeDescriptionMap &oidMap, + const Reference< XResultSet > &rs, + const Reference< XStatement > &stmt ) +{ + Reference< XRow > row( rs, UNO_QUERY ); + int domains = 0; + rtl::OUStringBuffer queryBuf(128); + queryBuf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "SELECT oid,typtype,typname FROM pg_TYPE WHERE " ) ); + while( rs->next() ) + { + if( row->getString( 9 ).equalsAscii( "d" ) && oidMap.find( row->getInt( 12 ) ) == oidMap.end() ) + { + oidMap[row->getInt(12)] = DatabaseTypeDescription(); + if( domains ) + queryBuf.appendAscii( " OR " ); + queryBuf.appendAscii( "oid = " ); + queryBuf.append( row->getInt(12 ), 10 ); + domains ++; + } + } + rs->beforeFirst(); + + if( domains ) + { + Reference< XResultSet > rsDomain = stmt->executeQuery( queryBuf.makeStringAndClear() ); + row = Reference< XRow >( rsDomain, UNO_QUERY ); + while( rsDomain->next() ) + { + oidMap[row->getInt(1)] = DatabaseTypeDescription(row->getString(3), row->getString(2) ); + } + disposeNoThrow( stmt ); + } + +} + + + ::com::sun::star::uno::Reference< XResultSet > DatabaseMetaData::getColumns( const ::com::sun::star::uno::Any& catalog, const OUString& schemaPattern, @@ -1131,7 +1243,8 @@ "pg_attribute.attnum, " // 8 "pg_type.typtype, " // 9 "pg_attrdef.adsrc, " // 10 - "pg_description.description " // 11 + "pg_description.description, " // 11 + "pg_type.typbasetype " // 12 "FROM pg_class, " "pg_attribute LEFT JOIN pg_attrdef ON pg_attribute.attrelid = pg_attrdef.adrelid AND pg_attribute.attnum = pg_attrdef.adnum " "LEFT JOIN pg_description ON pg_attribute.attrelid = pg_description.objoid AND pg_attribute.attnum=pg_description.objsubid," @@ -1154,6 +1267,10 @@ Reference< XRow > xRow( rs, UNO_QUERY ); SequenceAnyVector vec; + Oid2DatabaseTypeDescriptionMap domainMap; + Reference< XStatement > domainTypeStmt = m_origin->createStatement(); + columnMetaData2DatabaseTypeDescription( domainMap, rs, domainTypeStmt ); + while( rs->next() ) { OUString columnName = xRow->getString(3); @@ -1165,7 +1282,15 @@ row[1] <<= xRow->getString(1); // row[2] <<= xRow->getString(2); row[3] <<= columnName; + if( xRow->getString(9).equalsAscii( "d" ) ) + { + DatabaseTypeDescription desc( domainMap[xRow->getInt(12)] ); + type = typeNameToDataType( desc.typeName, desc.typeType ); + } + else + { type = typeNameToDataType( xRow->getString(4), xRow->getString(9) ); + } extractPrecisionAndScale( type, xRow->getInt(5) , &precision, &scale ); row[4] <<= type; row[5] <<= xRow->getString(4); @@ -1674,10 +1799,10 @@ sal_Int32 searchable; }; -::com::sun::star::uno::Reference< XResultSet > DatabaseMetaData::getTypeInfo( ) - throw (SQLException, RuntimeException) +static void pgTypeInfo2ResultSet( + SequenceAnyVector &vec, + const Reference< XResultSet > &rs ) { - // Note: Indexes start at 0 (in the API doc, they start at 1) static const sal_Int32 TYPE_NAME = 0; // string Type name static const sal_Int32 DATA_TYPE = 1; // short SQL data type from java.sql.Types static const sal_Int32 PRECISION = 2; // long maximum precision @@ -1712,34 +1837,12 @@ 15, SQL_DATA_TYPE long ==> unused 16. SQL_DATETIME_SUB long ==> unused */ - MutexGuard guard( m_refMutex->mutex ); - checkClosed(); - - if( isLog( m_pSettings, LogLevel::INFO ) ) - { - log( m_pSettings, LogLevel::INFO, "DatabaseMetaData::getTypeInfo() got called" ); - } - - Reference< XStatement > statement = m_origin->createStatement(); - Reference< XResultSet > rs = statement->executeQuery( - ASCII_STR( - "SELECT pg_type.typname AS typname," - "pg_type.typtype AS typtype," - "pg_type.typlen AS typlen," - "pg_type.typnotnull AS typnotnull " - "FROM pg_type " - "WHERE pg_type.typtype = 'b' " - "OR pg_type.typtype = 'd' " - "OR pg_type.typtype = 'p'" - ) ); - - SequenceAnyVector vec; Reference< XRow > xRow( rs, UNO_QUERY ); while( rs->next() ) { Sequence< Any > row(18); - sal_Int32 dataType =typeNameToDataType(xRow->getString(1),xRow->getString(2)); + sal_Int32 dataType =typeNameToDataType(xRow->getString(5),xRow->getString(2)); sal_Int32 precision = xRow->getString(3).toInt32(); if( dataType == com::sun::star::sdbc::DataType::CHAR ) @@ -1774,9 +1877,49 @@ vec.push_back( row ); } - std::sort( vec.begin(), vec.end(), TypeInfoByDataTypeSorter() ); +} + - // add the serial types by hand, as there are not reflected in pg_types +::com::sun::star::uno::Reference< XResultSet > DatabaseMetaData::getTypeInfo( ) + throw (SQLException, RuntimeException) +{ + // Note: Indexes start at 0 (in the API doc, they start at 1) + MutexGuard guard( m_refMutex->mutex ); + checkClosed(); + + if( isLog( m_pSettings, LogLevel::INFO ) ) + { + log( m_pSettings, LogLevel::INFO, "DatabaseMetaData::getTypeInfo() got called" ); + } + + Reference< XStatement > statement = m_origin->createStatement(); + Reference< XResultSet > rs = statement->executeQuery( + ASCII_STR( + "SELECT pg_type.typname AS typname," //1 + "pg_type.typtype AS typtype," //2 + "pg_type.typlen AS typlen," //3 + "pg_type.typnotnull AS typnotnull," //4 + "pg_type.typname AS typname " //5 + "WHERE pg_type.typtype = 'b' " + "OR pg_type.typtype = 'p'" + ) ); + + SequenceAnyVector vec; + pgTypeInfo2ResultSet( vec, rs ); + + // check for domain types + rs = statement->executeQuery( + ASCII_STR( + "SELECT t1.typname as typname," + "t2.typtype AS typtype," + "t2.typlen AS typlen," + "t2.typnotnull AS typnotnull," + "t2.typname as realtypname " + "FROM pg_type as t1 LEFT JOIN pg_type AS t2 ON t1.typbasetype=t2.oid " + "WHERE t1.typtype = 'd'" ) ); + pgTypeInfo2ResultSet( vec, rs ); + + std::sort( vec.begin(), vec.end(), TypeInfoByDataTypeSorter() ); return new SequenceResultSet( m_refMutex, File [changed]: pq_resultset.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_resultset.cxx?r1=1.1.2.2&r2=1.1.2.3 Delta lines: +138 -1 --------------------- --- pq_resultset.cxx 9 May 2004 19:47:15 -0000 1.1.2.2 +++ pq_resultset.cxx 1 May 2006 19:19:06 -0000 1.1.2.3 @@ -2,6 +2,7 @@ #include "pq_resultsetmetadata.hxx" #include <com/sun/star/sdbc/ResultSetType.hpp> +#include <com/sun/star/sdbc/DataType.hpp> using rtl::OUString; using rtl::OUStringToOString; @@ -103,7 +104,7 @@ MutexGuard guard( m_refMutex->mutex ); checkClosed(); return new ResultSetMetaData( - m_refMutex, this, m_ppSettings, m_result, m_schema, m_table ); + m_refMutex, this, this, m_ppSettings, m_result, m_schema, m_table ); } sal_Int32 ResultSet::findColumn( const ::rtl::OUString& columnName ) @@ -115,6 +116,142 @@ m_result, OUStringToOString( columnName, (*m_ppSettings)->encoding ).getStr()) +1; +} + +static bool isNumber( const char * data, sal_Int32 len ) +{ + bool ret = false; + if( len ) + { + ret = true; + for( int i = 0 ; i < len ; i ++ ) + { + if( ( data[i] >= '0' && data[i] <= '9' ) || + data[i] == '-' || data[i] == '+' || data[i] == '.' || data[i] == ',' ) + { + if( data[i] == '-' && i != 0 && i != len-1 ) + { + // no number, maybe a date + ret = false; + break; + } + } + else + { + ret = false; + break; + } + } + } + return ret; +} + +static bool isInteger( const char * data, sal_Int32 len ) +{ + bool ret = false; + if( len ) + { + ret = true; + for( int i = 0 ; i < len ; i ++ ) + { + if( ( data[i] >= '0' && data[i] <= '9' ) || + data[i] == '-' || data[i] == '+' ) + { + if( data[i] == '-' && i != 0 && i != len-1 ) + { + // no number, maybe a date + ret = false; + break; + } + } + else + { + ret = false; + break; + } + } + } + return ret; +} + +static bool isDate( const char * data, sal_Int32 len ) +{ + bool ret = false; + return 10 == len && + '-' == data[4] && + '-' == data[7] && + isInteger( &(data[0]),4 ) && + isInteger( &(data[5]),2) && + isInteger( &(data[8]),2 ); +} + +static bool isTime( const char * data, sal_Int32 len ) +{ + bool ret = false; + return 8 == len && + ':' == data[2] && + ':' == data[5] && + isInteger( &(data[0]),2 ) && + isInteger( &(data[3]),2) && + isInteger( &(data[6]),2 ); + +} + +static bool isTimestamp( const char * data, sal_Int32 len ) +{ + return len == 19 && isDate( data, 10) && isTime( &(data[11]),8 ); +} + +sal_Int32 ResultSet::guessDataType( sal_Int32 column ) +{ + // we don't look into more than 100 rows ... + sal_Int32 ret = com::sun::star::sdbc::DataType::INTEGER; + + int maxRows = ( m_rowCount > 100 ? 100 : m_rowCount ); + for( int i = 0 ; i < maxRows ; i ++ ) + { + if( ! PQgetisnull( m_result, i , column-1 ) ) + { + const char * p = PQgetvalue( m_result, i , column -1 ); + int len = PQgetlength( m_result, i , column -1 ); + + if( com::sun::star::sdbc::DataType::INTEGER == ret ) + { + if( ! isInteger( p,len ) ) + ret = com::sun::star::sdbc::DataType::NUMERIC; + } + if( com::sun::star::sdbc::DataType::NUMERIC == ret ) + { + if( ! isNumber( p,len ) ) + { + ret = com::sun::star::sdbc::DataType::DATE; + } + } + if( com::sun::star::sdbc::DataType::DATE == ret ) + { + if( ! isDate( p,len ) ) + { + ret = com::sun::star::sdbc::DataType::TIME; + } + } + if( com::sun::star::sdbc::DataType::TIME == ret ) + { + if( ! isTime( p,len ) ) + { + ret = com::sun::star::sdbc::DataType::TIMESTAMP; + } + } + if( com::sun::star::sdbc::DataType::TIMESTAMP == ret ) + { + if( ! isTimestamp( p,len ) ) + { + ret = com::sun::star::sdbc::DataType::LONGVARCHAR; + break; + } + } + } + } + return ret; } } File [changed]: pq_resultset.hxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_resultset.hxx?r1=1.1.2.2&r2=1.1.2.3 Delta lines: +5 -2 ------------------- --- pq_resultset.hxx 9 May 2004 19:47:15 -0000 1.1.2.2 +++ pq_resultset.hxx 1 May 2006 19:19:06 -0000 1.1.2.3 @@ -2,9 +2,9 @@ * * $RCSfile: pq_resultset.hxx,v $ * - * $Revision: 1.1.2.2 $ + * $Revision: 1.1.2.3 $ * - * last change: $Author: jbu $ $Date: 2004/05/09 19:47:15 $ + * last change: $Author: jbu $ $Date: 2006/05/01 19:19:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -113,6 +113,9 @@ public: // XColumnLocate virtual sal_Int32 SAL_CALL findColumn( const ::rtl::OUString& columnName ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + +public: + sal_Int32 guessDataType( sal_Int32 column ); }; } File [changed]: pq_resultsetmetadata.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx?r1=1.1.2.5&r2=1.1.2.6 Delta lines: +65 -27 --------------------- --- pq_resultsetmetadata.cxx 22 Jan 2006 15:14:30 -0000 1.1.2.5 +++ pq_resultsetmetadata.cxx 1 May 2006 19:19:06 -0000 1.1.2.6 @@ -2,9 +2,9 @@ * * $RCSfile: pq_resultsetmetadata.cxx,v $ * - * $Revision: 1.1.2.5 $ + * $Revision: 1.1.2.6 $ * - * last change: $Author: jbu $ $Date: 2006/01/22 15:14:30 $ + * last change: $Author: jbu $ $Date: 2006/05/01 19:19:06 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -61,11 +61,13 @@ #include <rtl/ustrbuf.hxx> #include "pq_resultsetmetadata.hxx" +#include "pq_resultset.hxx" #include "pq_tools.hxx" #include "pq_statics.hxx" #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> #include <com/sun/star/sdbc/ColumnValue.hpp> +#include <com/sun/star/sdbc/XRow.hpp> using osl::Mutex; @@ -85,6 +87,9 @@ using com::sun::star::lang::IllegalArgumentException; using com::sun::star::sdbc::SQLException; +using com::sun::star::sdbc::XStatement; +using com::sun::star::sdbc::XRow; +using com::sun::star::sdbc::XResultSet; // using com::sun::star::sdbc::XRow; using com::sun::star::sdbc::XResultSet; using com::sun::star::sdbcx::XColumnsSupplier; @@ -142,6 +147,7 @@ ResultSetMetaData::ResultSetMetaData( const ::rtl::Reference< RefCountedMutex > & refMutex, const ::com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > & origin, + ResultSet * pResultSet, ConnectionSettings **ppSettings, PGresult *pResult, const rtl::OUString &schemaName, @@ -153,7 +159,9 @@ m_tableName( tableName ), m_schemaName( schemaName ), m_checkedForTable( false ), - m_colDesc( PQnfields( pResult ) ) + m_checkedForTypes( false ), + m_colDesc( PQnfields( pResult ) ), + m_pResultSet( pResultSet ) { // extract all needed information from the result object, so that we don't @@ -170,6 +178,8 @@ & ( m_colDesc[col].scale ) ); char *name = PQfname( pResult, col ); m_colDesc[col].name = OUString( name, strlen(name) , (*m_ppSettings)->encoding ); + m_colDesc[col].typeOid = PQfmod( pResult, col ); + m_colDesc[col].type = com::sun::star::sdbc::DataType::LONGVARCHAR; } } @@ -181,28 +191,45 @@ // Allocator < std::pair< Oid, rtl::OUString > > > PqTypeMap; -// void ResultSetMetaData::checkMetaData() -// { -// Reference< XStatement > stmt = -// extractConnectionFromStatement( m_origin->getStatement() )->createStatement(); -// OUStringBuffer buf(128); -// buf.appendAscii( "SELECT oid, typname FROM pg_type WHERE "); -// for( int i = 0 ; i < m_colCount ; i ++ ) -// { -// if( i > 0 ) -// buf.appendAscii( " OR " ); -// int oid = PQftyp( *ppResult, i ); -// buf.appendAscii( "oid=" ); -// buf.append( oid, 10 ); -// } -// Reference< XResultSet > rs = stmt->executeQuery( buf.makeStringAndClear() ); -// Reference< XRow > xRow( rs, UNO_QUERY ); -// m_metaData = std::vector< ColumnMetaData >( m_colCount ); -// while( rs->next() ) -// { +void ResultSetMetaData::checkForTypes() +{ + if( ! m_checkedForTypes ) + { + Reference< XStatement > stmt = + extractConnectionFromStatement( m_origin->getStatement() )->createStatement(); + DisposeGuard guard( stmt ); + OUStringBuffer buf(128); + buf.appendAscii( "SELECT oid, typname, typtype FROM pg_type WHERE "); + for( int i = 0 ; i < m_colCount ; i ++ ) + { + if( i > 0 ) + buf.appendAscii( " OR " ); + int oid = m_colDesc[i].typeOid; + buf.appendAscii( "oid=" ); + buf.append( (sal_Int32) oid, 10 ); + } + Reference< XResultSet > rs = stmt->executeQuery( buf.makeStringAndClear() ); + Reference< XRow > xRow( rs, UNO_QUERY ); + while( rs->next() ) + { + sal_Int32 oid = xRow->getInt( 1 ); + OUString typeName = xRow->getString( 2 ); + OUString typType = xRow->getString( 3 ); -// } -// } + sal_Int32 type = typeNameToDataType( typeName, typType ); + + for( int j = 0; j < m_colCount ; j ++ ) + { + if( m_colDesc[j].typeOid == oid ) + { + m_colDesc[j].typeName = typeName; + m_colDesc[j].type = type; + } + } + } + m_checkedForTypes = true; + } +} void ResultSetMetaData::checkTable() { @@ -410,8 +437,14 @@ sal_Int32 ResultSetMetaData::getColumnType( sal_Int32 column ) throw (SQLException, RuntimeException) { - int ret = getIntColumnProperty( getStatics().TYPE, column, -1 ); -// printf( "ResultSetMetaData %d %d\n" , column, ret ); + int ret = getIntColumnProperty( getStatics().TYPE, column, -100 ); + if( -100 == ret ) + { + checkForTypes(); + if( com::sun::star::sdbc::DataType::LONGVARCHAR == m_colDesc[column-1].type && m_pResultSet ) + m_colDesc[column-1].type = m_pResultSet->guessDataType( column ); + ret = m_colDesc[column-1].type; + } return ret; } @@ -428,6 +461,11 @@ if( set.is() ) { set->getPropertyValue( getStatics().TYPE_NAME ) >>= ret; + } + else + { + checkForTypes(); + ret = m_colDesc[column-1].typeName; } } catch( com::sun::star::uno::Exception & e ) File [changed]: pq_resultsetmetadata.hxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_resultsetmetadata.hxx?r1=1.1.2.2&r2=1.1.2.3 Delta lines: +12 -3 -------------------- --- pq_resultsetmetadata.hxx 9 May 2004 19:47:15 -0000 1.1.2.2 +++ pq_resultsetmetadata.hxx 1 May 2006 19:19:07 -0000 1.1.2.3 @@ -2,9 +2,9 @@ * * $RCSfile: pq_resultsetmetadata.hxx,v $ * - * $Revision: 1.1.2.2 $ + * $Revision: 1.1.2.3 $ * - * last change: $Author: jbu $ $Date: 2004/05/09 19:47:15 $ + * last change: $Author: jbu $ $Date: 2006/05/01 19:19:07 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -78,8 +78,13 @@ sal_Int32 precision; sal_Int32 scale; sal_Int32 displaySize; + Oid typeOid; + rtl::OUString typeName; + sal_Int32 type; }; +class ResultSet; + typedef std::vector< ColDesc, Allocator< ColDesc > > ColDescVector; @@ -93,8 +98,10 @@ ::rtl::OUString m_tableName; ::rtl::OUString m_schemaName; ColDescVector m_colDesc; + ResultSet *m_pResultSet; bool m_checkedForTable; + bool m_checkedForTypes; sal_Int32 m_colCount; @@ -103,6 +110,7 @@ void checkColumnIndex( sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); void checkTable(); + void checkForTypes(); com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > getColumnByIndex( int index ); sal_Int32 getIntColumnProperty( const rtl::OUString & name, int index, int def ); @@ -112,6 +120,7 @@ ResultSetMetaData( const ::rtl::Reference< RefCountedMutex > & reMutex, const ::com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > & origin, + ResultSet *pResultSet, ConnectionSettings **pSettings, PGresult *pResult, const rtl::OUString &schemaName, File [changed]: pq_tools.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_tools.cxx?r1=1.1.2.6&r2=1.1.2.7 Delta lines: +4 -4 ------------------- --- pq_tools.cxx 22 Jan 2006 15:14:37 -0000 1.1.2.6 +++ pq_tools.cxx 1 May 2006 19:19:07 -0000 1.1.2.7 @@ -272,12 +272,12 @@ ret = owner->getConnection(); else { - Reference< com::sun::star::sdbc::XPreparedStatement > owner( owner, UNO_QUERY ); - if( owner.is() ) - ret = owner->getConnection(); + Reference< com::sun::star::sdbc::XPreparedStatement > myowner( stmt, UNO_QUERY ); + if( myowner.is() ) + ret = myowner->getConnection(); if( ! ret.is() ) throw SQLException( - ASCII_STR( "Couldn't retrieve connection from statement" ), + ASCII_STR( "PQSDBC: Couldn't retrieve connection from statement" ), Reference< XInterface > () , rtl::OUString(), 0 , com::sun::star::uno::Any() ); } File [changed]: pq_tools.hxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_tools.hxx?r1=1.1.2.5&r2=1.1.2.6 Delta lines: +3 -2 ------------------- --- pq_tools.hxx 22 Jan 2006 15:14:37 -0000 1.1.2.5 +++ pq_tools.hxx 1 May 2006 19:19:07 -0000 1.1.2.6 @@ -2,9 +2,9 @@ * * $RCSfile: pq_tools.hxx,v $ * - * $Revision: 1.1.2.5 $ + * $Revision: 1.1.2.6 $ * - * last change: $Author: jbu $ $Date: 2006/01/22 15:14:37 $ + * last change: $Author: jbu $ $Date: 2006/05/01 19:19:07 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -167,6 +167,7 @@ const rtl::OUString &query ); void extractNameValuePairsFromInsert( String2StringMap & map, const rtl::OString & lastQuery ); +sal_Int32 typeNameToDataType( const rtl::OUString &typeName, const rtl::OUString &typtype ); class DisposeGuard { File [changed]: pq_updateableresultset.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx?r1=1.1.2.2&r2=1.1.2.3 Delta lines: +1 -1 ------------------- --- pq_updateableresultset.cxx 10 Jun 2004 15:26:59 -0000 1.1.2.2 +++ pq_updateableresultset.cxx 1 May 2006 19:19:07 -0000 1.1.2.3 @@ -91,7 +91,7 @@ Reference <XCloseable > ret = pRS; // give it an refcount - pRS->m_meta = new ResultSetMetaData( mutex, pRS, ppSettings, result, schema, table ); + pRS->m_meta = new ResultSetMetaData( mutex, pRS,0, ppSettings, result, schema, table ); PQclear( result ); // we don't need it anymore File [changed]: pq_xtable.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_xtable.cxx?r1=1.1.2.4&r2=1.1.2.5 Delta lines: +25 -11 --------------------- --- pq_xtable.cxx 22 Jan 2006 15:14:39 -0000 1.1.2.4 +++ pq_xtable.cxx 1 May 2006 19:19:08 -0000 1.1.2.5 @@ -2,9 +2,9 @@ * * $RCSfile: pq_xtable.cxx,v $ * - * $Revision: 1.1.2.4 $ + * $Revision: 1.1.2.5 $ * - * last change: $Author: jbu $ $Date: 2006/01/22 15:14:39 $ + * last change: $Author: jbu $ $Date: 2006/05/01 19:19:08 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,6 +71,7 @@ #include "pq_xtable.hxx" #include "pq_xtables.hxx" +#include "pq_xviews.hxx" #include "pq_xindexes.hxx" #include "pq_xkeys.hxx" #include "pq_xcolumns.hxx" @@ -203,6 +204,19 @@ realNewName = newName.copy( schema.getLength() +1); } + if( extractStringProperty( this, st.TYPE ).equals( st.VIEW ) && m_pSettings->views.is() ) + { + // maintain view list (really strange API !) + Any a = m_pSettings->pViewsImpl->getByName( concatQualified( schema, oldName ) ); + Reference< com::sun::star::sdbcx::XRename > rename; + a >>= rename; + if( rename.is() ) + { + rename->rename( newName ); + } + } + else + { OUStringBuffer buf(128); buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) ); bufferQuoteQualifiedIdentifier(buf, schema, oldName ); @@ -210,8 +224,8 @@ bufferQuoteIdentifier( buf, realNewName ); Reference< XStatement > statement = m_conn->createStatement(); statement->executeUpdate( buf.makeStringAndClear() ); + } setPropertyValue_NoBroadcast_public( st.NAME, makeAny(realNewName) ); - // inform the container of the name change ! if( m_pSettings->tables.is() ) { File [changed]: pq_xtables.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_xtables.cxx?r1=1.1.2.3&r2=1.1.2.4 Delta lines: +21 -8 -------------------- --- pq_xtables.cxx 29 Aug 2004 08:33:32 -0000 1.1.2.3 +++ pq_xtables.cxx 1 May 2006 19:19:08 -0000 1.1.2.4 @@ -2,9 +2,9 @@ * * $RCSfile: pq_xtables.cxx,v $ * - * $Revision: 1.1.2.3 $ + * $Revision: 1.1.2.4 $ * - * last change: $Author: jbu $ $Date: 2004/08/29 08:33:32 $ + * last change: $Author: jbu $ $Date: 2006/05/01 19:19:08 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,6 +71,7 @@ #include <com/sun/star/sdbc/DataType.hpp> #include "pq_xtables.hxx" +#include "pq_xviews.hxx" #include "pq_xtable.hxx" #include "pq_statics.hxx" #include "pq_tools.hxx" @@ -107,6 +108,7 @@ 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 @@ -413,13 +415,24 @@ OUString name,schema; set->getPropertyValue( st.SCHEMA_NAME ) >>= schema; set->getPropertyValue( st.NAME ) >>= name; - + if( extractStringProperty( set, st.TYPE ).equals( st.VIEW ) && m_pSettings->views.is() ) + { + m_pSettings->pViewsImpl->dropByName( concatQualified( schema, name ) ); + } + else + { OUStringBuffer update( 128 ); - update.appendAscii( "DROP TABLE \"" ).append( schema ).appendAscii( "\".\"" ); - update.append( name ).appendAscii( "\"" ); + update.appendAscii( RTL_CONSTASCII_STRINGPARAM( "DROP " ) ); + if( extractStringProperty( set, st.TYPE ).equals( st.VIEW ) ) + update.appendAscii( RTL_CONSTASCII_STRINGPARAM( "VIEW " ) ); + else + update.appendAscii( RTL_CONSTASCII_STRINGPARAM( "TABLE " ) ); + bufferQuoteQualifiedIdentifier( update, schema, name ); Reference< XStatement > stmt = m_origin->createStatement( ); - + DisposeGuard dispGuard( stmt ); stmt->executeUpdate( update.makeStringAndClear() ); + } + Container::dropByIndex( index ); } File [changed]: pq_xview.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_xview.cxx?r1=1.1.2.3&r2=1.1.2.4 Delta lines: +13 -5 -------------------- --- pq_xview.cxx 29 Aug 2004 08:33:33 -0000 1.1.2.3 +++ pq_xview.cxx 1 May 2006 19:19:08 -0000 1.1.2.4 @@ -2,9 +2,9 @@ * * $RCSfile: pq_xview.cxx,v $ * - * $Revision: 1.1.2.3 $ + * $Revision: 1.1.2.4 $ * - * last change: $Author: jbu $ $Date: 2004/08/29 08:33:33 $ + * last change: $Author: jbu $ $Date: 2006/05/01 19:19:08 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -149,19 +149,27 @@ ::rtl::OUString oldName( extractStringProperty( this,st.NAME ) ); ::rtl::OUString schema( extractStringProperty( this, st.SCHEMA_NAME ) ); + OUString realNewName = newName; + // OOo2.0 passes schema + dot + new-table-name while + // OO1.1.x passes new Name without schema + if( newName.match( schema ) && newName[schema.getLength() == '.'] ) + { + realNewName = newName.copy( schema.getLength() +1); + } + OUStringBuffer buf(128); buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "ALTER TABLE" ) ); bufferQuoteQualifiedIdentifier( buf, schema, oldName ); buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("RENAME TO" ) ); - bufferQuoteIdentifier( buf, newName ); + bufferQuoteIdentifier( buf, realNewName ); Reference< XStatement > statement = m_conn->createStatement(); statement->executeUpdate( buf.makeStringAndClear() ); - setPropertyValue_NoBroadcast_public( st.NAME, makeAny(newName) ); + setPropertyValue_NoBroadcast_public( st.NAME, makeAny(realNewName) ); // inform the container of the name change ! if( m_pSettings->views.is() ) { - m_pSettings->pViewsImpl->rename( schema, oldName, newName ); + m_pSettings->pViewsImpl->rename( schema, oldName, realNewName ); } } File [changed]: pq_xviews.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_xviews.cxx?r1=1.1.2.3&r2=1.1.2.4 Delta lines: +10 -3 -------------------- --- pq_xviews.cxx 29 Aug 2004 08:33:33 -0000 1.1.2.3 +++ pq_xviews.cxx 1 May 2006 19:19:09 -0000 1.1.2.4 @@ -2,9 +2,9 @@ * * $RCSfile: pq_xviews.cxx,v $ * - * $Revision: 1.1.2.3 $ + * $Revision: 1.1.2.4 $ * - * last change: $Author: jbu $ $Date: 2004/08/29 08:33:33 $ + * last change: $Author: jbu $ $Date: 2006/05/01 19:19:09 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -69,6 +69,7 @@ #include "pq_xviews.hxx" #include "pq_xview.hxx" +#include "pq_xtables.hxx" #include "pq_statics.hxx" #include "pq_tools.hxx" @@ -199,6 +200,12 @@ stmt->executeUpdate( buf.makeStringAndClear() ); + disposeNoThrow( stmt ); + refresh(); + if( m_pSettings->tables.is() ) + { + m_pSettings->pTablesImpl->refresh(); + } // increase the vector // sal_Int32 index = m_values.getLength(); // m_values.realloc( index + 1 ); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
