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