merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / tabledesign / FieldDescriptions.cxx
blobbfec01a1a1dc2cf143cbd6df9c0213b8708bc7eb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FieldDescriptions.cxx,v $
10 * $Revision: 1.29.50.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
34 #include "FieldDescriptions.hxx"
35 #endif
36 #ifndef _TOOLS_DEBUG_HXX
37 #include <tools/debug.hxx>
38 #endif
39 #ifndef TOOLS_DIAGNOSE_EX_H
40 #include <tools/diagnose_ex.h>
41 #endif
42 #ifndef _DBU_TBL_HRC_
43 #include "dbu_tbl.hrc"
44 #endif
45 #ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_
46 #include <com/sun/star/sdbc/ColumnValue.hpp>
47 #endif
48 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
49 #include "dbustrings.hrc"
50 #endif
51 #ifndef _COMPHELPER_TYPES_HXX_
52 #include <comphelper/types.hxx>
53 #endif
54 #ifndef _COMPHELPER_EXTRACT_HXX_
55 #include <comphelper/extract.hxx>
56 #endif
57 #ifndef DBAUI_TOOLS_HXX
58 #include "UITools.hxx"
59 #endif
60 #ifndef _COM_SUN_STAR_UTIL_NUMBERFORMAT_HPP_
61 #include <com/sun/star/util/NumberFormat.hpp>
62 #endif
64 #define DEFAULT_VARCHAR_PRECSION 100
65 #define DEFAULT_OTHER_PRECSION 16
66 #define DEFAULT_NUMERIC_PRECSION 5
67 #define DEFAULT_NUMERIC_SCALE 0
70 using namespace dbaui;
71 using namespace ::com::sun::star::sdbc;
72 using namespace ::com::sun::star::uno;
73 using namespace ::com::sun::star::beans;
74 using namespace ::com::sun::star::util;
76 //========================================================================
77 // class OFieldDescription
78 //========================================================================
79 DBG_NAME(OFieldDescription)
80 //------------------------------------------------------------------------------
81 OFieldDescription::OFieldDescription()
82 :m_pType()
83 ,m_nType(DataType::VARCHAR)
84 ,m_nPrecision(0)
85 ,m_nScale(0)
86 ,m_nIsNullable(ColumnValue::NULLABLE)
87 ,m_nFormatKey(0)
88 ,m_eHorJustify(SVX_HOR_JUSTIFY_STANDARD)
89 ,m_bIsAutoIncrement(sal_False)
90 ,m_bIsPrimaryKey(sal_False)
91 ,m_bIsCurrency(sal_False)
92 ,m_bHidden(sal_False)
94 DBG_CTOR(OFieldDescription,NULL);
96 //------------------------------------------------------------------------------
97 OFieldDescription::OFieldDescription( const OFieldDescription& rDescr )
98 :m_aDefaultValue(rDescr.m_aDefaultValue)
99 ,m_aControlDefault(rDescr.m_aControlDefault)
100 ,m_aWidth(rDescr.m_aWidth)
101 ,m_aRelativePosition(rDescr.m_aRelativePosition)
102 ,m_pType(rDescr.m_pType)
103 ,m_xDest(rDescr.m_xDest)
104 ,m_xDestInfo(rDescr.m_xDestInfo)
105 ,m_sName(rDescr.m_sName)
106 ,m_sTypeName(rDescr.m_sTypeName)
107 ,m_sDescription(rDescr.m_sDescription)
108 ,m_sAutoIncrementValue(rDescr.m_sAutoIncrementValue)
109 ,m_nType(rDescr.m_nType)
110 ,m_nPrecision(rDescr.m_nPrecision)
111 ,m_nScale(rDescr.m_nScale)
112 ,m_nIsNullable(rDescr.m_nIsNullable)
113 ,m_nFormatKey(rDescr.m_nFormatKey)
114 ,m_eHorJustify(rDescr.m_eHorJustify)
115 ,m_bIsAutoIncrement(rDescr.m_bIsAutoIncrement)
116 ,m_bIsPrimaryKey(rDescr.m_bIsPrimaryKey)
117 ,m_bIsCurrency(rDescr.m_bIsCurrency)
118 ,m_bHidden(rDescr.m_bHidden)
120 DBG_CTOR(OFieldDescription,NULL);
123 //------------------------------------------------------------------------------
124 OFieldDescription::~OFieldDescription()
126 DBG_DTOR(OFieldDescription,NULL);
128 //------------------------------------------------------------------------------
129 OFieldDescription::OFieldDescription(const Reference< XPropertySet >& xAffectedCol,sal_Bool _bUseAsDest)
130 :m_pType()
131 ,m_nType(DataType::VARCHAR)
132 ,m_nPrecision(0)
133 ,m_nScale(0)
134 ,m_nIsNullable(ColumnValue::NULLABLE)
135 ,m_nFormatKey(0)
136 ,m_eHorJustify(SVX_HOR_JUSTIFY_STANDARD)
137 ,m_bIsAutoIncrement(sal_False)
138 ,m_bIsPrimaryKey(sal_False)
139 ,m_bIsCurrency(sal_False)
140 ,m_bHidden(sal_False)
142 DBG_CTOR(OFieldDescription,NULL);
143 OSL_ENSURE(xAffectedCol.is(),"PropetySet can notbe null!");
144 if ( xAffectedCol.is() )
146 if ( _bUseAsDest )
148 m_xDest = xAffectedCol;
149 m_xDestInfo = xAffectedCol->getPropertySetInfo();;
151 else
155 Reference<XPropertySetInfo> xPropSetInfo = xAffectedCol->getPropertySetInfo();
156 if(xPropSetInfo->hasPropertyByName(PROPERTY_NAME))
157 SetName(::comphelper::getString(xAffectedCol->getPropertyValue(PROPERTY_NAME)));
158 if(xPropSetInfo->hasPropertyByName(PROPERTY_DESCRIPTION))
159 SetDescription(::comphelper::getString(xAffectedCol->getPropertyValue(PROPERTY_DESCRIPTION)));
160 if(xPropSetInfo->hasPropertyByName(PROPERTY_DEFAULTVALUE))
161 SetDefaultValue( xAffectedCol->getPropertyValue(PROPERTY_DEFAULTVALUE) );
163 if(xPropSetInfo->hasPropertyByName(PROPERTY_CONTROLDEFAULT))
164 SetControlDefault( xAffectedCol->getPropertyValue(PROPERTY_CONTROLDEFAULT) );
166 if(xPropSetInfo->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION))
167 SetAutoIncrementValue(::comphelper::getString(xAffectedCol->getPropertyValue(PROPERTY_AUTOINCREMENTCREATION)));
168 if(xPropSetInfo->hasPropertyByName(PROPERTY_TYPE))
169 SetTypeValue(::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_TYPE)));
170 if (xPropSetInfo->hasPropertyByName(PROPERTY_TYPENAME))
171 SetTypeName(::comphelper::getString(xAffectedCol->getPropertyValue(PROPERTY_TYPENAME)));
172 if(xPropSetInfo->hasPropertyByName(PROPERTY_PRECISION))
173 SetPrecision(::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_PRECISION)));
174 if(xPropSetInfo->hasPropertyByName(PROPERTY_SCALE))
175 SetScale(::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_SCALE)));
176 if(xPropSetInfo->hasPropertyByName(PROPERTY_ISNULLABLE))
177 SetIsNullable(::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_ISNULLABLE)));
178 if(xPropSetInfo->hasPropertyByName(PROPERTY_FORMATKEY))
180 const Any aValue = xAffectedCol->getPropertyValue(PROPERTY_FORMATKEY);
181 if ( aValue.hasValue() )
182 SetFormatKey(::comphelper::getINT32(aValue));
184 if(xPropSetInfo->hasPropertyByName(PROPERTY_RELATIVEPOSITION))
185 m_aRelativePosition = xAffectedCol->getPropertyValue(PROPERTY_RELATIVEPOSITION);
186 if(xPropSetInfo->hasPropertyByName(PROPERTY_WIDTH))
187 m_aWidth = xAffectedCol->getPropertyValue(PROPERTY_WIDTH);
188 if(xPropSetInfo->hasPropertyByName(PROPERTY_HIDDEN))
189 xAffectedCol->getPropertyValue(PROPERTY_HIDDEN) >>= m_bHidden;
190 if(xPropSetInfo->hasPropertyByName(PROPERTY_ALIGN))
192 const Any aValue = xAffectedCol->getPropertyValue(PROPERTY_ALIGN);
193 if ( aValue.hasValue() )
194 SetHorJustify( ::dbaui::mapTextJustify(::comphelper::getINT32(aValue)));
196 if(xPropSetInfo->hasPropertyByName(PROPERTY_ISAUTOINCREMENT))
197 SetAutoIncrement(::cppu::any2bool(xAffectedCol->getPropertyValue(PROPERTY_ISAUTOINCREMENT)));
199 catch(const Exception&)
201 DBG_UNHANDLED_EXCEPTION();
206 // -----------------------------------------------------------------------------
207 void OFieldDescription::FillFromTypeInfo(const TOTypeInfoSP& _pType,sal_Bool _bForce,sal_Bool _bReset)
209 TOTypeInfoSP pOldType = getTypeInfo();
210 if ( _pType != pOldType )
212 // reset type depending information
213 if ( _bReset )
215 SetFormatKey(0);
216 SetControlDefault(Any());
219 sal_Bool bForce = _bForce || pOldType.get() == NULL || pOldType->nType != _pType->nType;
220 switch ( _pType->nType )
222 case DataType::CHAR:
223 case DataType::VARCHAR:
224 if ( bForce )
226 sal_Int32 nPrec = DEFAULT_VARCHAR_PRECSION;
227 if ( GetPrecision() )
228 nPrec = GetPrecision();
229 SetPrecision(::std::min<sal_Int32>(nPrec,_pType->nPrecision));
231 break;
232 case DataType::TIMESTAMP:
233 if ( bForce && _pType->nMaximumScale)
235 SetScale(::std::min<sal_Int32>(GetScale() ? GetScale() : DEFAULT_NUMERIC_SCALE,_pType->nMaximumScale));
237 break;
238 default:
239 if ( bForce )
241 sal_Int32 nPrec = DEFAULT_OTHER_PRECSION;
242 if ( GetPrecision() )
243 nPrec = GetPrecision();
244 if ( _pType->nPrecision )
245 SetPrecision(::std::min<sal_Int32>(nPrec ? nPrec : DEFAULT_NUMERIC_PRECSION,_pType->nPrecision));
246 if ( _pType->nMaximumScale )
247 SetScale(::std::min<sal_Int32>(GetScale() ? GetScale() : DEFAULT_NUMERIC_SCALE,_pType->nMaximumScale));
250 if ( !_pType->aCreateParams.getLength() )
252 SetPrecision(_pType->nPrecision);
253 SetScale(_pType->nMinimumScale);
255 if ( !_pType->bNullable && IsNullable() )
256 SetIsNullable(ColumnValue::NO_NULLS);
257 if ( !_pType->bAutoIncrement && IsAutoIncrement() )
258 SetAutoIncrement(sal_False);
259 SetCurrency( _pType->bCurrency );
260 SetType(_pType);
261 SetTypeName(_pType->aTypeName);
264 // -----------------------------------------------------------------------------
265 void OFieldDescription::SetName(const ::rtl::OUString& _rName)
269 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_NAME) )
270 m_xDest->setPropertyValue(PROPERTY_NAME,makeAny(_rName));
271 else
272 m_sName = _rName;
274 catch(const Exception& )
276 DBG_UNHANDLED_EXCEPTION();
279 // -----------------------------------------------------------------------------
280 void OFieldDescription::SetDescription(const ::rtl::OUString& _rDescription)
284 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_DESCRIPTION) )
285 m_xDest->setPropertyValue(PROPERTY_DESCRIPTION,makeAny(_rDescription));
286 else
287 m_sDescription = _rDescription;
289 catch(const Exception& )
291 DBG_UNHANDLED_EXCEPTION();
294 // -----------------------------------------------------------------------------
295 void OFieldDescription::SetDefaultValue(const Any& _rDefaultValue)
299 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_DEFAULTVALUE) )
300 m_xDest->setPropertyValue(PROPERTY_DEFAULTVALUE,makeAny(_rDefaultValue));
301 else
302 m_aDefaultValue = _rDefaultValue;
304 catch( const Exception& )
306 DBG_UNHANDLED_EXCEPTION();
309 // -----------------------------------------------------------------------------
310 void OFieldDescription::SetControlDefault(const Any& _rControlDefault)
314 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_CONTROLDEFAULT) )
315 m_xDest->setPropertyValue(PROPERTY_CONTROLDEFAULT,makeAny(_rControlDefault));
316 else
317 m_aControlDefault = _rControlDefault;
319 catch( const Exception& )
321 DBG_UNHANDLED_EXCEPTION();
324 // -----------------------------------------------------------------------------
325 void OFieldDescription::SetAutoIncrementValue(const ::rtl::OUString& _sAutoIncValue)
329 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION) )
330 m_xDest->setPropertyValue(PROPERTY_AUTOINCREMENTCREATION,makeAny(_sAutoIncValue));
331 else
332 m_sAutoIncrementValue = _sAutoIncValue;
334 catch( const Exception& )
336 DBG_UNHANDLED_EXCEPTION();
339 // -----------------------------------------------------------------------------
340 void OFieldDescription::SetType(TOTypeInfoSP _pType)
342 m_pType = _pType;
343 if ( m_pType.get() )
347 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_TYPE) )
348 m_xDest->setPropertyValue(PROPERTY_TYPE,makeAny(m_pType->nType));
349 else
350 m_nType = m_pType->nType;
352 catch( const Exception& )
354 DBG_UNHANDLED_EXCEPTION();
358 // -----------------------------------------------------------------------------
359 void OFieldDescription::SetTypeValue(sal_Int32 _nType)
363 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_TYPE) )
364 m_xDest->setPropertyValue(PROPERTY_TYPE,makeAny(_nType));
365 else
367 m_nType = _nType;
368 OSL_ENSURE(!m_pType.get(),"Invalid call here!");
371 catch( const Exception& )
373 DBG_UNHANDLED_EXCEPTION();
376 // -----------------------------------------------------------------------------
377 void OFieldDescription::SetPrecision(const sal_Int32& _rPrecision)
381 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_PRECISION) )
382 m_xDest->setPropertyValue(PROPERTY_PRECISION,makeAny(_rPrecision));
383 else
384 m_nPrecision = _rPrecision;
386 catch( const Exception& )
388 DBG_UNHANDLED_EXCEPTION();
391 // -----------------------------------------------------------------------------
392 void OFieldDescription::SetScale(const sal_Int32& _rScale)
396 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_SCALE) )
397 m_xDest->setPropertyValue(PROPERTY_SCALE,makeAny(_rScale));
398 else
399 m_nScale = _rScale;
401 catch( const Exception& )
403 DBG_UNHANDLED_EXCEPTION();
406 // -----------------------------------------------------------------------------
407 void OFieldDescription::SetIsNullable(const sal_Int32& _rIsNullable)
411 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ISNULLABLE) )
412 m_xDest->setPropertyValue(PROPERTY_ISNULLABLE,makeAny(_rIsNullable));
413 else
414 m_nIsNullable = _rIsNullable;
416 catch( const Exception& )
418 DBG_UNHANDLED_EXCEPTION();
421 // -----------------------------------------------------------------------------
422 void OFieldDescription::SetFormatKey(const sal_Int32& _rFormatKey)
426 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_FORMATKEY) )
427 m_xDest->setPropertyValue(PROPERTY_FORMATKEY,makeAny(_rFormatKey));
428 else
429 m_nFormatKey = _rFormatKey;
431 catch( const Exception& )
433 DBG_UNHANDLED_EXCEPTION();
436 // -----------------------------------------------------------------------------
437 void OFieldDescription::SetHorJustify(const SvxCellHorJustify& _rHorJustify)
441 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ALIGN) )
442 m_xDest->setPropertyValue(PROPERTY_ALIGN,makeAny( dbaui::mapTextAllign(_rHorJustify)));
443 else
444 m_eHorJustify = _rHorJustify;
446 catch( const Exception& )
448 DBG_UNHANDLED_EXCEPTION();
451 // -----------------------------------------------------------------------------
452 void OFieldDescription::SetAutoIncrement(sal_Bool _bAuto)
456 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ISAUTOINCREMENT) )
457 m_xDest->setPropertyValue(PROPERTY_ISAUTOINCREMENT,makeAny(_bAuto));
458 else
459 m_bIsAutoIncrement = _bAuto;
461 catch( const Exception& )
463 DBG_UNHANDLED_EXCEPTION();
466 // -----------------------------------------------------------------------------
467 void OFieldDescription::SetPrimaryKey(sal_Bool _bPKey)
469 m_bIsPrimaryKey = _bPKey;
470 if ( _bPKey )
471 SetIsNullable(::com::sun::star::sdbc::ColumnValue::NO_NULLS);
473 // -----------------------------------------------------------------------------
474 void OFieldDescription::SetCurrency(sal_Bool _bIsCurrency)
476 m_bIsCurrency = _bIsCurrency;
478 // -----------------------------------------------------------------------------
480 ::rtl::OUString OFieldDescription::GetName() const
482 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_NAME) )
483 return ::comphelper::getString(m_xDest->getPropertyValue(PROPERTY_NAME));
484 else
485 return m_sName;
487 // -----------------------------------------------------------------------------
488 ::rtl::OUString OFieldDescription::GetDescription() const
490 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_DESCRIPTION) )
491 return ::comphelper::getString(m_xDest->getPropertyValue(PROPERTY_DESCRIPTION));
492 else
493 return m_sDescription;
495 // -----------------------------------------------------------------------------
496 ::com::sun::star::uno::Any OFieldDescription::GetControlDefault() const
498 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_CONTROLDEFAULT) )
499 return m_xDest->getPropertyValue(PROPERTY_CONTROLDEFAULT);
500 else
501 return m_aControlDefault;
503 // -----------------------------------------------------------------------------
504 ::rtl::OUString OFieldDescription::GetAutoIncrementValue() const
506 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION) )
507 return ::comphelper::getString(m_xDest->getPropertyValue(PROPERTY_AUTOINCREMENTCREATION));
508 else
509 return m_sAutoIncrementValue;
511 // -----------------------------------------------------------------------------
512 sal_Int32 OFieldDescription::GetType() const
514 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_TYPE) )
515 return ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_TYPE));
516 else
517 return m_pType.get() ? m_pType->nType : m_nType;
519 // -----------------------------------------------------------------------------
520 ::rtl::OUString OFieldDescription::GetTypeName() const
522 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_TYPENAME) )
523 return ::comphelper::getString(m_xDest->getPropertyValue(PROPERTY_TYPENAME));
524 else
525 return m_pType.get() ? m_pType->aTypeName : m_sTypeName;
527 // -----------------------------------------------------------------------------
528 sal_Int32 OFieldDescription::GetPrecision() const
530 sal_Int32 nPrec = m_nPrecision;
531 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_PRECISION) )
532 nPrec = ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_PRECISION));
534 TOTypeInfoSP pTypeInfo = getTypeInfo();
535 if ( pTypeInfo )
537 switch ( pTypeInfo->nType )
539 case DataType::TINYINT:
540 case DataType::SMALLINT:
541 case DataType::INTEGER:
542 case DataType::BIGINT:
543 if ( !nPrec )
544 nPrec = pTypeInfo->nPrecision;
545 break;
546 } // switch ( pTypeInfo->nType )
549 return nPrec;
551 // -----------------------------------------------------------------------------
552 sal_Int32 OFieldDescription::GetScale() const
554 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_SCALE) )
555 return ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_SCALE));
556 else
557 return m_nScale;
559 // -----------------------------------------------------------------------------
560 sal_Int32 OFieldDescription::GetIsNullable() const
562 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ISNULLABLE) )
563 return ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_ISNULLABLE));
564 else
565 return m_nIsNullable;
567 // -----------------------------------------------------------------------------
568 sal_Int32 OFieldDescription::GetFormatKey() const
570 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_FORMATKEY) )
571 return ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_FORMATKEY));
572 else
573 return m_nFormatKey;
575 // -----------------------------------------------------------------------------
576 SvxCellHorJustify OFieldDescription::GetHorJustify() const
578 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ALIGN) )
579 return ::dbaui::mapTextJustify(::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_ALIGN)));
580 else
581 return m_eHorJustify;
583 // -----------------------------------------------------------------------------
584 TOTypeInfoSP OFieldDescription::getTypeInfo() const
586 return m_pType;
588 // -----------------------------------------------------------------------------
589 TOTypeInfoSP OFieldDescription::getSpecialTypeInfo() const
591 TOTypeInfoSP pSpecialType( new OTypeInfo() );
592 *pSpecialType = *m_pType;
593 pSpecialType->nPrecision = GetPrecision();
594 pSpecialType->nMaximumScale = static_cast<sal_Int16>(GetScale());
595 return pSpecialType;
597 // -----------------------------------------------------------------------------
598 sal_Bool OFieldDescription::IsAutoIncrement() const
600 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ISAUTOINCREMENT) )
601 return ::cppu::any2bool(m_xDest->getPropertyValue(PROPERTY_ISAUTOINCREMENT));
602 else
603 return m_bIsAutoIncrement;
605 // -----------------------------------------------------------------------------
606 sal_Bool OFieldDescription::IsPrimaryKey() const
608 return m_bIsPrimaryKey;
610 // -----------------------------------------------------------------------------
611 sal_Bool OFieldDescription::IsCurrency() const
613 return m_bIsCurrency;
615 // -----------------------------------------------------------------------------
616 sal_Bool OFieldDescription::IsNullable() const
618 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ISNULLABLE) )
619 return ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_ISNULLABLE)) == ::com::sun::star::sdbc::ColumnValue::NULLABLE;
620 else
621 return m_nIsNullable == ::com::sun::star::sdbc::ColumnValue::NULLABLE;
623 // -----------------------------------------------------------------------------
624 void OFieldDescription::SetTypeName(const ::rtl::OUString& _sTypeName)
628 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_TYPENAME) )
629 m_xDest->setPropertyValue(PROPERTY_TYPENAME,makeAny(_sTypeName));
630 else
631 m_sTypeName = _sTypeName;
633 catch( const Exception& )
635 DBG_UNHANDLED_EXCEPTION();
638 // -----------------------------------------------------------------------------
639 void OFieldDescription::copyColumnSettingsTo(const Reference< XPropertySet >& _rxColumn)
641 if ( _rxColumn.is() )
643 Reference<XPropertySetInfo> xInfo = _rxColumn->getPropertySetInfo();
645 if ( GetFormatKey() != NumberFormat::ALL && xInfo->hasPropertyByName(PROPERTY_FORMATKEY) )
646 _rxColumn->setPropertyValue(PROPERTY_FORMATKEY,makeAny(GetFormatKey()));
647 if ( GetHorJustify() != SVX_HOR_JUSTIFY_STANDARD && xInfo->hasPropertyByName(PROPERTY_ALIGN) )
648 _rxColumn->setPropertyValue(PROPERTY_ALIGN,makeAny(dbaui::mapTextAllign(GetHorJustify())));
649 if ( GetDescription().getLength() && xInfo->hasPropertyByName(PROPERTY_HELPTEXT) )
650 _rxColumn->setPropertyValue(PROPERTY_HELPTEXT,makeAny(GetDescription()));
651 if ( GetControlDefault().hasValue() && xInfo->hasPropertyByName(PROPERTY_CONTROLDEFAULT) )
652 _rxColumn->setPropertyValue(PROPERTY_CONTROLDEFAULT,GetControlDefault());
654 if(xInfo->hasPropertyByName(PROPERTY_RELATIVEPOSITION))
655 _rxColumn->setPropertyValue(PROPERTY_RELATIVEPOSITION,m_aRelativePosition);
656 if(xInfo->hasPropertyByName(PROPERTY_WIDTH))
657 _rxColumn->setPropertyValue(PROPERTY_WIDTH,m_aWidth);
658 if(xInfo->hasPropertyByName(PROPERTY_HIDDEN))
659 _rxColumn->setPropertyValue(PROPERTY_HIDDEN,makeAny(m_bHidden));
662 // -----------------------------------------------------------------------------