2000-09-18 15:18:56 +00:00
/*************************************************************************
*
2005-09-08 04:24:25 +00:00
* OpenOffice . org - a multi - platform office productivity suite
2000-09-18 15:18:56 +00:00
*
2005-09-08 04:24:25 +00:00
* $ RCSfile : BTables . cxx , v $
2000-09-18 15:18:56 +00:00
*
2006-09-17 01:09:39 +00:00
* $ Revision : 1.35 $
2000-09-18 15:18:56 +00:00
*
2006-09-17 01:09:39 +00:00
* last change : $ Author : obo $ $ Date : 2006 - 09 - 17 02 : 09 : 39 $
2000-09-18 15:18:56 +00:00
*
2005-09-08 04:24:25 +00:00
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1 .
2000-09-18 15:18:56 +00:00
*
*
2005-09-08 04:24:25 +00:00
* GNU Lesser General Public License Version 2.1
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* Copyright 2005 by Sun Microsystems , Inc .
* 901 San Antonio Road , Palo Alto , CA 94303 , USA
2000-09-18 15:18:56 +00:00
*
2005-09-08 04:24:25 +00:00
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 , as published by the Free Software Foundation .
2000-09-18 15:18:56 +00:00
*
2005-09-08 04:24:25 +00:00
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
2000-09-18 15:18:56 +00:00
*
2005-09-08 04:24:25 +00:00
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston ,
* MA 02111 - 1307 USA
2000-09-18 15:18:56 +00:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-09-17 01:09:39 +00:00
// MARKER(update_precomp.py): autogen include statement, do not remove
# include "precompiled_connectivity.hxx"
2000-09-18 15:18:56 +00:00
# ifndef _CONNECTIVITY_ADABAS_TABLES_HXX_
# include "adabas/BTables.hxx"
# endif
2001-06-01 08:51:57 +00:00
# ifndef _CONNECTIVITY_ADABAS_VIEWS_HXX_
# include "adabas/BViews.hxx"
# endif
2000-09-18 15:18:56 +00:00
# ifndef _CONNECTIVITY_ADABAS_TABLE_HXX_
# include "adabas/BTable.hxx"
# endif
# ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
# include <com/sun/star/sdbc/XRow.hpp>
# endif
# ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_
# include <com/sun/star/sdbc/XResultSet.hpp>
# endif
# ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_
# include <com/sun/star/sdbc/ColumnValue.hpp>
# endif
# ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_
# include <com/sun/star/sdbc/KeyRule.hpp>
# endif
# ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_
# include <com/sun/star/sdbcx/KeyType.hpp>
# endif
# ifndef _CONNECTIVITY_ADABAS_CATALOG_HXX_
# include "adabas/BCatalog.hxx"
# endif
# ifndef _CONNECTIVITY_ADABAS_BCONNECTION_HXX_
# include "adabas/BConnection.hxx"
# endif
2001-03-15 07:47:25 +00:00
# ifndef _COMPHELPER_EXTRACT_HXX_
# include <comphelper/extract.hxx>
2001-02-14 09:25:17 +00:00
# endif
# ifndef _CONNECTIVITY_DBTOOLS_HXX_
# include "connectivity/dbtools.hxx"
# endif
# ifndef _DBHELPER_DBEXCEPTION_HXX_
# include "connectivity/dbexception.hxx"
# endif
2001-03-28 10:48:02 +00:00
# ifndef _CPPUHELPER_INTERFACECONTAINER_H_
# include <cppuhelper/interfacecontainer.h>
# endif
2001-05-18 07:51:34 +00:00
# ifndef _COMPHELPER_TYPES_HXX_
# include <comphelper/types.hxx>
# endif
using namespace : : comphelper ;
2005-03-10 14:21:18 +00:00
using namespace connectivity ;
2001-05-18 07:51:34 +00:00
using namespace : : cppu ;
2000-09-18 15:18:56 +00:00
using namespace connectivity : : adabas ;
using namespace : : com : : sun : : star : : uno ;
using namespace : : com : : sun : : star : : beans ;
using namespace : : com : : sun : : star : : sdbcx ;
using namespace : : com : : sun : : star : : sdbc ;
using namespace : : com : : sun : : star : : container ;
using namespace : : com : : sun : : star : : lang ;
2001-02-14 09:25:17 +00:00
using namespace dbtools ;
2000-09-18 15:18:56 +00:00
typedef connectivity : : sdbcx : : OCollection OCollection_TYPE ;
2005-03-10 14:21:18 +00:00
sdbcx : : ObjectType OTables : : createObject ( const : : rtl : : OUString & _rName )
2000-09-18 15:18:56 +00:00
{
: : rtl : : OUString aName , aSchema ;
sal_Int32 nLen = _rName . indexOf ( ' . ' ) ;
aSchema = _rName . copy ( 0 , nLen ) ;
aName = _rName . copy ( nLen + 1 ) ;
2000-11-03 13:21:22 +00:00
Sequence < : : rtl : : OUString > aTypes ( 1 ) ;
2000-09-18 15:18:56 +00:00
aTypes [ 0 ] = : : rtl : : OUString : : createFromAscii ( " % " ) ;
// aTypes[0] = ::rtl::OUString::createFromAscii("TABLE");
// aTypes[1] = ::rtl::OUString::createFromAscii("SYSTEMTABLE");
2001-03-28 10:48:02 +00:00
Reference < XResultSet > xResult = m_xMetaData - > getTables ( Any ( ) , aSchema , aName , aTypes ) ;
2000-09-18 15:18:56 +00:00
2005-03-10 14:21:18 +00:00
sdbcx : : ObjectType xRet = NULL ;
2000-09-18 15:18:56 +00:00
if ( xResult . is ( ) )
{
2000-11-03 13:21:22 +00:00
Reference < XRow > xRow ( xResult , UNO_QUERY ) ;
2000-09-18 15:18:56 +00:00
if ( xResult - > next ( ) ) // there can be only one table with this name
{
2001-09-25 12:12:51 +00:00
OAdabasTable * pRet = new OAdabasTable ( this , static_cast < OAdabasCatalog & > ( m_rParent ) . getConnection ( ) ,
2000-09-18 15:18:56 +00:00
aName , xRow - > getString ( 4 ) , xRow - > getString ( 5 ) , aSchema ) ;
xRet = pRet ;
}
2001-10-05 05:15:40 +00:00
: : comphelper : : disposeComponent ( xResult ) ;
2000-09-18 15:18:56 +00:00
}
return xRet ;
}
// -------------------------------------------------------------------------
void OTables : : impl_refresh ( ) throw ( RuntimeException )
{
static_cast < OAdabasCatalog & > ( m_rParent ) . refreshTables ( ) ;
}
// -------------------------------------------------------------------------
void OTables : : disposing ( void )
{
m_xMetaData = NULL ;
OCollection : : disposing ( ) ;
}
// -------------------------------------------------------------------------
2006-07-10 13:22:40 +00:00
Reference < XPropertySet > OTables : : createDescriptor ( )
2000-09-18 15:18:56 +00:00
{
2001-10-12 11:02:56 +00:00
return new OAdabasTable ( this , static_cast < OAdabasCatalog & > ( m_rParent ) . getConnection ( ) ) ;
}
2000-09-18 15:18:56 +00:00
// -------------------------------------------------------------------------
// XAppend
2006-07-10 13:22:40 +00:00
sdbcx : : ObjectType OTables : : appendObject ( const : : rtl : : OUString & _rForName , const Reference < XPropertySet > & descriptor )
2000-09-18 15:18:56 +00:00
{
2001-03-29 06:07:13 +00:00
createTable ( descriptor ) ;
2006-07-10 13:22:40 +00:00
return createObject ( _rForName ) ;
2001-03-28 10:48:02 +00:00
}
// -------------------------------------------------------------------------
void OTables : : setComments ( const Reference < XPropertySet > & descriptor ) throw ( SQLException , RuntimeException )
{
: : rtl : : OUString aSql = : : rtl : : OUString : : createFromAscii ( " CREATE TABLE " ) ;
: : rtl : : OUString aQuote = static_cast < OAdabasCatalog & > ( m_rParent ) . getConnection ( ) - > getMetaData ( ) - > getIdentifierQuoteString ( ) ;
2001-08-01 05:21:30 +00:00
const : : rtl : : OUString & sDot = OAdabasCatalog : : getDot ( ) ;
2001-03-28 10:48:02 +00:00
OAdabasConnection * pConnection = static_cast < OAdabasCatalog & > ( m_rParent ) . getConnection ( ) ;
Reference < XStatement > xStmt = pConnection - > createStatement ( ) ;
2001-10-26 06:45:13 +00:00
aSql = : : rtl : : OUString : : createFromAscii ( " COMMENT ON TABLE " ) ;
: : rtl : : OUString sSchema ;
descriptor - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_SCHEMANAME ) ) > > = sSchema ;
if ( sSchema . getLength ( ) )
aSql + = : : dbtools : : quoteName ( aQuote , sSchema ) + sDot ;
aSql + = aQuote + getString ( descriptor - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_NAME ) ) ) + aQuote
2001-03-28 10:48:02 +00:00
+ : : rtl : : OUString : : createFromAscii ( " ' " )
2001-05-14 10:55:19 +00:00
+ getString ( descriptor - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_DESCRIPTION ) ) )
2001-03-28 10:48:02 +00:00
+ : : rtl : : OUString : : createFromAscii ( " ' " ) ;
xStmt - > execute ( aSql ) ;
// columns
Reference < XColumnsSupplier > xColumnSup ( descriptor , UNO_QUERY ) ;
Reference < XIndexAccess > xColumns ( xColumnSup - > getColumns ( ) , UNO_QUERY ) ;
Reference < XPropertySet > xColProp ;
2001-10-26 06:45:13 +00:00
aSql = : : rtl : : OUString : : createFromAscii ( " COMMENT ON COLUMN " ) ;
if ( sSchema . getLength ( ) )
aSql + = : : dbtools : : quoteName ( aQuote , sSchema ) + sDot ;
aSql + = aQuote + getString ( descriptor - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_NAME ) ) ) + aQuote + sDot
2001-03-28 10:48:02 +00:00
+ aQuote ;
for ( sal_Int32 i = 0 ; i < xColumns - > getCount ( ) ; + + i )
{
: : cppu : : extractInterface ( xColProp , xColumns - > getByIndex ( i ) ) ;
if ( xColProp . is ( ) )
{
2001-05-14 10:55:19 +00:00
: : rtl : : OUString aDescription = getString ( xColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_DESCRIPTION ) ) ) ;
2001-03-28 10:48:02 +00:00
if ( aDescription . getLength ( ) )
{
2001-05-14 10:55:19 +00:00
: : rtl : : OUString aCom = aSql + getString ( xColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_NAME ) ) ) + aQuote
2001-03-28 10:48:02 +00:00
+ : : rtl : : OUString : : createFromAscii ( " ' " )
+ aDescription
+ : : rtl : : OUString : : createFromAscii ( " ' " ) ;
xStmt - > execute ( aSql ) ;
2001-10-02 12:12:32 +00:00
: : comphelper : : disposeComponent ( xStmt ) ;
2001-03-28 10:48:02 +00:00
}
}
}
2001-10-02 12:12:32 +00:00
: : comphelper : : disposeComponent ( xStmt ) ;
2001-03-28 10:48:02 +00:00
}
// -------------------------------------------------------------------------
// XDrop
2001-10-12 11:02:56 +00:00
void OTables : : dropObject ( sal_Int32 _nPos , const : : rtl : : OUString _sElementName )
2001-03-28 10:48:02 +00:00
{
2006-06-20 00:11:03 +00:00
Reference < XInterface > xObject ( getObject ( _nPos ) ) ;
sal_Bool bIsNew = connectivity : : sdbcx : : ODescriptor : : isNew ( xObject ) ;
2001-03-28 10:48:02 +00:00
if ( ! bIsNew )
{
OAdabasConnection * pConnection = static_cast < OAdabasCatalog & > ( m_rParent ) . getConnection ( ) ;
Reference < XStatement > xStmt = pConnection - > createStatement ( ) ;
: : rtl : : OUString aName , aSchema ;
2001-10-12 11:02:56 +00:00
sal_Int32 nLen = _sElementName . indexOf ( ' . ' ) ;
aSchema = _sElementName . copy ( 0 , nLen ) ;
aName = _sElementName . copy ( nLen + 1 ) ;
2001-03-28 10:48:02 +00:00
: : rtl : : OUString aSql = : : rtl : : OUString : : createFromAscii ( " DROP " ) ;
2001-08-01 05:21:30 +00:00
const : : rtl : : OUString & sDot = OAdabasCatalog : : getDot ( ) ;
2006-06-20 00:11:03 +00:00
Reference < XPropertySet > xProp ( xObject , UNO_QUERY ) ;
2001-06-01 08:51:57 +00:00
sal_Bool bIsView ;
2006-07-19 14:52:17 +00:00
if ( ( bIsView = ( xProp . is ( ) & & : : comphelper : : getString ( xProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_TYPE ) ) ) = = : : rtl : : OUString : : createFromAscii ( " VIEW " ) ) ) ) // here we have a view
2001-03-28 10:48:02 +00:00
aSql + = : : rtl : : OUString : : createFromAscii ( " VIEW " ) ;
else
aSql + = : : rtl : : OUString : : createFromAscii ( " TABLE " ) ;
2001-07-03 12:01:47 +00:00
aSql + = m_xMetaData - > getIdentifierQuoteString ( ) + aSchema + m_xMetaData - > getIdentifierQuoteString ( ) ;
2001-08-01 05:21:30 +00:00
aSql + = sDot ;
2001-07-03 12:01:47 +00:00
aSql + = m_xMetaData - > getIdentifierQuoteString ( ) + aName + m_xMetaData - > getIdentifierQuoteString ( ) ;
2001-03-28 10:48:02 +00:00
xStmt - > execute ( aSql ) ;
2001-10-02 12:12:32 +00:00
: : comphelper : : disposeComponent ( xStmt ) ;
2001-06-01 08:51:57 +00:00
// if no exception was thrown we must delete it from the views
if ( bIsView )
{
OViews * pViews = static_cast < OViews * > ( static_cast < OAdabasCatalog & > ( m_rParent ) . getPrivateViews ( ) ) ;
2001-10-12 11:02:56 +00:00
if ( pViews & & pViews - > hasByName ( _sElementName ) )
pViews - > dropByNameImpl ( _sElementName ) ;
2001-06-01 08:51:57 +00:00
}
2001-03-28 10:48:02 +00:00
}
}
// -------------------------------------------------------------------------
void OTables : : createTable ( const Reference < XPropertySet > & descriptor )
{
2000-09-18 15:18:56 +00:00
: : rtl : : OUString aSql = : : rtl : : OUString : : createFromAscii ( " CREATE TABLE " ) ;
: : rtl : : OUString aQuote = static_cast < OAdabasCatalog & > ( m_rParent ) . getConnection ( ) - > getMetaData ( ) - > getIdentifierQuoteString ( ) ;
2001-08-01 05:21:30 +00:00
const : : rtl : : OUString & sDot = OAdabasCatalog : : getDot ( ) ;
: : rtl : : OUString sSchema ;
2001-02-14 09:25:17 +00:00
2001-05-14 10:55:19 +00:00
descriptor - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_SCHEMANAME ) ) > > = sSchema ;
2001-02-14 09:25:17 +00:00
if ( sSchema . getLength ( ) )
2001-08-01 05:21:30 +00:00
aSql + = : : dbtools : : quoteName ( aQuote , sSchema ) + sDot ;
2001-02-14 09:25:17 +00:00
else
2001-05-15 07:18:32 +00:00
descriptor - > setPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_SCHEMANAME ) , makeAny ( static_cast < OAdabasCatalog & > ( m_rParent ) . getConnection ( ) - > getUserName ( ) .
toAsciiUpperCase ( )
) ) ;
2000-09-18 15:18:56 +00:00
2001-05-14 10:55:19 +00:00
aSql + = : : dbtools : : quoteName ( aQuote , getString ( descriptor - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_NAME ) ) ) )
2000-09-18 15:18:56 +00:00
+ : : rtl : : OUString : : createFromAscii ( " ( " ) ;
// columns
2000-10-30 06:55:15 +00:00
Reference < XColumnsSupplier > xColumnSup ( descriptor , UNO_QUERY ) ;
Reference < XIndexAccess > xColumns ( xColumnSup - > getColumns ( ) , UNO_QUERY ) ;
Reference < XPropertySet > xColProp ;
2000-09-18 15:18:56 +00:00
2000-10-30 06:55:15 +00:00
Any aTypeName ;
2001-02-14 09:25:17 +00:00
sal_Int32 nCount = xColumns - > getCount ( ) ;
if ( ! nCount )
2004-10-22 07:41:50 +00:00
: : dbtools : : throwFunctionSequenceException ( static_cast < XTypeProvider * > ( this ) ) ;
2001-02-14 09:25:17 +00:00
for ( sal_Int32 i = 0 ; i < nCount ; + + i )
2000-09-18 15:18:56 +00:00
{
2001-02-14 09:25:17 +00:00
if ( : : cppu : : extractInterface ( xColProp , xColumns - > getByIndex ( i ) ) & & xColProp . is ( ) )
2000-09-18 15:18:56 +00:00
{
2001-07-03 12:01:47 +00:00
aSql + = aQuote + getString ( xColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_NAME ) ) ) + aQuote ;
2000-09-18 15:18:56 +00:00
2001-07-03 12:01:47 +00:00
aSql + = : : rtl : : OUString : : createFromAscii ( " " ) ;
2001-07-06 07:12:36 +00:00
aSql + = OTables : : getColumnSqlType ( xColProp ) ;
aSql + = OTables : : getColumnSqlNotNullDefault ( xColProp ) ;
2001-07-03 12:01:47 +00:00
aSql + = : : rtl : : OUString : : createFromAscii ( " , " ) ;
2000-09-18 15:18:56 +00:00
}
}
// keys
2000-10-30 06:55:15 +00:00
Reference < XKeysSupplier > xKeySup ( descriptor , UNO_QUERY ) ;
2000-09-18 15:18:56 +00:00
2000-10-30 06:55:15 +00:00
Reference < XIndexAccess > xKeys = xKeySup - > getKeys ( ) ;
2000-09-18 15:18:56 +00:00
if ( xKeys . is ( ) )
{
sal_Bool bPKey = sal_False ;
2006-06-20 00:11:03 +00:00
for ( sal_Int32 key = 0 ; key < xKeys - > getCount ( ) ; + + key )
2000-09-18 15:18:56 +00:00
{
2006-06-20 00:11:03 +00:00
if ( : : cppu : : extractInterface ( xColProp , xKeys - > getByIndex ( key ) ) & & xColProp . is ( ) )
2000-09-18 15:18:56 +00:00
{
2001-05-14 10:55:19 +00:00
sal_Int32 nKeyType = getINT32 ( xColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_TYPE ) ) ) ;
2000-09-18 15:18:56 +00:00
2000-10-30 06:55:15 +00:00
if ( nKeyType = = KeyType : : PRIMARY )
2000-09-18 15:18:56 +00:00
{
2001-02-14 09:25:17 +00:00
if ( bPKey )
2000-10-30 06:55:15 +00:00
throw SQLException ( ) ;
2000-09-18 15:18:56 +00:00
bPKey = sal_True ;
2000-10-30 06:55:15 +00:00
xColumnSup = Reference < XColumnsSupplier > ( xColProp , UNO_QUERY ) ;
xColumns = Reference < XIndexAccess > ( xColumnSup - > getColumns ( ) , UNO_QUERY ) ;
2000-09-18 15:18:56 +00:00
if ( ! xColumns - > getCount ( ) )
2000-10-30 06:55:15 +00:00
throw SQLException ( ) ;
2000-09-18 15:18:56 +00:00
2001-07-03 12:01:47 +00:00
aSql + = : : rtl : : OUString : : createFromAscii ( " PRIMARY KEY ( " ) ;
2006-06-20 00:11:03 +00:00
for ( sal_Int32 column = 0 ; column < xColumns - > getCount ( ) ; + + column )
2000-09-18 15:18:56 +00:00
{
2006-06-20 00:11:03 +00:00
if ( : : cppu : : extractInterface ( xColProp , xColumns - > getByIndex ( column ) ) & & xColProp . is ( ) )
2001-07-03 12:01:47 +00:00
aSql + = aQuote + getString ( xColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_NAME ) ) ) + aQuote
2000-09-18 15:18:56 +00:00
+ : : rtl : : OUString : : createFromAscii ( " , " ) ;
}
aSql = aSql . replaceAt ( aSql . getLength ( ) - 1 , 1 , : : rtl : : OUString : : createFromAscii ( " ) " ) ) ;
}
2000-10-30 06:55:15 +00:00
else if ( nKeyType = = KeyType : : UNIQUE )
2000-09-18 15:18:56 +00:00
{
2000-10-30 06:55:15 +00:00
xColumnSup = Reference < XColumnsSupplier > ( xColProp , UNO_QUERY ) ;
xColumns = Reference < XIndexAccess > ( xColumnSup - > getColumns ( ) , UNO_QUERY ) ;
2000-09-18 15:18:56 +00:00
if ( ! xColumns - > getCount ( ) )
2000-10-30 06:55:15 +00:00
throw SQLException ( ) ;
2000-09-18 15:18:56 +00:00
2001-07-03 12:01:47 +00:00
aSql + = : : rtl : : OUString : : createFromAscii ( " UNIQUE ( " ) ;
2006-06-20 00:11:03 +00:00
for ( sal_Int32 column = 0 ; column < xColumns - > getCount ( ) ; + + column )
2000-09-18 15:18:56 +00:00
{
2006-06-20 00:11:03 +00:00
if ( : : cppu : : extractInterface ( xColProp , xColumns - > getByIndex ( column ) ) & & xColProp . is ( ) )
2001-07-03 12:01:47 +00:00
aSql + = aQuote + getString ( xColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_NAME ) ) ) + aQuote
2000-09-18 15:18:56 +00:00
+ : : rtl : : OUString : : createFromAscii ( " , " ) ;
}
aSql = aSql . replaceAt ( aSql . getLength ( ) - 1 , 1 , : : rtl : : OUString : : createFromAscii ( " ) " ) ) ;
}
2000-10-30 06:55:15 +00:00
else if ( nKeyType = = KeyType : : FOREIGN )
2000-09-18 15:18:56 +00:00
{
2001-05-14 10:55:19 +00:00
sal_Int32 nDeleteRule = getINT32 ( xColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_DELETERULE ) ) ) ;
2000-09-18 15:18:56 +00:00
2000-10-30 06:55:15 +00:00
xColumnSup = Reference < XColumnsSupplier > ( xColProp , UNO_QUERY ) ;
xColumns = Reference < XIndexAccess > ( xColumnSup - > getColumns ( ) , UNO_QUERY ) ;
2000-09-18 15:18:56 +00:00
if ( ! xColumns - > getCount ( ) )
2000-10-30 06:55:15 +00:00
throw SQLException ( ) ;
2000-09-18 15:18:56 +00:00
2001-07-03 12:01:47 +00:00
aSql + = : : rtl : : OUString : : createFromAscii ( " FOREIGN KEY " ) ;
2001-05-14 10:55:19 +00:00
: : rtl : : OUString aName , aSchema , aRefTable = getString ( xColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_REFERENCEDTABLE ) ) ) ;
2000-09-18 15:18:56 +00:00
sal_Int32 nLen = aRefTable . indexOf ( ' . ' ) ;
aSchema = aRefTable . copy ( 0 , nLen ) ;
aName = aRefTable . copy ( nLen + 1 ) ;
2001-08-01 05:21:30 +00:00
aSql + = aQuote + aSchema + aQuote + sDot
2000-09-18 15:18:56 +00:00
+ aQuote + aName + aQuote
+ : : rtl : : OUString : : createFromAscii ( " ( " ) ;
2006-06-20 00:11:03 +00:00
for ( sal_Int32 column = 0 ; column < xColumns - > getCount ( ) ; + + column )
2000-09-18 15:18:56 +00:00
{
2006-06-20 00:11:03 +00:00
if ( : : cppu : : extractInterface ( xColProp , xColumns - > getByIndex ( column ) ) & & xColProp . is ( ) )
2001-07-03 12:01:47 +00:00
aSql + = aQuote + getString ( xColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_NAME ) ) ) + aQuote
2000-09-18 15:18:56 +00:00
+ : : rtl : : OUString : : createFromAscii ( " , " ) ;
}
aSql = aSql . replaceAt ( aSql . getLength ( ) - 1 , 1 , : : rtl : : OUString : : createFromAscii ( " ) " ) ) ;
switch ( nDeleteRule )
{
2000-10-30 06:55:15 +00:00
case KeyRule : : CASCADE :
2001-07-03 12:01:47 +00:00
aSql + = : : rtl : : OUString : : createFromAscii ( " ON DELETE CASCADE " ) ;
2000-09-18 15:18:56 +00:00
break ;
2000-10-30 06:55:15 +00:00
case KeyRule : : RESTRICT :
2001-07-03 12:01:47 +00:00
aSql + = : : rtl : : OUString : : createFromAscii ( " ON DELETE RESTRICT " ) ;
2000-09-18 15:18:56 +00:00
break ;
2000-10-30 06:55:15 +00:00
case KeyRule : : SET_NULL :
2001-07-03 12:01:47 +00:00
aSql + = : : rtl : : OUString : : createFromAscii ( " ON DELETE SET NULL " ) ;
2000-09-18 15:18:56 +00:00
break ;
2000-10-30 06:55:15 +00:00
case KeyRule : : SET_DEFAULT :
2001-07-03 12:01:47 +00:00
aSql + = : : rtl : : OUString : : createFromAscii ( " ON DELETE SET DEFAULT " ) ;
2000-09-18 15:18:56 +00:00
break ;
default :
;
}
}
}
}
}
2001-02-14 09:25:17 +00:00
if ( aSql . lastIndexOf ( ' , ' ) = = ( aSql . getLength ( ) - 1 ) )
aSql = aSql . replaceAt ( aSql . getLength ( ) - 1 , 1 , : : rtl : : OUString : : createFromAscii ( " ) " ) ) ;
else
aSql + = : : rtl : : OUString : : createFromAscii ( " ) " ) ;
2000-09-18 15:18:56 +00:00
OAdabasConnection * pConnection = static_cast < OAdabasCatalog & > ( m_rParent ) . getConnection ( ) ;
Reference < XStatement > xStmt = pConnection - > createStatement ( ) ;
xStmt - > execute ( aSql ) ;
2001-10-02 12:12:32 +00:00
: : comphelper : : disposeComponent ( xStmt ) ;
2000-09-18 15:18:56 +00:00
2001-05-14 10:55:19 +00:00
if ( getString ( descriptor - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_DESCRIPTION ) ) ) . getLength ( ) )
2000-09-18 15:18:56 +00:00
setComments ( descriptor ) ;
}
2001-03-28 10:48:02 +00:00
// -----------------------------------------------------------------------------
void OTables : : appendNew ( const : : rtl : : OUString & _rsNewTable )
2000-09-18 15:18:56 +00:00
{
2001-08-13 13:03:54 +00:00
insertElement ( _rsNewTable , NULL ) ;
// notify our container listeners
2001-03-28 10:48:02 +00:00
ContainerEvent aEvent ( static_cast < XContainer * > ( this ) , makeAny ( _rsNewTable ) , Any ( ) , Any ( ) ) ;
OInterfaceIteratorHelper aListenerLoop ( m_aContainerListeners ) ;
while ( aListenerLoop . hasMoreElements ( ) )
static_cast < XContainerListener * > ( aListenerLoop . next ( ) ) - > elementInserted ( aEvent ) ;
2000-09-18 15:18:56 +00:00
}
2001-03-28 10:48:02 +00:00
// -----------------------------------------------------------------------------
2001-07-06 07:12:36 +00:00
: : rtl : : OUString OTables : : getColumnSqlType ( const Reference < XPropertySet > & _rxColProp )
{
: : rtl : : OUString sSql ;
sal_Int32 nDataType = 0 ;
_rxColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_TYPE ) ) > > = nDataType ;
switch ( nDataType )
{
case DataType : : VARBINARY :
sSql + = : : rtl : : OUString : : createFromAscii ( " VAR " ) ;
/* run through*/
case DataType : : BINARY :
sSql + = : : rtl : : OUString : : createFromAscii ( " CHAR " ) ;
break ;
default :
{
Any aTypeName = _rxColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_TYPENAME ) ) ;
if ( aTypeName . hasValue ( ) & & getString ( aTypeName ) . getLength ( ) )
sSql + = getString ( aTypeName ) ;
else
sSql + = OTables : : getTypeString ( _rxColProp ) + : : rtl : : OUString : : createFromAscii ( " " ) ;
}
}
2000-09-18 15:18:56 +00:00
2001-07-06 07:12:36 +00:00
switch ( nDataType )
{
case DataType : : CHAR :
case DataType : : VARCHAR :
case DataType : : FLOAT :
case DataType : : REAL :
sSql + = : : rtl : : OUString : : createFromAscii ( " ( " )
+ : : rtl : : OUString : : valueOf ( getINT32 ( _rxColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_PRECISION ) ) ) )
+ : : rtl : : OUString : : createFromAscii ( " ) " ) ;
break ;
case DataType : : DECIMAL :
case DataType : : NUMERIC :
sSql + = : : rtl : : OUString : : createFromAscii ( " ( " )
+ : : rtl : : OUString : : valueOf ( getINT32 ( _rxColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_PRECISION ) ) ) )
+ : : rtl : : OUString : : createFromAscii ( " , " )
+ : : rtl : : OUString : : valueOf ( getINT32 ( _rxColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_SCALE ) ) ) )
+ : : rtl : : OUString : : createFromAscii ( " ) " ) ;
break ;
case DataType : : BINARY :
case DataType : : VARBINARY :
sSql + = : : rtl : : OUString : : createFromAscii ( " ( " )
+ : : rtl : : OUString : : valueOf ( getINT32 ( _rxColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_PRECISION ) ) ) )
+ : : rtl : : OUString : : createFromAscii ( " ) BYTE " ) ;
break ;
}
return sSql ;
}
// -----------------------------------------------------------------------------
: : rtl : : OUString OTables : : getColumnSqlNotNullDefault ( const Reference < XPropertySet > & _rxColProp )
{
OSL_ENSURE ( _rxColProp . is ( ) , " OTables::getColumnSqlNotNullDefault: Column is null! " ) ;
: : rtl : : OUString sSql ;
: : rtl : : OUString aDefault = getString ( _rxColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_DEFAULTVALUE ) ) ) ;
if ( getINT32 ( _rxColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_ISNULLABLE ) ) ) = = ColumnValue : : NO_NULLS )
{
sSql + = : : rtl : : OUString : : createFromAscii ( " NOT NULL " ) ;
if ( aDefault . getLength ( ) )
sSql + = : : rtl : : OUString : : createFromAscii ( " WITH DEFAULT " ) ;
}
else if ( aDefault . getLength ( ) )
{
sSql + = : : rtl : : OUString : : createFromAscii ( " DEFAULT ' " ) + aDefault ;
sSql + = : : rtl : : OUString : : createFromAscii ( " ' " ) ;
}
return sSql ;
}
// -----------------------------------------------------------------------------
: : rtl : : OUString OTables : : getTypeString ( const Reference < XPropertySet > & _rxColProp )
{
: : rtl : : OUString aValue ;
switch ( getINT32 ( _rxColProp - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_TYPE ) ) ) )
{
case DataType : : BIT :
aValue = : : rtl : : OUString : : createFromAscii ( " BOOLEAN " ) ;
break ;
case DataType : : TINYINT :
aValue = : : rtl : : OUString : : createFromAscii ( " SMALLINT " ) ;
break ;
case DataType : : SMALLINT :
aValue = : : rtl : : OUString : : createFromAscii ( " SMALLINT " ) ;
break ;
case DataType : : INTEGER :
aValue = : : rtl : : OUString : : createFromAscii ( " INT " ) ;
break ;
case DataType : : FLOAT :
aValue = : : rtl : : OUString : : createFromAscii ( " FLOAT " ) ;
break ;
case DataType : : REAL :
aValue = : : rtl : : OUString : : createFromAscii ( " REAL " ) ;
break ;
case DataType : : DOUBLE :
aValue = : : rtl : : OUString : : createFromAscii ( " DOUBLE " ) ;
break ;
case DataType : : NUMERIC :
aValue = : : rtl : : OUString : : createFromAscii ( " DECIMAL " ) ;
break ;
case DataType : : DECIMAL :
aValue = : : rtl : : OUString : : createFromAscii ( " DECIMAL " ) ;
break ;
case DataType : : CHAR :
aValue = : : rtl : : OUString : : createFromAscii ( " CHAR " ) ;
break ;
case DataType : : VARCHAR :
aValue = : : rtl : : OUString : : createFromAscii ( " VARCHAR " ) ;
break ;
case DataType : : LONGVARCHAR :
aValue = : : rtl : : OUString : : createFromAscii ( " LONG VARCHAR " ) ;
break ;
case DataType : : DATE :
aValue = : : rtl : : OUString : : createFromAscii ( " DATE " ) ;
break ;
case DataType : : TIME :
aValue = : : rtl : : OUString : : createFromAscii ( " TIME " ) ;
break ;
case DataType : : TIMESTAMP :
aValue = : : rtl : : OUString : : createFromAscii ( " TIMESTAMP " ) ;
break ;
case DataType : : BINARY :
aValue = : : rtl : : OUString : : createFromAscii ( " CHAR () BYTE " ) ;
break ;
case DataType : : VARBINARY :
aValue = : : rtl : : OUString : : createFromAscii ( " VARCHAR () BYTE " ) ;
break ;
case DataType : : LONGVARBINARY :
aValue = : : rtl : : OUString : : createFromAscii ( " LONG BYTE " ) ;
break ;
}
return aValue ;
}
// -----------------------------------------------------------------------------
2005-03-10 14:21:18 +00:00
: : rtl : : OUString OTables : : getNameForObject ( const sdbcx : : ObjectType & _xObject )
{
OSL_ENSURE ( _xObject . is ( ) , " OTables::getNameForObject: Object is NULL! " ) ;
: : rtl : : OUString sName , sTemp ;
_xObject - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_SCHEMANAME ) ) > > = sName ;
if ( sName . getLength ( ) )
{
const : : rtl : : OUString & sDot = OAdabasCatalog : : getDot ( ) ;
sName + = sDot ;
}
_xObject - > getPropertyValue ( OMetaConnection : : getPropMap ( ) . getNameByIndex ( PROPERTY_ID_NAME ) ) > > = sTemp ;
sName + = sTemp ;
2000-09-18 15:18:56 +00:00
2005-03-10 14:21:18 +00:00
return sName ;
}
// -----------------------------------------------------------------------------