LCOV - code coverage report
Current view: top level - dbaccess/source/ui/tabledesign - TableController.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 10 818 1.2 %
Date: 2012-08-25 Functions: 5 46 10.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 2464 0.3 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : 
      21                 :            : #include "FieldDescriptions.hxx"
      22                 :            : #include "TEditControl.hxx"
      23                 :            : #include "TableController.hxx"
      24                 :            : #include "TableDesignView.hxx"
      25                 :            : #include "TableRow.hxx"
      26                 :            : #include "TypeInfo.hxx"
      27                 :            : #include "UITools.hxx"
      28                 :            : #include "browserids.hxx"
      29                 :            : #include "dbu_reghelper.hxx"
      30                 :            : #include "dbu_tbl.hrc"
      31                 :            : #include "dbustrings.hrc"
      32                 :            : #include "defaultobjectnamecheck.hxx"
      33                 :            : #include "dlgsave.hxx"
      34                 :            : #include "dsmeta.hxx"
      35                 :            : #include "indexdialog.hxx"
      36                 :            : #include "sqlmessage.hxx"
      37                 :            : 
      38                 :            : #include <com/sun/star/container/XChild.hpp>
      39                 :            : #include <com/sun/star/container/XNameContainer.hpp>
      40                 :            : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      41                 :            : #include <com/sun/star/frame/XTitleChangeListener.hpp>
      42                 :            : #include <com/sun/star/frame/XUntitledNumbers.hpp>
      43                 :            : #include <com/sun/star/io/XActiveDataSink.hpp>
      44                 :            : #include <com/sun/star/io/XActiveDataSource.hpp>
      45                 :            : #include <com/sun/star/sdb/CommandType.hpp>
      46                 :            : #include <com/sun/star/sdb/SQLContext.hpp>
      47                 :            : #include <com/sun/star/sdbc/ColumnValue.hpp>
      48                 :            : #include <com/sun/star/sdbc/SQLWarning.hpp>
      49                 :            : #include <com/sun/star/sdbc/XRow.hpp>
      50                 :            : #include <com/sun/star/sdbcx/KeyType.hpp>
      51                 :            : #include <com/sun/star/sdbcx/XAlterTable.hpp>
      52                 :            : #include <com/sun/star/sdbcx/XAppend.hpp>
      53                 :            : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
      54                 :            : #include <com/sun/star/sdbcx/XDrop.hpp>
      55                 :            : #include <com/sun/star/sdbcx/XIndexesSupplier.hpp>
      56                 :            : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      57                 :            : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      58                 :            : 
      59                 :            : #include <comphelper/extract.hxx>
      60                 :            : #include <comphelper/streamsection.hxx>
      61                 :            : #include <comphelper/types.hxx>
      62                 :            : #include <connectivity/dbexception.hxx>
      63                 :            : #include <connectivity/dbtools.hxx>
      64                 :            : #include <connectivity/dbmetadata.hxx>
      65                 :            : #include <cppuhelper/exc_hlp.hxx>
      66                 :            : #include <sfx2/sfxsids.hrc>
      67                 :            : #include <tools/diagnose_ex.h>
      68                 :            : #include <tools/string.hxx>
      69                 :            : #include <vcl/msgbox.hxx>
      70                 :            : 
      71                 :            : #include <boost/mem_fn.hpp>
      72                 :            : #include <boost/bind.hpp>
      73                 :            : 
      74                 :            : #include <algorithm>
      75                 :            : #include <functional>
      76                 :            : 
      77                 :          8 : extern "C" void SAL_CALL createRegistryInfo_OTableControl()
      78                 :            : {
      79 [ +  - ][ +  - ]:          8 :     static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OTableController > aAutoRegistration;
         [ +  - ][ #  # ]
      80                 :          8 : }
      81                 :            : 
      82                 :            : using namespace ::com::sun::star;
      83                 :            : using namespace ::com::sun::star::uno;
      84                 :            : using namespace ::com::sun::star::io;
      85                 :            : using namespace ::com::sun::star::beans;
      86                 :            : using namespace ::com::sun::star::frame;
      87                 :            : using namespace ::com::sun::star::util;
      88                 :            : using namespace ::com::sun::star::lang;
      89                 :            : using namespace ::com::sun::star::container;
      90                 :            : using namespace ::com::sun::star::sdbcx;
      91                 :            : using namespace ::com::sun::star::sdbc;
      92                 :            : using namespace ::com::sun::star::sdb;
      93                 :            : using namespace ::com::sun::star::ui;
      94                 :            : using namespace ::com::sun::star::util;
      95                 :            : using namespace ::dbtools;
      96                 :            : using namespace ::dbaui;
      97                 :            : using namespace ::comphelper;
      98                 :            : 
      99                 :            : // Anzahl Spalten beim Neuanlegen
     100                 :            : #define NEWCOLS        128
     101                 :            : 
     102                 :            : namespace
     103                 :            : {
     104                 :          0 :     void dropTable(const Reference<XNameAccess>& _rxTable,const ::rtl::OUString& _sTableName)
     105                 :            :     {
     106         [ #  # ]:          0 :         if ( _rxTable->hasByName(_sTableName) )
     107                 :            :         {
     108         [ #  # ]:          0 :             Reference<XDrop> xNameCont(_rxTable,UNO_QUERY);
     109                 :            :             OSL_ENSURE(xNameCont.is(),"No drop interface for tables!");
     110         [ #  # ]:          0 :             if ( xNameCont.is() )
     111 [ #  # ][ #  # ]:          0 :                 xNameCont->dropByName(_sTableName);
     112                 :            :         }
     113                 :          0 :     }
     114                 :            :     //------------------------------------------------------------------------------
     115                 :            :     struct OTableRowCompare : public ::std::binary_function<  ::boost::shared_ptr<OTableRow> , ::rtl::OUString, bool>
     116                 :            :     {
     117                 :            :         bool operator() (const  ::boost::shared_ptr<OTableRow>  lhs, const ::rtl::OUString& rhs) const
     118                 :            :         {
     119                 :            :             OFieldDescription* pField = lhs->GetActFieldDescr();
     120                 :            :             return pField && pField->GetName() == rhs;
     121                 :            :         }
     122                 :            :     };
     123                 :            : 
     124                 :            : }
     125                 :            : 
     126                 :            : //------------------------------------------------------------------------------
     127                 :          0 : ::rtl::OUString SAL_CALL OTableController::getImplementationName() throw( RuntimeException )
     128                 :            : {
     129                 :          0 :     return getImplementationName_Static();
     130                 :            : }
     131                 :            : 
     132                 :            : //------------------------------------------------------------------------------
     133                 :         16 : ::rtl::OUString OTableController::getImplementationName_Static() throw( RuntimeException )
     134                 :            : {
     135                 :         16 :     return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.dbu.OTableDesign"));
     136                 :            : }
     137                 :            : //------------------------------------------------------------------------------
     138                 :          8 : Sequence< ::rtl::OUString> OTableController::getSupportedServiceNames_Static(void) throw( RuntimeException )
     139                 :            : {
     140                 :          8 :     Sequence< ::rtl::OUString> aSupported(1);
     141 [ +  - ][ +  - ]:          8 :     aSupported.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.TableDesign"));
     142                 :          8 :     return aSupported;
     143                 :            : }
     144                 :            : //-------------------------------------------------------------------------
     145                 :          0 : Sequence< ::rtl::OUString> SAL_CALL OTableController::getSupportedServiceNames() throw(RuntimeException)
     146                 :            : {
     147                 :          0 :     return getSupportedServiceNames_Static();
     148                 :            : }
     149                 :            : // -------------------------------------------------------------------------
     150                 :          0 : Reference< XInterface > SAL_CALL OTableController::Create(const Reference<XMultiServiceFactory >& _rxFactory)
     151                 :            : {
     152         [ #  # ]:          0 :     return *(new OTableController(_rxFactory));
     153                 :            : }
     154                 :            : 
     155                 :            : DBG_NAME(OTableController)
     156                 :            : // -----------------------------------------------------------------------------
     157                 :          0 : OTableController::OTableController(const Reference< XMultiServiceFactory >& _rM) : OTableController_BASE(_rM)
     158                 :            :     ,m_sTypeNames(ModuleRes(STR_TABLEDESIGN_DBFIELDTYPES))
     159                 :            :     ,m_pTypeInfo()
     160                 :            :     ,m_bAllowAutoIncrementValue(sal_False)
     161 [ #  # ][ #  # ]:          0 :     ,m_bNew(sal_True)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     162                 :            : {
     163                 :            :     DBG_CTOR(OTableController,NULL);
     164                 :            : 
     165         [ #  # ]:          0 :     InvalidateAll();
     166 [ #  # ][ #  # ]:          0 :     m_pTypeInfo = TOTypeInfoSP(new OTypeInfo());
         [ #  # ][ #  # ]
     167 [ #  # ][ #  # ]:          0 :     m_pTypeInfo->aUIName = m_sTypeNames.GetToken(TYPE_OTHER);
                 [ #  # ]
     168                 :          0 : }
     169                 :            : // -----------------------------------------------------------------------------
     170 [ #  # ][ #  # ]:          0 : OTableController::~OTableController()
                 [ #  # ]
     171                 :            : {
     172                 :          0 :     m_aTypeInfoIndex.clear();
     173                 :          0 :     m_aTypeInfo.clear();
     174                 :            : 
     175                 :            :     DBG_DTOR(OTableController,NULL);
     176         [ #  # ]:          0 : }
     177                 :            : 
     178                 :            : // -----------------------------------------------------------------------------
     179                 :          0 : void OTableController::startTableListening()
     180                 :            : {
     181         [ #  # ]:          0 :     Reference< XComponent >  xComponent(m_xTable, UNO_QUERY);
     182         [ #  # ]:          0 :     if (xComponent.is())
     183 [ #  # ][ #  # ]:          0 :         xComponent->addEventListener(static_cast<XModifyListener*>(this));
                 [ #  # ]
     184                 :          0 : }
     185                 :            : 
     186                 :            : // -----------------------------------------------------------------------------
     187                 :          0 : void OTableController::stopTableListening()
     188                 :            : {
     189         [ #  # ]:          0 :     Reference< XComponent >  xComponent(m_xTable, UNO_QUERY);
     190         [ #  # ]:          0 :     if (xComponent.is())
     191 [ #  # ][ #  # ]:          0 :         xComponent->removeEventListener(static_cast<XModifyListener*>(this));
                 [ #  # ]
     192                 :          0 : }
     193                 :            : 
     194                 :            : // -----------------------------------------------------------------------------
     195                 :          0 : void OTableController::disposing()
     196                 :            : {
     197                 :          0 :     OTableController_BASE::disposing();
     198                 :          0 :     clearView();
     199                 :            : 
     200                 :          0 :     m_vRowList.clear();
     201                 :          0 : }
     202                 :            : // -----------------------------------------------------------------------------
     203                 :          0 : FeatureState OTableController::GetState(sal_uInt16 _nId) const
     204                 :            : {
     205                 :          0 :     FeatureState aReturn;
     206                 :            :     // (disabled automatically)
     207                 :            : 
     208   [ #  #  #  #  :          0 :     switch (_nId)
             #  #  #  #  
                      # ]
     209                 :            :     {
     210                 :            :         case ID_BROWSER_CLOSE:
     211                 :          0 :             aReturn.bEnabled = sal_True;
     212                 :          0 :             break;
     213                 :            :         case ID_BROWSER_EDITDOC:
     214 [ #  # ][ #  # ]:          0 :             aReturn.bChecked = isEditable();
     215 [ #  # ][ #  # ]:          0 :             aReturn.bEnabled = m_bNew || isEditable();// the editable flag is set through this one -> || isAddAllowed() || isDropAllowed() || isAlterAllowed();
                 [ #  # ]
     216                 :          0 :             break;
     217                 :            :         case ID_BROWSER_SAVEDOC:
     218         [ #  # ]:          0 :             aReturn.bEnabled = impl_isModified();
     219         [ #  # ]:          0 :             if ( aReturn.bEnabled )
     220                 :            :             {
     221                 :            :                 ::std::vector< ::boost::shared_ptr<OTableRow> >::const_iterator aIter = ::std::find_if(m_vRowList.begin(),m_vRowList.end(),
     222 [ #  # ][ #  # ]:          0 :                     ::boost::mem_fn(&OTableRow::isValid));
     223         [ #  # ]:          0 :                 aReturn.bEnabled = aIter != m_vRowList.end();
     224                 :            :             }
     225                 :          0 :             break;
     226                 :            :         case ID_BROWSER_SAVEASDOC:
     227 [ #  # ][ #  # ]:          0 :             aReturn.bEnabled = isConnected() && isEditable();
         [ #  # ][ #  # ]
     228         [ #  # ]:          0 :             if ( aReturn.bEnabled )
     229                 :            :             {
     230                 :            :                 ::std::vector< ::boost::shared_ptr<OTableRow> >::const_iterator aIter = ::std::find_if(m_vRowList.begin(),m_vRowList.end(),
     231 [ #  # ][ #  # ]:          0 :                     ::boost::mem_fn(&OTableRow::isValid));
     232         [ #  # ]:          0 :                 aReturn.bEnabled = aIter != m_vRowList.end();
     233                 :            :             }
     234                 :          0 :             break;
     235                 :            : 
     236                 :            :         case ID_BROWSER_CUT:
     237 [ #  # ][ #  # ]:          0 :             aReturn.bEnabled = isEditable() && m_aCurrentFrame.isActive() && getView() && static_cast<OTableDesignView*>(getView())->isCutAllowed();
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     238                 :          0 :             break;
     239                 :            :         case ID_BROWSER_COPY:
     240 [ #  # ][ #  # ]:          0 :             aReturn.bEnabled = m_aCurrentFrame.isActive() && getView() && static_cast<OTableDesignView*>(getView())->isCopyAllowed();
         [ #  # ][ #  # ]
                 [ #  # ]
     241                 :          0 :             break;
     242                 :            :         case ID_BROWSER_PASTE:
     243 [ #  # ][ #  # ]:          0 :             aReturn.bEnabled = isEditable() && m_aCurrentFrame.isActive() && getView() && static_cast<OTableDesignView*>(getView())->isPasteAllowed();
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     244                 :          0 :             break;
     245                 :            :         case SID_INDEXDESIGN:
     246                 :            :             aReturn.bEnabled =
     247 [ #  # ][ #  # ]:          0 :                 (   (   ((!m_bNew && impl_isModified()) || impl_isModified())
     248 [ #  # ][ #  # ]:          0 :                     ||  Reference< XIndexesSupplier >(m_xTable, UNO_QUERY).is()
                 [ #  # ]
     249                 :            :                     )
     250         [ #  # ]:          0 :                 &&  isConnected()
     251 [ #  # ][ #  # ]:          0 :                 );
           [ #  #  #  # ]
                 [ #  # ]
     252         [ #  # ]:          0 :             if ( aReturn.bEnabled )
     253                 :            :             {
     254                 :            :                 ::std::vector< ::boost::shared_ptr<OTableRow> >::const_iterator aIter = ::std::find_if(m_vRowList.begin(),m_vRowList.end(),
     255 [ #  # ][ #  # ]:          0 :                     ::boost::mem_fn(&OTableRow::isValid));
     256         [ #  # ]:          0 :                 aReturn.bEnabled = aIter != m_vRowList.end();
     257                 :            :             }
     258                 :          0 :             break;
     259                 :            :         default:
     260 [ #  # ][ #  # ]:          0 :             aReturn = OTableController_BASE::GetState(_nId);
                 [ #  # ]
     261                 :            :     }
     262                 :          0 :     return aReturn;
     263                 :            : }
     264                 :            : // -----------------------------------------------------------------------------
     265                 :          0 : void OTableController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs)
     266                 :            : {
     267   [ #  #  #  #  :          0 :     switch(_nId)
             #  #  #  # ]
     268                 :            :     {
     269                 :            :         case ID_BROWSER_EDITDOC:
     270                 :          0 :             setEditable(!isEditable());
     271                 :          0 :             static_cast<OTableDesignView*>(getView())->setReadOnly(!isEditable());
     272         [ #  # ]:          0 :             InvalidateFeature(ID_BROWSER_PASTE);
     273         [ #  # ]:          0 :             InvalidateFeature(SID_BROWSER_CLEAR_QUERY);
     274                 :          0 :             break;
     275                 :            :         case ID_BROWSER_SAVEASDOC:
     276                 :          0 :             doSaveDoc(sal_True);
     277                 :          0 :             break;
     278                 :            :         case ID_BROWSER_SAVEDOC:
     279                 :          0 :             static_cast<OTableDesignView*>(getView())->GetEditorCtrl()->SaveCurRow();
     280                 :          0 :             doSaveDoc(sal_False);
     281                 :          0 :             break;
     282                 :            :         case ID_BROWSER_CUT:
     283                 :          0 :             static_cast<OTableDesignView*>(getView())->cut();
     284                 :          0 :             break;
     285                 :            :         case ID_BROWSER_COPY:
     286                 :          0 :             static_cast<OTableDesignView*>(getView())->copy();
     287                 :          0 :             break;
     288                 :            :         case ID_BROWSER_PASTE:
     289                 :          0 :             static_cast<OTableDesignView*>(getView())->paste();
     290                 :          0 :             break;
     291                 :            :         case SID_INDEXDESIGN:
     292                 :          0 :             doEditIndexes();
     293                 :          0 :             break;
     294                 :            :         default:
     295                 :          0 :             OTableController_BASE::Execute(_nId,aArgs);
     296                 :            :     }
     297         [ #  # ]:          0 :     InvalidateFeature(_nId);
     298                 :          0 : }
     299                 :            : 
     300                 :            : // -----------------------------------------------------------------------------
     301                 :          0 : sal_Bool OTableController::doSaveDoc(sal_Bool _bSaveAs)
     302                 :            : {
     303 [ #  # ][ #  # ]:          0 :     if (!isConnected())
     304         [ #  # ]:          0 :         reconnect(sal_True); // ask the user for a new connection
     305 [ #  # ][ #  # ]:          0 :     Reference<XTablesSupplier> xTablesSup(getConnection(),UNO_QUERY);
     306                 :            : 
     307         [ #  # ]:          0 :     if (!xTablesSup.is())
     308                 :            :     {
     309 [ #  # ][ #  # ]:          0 :         String aMessage(ModuleRes(STR_TABLEDESIGN_CONNECTION_MISSING));
     310 [ #  # ][ #  # ]:          0 :         OSQLWarningBox( getView(), aMessage ).Execute();
                 [ #  # ]
     311         [ #  # ]:          0 :         return sal_False;
     312                 :            :     }
     313                 :            : 
     314                 :            :     // check if a column exists
     315                 :            :     // TODO
     316                 :            : 
     317                 :          0 :     Reference<XNameAccess> xTables;
     318                 :          0 :     ::rtl::OUString sCatalog, sSchema;
     319                 :            : 
     320                 :          0 :     sal_Bool bNew = m_sName.isEmpty();
     321 [ #  # ][ #  # ]:          0 :     bNew = bNew || m_bNew || _bSaveAs;
                 [ #  # ]
     322                 :            : 
     323                 :            :     try
     324                 :            :     {
     325 [ #  # ][ #  # ]:          0 :         xTables = xTablesSup->getTables();
                 [ #  # ]
     326                 :            :         OSL_ENSURE(xTables.is(),"The tables can't be null!");
     327 [ #  # ][ #  # ]:          0 :         bNew = bNew || (xTables.is() && !xTables->hasByName(m_sName));
         [ #  # ][ #  # ]
                 [ #  # ]
     328                 :            : 
     329                 :            :         // first we need a name for our query so ask the user
     330         [ #  # ]:          0 :         if(bNew)
     331                 :            :         {
     332         [ #  # ]:          0 :             String aDefaultName;
     333 [ #  # ][ #  # ]:          0 :             if (_bSaveAs && !bNew)
     334 [ #  # ][ #  # ]:          0 :                  aDefaultName = String(m_sName);
                 [ #  # ]
     335                 :            :             else
     336                 :            :             {
     337 [ #  # ][ #  # ]:          0 :                 String aName = String(ModuleRes(STR_TBL_TITLE));
     338 [ #  # ][ #  # ]:          0 :                 aDefaultName = aName.GetToken(0,' ');
                 [ #  # ]
     339 [ #  # ][ #  # ]:          0 :                 aDefaultName = ::dbtools::createUniqueName(xTables,aDefaultName);
         [ #  # ][ #  # ]
     340                 :            :             }
     341                 :            : 
     342 [ #  # ][ #  # ]:          0 :             DynamicTableOrQueryNameCheck aNameChecker( getConnection(), CommandType::TABLE );
     343 [ #  # ][ #  # ]:          0 :             OSaveAsDlg aDlg( getView(), CommandType::TABLE, getORB(), getConnection(), aDefaultName, aNameChecker );
                 [ #  # ]
     344 [ #  # ][ #  # ]:          0 :             if ( aDlg.Execute() != RET_OK )
     345                 :          0 :                 return sal_False;
     346                 :            : 
     347 [ #  # ][ #  # ]:          0 :             m_sName = aDlg.getName();
                 [ #  # ]
     348 [ #  # ][ #  # ]:          0 :             sCatalog = aDlg.getCatalog();
                 [ #  # ]
     349 [ #  # ][ #  # ]:          0 :             sSchema  = aDlg.getSchema();
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     350                 :            :         }
     351                 :            : 
     352                 :            :         // did we get a name
     353         [ #  # ]:          0 :         if(m_sName.isEmpty())
     354                 :          0 :             return sal_False;
     355                 :            :     }
     356         [ #  # ]:          0 :     catch(Exception&)
     357                 :            :     {
     358                 :            :         OSL_FAIL("OTableController::doSaveDoc: nothing is expected to happen here!");
     359                 :            :     }
     360                 :            : 
     361                 :          0 :     sal_Bool bAlter = sal_False;
     362                 :          0 :     sal_Bool bError = sal_False;
     363         [ #  # ]:          0 :     SQLExceptionInfo aInfo;
     364                 :            :     try
     365                 :            :     {
     366                 :            :         // check the columns for double names
     367 [ #  # ][ #  # ]:          0 :         if(!checkColumns(bNew || !xTables->hasByName(m_sName)))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     368                 :            :         {
     369                 :          0 :             return sal_False;
     370                 :            :         }
     371                 :            : 
     372                 :          0 :         Reference<XPropertySet> xTable;
     373 [ #  # ][ #  # ]:          0 :         if(bNew || !xTables->hasByName(m_sName)) // just to make sure the table already exists
         [ #  # ][ #  # ]
                 [ #  # ]
     374                 :            :         {
     375         [ #  # ]:          0 :             dropTable(xTables,m_sName);
     376                 :            : 
     377         [ #  # ]:          0 :             Reference<XDataDescriptorFactory> xFact(xTables,UNO_QUERY);
     378                 :            :             OSL_ENSURE(xFact.is(),"OTableController::doSaveDoc: No XDataDescriptorFactory available!");
     379 [ #  # ][ #  # ]:          0 :             xTable = xFact->createDataDescriptor();
                 [ #  # ]
     380                 :            :             OSL_ENSURE(xTable.is(),"OTableController::doSaveDoc: Create query failed!");
     381                 :            :             // to set the name is only allowed when the wuery is new
     382 [ #  # ][ #  # ]:          0 :             xTable->setPropertyValue(PROPERTY_CATALOGNAME,makeAny(sCatalog));
         [ #  # ][ #  # ]
     383 [ #  # ][ #  # ]:          0 :             xTable->setPropertyValue(PROPERTY_SCHEMANAME,makeAny(sSchema));
         [ #  # ][ #  # ]
     384 [ #  # ][ #  # ]:          0 :             xTable->setPropertyValue(PROPERTY_NAME,makeAny(m_sName));
         [ #  # ][ #  # ]
     385                 :            : 
     386                 :            :             // now append the columns
     387         [ #  # ]:          0 :             Reference<XColumnsSupplier> xColSup(xTable,UNO_QUERY);
     388         [ #  # ]:          0 :             appendColumns(xColSup,bNew);
     389                 :            :             // now append the primary key
     390         [ #  # ]:          0 :             Reference<XKeysSupplier> xKeySup(xTable,UNO_QUERY);
     391         [ #  # ]:          0 :             appendPrimaryKey(xKeySup,bNew);
     392                 :            :         }
     393                 :            :         // now set the properties
     394         [ #  # ]:          0 :         if(bNew)
     395                 :            :         {
     396         [ #  # ]:          0 :             Reference<XAppend> xAppend(xTables,UNO_QUERY);
     397                 :            :             OSL_ENSURE(xAppend.is(),"OTableController::doSaveDoc: No XAppend Interface!");
     398 [ #  # ][ #  # ]:          0 :             xAppend->appendByDescriptor(xTable);
     399                 :            : 
     400         [ #  # ]:          0 :             assignTable();
     401         [ #  # ]:          0 :             if(!m_xTable.is()) // correct name and try again
     402                 :            :             {
     403                 :            :                 // it can be that someone inserted new data for us
     404 [ #  # ][ #  # ]:          0 :                 m_sName = ::dbtools::composeTableName( getConnection()->getMetaData(), xTable, ::dbtools::eInDataManipulation, false, false, false );
         [ #  # ][ #  # ]
     405         [ #  # ]:          0 :                 assignTable();
     406                 :            :             }
     407                 :            :             // now check if our datasource has set a tablefilter and if append the new table name to it
     408 [ #  # ][ #  # ]:          0 :             ::dbaui::appendToFilter(getConnection(),m_sName,getORB(),getView()); // we are not interessted in the return value
                 [ #  # ]
     409 [ #  # ][ #  # ]:          0 :             Reference< frame::XTitleChangeListener> xEventListener(impl_getTitleHelper_throw(),UNO_QUERY);
     410         [ #  # ]:          0 :             if ( xEventListener.is() )
     411                 :            :             {
     412         [ #  # ]:          0 :                 frame::TitleChangedEvent aEvent;
     413 [ #  # ][ #  # ]:          0 :                 xEventListener->titleChanged(aEvent);
                 [ #  # ]
     414                 :            :             }
     415         [ #  # ]:          0 :             releaseNumberForComponent();
     416                 :            :         }
     417         [ #  # ]:          0 :         else if(m_xTable.is())
     418                 :            :         {
     419                 :          0 :             bAlter = sal_True;
     420         [ #  # ]:          0 :             alterColumns();
     421                 :            :         }
     422         [ #  # ]:          0 :         reSyncRows();
     423                 :            :     }
     424         [ #  # ]:          0 :     catch(const SQLContext& e)
     425                 :            :     {
     426   [ #  #  #  #  :          0 :         aInfo = SQLExceptionInfo(e);
                   #  # ]
     427                 :            :     }
     428         [ #  # ]:          0 :     catch(const SQLWarning& e)
     429                 :            :     {
     430   [ #  #  #  #  :          0 :         aInfo = SQLExceptionInfo(e);
                   #  # ]
     431                 :            :     }
     432         [ #  # ]:          0 :     catch(const SQLException& e)
     433                 :            :     {
     434   [ #  #  #  #  :          0 :         aInfo = SQLExceptionInfo(e);
                   #  # ]
     435                 :            :     }
     436   [ #  #  #  #  :          0 :     catch(const ElementExistException& )
             #  #  #  # ]
     437                 :            :     {
     438   [ #  #  #  # ]:          0 :         String sText( ModuleRes( STR_NAME_ALREADY_EXISTS ) );
     439   [ #  #  #  #  :          0 :         sText.SearchAndReplaceAscii( "#" , m_sName);
                   #  # ]
     440   [ #  #  #  #  :          0 :         OSQLMessageBox aDlg( getView(), String( ModuleRes( STR_ERROR_DURING_CREATION ) ), sText, WB_OK, OSQLMessageBox::Error );
             #  #  #  # ]
     441                 :            : 
     442         [ #  # ]:          0 :         aDlg.Execute();
     443   [ #  #  #  # ]:          0 :         bError = sal_True;
     444                 :            :     }
     445         [ #  # ]:          0 :     catch( const Exception& )
     446                 :            :     {
     447                 :          0 :         bError = sal_True;
     448                 :            :         DBG_UNHANDLED_EXCEPTION();
     449                 :            :     }
     450                 :            : 
     451         [ #  # ]:          0 :     if ( aInfo.isValid() )
     452 [ #  # ][ #  # ]:          0 :         aInfo.prepend( String( ModuleRes( STR_TABLEDESIGN_SAVE_ERROR ) ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     453         [ #  # ]:          0 :     showError(aInfo);
     454                 :            : 
     455 [ #  # ][ #  # ]:          0 :     if (aInfo.isValid() || bError)
                 [ #  # ]
     456                 :            :     {
     457 [ #  # ][ #  # ]:          0 :         if(!bAlter || bNew)
     458                 :            :         {
     459                 :          0 :             m_sName = ::rtl::OUString();
     460         [ #  # ]:          0 :             stopTableListening();
     461         [ #  # ]:          0 :             m_xTable = NULL;
     462                 :            :         }
     463                 :            :     }
     464 [ #  # ][ #  # ]:          0 :     return ! (aInfo.isValid() || bError);
                 [ #  # ]
     465                 :            : }
     466                 :            : 
     467                 :            : // -----------------------------------------------------------------------------
     468                 :          0 : void OTableController::doEditIndexes()
     469                 :            : {
     470                 :            :     // table needs to be saved before editing indexes
     471 [ #  # ][ #  # ]:          0 :     if (m_bNew || isModified())
         [ #  # ][ #  # ]
     472                 :            :     {
     473 [ #  # ][ #  # ]:          0 :         QueryBox aAsk(getView(), ModuleRes(QUERY_SAVE_TABLE_EDIT_INDEXES));
     474 [ #  # ][ #  # ]:          0 :         if (RET_YES != aAsk.Execute())
     475                 :            :             return;
     476                 :            : 
     477 [ #  # ][ #  # ]:          0 :         if (!doSaveDoc(sal_False))
     478                 :            :             return;
     479                 :            : 
     480 [ #  # ][ #  # ]:          0 :         OSL_ENSURE(!m_bNew && !isModified(), "OTableController::doEditIndexes: what the hell did doSaveDoc do?");
     481                 :            :     }
     482                 :            : 
     483                 :          0 :     Reference< XNameAccess > xIndexes;          // will be the keys of the table
     484         [ #  # ]:          0 :     Sequence< ::rtl::OUString > aFieldNames;    // will be the column names of the table
     485                 :            :     try
     486                 :            :     {
     487                 :            :         // get the keys
     488         [ #  # ]:          0 :         Reference< XIndexesSupplier > xIndexesSupp(m_xTable, UNO_QUERY);
     489         [ #  # ]:          0 :         if (xIndexesSupp.is())
     490                 :            :         {
     491 [ #  # ][ #  # ]:          0 :             xIndexes = xIndexesSupp->getIndexes();
                 [ #  # ]
     492                 :            :             OSL_ENSURE(xIndexes.is(), "OTableController::doEditIndexes: no keys got from the indexes supplier!");
     493                 :            :         }
     494                 :            :         else
     495                 :            :             OSL_FAIL("OTableController::doEditIndexes: should never have reached this (no indexes supplier)!");
     496                 :            : 
     497                 :            :         // get the field names
     498         [ #  # ]:          0 :         Reference< XColumnsSupplier > xColSupp(m_xTable, UNO_QUERY);
     499                 :            :         OSL_ENSURE(xColSupp.is(), "OTableController::doEditIndexes: no columns supplier!");
     500         [ #  # ]:          0 :         if (xColSupp.is())
     501                 :            :         {
     502 [ #  # ][ #  # ]:          0 :             Reference< XNameAccess > xCols = xColSupp->getColumns();
     503                 :            :             OSL_ENSURE(xCols.is(), "OTableController::doEditIndexes: no columns!");
     504         [ #  # ]:          0 :             if (xCols.is())
     505 [ #  # ][ #  # ]:          0 :                 aFieldNames = xCols->getElementNames();
         [ #  # ][ #  # ]
     506         [ #  # ]:          0 :         }
     507                 :            :     }
     508         [ #  # ]:          0 :     catch( const Exception& )
     509                 :            :     {
     510                 :            :         DBG_UNHANDLED_EXCEPTION();
     511                 :            :     }
     512                 :            : 
     513         [ #  # ]:          0 :     if (!xIndexes.is())
     514                 :            :         return;
     515                 :            : 
     516 [ #  # ][ #  # ]:          0 :     DbaIndexDialog aDialog(getView(), aFieldNames, xIndexes, getConnection(),getORB(),isConnected() ? getConnection()->getMetaData().is() && getConnection()->getMetaData()->getMaxColumnsInIndex() : sal_Int32(0));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     517 [ #  # ][ #  # ]:          0 :     if (RET_OK != aDialog.Execute())
     518 [ #  # ][ #  # ]:          0 :         return;
         [ #  # ][ #  # ]
                 [ #  # ]
     519                 :            : 
     520                 :            : }
     521                 :            : 
     522                 :            : // -----------------------------------------------------------------------------
     523                 :          0 : void OTableController::impl_initialize()
     524                 :            : {
     525                 :            :     try
     526                 :            :     {
     527         [ #  # ]:          0 :         OTableController_BASE::impl_initialize();
     528                 :            : 
     529                 :          0 :         const NamedValueCollection& rArguments( getInitParams() );
     530                 :            : 
     531 [ #  # ][ #  # ]:          0 :         rArguments.get_ensureType( (::rtl::OUString)PROPERTY_CURRENTTABLE, m_sName );
                 [ #  # ]
     532                 :            : 
     533                 :            :         // read autoincrement value set in the datasource
     534 [ #  # ][ #  # ]:          0 :         ::dbaui::fillAutoIncrementValue(getDataSource(),m_bAllowAutoIncrementValue,m_sAutoIncrementValue);
     535                 :            : 
     536         [ #  # ]:          0 :         assignTable();
     537                 :            :     }
     538                 :          0 :     catch( const Exception& )
     539                 :            :     {
     540                 :            :         DBG_UNHANDLED_EXCEPTION();
     541                 :            :     }
     542                 :            : 
     543                 :            :     try
     544                 :            :     {
     545 [ #  # ][ #  # ]:          0 :         ::dbaui::fillTypeInfo(getConnection(),m_sTypeNames,m_aTypeInfo,m_aTypeInfoIndex);               // fill the needed type information
     546                 :            :     }
     547         [ #  # ]:          0 :     catch(const SQLException&)
     548                 :            :     {
     549   [ #  #  #  #  :          0 :         OSQLWarningBox( getView(), ModuleRes( STR_NO_TYPE_INFO_AVAILABLE ) ).Execute();
          #  #  #  #  #  
                #  #  # ]
     550         [ #  # ]:          0 :         throw;
     551                 :            :     }
     552                 :            :     try
     553                 :            :     {
     554         [ #  # ]:          0 :         loadData();                 // fill the column information form the table
     555         [ #  # ]:          0 :         getView()->initialize();    // show the windows and fill with our informations
     556         [ #  # ]:          0 :         ClearUndoManager();
     557         [ #  # ]:          0 :         setModified(sal_False);     // and we are not modified yet
     558                 :            :     }
     559                 :          0 :     catch( const Exception& )
     560                 :            :     {
     561                 :            :         DBG_UNHANDLED_EXCEPTION();
     562                 :            :     }
     563                 :          0 : }
     564                 :            : // -----------------------------------------------------------------------------
     565                 :          0 : sal_Bool OTableController::Construct(Window* pParent)
     566                 :            : {
     567 [ #  # ][ #  # ]:          0 :     setView( * new OTableDesignView( pParent, getORB(), *this ) );
     568                 :          0 :     OTableController_BASE::Construct(pParent);
     569                 :          0 :     return sal_True;
     570                 :            : }
     571                 :            : // -----------------------------------------------------------------------------
     572                 :          0 : sal_Bool SAL_CALL OTableController::suspend(sal_Bool /*_bSuspend*/) throw( RuntimeException )
     573                 :            : {
     574 [ #  # ][ #  # ]:          0 :     if ( getBroadcastHelper().bInDispose || getBroadcastHelper().bDisposed )
                 [ #  # ]
     575                 :          0 :         return sal_True;
     576                 :            : 
     577         [ #  # ]:          0 :     SolarMutexGuard aSolarGuard;
     578 [ #  # ][ #  # ]:          0 :     ::osl::MutexGuard aGuard( getMutex() );
     579 [ #  # ][ #  # ]:          0 :     if ( getView() && getView()->IsInModalMode() )
         [ #  # ][ #  # ]
     580                 :          0 :         return sal_False;
     581         [ #  # ]:          0 :     if ( getView() )
     582         [ #  # ]:          0 :         static_cast<OTableDesignView*>(getView())->GrabFocus();
     583                 :          0 :     sal_Bool bCheck = sal_True;
     584 [ #  # ][ #  # ]:          0 :     if ( isModified() )
     585                 :            :     {
     586                 :            :         ::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aIter = ::std::find_if(m_vRowList.begin(),m_vRowList.end(),
     587 [ #  # ][ #  # ]:          0 :             ::boost::mem_fn(&OTableRow::isValid));
     588 [ #  # ][ #  # ]:          0 :         if ( aIter != m_vRowList.end() )
     589                 :            :         {
     590 [ #  # ][ #  # ]:          0 :             QueryBox aQry(getView(), ModuleRes(TABLE_DESIGN_SAVEMODIFIED));
     591         [ #  # ]:          0 :             switch (aQry.Execute())
              [ #  #  # ]
     592                 :            :             {
     593                 :            :                 case RET_YES:
     594 [ #  # ][ #  # ]:          0 :                     Execute(ID_BROWSER_SAVEDOC,Sequence<PropertyValue>());
                 [ #  # ]
     595 [ #  # ][ #  # ]:          0 :                     if ( isModified() )
     596                 :          0 :                         bCheck = sal_False; // when we save the table this must be false else some press cancel
     597                 :          0 :                     break;
     598                 :            :                 case RET_CANCEL:
     599                 :          0 :                     bCheck = sal_False;
     600                 :            :                 default:
     601                 :          0 :                     break;
     602         [ #  # ]:          0 :             }
     603                 :            :         }
     604         [ #  # ]:          0 :         else if ( !m_bNew )
     605                 :            :         {
     606 [ #  # ][ #  # ]:          0 :             QueryBox aQry(getView(), ModuleRes(TABLE_DESIGN_ALL_ROWS_DELETED));
     607         [ #  # ]:          0 :             switch (aQry.Execute())
              [ #  #  # ]
     608                 :            :             {
     609                 :            :                 case RET_YES:
     610                 :            :                     {
     611                 :            :                         try
     612                 :            :                         {
     613 [ #  # ][ #  # ]:          0 :                             Reference<XTablesSupplier> xTablesSup(getConnection(),UNO_QUERY);
     614 [ #  # ][ #  # ]:          0 :                             Reference<XNameAccess> xTables = xTablesSup->getTables();
     615 [ #  # ][ #  # ]:          0 :                             dropTable(xTables,m_sName);
     616                 :            :                         }
     617         [ #  # ]:          0 :                         catch(const Exception&)
     618                 :            :                         {
     619                 :            :                             OSL_FAIL("OTableController::suspend: nothing is expected to happen here!");
     620                 :            :                         }
     621                 :            : 
     622                 :            :                     }
     623                 :          0 :                     break;
     624                 :            :                 case RET_CANCEL:
     625                 :          0 :                     bCheck = sal_False;
     626                 :            :                 default:
     627                 :          0 :                     break;
     628         [ #  # ]:          0 :             }
     629                 :            :         }
     630                 :            :     }
     631                 :            : 
     632 [ #  # ][ #  # ]:          0 :     return bCheck;
     633                 :            : }
     634                 :            : // -----------------------------------------------------------------------------
     635                 :          0 : void OTableController::describeSupportedFeatures()
     636                 :            : {
     637                 :          0 :     OSingleDocumentController::describeSupportedFeatures();
     638                 :            : 
     639                 :          0 :     implDescribeSupportedFeature( ".uno:Redo",          ID_BROWSER_REDO,        CommandGroup::EDIT );
     640                 :          0 :     implDescribeSupportedFeature( ".uno:Save",          ID_BROWSER_SAVEDOC,     CommandGroup::EDIT );
     641                 :          0 :     implDescribeSupportedFeature( ".uno:Undo",          ID_BROWSER_UNDO,        CommandGroup::EDIT );
     642                 :          0 :     implDescribeSupportedFeature( ".uno:HelpMenu",      SID_HELPMENU,           CommandGroup::APPLICATION );
     643                 :          0 :     implDescribeSupportedFeature( ".uno:NewDoc",        SID_NEWDOC,             CommandGroup::DOCUMENT );
     644                 :          0 :     implDescribeSupportedFeature( ".uno:SaveAs",        ID_BROWSER_SAVEASDOC,   CommandGroup::DOCUMENT );
     645                 :          0 :     implDescribeSupportedFeature( ".uno:DBIndexDesign", SID_INDEXDESIGN,        CommandGroup::APPLICATION );
     646                 :          0 :     implDescribeSupportedFeature( ".uno:EditDoc",       ID_BROWSER_EDITDOC,     CommandGroup::EDIT );
     647                 :          0 : }
     648                 :            : // -----------------------------------------------------------------------------
     649                 :          0 : void OTableController::impl_onModifyChanged()
     650                 :            : {
     651                 :          0 :     OSingleDocumentController::impl_onModifyChanged();
     652         [ #  # ]:          0 :     InvalidateFeature( SID_INDEXDESIGN );
     653                 :          0 : }
     654                 :            : // -----------------------------------------------------------------------------
     655                 :          0 : void SAL_CALL OTableController::disposing( const EventObject& _rSource ) throw(RuntimeException)
     656                 :            : {
     657         [ #  # ]:          0 :     if ( _rSource.Source == m_xTable )
     658                 :            :     {   // some deleted our table so we have a new one
     659                 :          0 :         stopTableListening();
     660                 :          0 :         m_xTable    = NULL;
     661                 :          0 :         m_bNew      = sal_True;
     662                 :          0 :         setModified(sal_True);
     663                 :            :     }
     664                 :            :     else
     665                 :          0 :         OTableController_BASE::disposing( _rSource );
     666                 :          0 : }
     667                 :            : // -----------------------------------------------------------------------------
     668                 :          0 : void OTableController::Save(const Reference< XObjectOutputStream>& _rxOut)
     669                 :            : {
     670 [ #  # ][ #  # ]:          0 :     OStreamSection aSection(_rxOut.get());
         [ #  # ][ #  # ]
     671                 :            : 
     672                 :          0 : }
     673                 :            : // -----------------------------------------------------------------------------
     674                 :          0 : void OTableController::Load(const Reference< XObjectInputStream>& _rxIn)
     675                 :            : {
     676 [ #  # ][ #  # ]:          0 :     OStreamSection aSection(_rxIn.get());
         [ #  # ][ #  # ]
     677                 :          0 : }
     678                 :            : 
     679                 :            : // -----------------------------------------------------------------------------
     680                 :          0 : void OTableController::losingConnection( )
     681                 :            : {
     682                 :            :     // let the base class do it's reconnect
     683         [ #  # ]:          0 :     OTableController_BASE::losingConnection( );
     684                 :            : 
     685                 :            :     // remove from the table
     686         [ #  # ]:          0 :     Reference< XComponent >  xComponent(m_xTable, UNO_QUERY);
     687         [ #  # ]:          0 :     if (xComponent.is())
     688                 :            :     {
     689         [ #  # ]:          0 :         Reference<XEventListener> xEvtL( static_cast< ::cppu::OWeakObject*>(this), UNO_QUERY);
     690 [ #  # ][ #  # ]:          0 :         xComponent->removeEventListener(xEvtL);
     691                 :            :     }
     692         [ #  # ]:          0 :     stopTableListening();
     693         [ #  # ]:          0 :     m_xTable    = NULL;
     694         [ #  # ]:          0 :     assignTable();
     695         [ #  # ]:          0 :     if(!m_xTable.is())
     696                 :            :     {
     697                 :          0 :         m_bNew      = sal_True;
     698         [ #  # ]:          0 :         setModified(sal_True);
     699                 :            :     }
     700         [ #  # ]:          0 :     InvalidateAll();
     701                 :          0 : }
     702                 :            : // -----------------------------------------------------------------------------
     703                 :          0 : TOTypeInfoSP OTableController::getTypeInfoByType(sal_Int32 _nDataType) const
     704                 :            : {
     705                 :          0 :     return queryTypeInfoByType(_nDataType,m_aTypeInfo);
     706                 :            : }
     707                 :            : // -----------------------------------------------------------------------------
     708                 :          0 : void OTableController::appendColumns(Reference<XColumnsSupplier>& _rxColSup,sal_Bool _bNew,sal_Bool _bKeyColumns)
     709                 :            : {
     710                 :            :     try
     711                 :            :     {
     712                 :            :         // now append the columns
     713                 :            :         OSL_ENSURE(_rxColSup.is(),"No columns supplier");
     714         [ #  # ]:          0 :         if(!_rxColSup.is())
     715                 :          0 :             return;
     716 [ #  # ][ #  # ]:          0 :         Reference<XNameAccess> xColumns = _rxColSup->getColumns();
     717                 :            :         OSL_ENSURE(xColumns.is(),"No columns");
     718         [ #  # ]:          0 :         Reference<XDataDescriptorFactory> xColumnFactory(xColumns,UNO_QUERY);
     719                 :            : 
     720         [ #  # ]:          0 :         Reference<XAppend> xAppend(xColumns,UNO_QUERY);
     721                 :            :         OSL_ENSURE(xAppend.is(),"No XAppend Interface!");
     722                 :            : 
     723                 :          0 :         ::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aIter = m_vRowList.begin();
     724                 :          0 :         ::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aEnd = m_vRowList.end();
     725 [ #  # ][ #  # ]:          0 :         for(;aIter != aEnd;++aIter)
     726                 :            :         {
     727                 :            :             OSL_ENSURE(*aIter,"OTableRow is null!");
     728                 :          0 :             OFieldDescription* pField = (*aIter)->GetActFieldDescr();
     729 [ #  # ][ #  # ]:          0 :             if ( !pField || (!_bNew && (*aIter)->IsReadOnly() && !_bKeyColumns) )
         [ #  # ][ #  # ]
                 [ #  # ]
     730                 :          0 :                 continue;
     731                 :            : 
     732                 :          0 :             Reference<XPropertySet> xColumn;
     733 [ #  # ][ #  # ]:          0 :             if(pField->IsPrimaryKey() || !_bKeyColumns)
         [ #  # ][ #  # ]
     734 [ #  # ][ #  # ]:          0 :                 xColumn = xColumnFactory->createDataDescriptor();
                 [ #  # ]
     735         [ #  # ]:          0 :             if(xColumn.is())
     736                 :            :             {
     737         [ #  # ]:          0 :                 if(!_bKeyColumns)
     738         [ #  # ]:          0 :                     ::dbaui::setColumnProperties(xColumn,pField);
     739                 :            :                 else
     740 [ #  # ][ #  # ]:          0 :                     xColumn->setPropertyValue(PROPERTY_NAME,makeAny(pField->GetName()));
         [ #  # ][ #  # ]
                 [ #  # ]
     741                 :            : 
     742 [ #  # ][ #  # ]:          0 :                 xAppend->appendByDescriptor(xColumn);
     743         [ #  # ]:          0 :                 xColumn = NULL;
     744                 :            :                 // now only the settings are missing
     745 [ #  # ][ #  # ]:          0 :                 if(xColumns->hasByName(pField->GetName()))
         [ #  # ][ #  # ]
     746                 :            :                 {
     747 [ #  # ][ #  # ]:          0 :                     xColumns->getByName(pField->GetName()) >>= xColumn;
         [ #  # ][ #  # ]
     748         [ #  # ]:          0 :                     if(xColumn.is())
     749         [ #  # ]:          0 :                         pField->copyColumnSettingsTo(xColumn);
     750                 :            :                 }
     751                 :            :                 else
     752                 :            :                 {
     753                 :            :                     OSL_FAIL("OTableController::appendColumns: invalid field name!");
     754                 :            :                 }
     755                 :            : 
     756                 :            :             }
     757                 :          0 :         }
     758                 :            :     }
     759      [ #  #  # ]:          0 :     catch(const SQLException& )
     760                 :            :     {
     761   [ #  #  #  #  :          0 :         showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
             #  #  #  # ]
     762                 :            :     }
     763                 :          0 :     catch( const Exception& )
     764                 :            :     {
     765                 :            :         DBG_UNHANDLED_EXCEPTION();
     766                 :            :     }
     767                 :            : }
     768                 :            : // -----------------------------------------------------------------------------
     769                 :          0 : void OTableController::appendPrimaryKey(Reference<XKeysSupplier>& _rxSup,sal_Bool _bNew)
     770                 :            : {
     771         [ #  # ]:          0 :     if(!_rxSup.is())
     772                 :            :         return; // the database doesn't support keys
     773                 :            : 
     774                 :            :     OSL_ENSURE(_rxSup.is(),"No XKeysSupplier!");
     775 [ #  # ][ #  # ]:          0 :     Reference<XIndexAccess> xKeys(_rxSup->getKeys(),UNO_QUERY);
                 [ #  # ]
     776                 :          0 :     Reference<XPropertySet> xProp;
     777 [ #  # ][ #  # ]:          0 :     const sal_Int32 nCount = xKeys->getCount();
     778         [ #  # ]:          0 :     for(sal_Int32 i=0;i< nCount ;++i)
     779                 :            :     {
     780 [ #  # ][ #  # ]:          0 :         xKeys->getByIndex(i) >>= xProp;
                 [ #  # ]
     781                 :          0 :         sal_Int32 nKeyType = 0;
     782 [ #  # ][ #  # ]:          0 :         xProp->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
                 [ #  # ]
     783         [ #  # ]:          0 :         if(KeyType::PRIMARY == nKeyType)
     784                 :            :         {
     785                 :            :             return; // primary key already exists after appending a column
     786                 :            :         }
     787                 :            :     }
     788         [ #  # ]:          0 :     Reference<XDataDescriptorFactory> xKeyFactory(xKeys,UNO_QUERY);
     789                 :            :     OSL_ENSURE(xKeyFactory.is(),"No XDataDescriptorFactory Interface!");
     790         [ #  # ]:          0 :     if ( !xKeyFactory.is() )
     791                 :            :         return;
     792         [ #  # ]:          0 :     Reference<XAppend> xAppend(xKeyFactory,UNO_QUERY);
     793                 :            :     OSL_ENSURE(xAppend.is(),"No XAppend Interface!");
     794                 :            : 
     795 [ #  # ][ #  # ]:          0 :     Reference<XPropertySet> xKey = xKeyFactory->createDataDescriptor();
     796                 :            :     OSL_ENSURE(xKey.is(),"Key is null!");
     797 [ #  # ][ #  # ]:          0 :     xKey->setPropertyValue(PROPERTY_TYPE,makeAny(KeyType::PRIMARY));
         [ #  # ][ #  # ]
     798                 :            : 
     799         [ #  # ]:          0 :     Reference<XColumnsSupplier> xColSup(xKey,UNO_QUERY);
     800         [ #  # ]:          0 :     if(xColSup.is())
     801                 :            :     {
     802         [ #  # ]:          0 :         appendColumns(xColSup,_bNew,sal_True);
     803 [ #  # ][ #  # ]:          0 :         Reference<XNameAccess> xColumns = xColSup->getColumns();
     804 [ #  # ][ #  # ]:          0 :         if(xColumns->hasElements())
                 [ #  # ]
     805 [ #  # ][ #  # ]:          0 :             xAppend->appendByDescriptor(xKey);
     806 [ #  # ][ #  # ]:          0 :     }
                 [ #  # ]
     807                 :            : }
     808                 :            : // -----------------------------------------------------------------------------
     809                 :          0 : void OTableController::loadData()
     810                 :            : {
     811                 :            :     //////////////////////////////////////////////////////////////////////
     812                 :            :     // Wenn Datenstruktur bereits vorhanden, Struktur leeren
     813                 :          0 :     m_vRowList.clear();
     814                 :            : 
     815         [ #  # ]:          0 :     ::boost::shared_ptr<OTableRow>  pTabEdRow;
     816         [ #  # ]:          0 :     Reference< XDatabaseMetaData> xMetaData = getMetaData( );
     817                 :            :     //////////////////////////////////////////////////////////////////////
     818                 :            :     // Datenstruktur mit Daten aus DatenDefinitionsObjekt fuellen
     819 [ #  # ][ #  # ]:          0 :     if(m_xTable.is() && xMetaData.is())
                 [ #  # ]
     820                 :            :     {
     821         [ #  # ]:          0 :         Reference<XColumnsSupplier> xColSup(m_xTable,UNO_QUERY);
     822                 :            :         OSL_ENSURE(xColSup.is(),"No XColumnsSupplier!");
     823 [ #  # ][ #  # ]:          0 :         Reference<XNameAccess> xColumns = xColSup->getColumns();
     824                 :          0 :         OFieldDescription* pActFieldDescr = NULL;
     825         [ #  # ]:          0 :         String aType;
     826                 :            :         //////////////////////////////////////////////////////////////////////
     827                 :            :         // ReadOnly-Flag
     828                 :            :         // Bei Drop darf keine Zeile editierbar sein.
     829                 :            :         // Bei Add duerfen nur die leeren Zeilen editierbar sein.
     830                 :            :         // Bei Add und Drop koennen alle Zeilen editiert werden.
     831                 :            :         //  sal_Bool bReadOldRow = xMetaData->supportsAlterTableWithAddColumn() && xMetaData->supportsAlterTableWithDropColumn();
     832         [ #  # ]:          0 :         sal_Bool bIsAlterAllowed = isAlterAllowed();
     833 [ #  # ][ #  # ]:          0 :         Sequence< ::rtl::OUString> aColumns = xColumns->getElementNames();
     834                 :          0 :         const ::rtl::OUString* pIter    = aColumns.getConstArray();
     835                 :          0 :         const ::rtl::OUString* pEnd     = pIter + aColumns.getLength();
     836                 :            : 
     837         [ #  # ]:          0 :         for(;pIter != pEnd;++pIter)
     838                 :            :         {
     839                 :          0 :             Reference<XPropertySet> xColumn;
     840 [ #  # ][ #  # ]:          0 :             xColumns->getByName(*pIter) >>= xColumn;
                 [ #  # ]
     841                 :          0 :             sal_Int32 nType         = 0;
     842                 :          0 :             sal_Int32 nScale        = 0;
     843                 :          0 :             sal_Int32 nPrecision    = 0;
     844                 :          0 :             sal_Int32 nNullable     = 0;
     845                 :          0 :             sal_Int32 nFormatKey    = 0;
     846                 :          0 :             sal_Int32 nAlign        = 0;
     847                 :            : 
     848                 :          0 :             sal_Bool bIsAutoIncrement = false, bIsCurrency = false;
     849                 :          0 :             ::rtl::OUString sName,sDescription,sTypeName,sHelpText;
     850                 :          0 :             Any aControlDefault;
     851                 :            : 
     852                 :            :             // get the properties from the column
     853 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue(PROPERTY_NAME)            >>= sName;
                 [ #  # ]
     854 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue(PROPERTY_TYPENAME)        >>= sTypeName;
                 [ #  # ]
     855 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue(PROPERTY_ISNULLABLE)      >>= nNullable;
                 [ #  # ]
     856 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue(PROPERTY_ISAUTOINCREMENT) >>= bIsAutoIncrement;
                 [ #  # ]
     857 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue(PROPERTY_ISCURRENCY)      >>= bIsCurrency;
                 [ #  # ]
     858 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue(PROPERTY_TYPE)            >>= nType;
                 [ #  # ]
     859 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue(PROPERTY_SCALE)           >>= nScale;
                 [ #  # ]
     860 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue(PROPERTY_PRECISION)       >>= nPrecision;
                 [ #  # ]
     861 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue(PROPERTY_DESCRIPTION)     >>= sDescription;
                 [ #  # ]
     862                 :            : 
     863 [ #  # ][ #  # ]:          0 :             if(xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_HELPTEXT))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     864 [ #  # ][ #  # ]:          0 :                 xColumn->getPropertyValue(PROPERTY_HELPTEXT)    >>= sHelpText;
                 [ #  # ]
     865                 :            : 
     866 [ #  # ][ #  # ]:          0 :             if(xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_CONTROLDEFAULT))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     867 [ #  # ][ #  # ]:          0 :                 aControlDefault = xColumn->getPropertyValue(PROPERTY_CONTROLDEFAULT);
                 [ #  # ]
     868 [ #  # ][ #  # ]:          0 :             if(xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_FORMATKEY))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     869 [ #  # ][ #  # ]:          0 :                 xColumn->getPropertyValue(PROPERTY_FORMATKEY)   >>= nFormatKey;
                 [ #  # ]
     870 [ #  # ][ #  # ]:          0 :             if(xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_ALIGN))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     871 [ #  # ][ #  # ]:          0 :                 xColumn->getPropertyValue(PROPERTY_ALIGN)       >>= nAlign;
                 [ #  # ]
     872                 :            : 
     873 [ #  # ][ #  # ]:          0 :             pTabEdRow.reset(new OTableRow());
                 [ #  # ]
     874                 :          0 :             pTabEdRow->SetReadOnly(!bIsAlterAllowed);
     875                 :            :             // search for type
     876                 :            :             sal_Bool bForce;
     877         [ #  # ]:          0 :             ::rtl::OUString sCreate(RTL_CONSTASCII_USTRINGPARAM("x"));
     878         [ #  # ]:          0 :             TOTypeInfoSP pTypeInfo = ::dbaui::getTypeInfoFromType(m_aTypeInfo,nType,sTypeName,sCreate,nPrecision,nScale,bIsAutoIncrement,bForce);
     879         [ #  # ]:          0 :             if ( !pTypeInfo.get() )
     880         [ #  # ]:          0 :                 pTypeInfo = m_pTypeInfo;
     881         [ #  # ]:          0 :             pTabEdRow->SetFieldType( pTypeInfo, bForce );
     882                 :            : 
     883                 :          0 :             pActFieldDescr = pTabEdRow->GetActFieldDescr();
     884                 :            :             OSL_ENSURE(pActFieldDescr, "OTableController::loadData: invalid field description generated by the table row!");
     885         [ #  # ]:          0 :             if ( pActFieldDescr )
     886                 :            :             {
     887         [ #  # ]:          0 :                 pActFieldDescr->SetName(sName);
     888         [ #  # ]:          0 :                 pActFieldDescr->SetFormatKey(nFormatKey);
     889         [ #  # ]:          0 :                 pActFieldDescr->SetDescription(sDescription);
     890         [ #  # ]:          0 :                 pActFieldDescr->SetHelpText(sHelpText);
     891         [ #  # ]:          0 :                 pActFieldDescr->SetAutoIncrement(bIsAutoIncrement);
     892 [ #  # ][ #  # ]:          0 :                 pActFieldDescr->SetHorJustify(dbaui::mapTextJustify(nAlign));
     893         [ #  # ]:          0 :                 pActFieldDescr->SetCurrency(bIsCurrency);
     894                 :            : 
     895                 :            :                 //////////////////////////////////////////////////////////////////////
     896                 :            :                 // Spezielle Daten
     897         [ #  # ]:          0 :                 pActFieldDescr->SetIsNullable(nNullable);
     898         [ #  # ]:          0 :                 pActFieldDescr->SetControlDefault(aControlDefault);
     899         [ #  # ]:          0 :                 pActFieldDescr->SetPrecision(nPrecision);
     900         [ #  # ]:          0 :                 pActFieldDescr->SetScale(nScale);
     901                 :            :             }
     902         [ #  # ]:          0 :             m_vRowList.push_back( pTabEdRow);
     903         [ #  # ]:          0 :         }
     904                 :            :         // fill the primary  key information
     905         [ #  # ]:          0 :         Reference<XNameAccess> xKeyColumns  = getKeyColumns();
     906         [ #  # ]:          0 :         if(xKeyColumns.is())
     907                 :            :         {
     908 [ #  # ][ #  # ]:          0 :             Sequence< ::rtl::OUString> aKeyColumns = xKeyColumns->getElementNames();
     909                 :          0 :             const ::rtl::OUString* pKeyBegin    = aKeyColumns.getConstArray();
     910                 :          0 :             const ::rtl::OUString* pKeyEnd      = pKeyBegin + aKeyColumns.getLength();
     911                 :            : 
     912         [ #  # ]:          0 :             for(;pKeyBegin != pKeyEnd;++pKeyBegin)
     913                 :            :             {
     914                 :          0 :                 ::std::vector< ::boost::shared_ptr<OTableRow> >::iterator rowIter = m_vRowList.begin();
     915                 :          0 :                 ::std::vector< ::boost::shared_ptr<OTableRow> >::iterator rowEnd = m_vRowList.end();
     916 [ #  # ][ #  # ]:          0 :                 for(;rowIter != rowEnd;++rowIter)
     917                 :            :                 {
     918 [ #  # ][ #  # ]:          0 :                     if((*rowIter)->GetActFieldDescr()->GetName() == *pKeyBegin)
     919                 :            :                     {
     920         [ #  # ]:          0 :                         (*rowIter)->SetPrimaryKey(sal_True);
     921                 :          0 :                         break;
     922                 :            :                     }
     923                 :            :                 }
     924         [ #  # ]:          0 :             }
     925 [ #  # ][ #  # ]:          0 :         }
     926                 :            :     }
     927                 :            : 
     928                 :            :     //////////////////////////////////////////////////////////////////////
     929                 :            :     // Leere Zeilen fuellen
     930                 :            : 
     931         [ #  # ]:          0 :     OTypeInfoMap::iterator aTypeIter = m_aTypeInfo.find(DataType::VARCHAR);
     932         [ #  # ]:          0 :     if(aTypeIter == m_aTypeInfo.end())
     933                 :          0 :         aTypeIter = m_aTypeInfo.begin();
     934                 :            : 
     935                 :            :     OSL_ENSURE(aTypeIter != m_aTypeInfo.end(),"We have no type information!");
     936                 :            : 
     937         [ #  # ]:          0 :     bool bReadRow = !isAddAllowed();
     938         [ #  # ]:          0 :     for(sal_Int32 i=m_vRowList.size(); i < NEWCOLS; i++ )
     939                 :            :     {
     940 [ #  # ][ #  # ]:          0 :         pTabEdRow.reset(new OTableRow());
                 [ #  # ]
     941                 :          0 :         pTabEdRow->SetReadOnly(bReadRow);
     942         [ #  # ]:          0 :         m_vRowList.push_back( pTabEdRow);
     943         [ #  # ]:          0 :     }
     944                 :          0 : }
     945                 :            : // -----------------------------------------------------------------------------
     946                 :          0 : Reference<XNameAccess> OTableController::getKeyColumns() const
     947                 :            : {
     948                 :          0 :     return getPrimaryKeyColumns_throw(m_xTable);
     949                 :            : }
     950                 :            : // -----------------------------------------------------------------------------
     951                 :          0 : sal_Bool OTableController::checkColumns(sal_Bool _bNew) throw(::com::sun::star::sdbc::SQLException)
     952                 :            : {
     953                 :          0 :     sal_Bool bOk = sal_True;
     954                 :          0 :     sal_Bool bFoundPKey = sal_False;
     955         [ #  # ]:          0 :     Reference< XDatabaseMetaData > xMetaData = getMetaData( );
     956 [ #  # ][ #  # ]:          0 :     DatabaseMetaData aMetaData( getConnection() );
     957                 :            : 
     958 [ #  # ][ #  # ]:          0 :     ::comphelper::UStringMixEqual bCase(xMetaData.is() ? xMetaData->supportsMixedCaseQuotedIdentifiers() : sal_True);
                 [ #  # ]
     959         [ #  # ]:          0 :     ::std::vector< ::boost::shared_ptr<OTableRow> >::const_iterator aIter = m_vRowList.begin();
     960         [ #  # ]:          0 :     ::std::vector< ::boost::shared_ptr<OTableRow> >::const_iterator aEnd = m_vRowList.end();
     961 [ #  # ][ #  # ]:          0 :     for(;aIter != aEnd;++aIter)
     962                 :            :     {
     963                 :          0 :         OFieldDescription* pFieldDesc = (*aIter)->GetActFieldDescr();
     964 [ #  # ][ #  # ]:          0 :         if (pFieldDesc && !pFieldDesc->GetName().isEmpty())
                 [ #  # ]
           [ #  #  #  # ]
                 [ #  # ]
     965                 :            :         {
     966         [ #  # ]:          0 :             bFoundPKey |=  (*aIter)->IsPrimaryKey();
     967                 :            :             // first check for duplicate names
     968         [ #  # ]:          0 :             ::std::vector< ::boost::shared_ptr<OTableRow> >::const_iterator aIter2 = aIter+1;
     969 [ #  # ][ #  # ]:          0 :             for(;aIter2 != aEnd;++aIter2)
     970                 :            :             {
     971                 :          0 :                 OFieldDescription* pCompareDesc = (*aIter2)->GetActFieldDescr();
     972 [ #  # ][ #  # ]:          0 :                 if (pCompareDesc && bCase(pCompareDesc->GetName(),pFieldDesc->GetName()))
         [ #  # ][ #  # ]
         [ #  # ][ #  #  
             #  #  #  # ]
                 [ #  # ]
     973                 :            :                 {
     974 [ #  # ][ #  # ]:          0 :                     String strMessage = String(ModuleRes(STR_TABLEDESIGN_DUPLICATE_NAME));
     975 [ #  # ][ #  # ]:          0 :                     strMessage.SearchAndReplaceAscii("$column$", pFieldDesc->GetName());
         [ #  # ][ #  # ]
     976 [ #  # ][ #  # ]:          0 :                     OSQLWarningBox( getView(), strMessage ).Execute();
                 [ #  # ]
     977         [ #  # ]:          0 :                     return sal_False;
     978                 :            :                 }
     979                 :            :             }
     980                 :            :         }
     981                 :            :     }
     982 [ #  # ][ #  # ]:          0 :     if ( _bNew && !bFoundPKey && aMetaData.supportsPrimaryKeys() )
         [ #  # ][ #  # ]
                 [ #  # ]
     983                 :            :     {
     984 [ #  # ][ #  # ]:          0 :         String sTitle(ModuleRes(STR_TABLEDESIGN_NO_PRIM_KEY_HEAD));
     985 [ #  # ][ #  # ]:          0 :         String sMsg(ModuleRes(STR_TABLEDESIGN_NO_PRIM_KEY));
     986         [ #  # ]:          0 :         OSQLMessageBox aBox(getView(), sTitle,sMsg, WB_YES_NO_CANCEL | WB_DEF_YES);
     987                 :            : 
     988         [ #  # ]:          0 :         switch ( aBox.Execute() )
              [ #  #  # ]
     989                 :            :         {
     990                 :            :         case RET_YES:
     991                 :            :         {
     992 [ #  # ][ #  # ]:          0 :             ::boost::shared_ptr<OTableRow>  pNewRow(new OTableRow());
                 [ #  # ]
     993         [ #  # ]:          0 :             TOTypeInfoSP pTypeInfo = ::dbaui::queryPrimaryKeyType(m_aTypeInfo);
     994         [ #  # ]:          0 :             if ( !pTypeInfo.get() )
     995                 :            :                 break;
     996                 :            : 
     997         [ #  # ]:          0 :             pNewRow->SetFieldType( pTypeInfo );
     998                 :          0 :             OFieldDescription* pActFieldDescr = pNewRow->GetActFieldDescr();
     999                 :            : 
    1000         [ #  # ]:          0 :             pActFieldDescr->SetAutoIncrement(sal_False);
    1001         [ #  # ]:          0 :             pActFieldDescr->SetIsNullable(ColumnValue::NO_NULLS);
    1002                 :            : 
    1003 [ #  # ][ #  # ]:          0 :             pActFieldDescr->SetName( createUniqueName(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ID")) ));
                 [ #  # ]
    1004         [ #  # ]:          0 :             pActFieldDescr->SetPrimaryKey( sal_True );
    1005         [ #  # ]:          0 :             m_vRowList.insert(m_vRowList.begin(),pNewRow);
    1006                 :            : 
    1007         [ #  # ]:          0 :             static_cast<OTableDesignView*>(getView())->GetEditorCtrl()->Invalidate();
    1008 [ #  # ][ #  # ]:          0 :             static_cast<OTableDesignView*>(getView())->GetEditorCtrl()->RowInserted(0);
         [ #  # ][ #  # ]
                 [ #  # ]
    1009                 :            :         }
    1010                 :          0 :         break;
    1011                 :            :         case RET_CANCEL:
    1012                 :          0 :             bOk = sal_False;
    1013                 :          0 :             break;
    1014 [ #  # ][ #  # ]:          0 :         }
                 [ #  # ]
    1015                 :            :     }
    1016         [ #  # ]:          0 :     return bOk;
    1017                 :            : }
    1018                 :            : // -----------------------------------------------------------------------------
    1019                 :          0 : void OTableController::alterColumns()
    1020                 :            : {
    1021         [ #  # ]:          0 :     Reference<XColumnsSupplier> xColSup(m_xTable,UNO_QUERY_THROW);
    1022                 :            :     OSL_ENSURE(xColSup.is(),"What happen here?!");
    1023                 :            : 
    1024 [ #  # ][ #  # ]:          0 :     Reference<XNameAccess> xColumns = xColSup->getColumns();
    1025         [ #  # ]:          0 :     Reference<XIndexAccess> xIdxColumns(xColumns,UNO_QUERY_THROW);
    1026                 :            :     OSL_ENSURE(xColumns.is(),"No columns");
    1027         [ #  # ]:          0 :     if ( !xColumns.is() )
    1028                 :          0 :         return;
    1029         [ #  # ]:          0 :     Reference<XAlterTable> xAlter(m_xTable,UNO_QUERY);  // can be null
    1030                 :            : 
    1031 [ #  # ][ #  # ]:          0 :     sal_Int32 nColumnCount = xIdxColumns->getCount();
    1032         [ #  # ]:          0 :     Reference<XDrop> xDrop(xColumns,UNO_QUERY);         // can be null
    1033         [ #  # ]:          0 :     Reference<XAppend> xAppend(xColumns,UNO_QUERY);     // can be null
    1034         [ #  # ]:          0 :     Reference<XDataDescriptorFactory> xColumnFactory(xColumns,UNO_QUERY); // can be null
    1035                 :            : 
    1036                 :          0 :     sal_Bool bReload = sal_False; // refresh the data
    1037                 :            : 
    1038                 :            :     // contains all columns names which are already handled those which are not in the list will be deleted
    1039         [ #  # ]:          0 :     Reference< XDatabaseMetaData> xMetaData = getMetaData( );
    1040                 :            : 
    1041 [ #  # ][ #  # ]:          0 :     ::std::map< ::rtl::OUString,sal_Bool,::comphelper::UStringMixLess> aColumns(xMetaData.is() ? (xMetaData->supportsMixedCaseQuotedIdentifiers() ? true : false): sal_True);
         [ #  # ][ #  # ]
                 [ #  # ]
    1042                 :          0 :     ::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aIter = m_vRowList.begin();
    1043                 :          0 :     ::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aEnd = m_vRowList.end();
    1044                 :            :     // first look for columns where something other than the name changed
    1045                 :          0 :     sal_Int32 nPos = 0;
    1046 [ #  # ][ #  # ]:          0 :     for(;aIter != aEnd;++aIter,++nPos)
    1047                 :            :     {
    1048                 :            :         OSL_ENSURE(*aIter,"OTableRow is null!");
    1049                 :          0 :         OFieldDescription* pField = (*aIter)->GetActFieldDescr();
    1050         [ #  # ]:          0 :         if ( !pField )
    1051                 :          0 :             continue;
    1052         [ #  # ]:          0 :         if ( (*aIter)->IsReadOnly() )
    1053                 :            :         {
    1054 [ #  # ][ #  # ]:          0 :             aColumns[pField->GetName()] = sal_True;
    1055                 :          0 :             continue;
    1056                 :            :         }
    1057                 :            : 
    1058                 :          0 :         Reference<XPropertySet> xColumn;
    1059 [ #  # ][ #  # ]:          0 :         if ( xColumns->hasByName(pField->GetName()) )
         [ #  # ][ #  # ]
    1060                 :            :         {
    1061 [ #  # ][ #  # ]:          0 :             aColumns[pField->GetName()] = sal_True;
    1062 [ #  # ][ #  # ]:          0 :             xColumns->getByName(pField->GetName()) >>= xColumn;
         [ #  # ][ #  # ]
    1063                 :            :             OSL_ENSURE(xColumn.is(),"Column is null!");
    1064                 :            : 
    1065                 :          0 :             sal_Int32 nType=0,nPrecision=0,nScale=0,nNullable=0;
    1066                 :          0 :             sal_Bool bAutoIncrement = false;
    1067                 :          0 :             ::rtl::OUString sTypeName,sDescription;
    1068                 :            : 
    1069 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue(PROPERTY_TYPE)            >>= nType;
                 [ #  # ]
    1070 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue(PROPERTY_PRECISION)       >>= nPrecision;
                 [ #  # ]
    1071 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue(PROPERTY_SCALE)           >>= nScale;
                 [ #  # ]
    1072 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue(PROPERTY_ISNULLABLE)      >>= nNullable;
                 [ #  # ]
    1073 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue(PROPERTY_ISAUTOINCREMENT) >>= bAutoIncrement;
                 [ #  # ]
    1074 [ #  # ][ #  # ]:          0 :             xColumn->getPropertyValue(PROPERTY_DESCRIPTION)     >>= sDescription;
                 [ #  # ]
    1075                 :            : 
    1076 [ #  # ][ #  # ]:          0 :             try { xColumn->getPropertyValue(PROPERTY_TYPENAME) >>= sTypeName; }
         [ #  # ][ #  # ]
    1077         [ #  # ]:          0 :             catch( const Exception& )
    1078                 :            :             {
    1079                 :            :                 OSL_FAIL( "no TypeName property?!" );
    1080                 :            :                 // since this is a last minute fix for #i41785#, I want to be on the safe side,
    1081                 :            :                 // and catch errors here as early as possible (instead of the whole process of altering
    1082                 :            :                 // the columns failing)
    1083                 :            :                 // Normally, sdbcx::Column objects are expected to have a TypeName property
    1084                 :            :             }
    1085                 :            : 
    1086                 :            :             // check if something changed
    1087         [ #  # ]:          0 :             if((nType != pField->GetType()                  ||
           [ #  #  #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
           [ #  #  #  # ]
                 [ #  # ]
    1088 [ #  # ][ #  # ]:          0 :                 sTypeName != pField->GetTypeName()         ||
                 [ #  # ]
    1089         [ #  # ]:          0 :                 (nPrecision != pField->GetPrecision() && nPrecision )       ||
    1090         [ #  # ]:          0 :                 nScale != pField->GetScale()                ||
    1091         [ #  # ]:          0 :                 nNullable != pField->GetIsNullable()        ||
    1092 [ #  # ][ #  # ]:          0 :                 sDescription != pField->GetDescription()        ||
                 [ #  # ]
    1093         [ #  # ]:          0 :                 bAutoIncrement != pField->IsAutoIncrement())&&
    1094                 :          0 :                 xColumnFactory.is())
    1095                 :            :             {
    1096                 :          0 :                 Reference<XPropertySet> xNewColumn;
    1097 [ #  # ][ #  # ]:          0 :                 xNewColumn = xColumnFactory->createDataDescriptor();
                 [ #  # ]
    1098         [ #  # ]:          0 :                 ::dbaui::setColumnProperties(xNewColumn,pField);
    1099                 :            :                 // first try to alter the column
    1100                 :          0 :                 sal_Bool bNotOk = sal_False;
    1101                 :            :                 try
    1102                 :            :                 {
    1103                 :            :                     // first try if we can alter the column
    1104         [ #  # ]:          0 :                     if(xAlter.is())
    1105 [ #  # ][ #  # ]:          0 :                         xAlter->alterColumnByName(pField->GetName(),xNewColumn);
                 [ #  # ]
    1106                 :            :                 }
    1107   [ #  #  #  # ]:          0 :                 catch(const SQLException&)
    1108                 :            :                 {
    1109   [ #  #  #  #  :          0 :                     if(xDrop.is() && xAppend.is())
                   #  # ]
    1110                 :            :                     {
    1111   [ #  #  #  # ]:          0 :                         String aMessage( ModuleRes( STR_TABLEDESIGN_ALTER_ERROR ) );
    1112   [ #  #  #  #  :          0 :                         aMessage.SearchAndReplaceAscii( "$column$", pField->GetName() );
             #  #  #  # ]
    1113                 :            : 
    1114   [ #  #  #  # ]:          0 :                         SQLExceptionInfo aError( ::cppu::getCaughtException() );
    1115         [ #  # ]:          0 :                         OSQLWarningBox aMsg( getView(), aMessage, WB_YES_NO | WB_DEF_YES , &aError );
    1116   [ #  #  #  #  :          0 :                         bNotOk = aMsg.Execute() == RET_YES;
             #  #  #  # ]
    1117                 :            :                     }
    1118                 :            :                     else
    1119                 :          0 :                         throw;
    1120                 :            :                 }
    1121                 :            :                 // if something went wrong or we can't alter columns
    1122                 :            :                 // drop and append a new one
    1123 [ #  # ][ #  # ]:          0 :                 if((!xAlter.is() || bNotOk) && xDrop.is() && xAppend.is())
         [ #  # ][ #  # ]
                 [ #  # ]
    1124                 :            :                 {
    1125 [ #  # ][ #  # ]:          0 :                     xDrop->dropByName(pField->GetName());
                 [ #  # ]
    1126                 :            :                     try
    1127                 :            :                     {
    1128 [ #  # ][ #  # ]:          0 :                         xAppend->appendByDescriptor(xNewColumn);
    1129                 :            :                     }
    1130         [ #  # ]:          0 :                     catch(const SQLException&)
    1131                 :            :                     { // an error occurred so we try to reactivate the old one
    1132   [ #  #  #  # ]:          0 :                         xAppend->appendByDescriptor(xColumn);
    1133                 :          0 :                         throw;
    1134                 :            :                     }
    1135                 :            :                 }
    1136                 :            :                 // exceptions are caught outside
    1137         [ #  # ]:          0 :                 xNewColumn = NULL;
    1138 [ #  # ][ #  # ]:          0 :                 if(xColumns->hasByName(pField->GetName()))
         [ #  # ][ #  # ]
    1139 [ #  # ][ #  # ]:          0 :                     xColumns->getByName(pField->GetName()) >>= xColumn;
         [ #  # ][ #  # ]
    1140                 :          0 :                 bReload = sal_True;
    1141                 :          0 :             }
    1142                 :            : 
    1143                 :            : 
    1144                 :            :         }
    1145 [ #  # ][ #  # ]:          0 :         else if(xColumnFactory.is() && xAlter.is() && nPos < nColumnCount)
         [ #  # ][ #  # ]
    1146                 :            :         { // we can't find the column so we could try it with the index before we drop and append a new column
    1147                 :            :             try
    1148                 :            :             {
    1149                 :          0 :                 Reference<XPropertySet> xNewColumn;
    1150 [ #  # ][ #  # ]:          0 :                 xNewColumn = xColumnFactory->createDataDescriptor();
                 [ #  # ]
    1151         [ #  # ]:          0 :                 ::dbaui::setColumnProperties(xNewColumn,pField);
    1152 [ #  # ][ #  # ]:          0 :                 xAlter->alterColumnByIndex(nPos,xNewColumn);
    1153 [ #  # ][ #  # ]:          0 :                 if(xColumns->hasByName(pField->GetName()))
         [ #  # ][ #  # ]
    1154                 :            :                 {   // ask for the append by name
    1155 [ #  # ][ #  # ]:          0 :                     aColumns[pField->GetName()] = sal_True;
    1156 [ #  # ][ #  # ]:          0 :                     xColumns->getByName(pField->GetName()) >>= xColumn;
         [ #  # ][ #  # ]
    1157         [ #  # ]:          0 :                     if(xColumn.is())
    1158         [ #  # ]:          0 :                         pField->copyColumnSettingsTo(xColumn);
    1159                 :            :                 }
    1160                 :            :                 else
    1161                 :            :                 {
    1162                 :            :                     OSL_FAIL("OTableController::alterColumns: invalid column (2)!");
    1163                 :          0 :                 }
    1164                 :            :             }
    1165   [ #  #  #  #  :          0 :             catch(const SQLException&)
                   #  # ]
    1166                 :            :             { // we couldn't alter the column so we have to add new columns
    1167                 :          0 :                 bReload = sal_True;
    1168   [ #  #  #  #  :          0 :                 if(xDrop.is() && xAppend.is())
                   #  # ]
    1169                 :            :                 {
    1170   [ #  #  #  # ]:          0 :                     String aMessage(ModuleRes(STR_TABLEDESIGN_ALTER_ERROR));
    1171   [ #  #  #  #  :          0 :                     aMessage.SearchAndReplaceAscii("$column$",pField->GetName());
             #  #  #  # ]
    1172         [ #  # ]:          0 :                     OSQLWarningBox aMsg( getView(), aMessage, WB_YES_NO | WB_DEF_YES );
    1173   [ #  #  #  # ]:          0 :                     if ( aMsg.Execute() != RET_YES )
    1174                 :            :                     {
    1175   [ #  #  #  #  :          0 :                         Reference<XPropertySet> xNewColumn(xIdxColumns->getByIndex(nPos),UNO_QUERY_THROW);
                   #  # ]
    1176                 :          0 :                         ::rtl::OUString sName;
    1177   [ #  #  #  #  :          0 :                         xNewColumn->getPropertyValue(PROPERTY_NAME) >>= sName;
                   #  # ]
    1178         [ #  # ]:          0 :                         aColumns[sName] = sal_True;
    1179   [ #  #  #  # ]:          0 :                         aColumns[pField->GetName()] = sal_True;
    1180                 :          0 :                         continue;
    1181   [ #  #  #  #  :          0 :                     }
             #  #  #  # ]
    1182                 :            :                 }
    1183                 :            :                 else
    1184                 :          0 :                     throw;
    1185                 :            :             }
    1186                 :            :         }
    1187                 :            :         else
    1188                 :          0 :             bReload = sal_True;
    1189         [ #  # ]:          0 :     }
    1190                 :            :     // alter column settings
    1191                 :          0 :     aIter = m_vRowList.begin();
    1192                 :            : 
    1193                 :            :     // first look for columns where something other than the name changed
    1194 [ #  # ][ #  # ]:          0 :     for(nPos = 0;aIter != aEnd;++aIter,++nPos)
    1195                 :            :     {
    1196                 :            :         OSL_ENSURE(*aIter,"OTableRow is null!");
    1197                 :          0 :         OFieldDescription* pField = (*aIter)->GetActFieldDescr();
    1198         [ #  # ]:          0 :         if ( !pField )
    1199                 :          0 :             continue;
    1200         [ #  # ]:          0 :         if ( (*aIter)->IsReadOnly() )
    1201                 :            :         {
    1202 [ #  # ][ #  # ]:          0 :             aColumns[pField->GetName()] = sal_True;
    1203                 :          0 :             continue;
    1204                 :            :         }
    1205                 :            : 
    1206                 :          0 :         Reference<XPropertySet> xColumn;
    1207 [ #  # ][ #  # ]:          0 :         if ( xColumns->hasByName(pField->GetName()) )
         [ #  # ][ #  # ]
    1208                 :            :         {
    1209 [ #  # ][ #  # ]:          0 :             xColumns->getByName(pField->GetName()) >>= xColumn;
         [ #  # ][ #  # ]
    1210 [ #  # ][ #  # ]:          0 :             Reference<XPropertySetInfo> xInfo = xColumn->getPropertySetInfo();
    1211 [ #  # ][ #  # ]:          0 :             if ( xInfo->hasPropertyByName(PROPERTY_HELPTEXT) )
         [ #  # ][ #  # ]
    1212 [ #  # ][ #  # ]:          0 :                 xColumn->setPropertyValue(PROPERTY_HELPTEXT,makeAny(pField->GetHelpText()));
         [ #  # ][ #  # ]
                 [ #  # ]
    1213                 :            : 
    1214 [ #  # ][ #  # ]:          0 :             if(xInfo->hasPropertyByName(PROPERTY_CONTROLDEFAULT))
         [ #  # ][ #  # ]
    1215 [ #  # ][ #  # ]:          0 :                 xColumn->setPropertyValue(PROPERTY_CONTROLDEFAULT,pField->GetControlDefault());
         [ #  # ][ #  # ]
    1216 [ #  # ][ #  # ]:          0 :             if(xInfo->hasPropertyByName(PROPERTY_FORMATKEY))
         [ #  # ][ #  # ]
    1217 [ #  # ][ #  # ]:          0 :                 xColumn->setPropertyValue(PROPERTY_FORMATKEY,makeAny(pField->GetFormatKey()));
         [ #  # ][ #  # ]
                 [ #  # ]
    1218 [ #  # ][ #  # ]:          0 :             if(xInfo->hasPropertyByName(PROPERTY_ALIGN))
         [ #  # ][ #  # ]
    1219 [ #  # ][ #  # ]:          0 :                 xColumn->setPropertyValue(PROPERTY_ALIGN,makeAny(dbaui::mapTextAllign(pField->GetHorJustify())));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1220                 :            :         }
    1221                 :          0 :     }
    1222                 :            :     // second drop all columns which could be found by name
    1223         [ #  # ]:          0 :     Reference<XNameAccess> xKeyColumns  = getKeyColumns();
    1224                 :            :     // now we have to look for the columns who could be deleted
    1225         [ #  # ]:          0 :     if ( xDrop.is() )
    1226                 :            :     {
    1227 [ #  # ][ #  # ]:          0 :         Sequence< ::rtl::OUString> aColumnNames = xColumns->getElementNames();
    1228                 :          0 :         const ::rtl::OUString* pIter = aColumnNames.getConstArray();
    1229                 :          0 :         const ::rtl::OUString* pEnd = pIter + aColumnNames.getLength();
    1230         [ #  # ]:          0 :         for(;pIter != pEnd;++pIter)
    1231                 :            :         {
    1232 [ #  # ][ #  # ]:          0 :             if(aColumns.find(*pIter) == aColumns.end()) // found a column to delete
    1233                 :            :             {
    1234 [ #  # ][ #  # ]:          0 :                 if(xKeyColumns.is() && xKeyColumns->hasByName(*pIter)) // check if this column is a member of the primary key
         [ #  # ][ #  # ]
                 [ #  # ]
    1235                 :            :                 {
    1236 [ #  # ][ #  # ]:          0 :                     String aMsgT(ModuleRes(STR_TBL_COLUMN_IS_KEYCOLUMN));
    1237 [ #  # ][ #  # ]:          0 :                     aMsgT.SearchAndReplaceAscii("$column$",*pIter);
                 [ #  # ]
    1238 [ #  # ][ #  # ]:          0 :                     String aTitle(ModuleRes(STR_TBL_COLUMN_IS_KEYCOLUMN_TITLE));
    1239         [ #  # ]:          0 :                     OSQLMessageBox aMsg(getView(),aTitle,aMsgT,WB_YES_NO| WB_DEF_YES);
    1240 [ #  # ][ #  # ]:          0 :                     if(aMsg.Execute() == RET_YES)
    1241                 :            :                     {
    1242         [ #  # ]:          0 :                         xKeyColumns = NULL;
    1243         [ #  # ]:          0 :                         dropPrimaryKey();
    1244                 :            :                     }
    1245                 :            :                     else
    1246                 :            :                     {
    1247                 :          0 :                         bReload = sal_True;
    1248                 :          0 :                         continue;
    1249 [ #  # ][ #  # ]:          0 :                     }
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1250                 :            :                 }
    1251                 :            :                 try
    1252                 :            :                 {
    1253 [ #  # ][ #  # ]:          0 :                     xDrop->dropByName(*pIter);
    1254                 :            :                 }
    1255         [ #  # ]:          0 :                 catch (const SQLException&)
    1256                 :            :                 {
    1257   [ #  #  #  # ]:          0 :                     String sError( ModuleRes( STR_TABLEDESIGN_COULD_NOT_DROP_COL ) );
    1258   [ #  #  #  #  :          0 :                     sError.SearchAndReplaceAscii( "$column$", *pIter );
                   #  # ]
    1259                 :            : 
    1260         [ #  # ]:          0 :                     SQLException aNewException;
    1261         [ #  # ]:          0 :                     aNewException.Message = sError;
    1262         [ #  # ]:          0 :                     aNewException.SQLState = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000"));
    1263         [ #  # ]:          0 :                     aNewException.NextException = ::cppu::getCaughtException();
    1264                 :            : 
    1265         [ #  # ]:          0 :                     throw aNewException;
    1266                 :            :                 }
    1267                 :            :             }
    1268         [ #  # ]:          0 :         }
    1269                 :            :     }
    1270                 :            : 
    1271                 :            :     // third append the new columns
    1272                 :          0 :     aIter = m_vRowList.begin();
    1273 [ #  # ][ #  # ]:          0 :     for(;aIter != aEnd;++aIter)
    1274                 :            :     {
    1275                 :            :         OSL_ENSURE(*aIter,"OTableRow is null!");
    1276                 :          0 :         OFieldDescription* pField = (*aIter)->GetActFieldDescr();
    1277 [ #  # ][ #  # ]:          0 :         if ( !pField || (*aIter)->IsReadOnly() || aColumns.find(pField->GetName()) != aColumns.end() )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  #  
          #  #  #  #  #  
              # ][ #  # ]
    1278                 :          0 :             continue;
    1279                 :            : 
    1280                 :          0 :         Reference<XPropertySet> xColumn;
    1281 [ #  # ][ #  # ]:          0 :         if(!xColumns->hasByName(pField->GetName()))
         [ #  # ][ #  # ]
    1282                 :            :         {
    1283 [ #  # ][ #  # ]:          0 :             if(xColumnFactory.is() && xAppend.is())
                 [ #  # ]
    1284                 :            :             {// column not found by its name so we assume it is new
    1285                 :            :                 // Column is new
    1286 [ #  # ][ #  # ]:          0 :                 xColumn = xColumnFactory->createDataDescriptor();
                 [ #  # ]
    1287         [ #  # ]:          0 :                 ::dbaui::setColumnProperties(xColumn,pField);
    1288 [ #  # ][ #  # ]:          0 :                 xAppend->appendByDescriptor(xColumn);
    1289 [ #  # ][ #  # ]:          0 :                 if(xColumns->hasByName(pField->GetName()))
         [ #  # ][ #  # ]
    1290                 :            :                 {   // ask for the append by name
    1291 [ #  # ][ #  # ]:          0 :                     aColumns[pField->GetName()] = sal_True;
    1292 [ #  # ][ #  # ]:          0 :                     xColumns->getByName(pField->GetName()) >>= xColumn;
         [ #  # ][ #  # ]
    1293         [ #  # ]:          0 :                     if(xColumn.is())
    1294         [ #  # ]:          0 :                         pField->copyColumnSettingsTo(xColumn);
    1295                 :            :                 }
    1296                 :            :                 else
    1297                 :            :                 {
    1298                 :            :                     OSL_FAIL("OTableController::alterColumns: invalid column!");
    1299                 :            :                 }
    1300                 :            :             }
    1301                 :            :         }
    1302                 :          0 :     }
    1303                 :            : 
    1304                 :            : 
    1305                 :            :     // check if we have to do something with the primary key
    1306                 :          0 :     sal_Bool bNeedDropKey = sal_False;
    1307                 :          0 :     sal_Bool bNeedAppendKey = sal_False;
    1308         [ #  # ]:          0 :     if ( xKeyColumns.is() )
    1309                 :            :     {
    1310                 :          0 :         aIter = m_vRowList.begin();
    1311 [ #  # ][ #  # ]:          0 :         for(;aIter != aEnd;++aIter)
    1312                 :            :         {
    1313                 :            :             OSL_ENSURE(*aIter,"OTableRow is null!");
    1314                 :          0 :             OFieldDescription* pField = (*aIter)->GetActFieldDescr();
    1315         [ #  # ]:          0 :             if ( !pField )
    1316                 :          0 :                 continue;
    1317                 :            : 
    1318 [ #  # ][ #  # ]:          0 :             if  (   pField->IsPrimaryKey()
         [ #  # ][ #  # ]
    1319 [ #  # ][ #  # ]:          0 :                 &&  !xKeyColumns->hasByName( pField->GetName() )
         [ #  # ][ #  # ]
                 [ #  # ]
    1320                 :            :                 )
    1321                 :            :             {   // new primary key column inserted which isn't already in the columns selection
    1322                 :          0 :                 bNeedDropKey = bNeedAppendKey = sal_True;
    1323                 :          0 :                 break;
    1324                 :            :             }
    1325 [ #  # ][ #  # ]:          0 :             else if (   !pField->IsPrimaryKey()
         [ #  # ][ #  # ]
    1326 [ #  # ][ #  # ]:          0 :                     &&  xKeyColumns->hasByName( pField->GetName() )
         [ #  # ][ #  # ]
                 [ #  # ]
    1327                 :            :                     )
    1328                 :            :             {   // found a column which currently is in the primary key, but is marked not to be anymore
    1329                 :          0 :                 bNeedDropKey = bNeedAppendKey = sal_True;
    1330                 :          0 :                 break;
    1331                 :            :             }
    1332                 :            :         }
    1333                 :            :     }
    1334                 :            :     else
    1335                 :            :     {   // no primary key available so we check if we should create one
    1336                 :          0 :         bNeedAppendKey = sal_True;
    1337                 :            :     }
    1338                 :            : 
    1339 [ #  # ][ #  # ]:          0 :     if ( bNeedDropKey && xKeyColumns.is() && xKeyColumns->getElementNames().getLength() )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
    1340         [ #  # ]:          0 :         dropPrimaryKey();
    1341                 :            : 
    1342         [ #  # ]:          0 :     if ( bNeedAppendKey )
    1343                 :            :     {
    1344         [ #  # ]:          0 :         Reference< XKeysSupplier > xKeySup( m_xTable, UNO_QUERY );
    1345         [ #  # ]:          0 :         appendPrimaryKey( xKeySup ,sal_False);
    1346                 :            :     }
    1347                 :            : 
    1348         [ #  # ]:          0 :     reSyncRows();
    1349                 :            : 
    1350         [ #  # ]:          0 :     if ( bReload )
    1351 [ #  # ][ #  # ]:          0 :         reload();
         [ #  # ][ #  # ]
    1352                 :            : }
    1353                 :            : // -----------------------------------------------------------------------------
    1354                 :          0 : void OTableController::dropPrimaryKey()
    1355                 :            : {
    1356         [ #  # ]:          0 :     SQLExceptionInfo aInfo;
    1357                 :            :     try
    1358                 :            :     {
    1359         [ #  # ]:          0 :         Reference<XKeysSupplier> xKeySup(m_xTable,UNO_QUERY);
    1360                 :          0 :         Reference<XIndexAccess> xKeys;
    1361         [ #  # ]:          0 :         if(xKeySup.is())
    1362 [ #  # ][ #  # ]:          0 :             xKeys = xKeySup->getKeys();
                 [ #  # ]
    1363                 :            : 
    1364         [ #  # ]:          0 :         if(xKeys.is())
    1365                 :            :         {
    1366                 :          0 :             Reference<XPropertySet> xProp;
    1367 [ #  # ][ #  # ]:          0 :             for(sal_Int32 i=0;i< xKeys->getCount();++i)
                 [ #  # ]
    1368                 :            :             {
    1369 [ #  # ][ #  # ]:          0 :                 xProp.set(xKeys->getByIndex(i),UNO_QUERY);
                 [ #  # ]
    1370                 :          0 :                 sal_Int32 nKeyType = 0;
    1371 [ #  # ][ #  # ]:          0 :                 xProp->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
                 [ #  # ]
    1372         [ #  # ]:          0 :                 if(KeyType::PRIMARY == nKeyType)
    1373                 :            :                 {
    1374         [ #  # ]:          0 :                     Reference<XDrop> xDrop(xKeys,UNO_QUERY);
    1375 [ #  # ][ #  # ]:          0 :                     xDrop->dropByIndex(i); // delete the key
    1376                 :          0 :                     break;
    1377                 :            :                 }
    1378                 :          0 :             }
    1379                 :          0 :         }
    1380                 :            :     }
    1381         [ #  # ]:          0 :     catch(const SQLContext& e)
    1382                 :            :     {
    1383   [ #  #  #  #  :          0 :         aInfo = SQLExceptionInfo(e);
                   #  # ]
    1384                 :            :     }
    1385         [ #  # ]:          0 :     catch(const SQLWarning& e)
    1386                 :            :     {
    1387   [ #  #  #  #  :          0 :         aInfo = SQLExceptionInfo(e);
                   #  # ]
    1388                 :            :     }
    1389   [ #  #  #  #  :          0 :     catch(const SQLException& e)
                #  #  # ]
    1390                 :            :     {
    1391   [ #  #  #  #  :          0 :         aInfo = SQLExceptionInfo(e);
                   #  # ]
    1392                 :            :     }
    1393         [ #  # ]:          0 :     catch( const Exception& )
    1394                 :            :     {
    1395                 :            :         DBG_UNHANDLED_EXCEPTION();
    1396                 :            :     }
    1397                 :            : 
    1398 [ #  # ][ #  # ]:          0 :     showError(aInfo);
    1399                 :          0 : }
    1400                 :            : // -----------------------------------------------------------------------------
    1401                 :          0 : void OTableController::assignTable()
    1402                 :            : {
    1403                 :            :     // get the table
    1404         [ #  # ]:          0 :     if(!m_sName.isEmpty())
    1405                 :            :     {
    1406                 :          0 :         Reference<XNameAccess> xNameAccess;
    1407 [ #  # ][ #  # ]:          0 :         Reference<XTablesSupplier> xSup(getConnection(),UNO_QUERY);
    1408         [ #  # ]:          0 :         if(xSup.is())
    1409                 :            :         {
    1410 [ #  # ][ #  # ]:          0 :             xNameAccess = xSup->getTables();
                 [ #  # ]
    1411                 :            :             OSL_ENSURE(xNameAccess.is(),"no nameaccess for the queries!");
    1412                 :            : 
    1413                 :          0 :             Reference<XPropertySet> xProp;
    1414 [ #  # ][ #  # ]:          0 :             if(xNameAccess->hasByName(m_sName) && ::cppu::extractInterface(xProp,xNameAccess->getByName(m_sName)) && xProp.is())
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
                 [ #  # ]
    1415                 :            :             {
    1416         [ #  # ]:          0 :                 m_xTable = xProp;
    1417         [ #  # ]:          0 :                 startTableListening();
    1418                 :            : 
    1419                 :            :                 // check if we set the table editable
    1420 [ #  # ][ #  # ]:          0 :                 Reference<XDatabaseMetaData> xMeta = getConnection()->getMetaData();
                 [ #  # ]
    1421 [ #  # ][ #  # ]:          0 :                 setEditable( xMeta.is() && !xMeta->isReadOnly() && (isAlterAllowed() || isDropAllowed() || isAddAllowed()) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1422 [ #  # ][ #  # ]:          0 :                 if(!isEditable())
    1423                 :            :                 {
    1424 [ #  # ][ #  # ]:          0 :                     ::std::for_each(m_vRowList.begin(),m_vRowList.end(),boost::bind( &OTableRow::SetReadOnly, _1, boost::cref( sal_True )));
                 [ #  # ]
    1425                 :            :                 }
    1426                 :          0 :                 m_bNew = sal_False;
    1427                 :            :                 // be notified when the table is in disposing
    1428         [ #  # ]:          0 :                 InvalidateAll();
    1429                 :          0 :             }
    1430                 :          0 :         }
    1431                 :            :     }
    1432                 :          0 : }
    1433                 :            : // -----------------------------------------------------------------------------
    1434                 :          0 : sal_Bool OTableController::isAddAllowed() const
    1435                 :            : {
    1436         [ #  # ]:          0 :     Reference<XColumnsSupplier> xColsSup(m_xTable,UNO_QUERY);
    1437                 :          0 :     sal_Bool bAddAllowed = !m_xTable.is();
    1438         [ #  # ]:          0 :     if(xColsSup.is())
    1439 [ #  # ][ #  # ]:          0 :         bAddAllowed = Reference<XAppend>(xColsSup->getColumns(),UNO_QUERY).is();
                 [ #  # ]
    1440                 :            : 
    1441                 :            :     try
    1442                 :            :     {
    1443         [ #  # ]:          0 :         Reference< XDatabaseMetaData > xMetaData = getMetaData( );
    1444 [ #  # ][ #  # ]:          0 :         bAddAllowed = bAddAllowed || ( xMetaData.is() && xMetaData->supportsAlterTableWithAddColumn());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1445                 :            :     }
    1446         [ #  # ]:          0 :     catch(Exception&)
    1447                 :            :     {
    1448                 :            :         DBG_UNHANDLED_EXCEPTION();
    1449                 :          0 :         bAddAllowed = sal_False;
    1450                 :            :     }
    1451                 :            : 
    1452                 :          0 :     return bAddAllowed;
    1453                 :            : }
    1454                 :            : // -----------------------------------------------------------------------------
    1455                 :          0 : sal_Bool OTableController::isDropAllowed() const
    1456                 :            : {
    1457         [ #  # ]:          0 :     Reference<XColumnsSupplier> xColsSup(m_xTable,UNO_QUERY);
    1458                 :          0 :     sal_Bool bDropAllowed = !m_xTable.is();
    1459         [ #  # ]:          0 :     if(xColsSup.is())
    1460                 :            :     {
    1461 [ #  # ][ #  # ]:          0 :         Reference<XNameAccess> xNameAccess = xColsSup->getColumns();
    1462 [ #  # ][ #  # ]:          0 :         bDropAllowed = Reference<XDrop>(xNameAccess,UNO_QUERY).is() && xNameAccess->hasElements();
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1463                 :            :     }
    1464                 :            : 
    1465         [ #  # ]:          0 :     Reference< XDatabaseMetaData> xMetaData = getMetaData( );
    1466 [ #  # ][ #  # ]:          0 :     bDropAllowed = bDropAllowed || ( xMetaData.is() && xMetaData->supportsAlterTableWithDropColumn());
         [ #  # ][ #  # ]
                 [ #  # ]
    1467                 :            : 
    1468                 :          0 :     return bDropAllowed;
    1469                 :            : }
    1470                 :            : // -----------------------------------------------------------------------------
    1471                 :          0 : sal_Bool OTableController::isAlterAllowed() const
    1472                 :            : {
    1473 [ #  # ][ #  # ]:          0 :     sal_Bool bAllowed(!m_xTable.is() || Reference<XAlterTable>(m_xTable,UNO_QUERY).is());
         [ #  # ][ #  # ]
                 [ #  # ]
    1474                 :          0 :     return bAllowed;
    1475                 :            : }
    1476                 :            : // -----------------------------------------------------------------------------
    1477                 :          0 : void OTableController::reSyncRows()
    1478                 :            : {
    1479         [ #  # ]:          0 :     sal_Bool bAlterAllowed  = isAlterAllowed();
    1480         [ #  # ]:          0 :     sal_Bool bAddAllowed    = isAddAllowed();
    1481                 :          0 :     ::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aIter = m_vRowList.begin();
    1482                 :          0 :     ::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aEnd = m_vRowList.end();
    1483 [ #  # ][ #  # ]:          0 :     for(;aIter != aEnd;++aIter)
    1484                 :            :     {
    1485                 :            :         OSL_ENSURE(*aIter,"OTableRow is null!");
    1486                 :          0 :         OFieldDescription* pField = (*aIter)->GetActFieldDescr();
    1487         [ #  # ]:          0 :         if ( pField )
    1488                 :          0 :             (*aIter)->SetReadOnly(!bAlterAllowed);
    1489                 :            :         else
    1490                 :          0 :             (*aIter)->SetReadOnly(!bAddAllowed);
    1491                 :            : 
    1492                 :            :     }
    1493         [ #  # ]:          0 :     static_cast<OTableDesignView*>(getView())->reSync();    // show the windows and fill with our informations
    1494                 :            : 
    1495         [ #  # ]:          0 :     ClearUndoManager();
    1496         [ #  # ]:          0 :     setModified(sal_False);     // and we are not modified yet
    1497                 :          0 : }
    1498                 :            : // -----------------------------------------------------------------------------
    1499                 :          0 : ::rtl::OUString OTableController::createUniqueName(const ::rtl::OUString& _rName)
    1500                 :            : {
    1501                 :          0 :     ::rtl::OUString sName = _rName;
    1502         [ #  # ]:          0 :     Reference< XDatabaseMetaData> xMetaData = getMetaData( );
    1503                 :            : 
    1504 [ #  # ][ #  # ]:          0 :     ::comphelper::UStringMixEqual bCase(xMetaData.is() ? xMetaData->supportsMixedCaseQuotedIdentifiers() : sal_True);
                 [ #  # ]
    1505                 :            : 
    1506         [ #  # ]:          0 :     ::std::vector< ::boost::shared_ptr<OTableRow> >::const_iterator aIter = m_vRowList.begin();
    1507         [ #  # ]:          0 :     ::std::vector< ::boost::shared_ptr<OTableRow> >::const_iterator aEnd = m_vRowList.end();
    1508 [ #  # ][ #  # ]:          0 :     for(sal_Int32 i=0;aIter != aEnd;++aIter)
    1509                 :            :     {
    1510                 :          0 :         OFieldDescription* pFieldDesc = (*aIter)->GetActFieldDescr();
    1511 [ #  # ][ #  # ]:          0 :         if (pFieldDesc && !pFieldDesc->GetName().isEmpty() && bCase(sName,pFieldDesc->GetName()))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  #  
           #  # ][ #  # ]
    1512                 :            :         { // found a second name of _rName so we need another
    1513                 :          0 :             sName = _rName + ::rtl::OUString::valueOf(++i);
    1514         [ #  # ]:          0 :             aIter = m_vRowList.begin(); // and retry
    1515                 :            :         }
    1516                 :            :     }
    1517                 :          0 :     return sName;
    1518                 :            : }
    1519                 :            : // -----------------------------------------------------------------------------
    1520                 :          0 : ::rtl::OUString OTableController::getPrivateTitle() const
    1521                 :            : {
    1522                 :          0 :     ::rtl::OUString sTitle;
    1523                 :            :     try
    1524                 :            :     {
    1525                 :            :         // get the table
    1526 [ #  # ][ #  # ]:          0 :         if ( !m_sName.isEmpty() && getConnection().is() )
         [ #  # ][ #  # ]
    1527                 :            :         {
    1528         [ #  # ]:          0 :             if ( m_xTable.is() )
    1529 [ #  # ][ #  # ]:          0 :                 sTitle = ::dbtools::composeTableName( getConnection()->getMetaData(), m_xTable, ::dbtools::eInDataManipulation, false, false, false );
         [ #  # ][ #  # ]
    1530                 :            :             else
    1531                 :          0 :                 sTitle = m_sName;
    1532                 :            :         }
    1533         [ #  # ]:          0 :         if ( sTitle.isEmpty() )
    1534                 :            :         {
    1535 [ #  # ][ #  # ]:          0 :             String aName = String(ModuleRes(STR_TBL_TITLE));
    1536 [ #  # ][ #  # ]:          0 :             sTitle = aName.GetToken(0,' ');
                 [ #  # ]
    1537 [ #  # ][ #  # ]:          0 :             sTitle += ::rtl::OUString::valueOf(getCurrentStartNumber());
                 [ #  # ]
    1538                 :            :         }
    1539                 :            :     }
    1540         [ #  # ]:          0 :     catch( const Exception& )
    1541                 :            :     {
    1542                 :            :         DBG_UNHANDLED_EXCEPTION();
    1543                 :            :     }
    1544                 :          0 :     return sTitle;
    1545                 :            : }
    1546                 :            : // -----------------------------------------------------------------------------
    1547                 :          0 : void OTableController::reload()
    1548                 :            : {
    1549                 :          0 :     loadData();                 // fill the column information form the table
    1550                 :          0 :     static_cast<OTableDesignView*>(getView())->reSync();    // show the windows and fill with our informations
    1551                 :          0 :     ClearUndoManager();
    1552                 :          0 :     setModified(sal_False);     // and we are not modified yet
    1553                 :          0 :     static_cast<OTableDesignView*>(getView())->Invalidate();
    1554                 :          0 : }
    1555                 :            : // -----------------------------------------------------------------------------
    1556                 :          0 : sal_Int32 OTableController::getFirstEmptyRowPosition()
    1557                 :            : {
    1558                 :          0 :     sal_Int32 nRet = -1;
    1559         [ #  # ]:          0 :     ::std::vector< ::boost::shared_ptr<OTableRow> >::const_iterator aIter = m_vRowList.begin();
    1560         [ #  # ]:          0 :     ::std::vector< ::boost::shared_ptr<OTableRow> >::const_iterator aEnd = m_vRowList.end();
    1561 [ #  # ][ #  # ]:          0 :     for(;aIter != aEnd;++aIter)
    1562                 :            :     {
    1563 [ #  # ][ #  # ]:          0 :         if ( !*aIter || !(*aIter)->GetActFieldDescr() || (*aIter)->GetActFieldDescr()->GetName().isEmpty() )
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
    1564                 :            :         {
    1565         [ #  # ]:          0 :             nRet = aIter - m_vRowList.begin();
    1566                 :          0 :             break;
    1567                 :            :         }
    1568                 :            :     }
    1569         [ #  # ]:          0 :     if ( nRet == -1 )
    1570                 :            :     {
    1571         [ #  # ]:          0 :         bool bReadRow = !isAddAllowed();
    1572 [ #  # ][ #  # ]:          0 :         ::boost::shared_ptr<OTableRow> pTabEdRow(new OTableRow());
                 [ #  # ]
    1573                 :          0 :         pTabEdRow->SetReadOnly(bReadRow);
    1574                 :          0 :         nRet = m_vRowList.size();
    1575 [ #  # ][ #  # ]:          0 :         m_vRowList.push_back( pTabEdRow);
    1576                 :            :     }
    1577                 :          0 :     return nRet;
    1578                 :            : }
    1579                 :            : // -----------------------------------------------------------------------------
    1580                 :          0 : bool OTableController::isAutoIncrementPrimaryKey() const
    1581                 :            : {
    1582                 :          0 :     return getSdbMetaData().isAutoIncrementPrimaryKey();
    1583 [ +  - ][ +  - ]:         42 : }
    1584                 :            : // -----------------------------------------------------------------------------
    1585                 :            : 
    1586                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10