1*96de5490SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*96de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*96de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*96de5490SAndrew Rist * distributed with this work for additional information 6*96de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*96de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*96de5490SAndrew Rist * "License"); you may not use this file except in compliance 9*96de5490SAndrew Rist * with the License. You may obtain a copy of the License at 10*96de5490SAndrew Rist * 11*96de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*96de5490SAndrew Rist * 13*96de5490SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*96de5490SAndrew Rist * software distributed under the License is distributed on an 15*96de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*96de5490SAndrew Rist * KIND, either express or implied. See the License for the 17*96de5490SAndrew Rist * specific language governing permissions and limitations 18*96de5490SAndrew Rist * under the License. 19*96de5490SAndrew Rist * 20*96de5490SAndrew Rist *************************************************************/ 21*96de5490SAndrew Rist 22*96de5490SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 26cdf0e10cSrcweir #ifndef DBAUI_TABLEROW_HXX 27cdf0e10cSrcweir #include "TableRow.hxx" 28cdf0e10cSrcweir #endif 29cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX 30cdf0e10cSrcweir #include <tools/debug.hxx> 31cdf0e10cSrcweir #endif 32cdf0e10cSrcweir #ifndef DBAUI_FIELDDESCRIPTIONS_HXX 33cdf0e10cSrcweir #include "FieldDescriptions.hxx" 34cdf0e10cSrcweir #endif 35cdf0e10cSrcweir #include <algorithm> 36cdf0e10cSrcweir #include <comphelper/types.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir using namespace dbaui; 39cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 40cdf0e10cSrcweir using namespace ::com::sun::star::uno; 41cdf0e10cSrcweir using namespace ::com::sun::star::beans; 42cdf0e10cSrcweir 43cdf0e10cSrcweir //======================================================================== 44cdf0e10cSrcweir // class OTableRow 45cdf0e10cSrcweir //======================================================================== 46cdf0e10cSrcweir DBG_NAME(OTableRow) 47cdf0e10cSrcweir //------------------------------------------------------------------------------ 48cdf0e10cSrcweir OTableRow::OTableRow() 49cdf0e10cSrcweir :m_pActFieldDescr( NULL ) 50cdf0e10cSrcweir ,m_nPos( -1 ) 51cdf0e10cSrcweir ,m_bReadOnly( false ) 52cdf0e10cSrcweir ,m_bOwnsDescriptions(false) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir DBG_CTOR(OTableRow,NULL); 55cdf0e10cSrcweir } 56cdf0e10cSrcweir //------------------------------------------------------------------------------ 57cdf0e10cSrcweir OTableRow::OTableRow(const Reference< XPropertySet >& xAffectedCol) 58cdf0e10cSrcweir :m_pActFieldDescr( NULL ) 59cdf0e10cSrcweir ,m_nPos( -1 ) 60cdf0e10cSrcweir ,m_bReadOnly( false ) 61cdf0e10cSrcweir ,m_bOwnsDescriptions(true) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir DBG_CTOR(OTableRow,NULL); 64cdf0e10cSrcweir m_pActFieldDescr = new OFieldDescription(xAffectedCol); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir //------------------------------------------------------------------------------ 67cdf0e10cSrcweir OTableRow::OTableRow( const OTableRow& rRow, long nPosition ) 68cdf0e10cSrcweir :m_pActFieldDescr(NULL) 69cdf0e10cSrcweir ,m_nPos( nPosition ) 70cdf0e10cSrcweir ,m_bReadOnly(rRow.IsReadOnly()) 71cdf0e10cSrcweir ,m_bOwnsDescriptions(false) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir DBG_CTOR(OTableRow,NULL); 74cdf0e10cSrcweir 75cdf0e10cSrcweir OFieldDescription* pSrcField = rRow.GetActFieldDescr(); 76cdf0e10cSrcweir if(pSrcField) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir m_pActFieldDescr = new OFieldDescription(*pSrcField); 79cdf0e10cSrcweir m_bOwnsDescriptions = true; 80cdf0e10cSrcweir } 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir //------------------------------------------------------------------------------ 84cdf0e10cSrcweir OTableRow::~OTableRow() 85cdf0e10cSrcweir { 86cdf0e10cSrcweir DBG_DTOR(OTableRow,NULL); 87cdf0e10cSrcweir if(m_bOwnsDescriptions) 88cdf0e10cSrcweir delete m_pActFieldDescr; 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir //------------------------------------------------------------------------------ 92cdf0e10cSrcweir void OTableRow::SetPrimaryKey( sal_Bool bSet ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir DBG_CHKTHIS(OTableRow,NULL); 95cdf0e10cSrcweir if(m_pActFieldDescr) 96cdf0e10cSrcweir m_pActFieldDescr->SetPrimaryKey(bSet); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir // ----------------------------------------------------------------------------- 99cdf0e10cSrcweir sal_Bool OTableRow::IsPrimaryKey() const 100cdf0e10cSrcweir { 101cdf0e10cSrcweir DBG_CHKTHIS(OTableRow,NULL); 102cdf0e10cSrcweir return m_pActFieldDescr && m_pActFieldDescr->IsPrimaryKey(); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir // ----------------------------------------------------------------------------- 105cdf0e10cSrcweir void OTableRow::SetFieldType( const TOTypeInfoSP& _pType, sal_Bool _bForce ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir DBG_CHKTHIS(OTableRow,NULL); 108cdf0e10cSrcweir if ( _pType.get() ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir if( !m_pActFieldDescr ) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir m_pActFieldDescr = new OFieldDescription(); 113cdf0e10cSrcweir m_bOwnsDescriptions = true; 114cdf0e10cSrcweir } 115cdf0e10cSrcweir m_pActFieldDescr->FillFromTypeInfo(_pType,_bForce,sal_True); 116cdf0e10cSrcweir } 117cdf0e10cSrcweir else 118cdf0e10cSrcweir { 119cdf0e10cSrcweir delete m_pActFieldDescr; 120cdf0e10cSrcweir m_pActFieldDescr = NULL; 121cdf0e10cSrcweir } 122cdf0e10cSrcweir } 123cdf0e10cSrcweir // ----------------------------------------------------------------------------- 124cdf0e10cSrcweir namespace dbaui 125cdf0e10cSrcweir { 126cdf0e10cSrcweir // ----------------------------------------------------------------------------- 127cdf0e10cSrcweir SvStream& operator<<( SvStream& _rStr, const OTableRow& _rRow ) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir _rStr << _rRow.m_nPos; 130cdf0e10cSrcweir OFieldDescription* pFieldDesc = _rRow.GetActFieldDescr(); 131cdf0e10cSrcweir if(pFieldDesc) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir _rStr << (sal_Int32)1; 134cdf0e10cSrcweir _rStr.WriteByteString(pFieldDesc->GetName()); 135cdf0e10cSrcweir _rStr.WriteByteString(pFieldDesc->GetDescription()); 136cdf0e10cSrcweir _rStr.WriteByteString(pFieldDesc->GetHelpText()); 137cdf0e10cSrcweir double nValue = 0.0; 138cdf0e10cSrcweir Any aValue = pFieldDesc->GetControlDefault(); 139cdf0e10cSrcweir if ( aValue >>= nValue ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir _rStr << sal_Int32(1); 142cdf0e10cSrcweir _rStr << nValue; 143cdf0e10cSrcweir } 144cdf0e10cSrcweir else 145cdf0e10cSrcweir { 146cdf0e10cSrcweir _rStr << sal_Int32(2); 147cdf0e10cSrcweir _rStr.WriteByteString(::comphelper::getString(aValue)); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir _rStr << pFieldDesc->GetType(); 151cdf0e10cSrcweir 152cdf0e10cSrcweir _rStr << pFieldDesc->GetPrecision(); 153cdf0e10cSrcweir _rStr << pFieldDesc->GetScale(); 154cdf0e10cSrcweir _rStr << pFieldDesc->GetIsNullable(); 155cdf0e10cSrcweir _rStr << pFieldDesc->GetFormatKey(); 156cdf0e10cSrcweir _rStr << (sal_Int32)pFieldDesc->GetHorJustify(); 157cdf0e10cSrcweir _rStr << sal_Int32(pFieldDesc->IsAutoIncrement() ? 1 : 0); 158cdf0e10cSrcweir _rStr << sal_Int32(pFieldDesc->IsPrimaryKey() ? 1 : 0); 159cdf0e10cSrcweir _rStr << sal_Int32(pFieldDesc->IsCurrency() ? 1 : 0); 160cdf0e10cSrcweir } // if(pFieldDesc) 161cdf0e10cSrcweir else 162cdf0e10cSrcweir _rStr << (sal_Int32)0; 163cdf0e10cSrcweir return _rStr; 164cdf0e10cSrcweir } 165cdf0e10cSrcweir // ----------------------------------------------------------------------------- 166cdf0e10cSrcweir SvStream& operator>>( SvStream& _rStr, OTableRow& _rRow ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir _rStr >> _rRow.m_nPos; 169cdf0e10cSrcweir sal_Int32 nValue = 0; 170cdf0e10cSrcweir _rStr >> nValue; 171cdf0e10cSrcweir if ( nValue ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir OFieldDescription* pFieldDesc = new OFieldDescription(); 174cdf0e10cSrcweir _rRow.m_pActFieldDescr = pFieldDesc; 175cdf0e10cSrcweir String sValue; 176cdf0e10cSrcweir _rStr.ReadByteString(sValue); 177cdf0e10cSrcweir pFieldDesc->SetName(sValue); 178cdf0e10cSrcweir 179cdf0e10cSrcweir _rStr.ReadByteString(sValue); 180cdf0e10cSrcweir pFieldDesc->SetDescription(sValue); 181cdf0e10cSrcweir _rStr.ReadByteString(sValue); 182cdf0e10cSrcweir pFieldDesc->SetHelpText(sValue); 183cdf0e10cSrcweir 184cdf0e10cSrcweir _rStr >> nValue; 185cdf0e10cSrcweir Any aControlDefault; 186cdf0e10cSrcweir switch ( nValue ) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir case 1: 189cdf0e10cSrcweir { 190cdf0e10cSrcweir double nControlDefault; 191cdf0e10cSrcweir _rStr >> nControlDefault; 192cdf0e10cSrcweir aControlDefault <<= nControlDefault; 193cdf0e10cSrcweir break; 194cdf0e10cSrcweir } 195cdf0e10cSrcweir case 2: 196cdf0e10cSrcweir _rStr.ReadByteString(sValue); 197cdf0e10cSrcweir aControlDefault <<= ::rtl::OUString(sValue); 198cdf0e10cSrcweir break; 199cdf0e10cSrcweir } 200cdf0e10cSrcweir 201cdf0e10cSrcweir pFieldDesc->SetControlDefault(aControlDefault); 202cdf0e10cSrcweir 203cdf0e10cSrcweir 204cdf0e10cSrcweir _rStr >> nValue; 205cdf0e10cSrcweir pFieldDesc->SetTypeValue(nValue); 206cdf0e10cSrcweir 207cdf0e10cSrcweir _rStr >> nValue; 208cdf0e10cSrcweir pFieldDesc->SetPrecision(nValue); 209cdf0e10cSrcweir _rStr >> nValue; 210cdf0e10cSrcweir pFieldDesc->SetScale(nValue); 211cdf0e10cSrcweir _rStr >> nValue; 212cdf0e10cSrcweir pFieldDesc->SetIsNullable(nValue); 213cdf0e10cSrcweir _rStr >> nValue; 214cdf0e10cSrcweir pFieldDesc->SetFormatKey(nValue); 215cdf0e10cSrcweir _rStr >> nValue; 216cdf0e10cSrcweir pFieldDesc->SetHorJustify((SvxCellHorJustify)nValue); 217cdf0e10cSrcweir 218cdf0e10cSrcweir _rStr >> nValue; 219cdf0e10cSrcweir pFieldDesc->SetAutoIncrement(nValue != 0); 220cdf0e10cSrcweir _rStr >> nValue; 221cdf0e10cSrcweir pFieldDesc->SetPrimaryKey(nValue != 0); 222cdf0e10cSrcweir _rStr >> nValue; 223cdf0e10cSrcweir pFieldDesc->SetCurrency(nValue != 0); 224cdf0e10cSrcweir } 225cdf0e10cSrcweir return _rStr; 226cdf0e10cSrcweir } 227cdf0e10cSrcweir // ----------------------------------------------------------------------------- 228cdf0e10cSrcweir } 229cdf0e10cSrcweir 230cdf0e10cSrcweir 231cdf0e10cSrcweir 232