1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbui.hxx"
26 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
27 #include "FieldDescriptions.hxx"
28 #endif
29 #ifndef _TOOLS_DEBUG_HXX
30 #include <tools/debug.hxx>
31 #endif
32 #ifndef TOOLS_DIAGNOSE_EX_H
33 #include <tools/diagnose_ex.h>
34 #endif
35 #ifndef _DBU_TBL_HRC_
36 #include "dbu_tbl.hrc"
37 #endif
38 #ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_
39 #include <com/sun/star/sdbc/ColumnValue.hpp>
40 #endif
41 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
42 #include "dbustrings.hrc"
43 #endif
44 #ifndef _COMPHELPER_TYPES_HXX_
45 #include <comphelper/types.hxx>
46 #endif
47 #ifndef _COMPHELPER_EXTRACT_HXX_
48 #include <comphelper/extract.hxx>
49 #endif
50 #ifndef DBAUI_TOOLS_HXX
51 #include "UITools.hxx"
52 #endif
53 #ifndef _COM_SUN_STAR_UTIL_NUMBERFORMAT_HPP_
54 #include <com/sun/star/util/NumberFormat.hpp>
55 #endif
56 
57 #define DEFAULT_VARCHAR_PRECSION	50
58 #define DEFAULT_OTHER_PRECSION		16
59 #define DEFAULT_NUMERIC_PRECSION	5
60 #define DEFAULT_NUMERIC_SCALE		0
61 
62 
63 using namespace dbaui;
64 using namespace ::com::sun::star::sdbc;
65 using namespace ::com::sun::star::uno;
66 using namespace ::com::sun::star::beans;
67 using namespace ::com::sun::star::util;
68 
69 //========================================================================
70 // class OFieldDescription
71 //========================================================================
DBG_NAME(OFieldDescription)72 DBG_NAME(OFieldDescription)
73 //------------------------------------------------------------------------------
74 OFieldDescription::OFieldDescription()
75     :m_pType()
76 	,m_nType(DataType::VARCHAR)
77 	,m_nPrecision(0)
78 	,m_nScale(0)
79 	,m_nIsNullable(ColumnValue::NULLABLE)
80     ,m_nFormatKey(0)
81 	,m_eHorJustify(SVX_HOR_JUSTIFY_STANDARD)
82 	,m_bIsAutoIncrement(sal_False)
83     ,m_bIsPrimaryKey(sal_False)
84 	,m_bIsCurrency(sal_False)
85 	,m_bHidden(sal_False)
86 {
87 	DBG_CTOR(OFieldDescription,NULL);
88 }
89 //------------------------------------------------------------------------------
OFieldDescription(const OFieldDescription & rDescr)90 OFieldDescription::OFieldDescription( const OFieldDescription& rDescr )
91     :m_aDefaultValue(rDescr.m_aDefaultValue)
92     ,m_aControlDefault(rDescr.m_aControlDefault)
93     ,m_aWidth(rDescr.m_aWidth)
94     ,m_aRelativePosition(rDescr.m_aRelativePosition)
95     ,m_pType(rDescr.m_pType)
96     ,m_xDest(rDescr.m_xDest)
97     ,m_xDestInfo(rDescr.m_xDestInfo)
98     ,m_sName(rDescr.m_sName)
99     ,m_sTypeName(rDescr.m_sTypeName)
100     ,m_sDescription(rDescr.m_sDescription)
101     ,m_sAutoIncrementValue(rDescr.m_sAutoIncrementValue)
102     ,m_nType(rDescr.m_nType)
103     ,m_nPrecision(rDescr.m_nPrecision)
104     ,m_nScale(rDescr.m_nScale)
105     ,m_nIsNullable(rDescr.m_nIsNullable)
106     ,m_nFormatKey(rDescr.m_nFormatKey)
107     ,m_eHorJustify(rDescr.m_eHorJustify)
108     ,m_bIsAutoIncrement(rDescr.m_bIsAutoIncrement)
109     ,m_bIsPrimaryKey(rDescr.m_bIsPrimaryKey)
110     ,m_bIsCurrency(rDescr.m_bIsCurrency)
111     ,m_bHidden(rDescr.m_bHidden)
112 {
113     DBG_CTOR(OFieldDescription,NULL);
114 }
115 
116 //------------------------------------------------------------------------------
~OFieldDescription()117 OFieldDescription::~OFieldDescription()
118 {
119 	DBG_DTOR(OFieldDescription,NULL);
120 }
121 //------------------------------------------------------------------------------
OFieldDescription(const Reference<XPropertySet> & xAffectedCol,sal_Bool _bUseAsDest)122 OFieldDescription::OFieldDescription(const Reference< XPropertySet >& xAffectedCol,sal_Bool _bUseAsDest)
123     :m_pType()
124 	,m_nType(DataType::VARCHAR)
125 	,m_nPrecision(0)
126 	,m_nScale(0)
127 	,m_nIsNullable(ColumnValue::NULLABLE)
128 	,m_nFormatKey(0)
129 	,m_eHorJustify(SVX_HOR_JUSTIFY_STANDARD)
130 	,m_bIsAutoIncrement(sal_False)
131     ,m_bIsPrimaryKey(sal_False)
132     ,m_bIsCurrency(sal_False)
133     ,m_bHidden(sal_False)
134 {
135 	DBG_CTOR(OFieldDescription,NULL);
136 	OSL_ENSURE(xAffectedCol.is(),"PropetySet can notbe null!");
137 	if ( xAffectedCol.is() )
138 	{
139 		if ( _bUseAsDest )
140 		{
141 			m_xDest = xAffectedCol;
142 			m_xDestInfo = xAffectedCol->getPropertySetInfo();;
143 		}
144 		else
145 		{
146 			try
147 			{
148 				Reference<XPropertySetInfo> xPropSetInfo = xAffectedCol->getPropertySetInfo();
149 				if(xPropSetInfo->hasPropertyByName(PROPERTY_NAME))
150 					SetName(::comphelper::getString(xAffectedCol->getPropertyValue(PROPERTY_NAME)));
151 				if(xPropSetInfo->hasPropertyByName(PROPERTY_DESCRIPTION))
152 					SetDescription(::comphelper::getString(xAffectedCol->getPropertyValue(PROPERTY_DESCRIPTION)));
153                 if(xPropSetInfo->hasPropertyByName(PROPERTY_HELPTEXT))
154                 {
155                     ::rtl::OUString sHelpText;
156                     xAffectedCol->getPropertyValue(PROPERTY_HELPTEXT) >>= sHelpText;
157 					SetHelpText(sHelpText);
158                 }
159 				if(xPropSetInfo->hasPropertyByName(PROPERTY_DEFAULTVALUE))
160 					SetDefaultValue( xAffectedCol->getPropertyValue(PROPERTY_DEFAULTVALUE) );
161 
162 				if(xPropSetInfo->hasPropertyByName(PROPERTY_CONTROLDEFAULT))
163 					SetControlDefault( xAffectedCol->getPropertyValue(PROPERTY_CONTROLDEFAULT) );
164 
165 				if(xPropSetInfo->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION))
166 					SetAutoIncrementValue(::comphelper::getString(xAffectedCol->getPropertyValue(PROPERTY_AUTOINCREMENTCREATION)));
167 				if(xPropSetInfo->hasPropertyByName(PROPERTY_TYPE))
168 					SetTypeValue(::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_TYPE)));
169                 if (xPropSetInfo->hasPropertyByName(PROPERTY_TYPENAME))
170 					SetTypeName(::comphelper::getString(xAffectedCol->getPropertyValue(PROPERTY_TYPENAME)));
171 				if(xPropSetInfo->hasPropertyByName(PROPERTY_PRECISION))
172 					SetPrecision(::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_PRECISION)));
173 				if(xPropSetInfo->hasPropertyByName(PROPERTY_SCALE))
174 					SetScale(::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_SCALE)));
175 				if(xPropSetInfo->hasPropertyByName(PROPERTY_ISNULLABLE))
176 					SetIsNullable(::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_ISNULLABLE)));
177 				if(xPropSetInfo->hasPropertyByName(PROPERTY_FORMATKEY))
178                 {
179                     const Any aValue = xAffectedCol->getPropertyValue(PROPERTY_FORMATKEY);
180                     if ( aValue.hasValue() )
181 					    SetFormatKey(::comphelper::getINT32(aValue));
182                 }
183 				if(xPropSetInfo->hasPropertyByName(PROPERTY_RELATIVEPOSITION))
184 					m_aRelativePosition = xAffectedCol->getPropertyValue(PROPERTY_RELATIVEPOSITION);
185 				if(xPropSetInfo->hasPropertyByName(PROPERTY_WIDTH))
186 					m_aWidth = xAffectedCol->getPropertyValue(PROPERTY_WIDTH);
187 				if(xPropSetInfo->hasPropertyByName(PROPERTY_HIDDEN))
188 					xAffectedCol->getPropertyValue(PROPERTY_HIDDEN) >>= m_bHidden;
189 				if(xPropSetInfo->hasPropertyByName(PROPERTY_ALIGN))
190                 {
191                     const Any aValue = xAffectedCol->getPropertyValue(PROPERTY_ALIGN);
192                     if ( aValue.hasValue() )
193 					    SetHorJustify( ::dbaui::mapTextJustify(::comphelper::getINT32(aValue)));
194                 }
195 				if(xPropSetInfo->hasPropertyByName(PROPERTY_ISAUTOINCREMENT))
196 					SetAutoIncrement(::cppu::any2bool(xAffectedCol->getPropertyValue(PROPERTY_ISAUTOINCREMENT)));
197 			}
198 			catch(const Exception&)
199 			{
200                 DBG_UNHANDLED_EXCEPTION();
201 			}
202 		}
203 	}
204 }
205 // -----------------------------------------------------------------------------
FillFromTypeInfo(const TOTypeInfoSP & _pType,sal_Bool _bForce,sal_Bool _bReset)206 void OFieldDescription::FillFromTypeInfo(const TOTypeInfoSP& _pType,sal_Bool _bForce,sal_Bool _bReset)
207 {
208 	TOTypeInfoSP pOldType = getTypeInfo();
209 	if ( _pType != pOldType )
210 	{
211 		// reset type depending information
212 		if ( _bReset )
213 		{
214 			SetFormatKey(0);
215 			SetControlDefault(Any());
216 		}
217 
218 		sal_Bool bForce = _bForce || pOldType.get() == NULL || pOldType->nType != _pType->nType;
219 		switch ( _pType->nType )
220 		{
221 			case DataType::CHAR:
222 			case DataType::VARCHAR:
223 				if ( bForce )
224 				{
225 					sal_Int32 nPrec = DEFAULT_VARCHAR_PRECSION;
226 					if ( GetPrecision() )
227 						nPrec = GetPrecision();
228 					SetPrecision(::std::min<sal_Int32>(nPrec,_pType->nPrecision));
229 				}
230 				break;
231             case DataType::TIMESTAMP:
232                 if ( bForce && _pType->nMaximumScale)
233 				{
234 					SetScale(::std::min<sal_Int32>(GetScale() ? GetScale() : DEFAULT_NUMERIC_SCALE,_pType->nMaximumScale));
235 				}
236                 break;
237 			default:
238 				if ( bForce )
239 				{
240 					sal_Int32 nPrec = DEFAULT_OTHER_PRECSION;
241 					switch ( _pType->nType )
242 					{
243 						case DataType::BIT:
244 						case DataType::BLOB:
245 						case DataType::CLOB:
246 							nPrec = _pType->nPrecision;
247 							break;
248 						default:
249 							if ( GetPrecision() )
250 								nPrec = GetPrecision();
251 							break;
252 					}
253 
254 					if ( _pType->nPrecision )
255 						SetPrecision(::std::min<sal_Int32>(nPrec ? nPrec : DEFAULT_NUMERIC_PRECSION,_pType->nPrecision));
256 					if ( _pType->nMaximumScale )
257 						SetScale(::std::min<sal_Int32>(GetScale() ? GetScale() : DEFAULT_NUMERIC_SCALE,_pType->nMaximumScale));
258 				}
259 		}
260 		if ( !_pType->aCreateParams.getLength() )
261 		{
262 			SetPrecision(_pType->nPrecision);
263 			SetScale(_pType->nMinimumScale);
264 		}
265 		if ( !_pType->bNullable && IsNullable() )
266 			SetIsNullable(ColumnValue::NO_NULLS);
267 		if ( !_pType->bAutoIncrement && IsAutoIncrement() )
268 			SetAutoIncrement(sal_False);
269 		SetCurrency( _pType->bCurrency );
270 		SetType(_pType);
271 		SetTypeName(_pType->aTypeName);
272 	}
273 }
274 // -----------------------------------------------------------------------------
SetName(const::rtl::OUString & _rName)275 void OFieldDescription::SetName(const ::rtl::OUString& _rName)
276 {
277 	try
278 	{
279 		if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_NAME) )
280 			m_xDest->setPropertyValue(PROPERTY_NAME,makeAny(_rName));
281 		else
282 			m_sName = _rName;
283 	}
284 	catch(const Exception& )
285 	{
286         DBG_UNHANDLED_EXCEPTION();
287 	}
288 }
289 // -----------------------------------------------------------------------------
SetHelpText(const::rtl::OUString & _sHelpText)290 void OFieldDescription::SetHelpText(const ::rtl::OUString& _sHelpText)
291 {
292     try
293 	{
294 		if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_HELPTEXT) )
295 			m_xDest->setPropertyValue(PROPERTY_HELPTEXT,makeAny(_sHelpText));
296 		else
297 			m_sHelpText = _sHelpText;
298 	}
299 	catch(const Exception& )
300 	{
301         DBG_UNHANDLED_EXCEPTION();
302 	}
303 }
304 // -----------------------------------------------------------------------------
SetDescription(const::rtl::OUString & _rDescription)305 void OFieldDescription::SetDescription(const ::rtl::OUString& _rDescription)
306 {
307 	try
308 	{
309 		if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_DESCRIPTION) )
310 			m_xDest->setPropertyValue(PROPERTY_DESCRIPTION,makeAny(_rDescription));
311 		else
312 			m_sDescription = _rDescription;
313 	}
314 	catch(const Exception& )
315 	{
316         DBG_UNHANDLED_EXCEPTION();
317 	}
318 }
319 // -----------------------------------------------------------------------------
SetDefaultValue(const Any & _rDefaultValue)320 void OFieldDescription::SetDefaultValue(const Any& _rDefaultValue)
321 {
322 	try
323 	{
324 		if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_DEFAULTVALUE) )
325 			m_xDest->setPropertyValue(PROPERTY_DEFAULTVALUE,makeAny(_rDefaultValue));
326 		else
327 			m_aDefaultValue = _rDefaultValue;
328 	}
329 	catch( const Exception& )
330 	{
331         DBG_UNHANDLED_EXCEPTION();
332 	}
333 }
334 // -----------------------------------------------------------------------------
SetControlDefault(const Any & _rControlDefault)335 void OFieldDescription::SetControlDefault(const Any& _rControlDefault)
336 {
337 	try
338 	{
339 		if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_CONTROLDEFAULT) )
340 			m_xDest->setPropertyValue(PROPERTY_CONTROLDEFAULT,makeAny(_rControlDefault));
341 		else
342 			m_aControlDefault = _rControlDefault;
343 	}
344 	catch( const Exception& )
345 	{
346         DBG_UNHANDLED_EXCEPTION();
347 	}
348 }
349 // -----------------------------------------------------------------------------
SetAutoIncrementValue(const::rtl::OUString & _sAutoIncValue)350 void OFieldDescription::SetAutoIncrementValue(const ::rtl::OUString& _sAutoIncValue)
351 {
352 	try
353 	{
354 		if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION) )
355 			m_xDest->setPropertyValue(PROPERTY_AUTOINCREMENTCREATION,makeAny(_sAutoIncValue));
356 		else
357 			m_sAutoIncrementValue = _sAutoIncValue;
358 	}
359 	catch( const Exception& )
360 	{
361         DBG_UNHANDLED_EXCEPTION();
362 	}
363 }
364 // -----------------------------------------------------------------------------
SetType(TOTypeInfoSP _pType)365 void OFieldDescription::SetType(TOTypeInfoSP _pType)
366 {
367 	m_pType = _pType;
368 	if ( m_pType.get() )
369 	{
370 		try
371 		{
372 			if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_TYPE) )
373 				m_xDest->setPropertyValue(PROPERTY_TYPE,makeAny(m_pType->nType));
374 			else
375 				m_nType = m_pType->nType;
376 		}
377 	    catch( const Exception& )
378 	    {
379             DBG_UNHANDLED_EXCEPTION();
380 	    }
381 	}
382 }
383 // -----------------------------------------------------------------------------
SetTypeValue(sal_Int32 _nType)384 void OFieldDescription::SetTypeValue(sal_Int32 _nType)
385 {
386 	try
387 	{
388 		if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_TYPE) )
389 			m_xDest->setPropertyValue(PROPERTY_TYPE,makeAny(_nType));
390 		else
391 		{
392 			m_nType = _nType;
393 			OSL_ENSURE(!m_pType.get(),"Invalid call here!");
394 		}
395 	}
396 	catch( const Exception& )
397 	{
398         DBG_UNHANDLED_EXCEPTION();
399 	}
400 }
401 // -----------------------------------------------------------------------------
SetPrecision(const sal_Int32 & _rPrecision)402 void OFieldDescription::SetPrecision(const sal_Int32& _rPrecision)
403 {
404 	try
405 	{
406 		if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_PRECISION) )
407 			m_xDest->setPropertyValue(PROPERTY_PRECISION,makeAny(_rPrecision));
408 		else
409 			m_nPrecision = _rPrecision;
410 	}
411 	catch( const Exception& )
412 	{
413         DBG_UNHANDLED_EXCEPTION();
414 	}
415 }
416 // -----------------------------------------------------------------------------
SetScale(const sal_Int32 & _rScale)417 void OFieldDescription::SetScale(const sal_Int32& _rScale)
418 {
419 	try
420 	{
421 		if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_SCALE) )
422 			m_xDest->setPropertyValue(PROPERTY_SCALE,makeAny(_rScale));
423 		else
424 			m_nScale = _rScale;
425 	}
426 	catch( const Exception& )
427 	{
428         DBG_UNHANDLED_EXCEPTION();
429 	}
430 }
431 // -----------------------------------------------------------------------------
SetIsNullable(const sal_Int32 & _rIsNullable)432 void OFieldDescription::SetIsNullable(const sal_Int32& _rIsNullable)
433 {
434 	try
435 	{
436 		if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ISNULLABLE) )
437 			m_xDest->setPropertyValue(PROPERTY_ISNULLABLE,makeAny(_rIsNullable));
438 		else
439 			m_nIsNullable = _rIsNullable;
440 	}
441 	catch( const Exception& )
442 	{
443         DBG_UNHANDLED_EXCEPTION();
444 	}
445 }
446 // -----------------------------------------------------------------------------
SetFormatKey(const sal_Int32 & _rFormatKey)447 void OFieldDescription::SetFormatKey(const sal_Int32& _rFormatKey)
448 {
449 	try
450 	{
451 		if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_FORMATKEY) )
452 			m_xDest->setPropertyValue(PROPERTY_FORMATKEY,makeAny(_rFormatKey));
453 		else
454 			m_nFormatKey = _rFormatKey;
455 	}
456 	catch( const Exception& )
457 	{
458         DBG_UNHANDLED_EXCEPTION();
459 	}
460 }
461 // -----------------------------------------------------------------------------
SetHorJustify(const SvxCellHorJustify & _rHorJustify)462 void OFieldDescription::SetHorJustify(const SvxCellHorJustify& _rHorJustify)
463 {
464 	try
465 	{
466 		if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ALIGN) )
467 			m_xDest->setPropertyValue(PROPERTY_ALIGN,makeAny( dbaui::mapTextAllign(_rHorJustify)));
468 		else
469 			m_eHorJustify = _rHorJustify;
470 	}
471 	catch( const Exception& )
472 	{
473         DBG_UNHANDLED_EXCEPTION();
474 	}
475 }
476 // -----------------------------------------------------------------------------
SetAutoIncrement(sal_Bool _bAuto)477 void OFieldDescription::SetAutoIncrement(sal_Bool _bAuto)
478 {
479 	try
480 	{
481 		if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ISAUTOINCREMENT) )
482 			m_xDest->setPropertyValue(PROPERTY_ISAUTOINCREMENT,makeAny(_bAuto));
483 		else
484 			m_bIsAutoIncrement = _bAuto;
485 	}
486 	catch( const Exception& )
487 	{
488         DBG_UNHANDLED_EXCEPTION();
489 	}
490 }
491 // -----------------------------------------------------------------------------
SetPrimaryKey(sal_Bool _bPKey)492 void OFieldDescription::SetPrimaryKey(sal_Bool _bPKey)
493 {
494 	m_bIsPrimaryKey = _bPKey;
495 	if ( _bPKey )
496 		SetIsNullable(::com::sun::star::sdbc::ColumnValue::NO_NULLS);
497 }
498 // -----------------------------------------------------------------------------
SetCurrency(sal_Bool _bIsCurrency)499 void OFieldDescription::SetCurrency(sal_Bool _bIsCurrency)
500 {
501 	m_bIsCurrency = _bIsCurrency;
502 }
503 // -----------------------------------------------------------------------------
504 
GetName() const505 ::rtl::OUString				OFieldDescription::GetName()				const
506 {
507 	if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_NAME) )
508 		return ::comphelper::getString(m_xDest->getPropertyValue(PROPERTY_NAME));
509 	else
510 		return m_sName;
511 }
512 // -----------------------------------------------------------------------------
GetDescription() const513 ::rtl::OUString				OFieldDescription::GetDescription()			const
514 {
515 	if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_DESCRIPTION) )
516 		return ::comphelper::getString(m_xDest->getPropertyValue(PROPERTY_DESCRIPTION));
517 	else
518 		return m_sDescription;
519 }
520 // -----------------------------------------------------------------------------
GetHelpText() const521 ::rtl::OUString				OFieldDescription::GetHelpText()			const
522 {
523 	if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_HELPTEXT) )
524 		return ::comphelper::getString(m_xDest->getPropertyValue(PROPERTY_HELPTEXT));
525 	else
526 		return m_sHelpText;
527 }
528 // -----------------------------------------------------------------------------
GetControlDefault() const529 ::com::sun::star::uno::Any	OFieldDescription::GetControlDefault()		const
530 {
531 	if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_CONTROLDEFAULT) )
532 		return m_xDest->getPropertyValue(PROPERTY_CONTROLDEFAULT);
533 	else
534 		return m_aControlDefault;
535 }
536 // -----------------------------------------------------------------------------
GetAutoIncrementValue() const537 ::rtl::OUString				OFieldDescription::GetAutoIncrementValue()	const
538 {
539 	if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION) )
540 		return ::comphelper::getString(m_xDest->getPropertyValue(PROPERTY_AUTOINCREMENTCREATION));
541 	else
542 		return m_sAutoIncrementValue;
543 }
544 // -----------------------------------------------------------------------------
GetType() const545 sal_Int32					OFieldDescription::GetType()				const
546 {
547 	if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_TYPE) )
548 		return ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_TYPE));
549 	else
550 		return m_pType.get() ? m_pType->nType : m_nType;
551 }
552 // -----------------------------------------------------------------------------
GetTypeName() const553 ::rtl::OUString             OFieldDescription::GetTypeName()			const
554 {
555 	if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_TYPENAME) )
556 		return ::comphelper::getString(m_xDest->getPropertyValue(PROPERTY_TYPENAME));
557 	else
558 		return m_pType.get() ? m_pType->aTypeName : m_sTypeName;
559 }
560 // -----------------------------------------------------------------------------
GetPrecision() const561 sal_Int32					OFieldDescription::GetPrecision()			const
562 {
563     sal_Int32 nPrec = m_nPrecision;
564     if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_PRECISION) )
565 		nPrec = ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_PRECISION));
566 
567     TOTypeInfoSP pTypeInfo = getTypeInfo();
568     if ( pTypeInfo )
569     {
570 	    switch ( pTypeInfo->nType )
571 	    {
572             case DataType::TINYINT:
573             case DataType::SMALLINT:
574 		    case DataType::INTEGER:
575             case DataType::BIGINT:
576                 if ( !nPrec )
577                     nPrec = pTypeInfo->nPrecision;
578                 break;
579         } // switch ( pTypeInfo->nType )
580     }
581 
582 	return nPrec;
583 }
584 // -----------------------------------------------------------------------------
GetScale() const585 sal_Int32					OFieldDescription::GetScale()				const
586 {
587 	if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_SCALE) )
588 		return ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_SCALE));
589 	else
590 		return m_nScale;
591 }
592 // -----------------------------------------------------------------------------
GetIsNullable() const593 sal_Int32					OFieldDescription::GetIsNullable()			const
594 {
595 	if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ISNULLABLE) )
596 		return ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_ISNULLABLE));
597 	else
598 		return m_nIsNullable;
599 }
600 // -----------------------------------------------------------------------------
GetFormatKey() const601 sal_Int32					OFieldDescription::GetFormatKey()			const
602 {
603 	if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_FORMATKEY) )
604 		return ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_FORMATKEY));
605 	else
606 		return m_nFormatKey;
607 }
608 // -----------------------------------------------------------------------------
GetHorJustify() const609 SvxCellHorJustify			OFieldDescription::GetHorJustify()			const
610 {
611 	if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ALIGN) )
612 		return ::dbaui::mapTextJustify(::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_ALIGN)));
613 	else
614 		return m_eHorJustify;
615 }
616 // -----------------------------------------------------------------------------
getTypeInfo() const617 TOTypeInfoSP				OFieldDescription::getTypeInfo()			const
618 {
619 	return m_pType;
620 }
621 // -----------------------------------------------------------------------------
getSpecialTypeInfo() const622 TOTypeInfoSP				OFieldDescription::getSpecialTypeInfo()	const
623 {
624     TOTypeInfoSP pSpecialType( new OTypeInfo() );
625     *pSpecialType = *m_pType;
626     pSpecialType->nPrecision = GetPrecision();
627     pSpecialType->nMaximumScale = static_cast<sal_Int16>(GetScale());
628     pSpecialType->bAutoIncrement = IsAutoIncrement(); // http://dba.openoffice.org/issues/show_bug.cgi?id=115398 fixed by ludob
629     return pSpecialType;
630 }
631 // -----------------------------------------------------------------------------
IsAutoIncrement() const632 sal_Bool					OFieldDescription::IsAutoIncrement()		const
633 {
634 	if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ISAUTOINCREMENT) )
635 		return ::cppu::any2bool(m_xDest->getPropertyValue(PROPERTY_ISAUTOINCREMENT));
636 	else
637 		return m_bIsAutoIncrement;
638 }
639 // -----------------------------------------------------------------------------
IsPrimaryKey() const640 sal_Bool					OFieldDescription::IsPrimaryKey()			const
641 {
642 	return m_bIsPrimaryKey;
643 }
644 // -----------------------------------------------------------------------------
IsCurrency() const645 sal_Bool					OFieldDescription::IsCurrency()				const
646 {
647 		return m_bIsCurrency;
648 }
649 // -----------------------------------------------------------------------------
IsNullable() const650 sal_Bool					OFieldDescription::IsNullable()				const
651 {
652 	if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ISNULLABLE) )
653 		return ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_ISNULLABLE)) == ::com::sun::star::sdbc::ColumnValue::NULLABLE;
654 	else
655 		return m_nIsNullable == ::com::sun::star::sdbc::ColumnValue::NULLABLE;
656 }
657 // -----------------------------------------------------------------------------
SetTypeName(const::rtl::OUString & _sTypeName)658 void OFieldDescription::SetTypeName(const ::rtl::OUString& _sTypeName)
659 {
660 	try
661 	{
662 		if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_TYPENAME) )
663 			m_xDest->setPropertyValue(PROPERTY_TYPENAME,makeAny(_sTypeName));
664 		else
665 			m_sTypeName = _sTypeName;
666 	}
667 	catch( const Exception& )
668 	{
669         DBG_UNHANDLED_EXCEPTION();
670 	}
671 }
672 // -----------------------------------------------------------------------------
copyColumnSettingsTo(const Reference<XPropertySet> & _rxColumn)673 void OFieldDescription::copyColumnSettingsTo(const Reference< XPropertySet >& _rxColumn)
674 {
675 	if ( _rxColumn.is() )
676 	{
677 		Reference<XPropertySetInfo> xInfo = _rxColumn->getPropertySetInfo();
678 
679 		if ( GetFormatKey() != NumberFormat::ALL && xInfo->hasPropertyByName(PROPERTY_FORMATKEY) )
680 			_rxColumn->setPropertyValue(PROPERTY_FORMATKEY,makeAny(GetFormatKey()));
681 		if ( GetHorJustify() != SVX_HOR_JUSTIFY_STANDARD && xInfo->hasPropertyByName(PROPERTY_ALIGN) )
682 			_rxColumn->setPropertyValue(PROPERTY_ALIGN,makeAny(dbaui::mapTextAllign(GetHorJustify())));
683 		if ( GetHelpText().getLength() && xInfo->hasPropertyByName(PROPERTY_HELPTEXT) )
684 			_rxColumn->setPropertyValue(PROPERTY_HELPTEXT,makeAny(GetHelpText()));
685 		if ( GetControlDefault().hasValue() && xInfo->hasPropertyByName(PROPERTY_CONTROLDEFAULT) )
686 			_rxColumn->setPropertyValue(PROPERTY_CONTROLDEFAULT,GetControlDefault());
687 
688 		if(xInfo->hasPropertyByName(PROPERTY_RELATIVEPOSITION))
689 			_rxColumn->setPropertyValue(PROPERTY_RELATIVEPOSITION,m_aRelativePosition);
690 		if(xInfo->hasPropertyByName(PROPERTY_WIDTH))
691 			_rxColumn->setPropertyValue(PROPERTY_WIDTH,m_aWidth);
692 		if(xInfo->hasPropertyByName(PROPERTY_HIDDEN))
693 			_rxColumn->setPropertyValue(PROPERTY_HIDDEN,makeAny(m_bHidden));
694 	}
695 }
696 // -----------------------------------------------------------------------------
697