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 #include <FieldDescriptions.hxx>
21 #include <comphelper/diagnose_ex.hxx>
22 #include <strings.hxx>
23 #include <com/sun/star/sdbc/ColumnValue.hpp>
24 #include <comphelper/types.hxx>
25 #include <comphelper/extract.hxx>
26 #include <UITools.hxx>
27 #include <com/sun/star/util/NumberFormat.hpp>
28
29 #define DEFAULT_VARCHAR_PRECISION 100
30 #define DEFAULT_OTHER_PRECISION 16
31 #define DEFAULT_NUMERIC_PRECISION 5
32 #define DEFAULT_NUMERIC_SCALE 0
33
34 using namespace dbaui;
35 using namespace ::com::sun::star::sdbc;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::beans;
38 using namespace ::com::sun::star::util;
39
OFieldDescription()40 OFieldDescription::OFieldDescription()
41 :m_nType(DataType::VARCHAR)
42 ,m_nPrecision(0)
43 ,m_nScale(0)
44 ,m_nIsNullable(ColumnValue::NULLABLE)
45 ,m_nFormatKey(0)
46 ,m_eHorJustify(SvxCellHorJustify::Standard)
47 ,m_bIsAutoIncrement(false)
48 ,m_bIsPrimaryKey(false)
49 ,m_bIsCurrency(false)
50 ,m_bHidden(false)
51 {
52 }
53
OFieldDescription(const OFieldDescription & rDescr)54 OFieldDescription::OFieldDescription( const OFieldDescription& rDescr )
55 :m_aControlDefault(rDescr.m_aControlDefault)
56 ,m_aWidth(rDescr.m_aWidth)
57 ,m_aRelativePosition(rDescr.m_aRelativePosition)
58 ,m_pType(rDescr.m_pType)
59 ,m_xDest(rDescr.m_xDest)
60 ,m_xDestInfo(rDescr.m_xDestInfo)
61 ,m_sName(rDescr.m_sName)
62 ,m_sTypeName(rDescr.m_sTypeName)
63 ,m_sDescription(rDescr.m_sDescription)
64 ,m_sAutoIncrementValue(rDescr.m_sAutoIncrementValue)
65 ,m_nType(rDescr.m_nType)
66 ,m_nPrecision(rDescr.m_nPrecision)
67 ,m_nScale(rDescr.m_nScale)
68 ,m_nIsNullable(rDescr.m_nIsNullable)
69 ,m_nFormatKey(rDescr.m_nFormatKey)
70 ,m_eHorJustify(rDescr.m_eHorJustify)
71 ,m_bIsAutoIncrement(rDescr.m_bIsAutoIncrement)
72 ,m_bIsPrimaryKey(rDescr.m_bIsPrimaryKey)
73 ,m_bIsCurrency(rDescr.m_bIsCurrency)
74 ,m_bHidden(rDescr.m_bHidden)
75 {
76 }
77
~OFieldDescription()78 OFieldDescription::~OFieldDescription()
79 {
80 }
81
OFieldDescription(const Reference<XPropertySet> & xAffectedCol,bool _bUseAsDest)82 OFieldDescription::OFieldDescription(const Reference< XPropertySet >& xAffectedCol,bool _bUseAsDest)
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(SvxCellHorJustify::Standard)
89 ,m_bIsAutoIncrement(false)
90 ,m_bIsPrimaryKey(false)
91 ,m_bIsCurrency(false)
92 ,m_bHidden(false)
93 {
94 OSL_ENSURE(xAffectedCol.is(),"PropertySet can not be null!");
95 if ( !xAffectedCol.is() )
96 return;
97
98 if ( _bUseAsDest )
99 {
100 m_xDest = xAffectedCol;
101 m_xDestInfo = xAffectedCol->getPropertySetInfo();
102 }
103 else
104 {
105 try
106 {
107 Reference<XPropertySetInfo> xPropSetInfo = xAffectedCol->getPropertySetInfo();
108 if(xPropSetInfo->hasPropertyByName(PROPERTY_NAME))
109 SetName(::comphelper::getString(xAffectedCol->getPropertyValue(PROPERTY_NAME)));
110 if(xPropSetInfo->hasPropertyByName(PROPERTY_DESCRIPTION))
111 SetDescription(::comphelper::getString(xAffectedCol->getPropertyValue(PROPERTY_DESCRIPTION)));
112 if(xPropSetInfo->hasPropertyByName(PROPERTY_HELPTEXT))
113 {
114 OUString sHelpText;
115 xAffectedCol->getPropertyValue(PROPERTY_HELPTEXT) >>= sHelpText;
116 SetHelpText(sHelpText);
117 }
118 if(xPropSetInfo->hasPropertyByName(PROPERTY_DEFAULTVALUE))
119 SetDefaultValue( xAffectedCol->getPropertyValue(PROPERTY_DEFAULTVALUE) );
120
121 if(xPropSetInfo->hasPropertyByName(PROPERTY_CONTROLDEFAULT))
122 SetControlDefault( xAffectedCol->getPropertyValue(PROPERTY_CONTROLDEFAULT) );
123
124 if(xPropSetInfo->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION))
125 SetAutoIncrementValue(::comphelper::getString(xAffectedCol->getPropertyValue(PROPERTY_AUTOINCREMENTCREATION)));
126 if(xPropSetInfo->hasPropertyByName(PROPERTY_TYPE))
127 SetTypeValue(::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_TYPE)));
128 if (xPropSetInfo->hasPropertyByName(PROPERTY_TYPENAME))
129 SetTypeName(::comphelper::getString(xAffectedCol->getPropertyValue(PROPERTY_TYPENAME)));
130 if(xPropSetInfo->hasPropertyByName(PROPERTY_PRECISION))
131 SetPrecision(::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_PRECISION)));
132 if(xPropSetInfo->hasPropertyByName(PROPERTY_SCALE))
133 SetScale(::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_SCALE)));
134 if(xPropSetInfo->hasPropertyByName(PROPERTY_ISNULLABLE))
135 SetIsNullable(::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_ISNULLABLE)));
136 if(xPropSetInfo->hasPropertyByName(PROPERTY_FORMATKEY))
137 {
138 const Any aValue = xAffectedCol->getPropertyValue(PROPERTY_FORMATKEY);
139 if ( aValue.hasValue() )
140 SetFormatKey(::comphelper::getINT32(aValue));
141 }
142 if(xPropSetInfo->hasPropertyByName(PROPERTY_RELATIVEPOSITION))
143 m_aRelativePosition = xAffectedCol->getPropertyValue(PROPERTY_RELATIVEPOSITION);
144 if(xPropSetInfo->hasPropertyByName(PROPERTY_WIDTH))
145 m_aWidth = xAffectedCol->getPropertyValue(PROPERTY_WIDTH);
146 if(xPropSetInfo->hasPropertyByName(PROPERTY_HIDDEN))
147 xAffectedCol->getPropertyValue(PROPERTY_HIDDEN) >>= m_bHidden;
148 if(xPropSetInfo->hasPropertyByName(PROPERTY_ALIGN))
149 {
150 const Any aValue = xAffectedCol->getPropertyValue(PROPERTY_ALIGN);
151 if ( aValue.hasValue() )
152 SetHorJustify( ::dbaui::mapTextJustify(::comphelper::getINT32(aValue)));
153 }
154 if(xPropSetInfo->hasPropertyByName(PROPERTY_ISAUTOINCREMENT))
155 SetAutoIncrement(::cppu::any2bool(xAffectedCol->getPropertyValue(PROPERTY_ISAUTOINCREMENT)));
156 }
157 catch(const Exception&)
158 {
159 DBG_UNHANDLED_EXCEPTION("dbaccess");
160 }
161 }
162 }
163
FillFromTypeInfo(const TOTypeInfoSP & _pType,bool _bForce,bool _bReset)164 void OFieldDescription::FillFromTypeInfo(const TOTypeInfoSP& _pType,bool _bForce,bool _bReset)
165 {
166 TOTypeInfoSP pOldType = getTypeInfo();
167 if ( _pType == pOldType )
168 return;
169
170 // reset type depending information
171 if ( _bReset )
172 {
173 SetFormatKey(0);
174 SetControlDefault(Any());
175 }
176
177 bool bForce = _bForce || !pOldType || pOldType->nType != _pType->nType;
178 switch ( _pType->nType )
179 {
180 case DataType::CHAR:
181 case DataType::VARCHAR:
182 if ( bForce )
183 {
184 sal_Int32 nPrec = DEFAULT_VARCHAR_PRECISION;
185 if ( GetPrecision() )
186 nPrec = GetPrecision();
187 SetPrecision(std::min<sal_Int32>(nPrec,_pType->nPrecision));
188 }
189 break;
190 case DataType::TIME:
191 case DataType::TIME_WITH_TIMEZONE:
192 case DataType::TIMESTAMP:
193 case DataType::TIMESTAMP_WITH_TIMEZONE:
194 if ( bForce && _pType->nMaximumScale)
195 {
196 SetScale(std::min<sal_Int32>(GetScale() ? GetScale() : DEFAULT_NUMERIC_SCALE,_pType->nMaximumScale));
197 }
198 break;
199 default:
200 if ( bForce )
201 {
202 sal_Int32 nPrec = DEFAULT_OTHER_PRECISION;
203 switch ( _pType->nType )
204 {
205 case DataType::BIT:
206 case DataType::BLOB:
207 case DataType::CLOB:
208 nPrec = _pType->nPrecision;
209 break;
210 default:
211 if ( GetPrecision() )
212 nPrec = GetPrecision();
213 break;
214 }
215
216 if ( _pType->nPrecision )
217 SetPrecision(std::min<sal_Int32>(nPrec ? nPrec : DEFAULT_NUMERIC_PRECISION,_pType->nPrecision));
218 if ( _pType->nMaximumScale )
219 SetScale(std::min<sal_Int32>(GetScale() ? GetScale() : DEFAULT_NUMERIC_SCALE,_pType->nMaximumScale));
220 }
221 }
222 if ( _pType->aCreateParams.isEmpty() )
223 {
224 SetPrecision(_pType->nPrecision);
225 SetScale(_pType->nMinimumScale);
226 }
227 if ( !_pType->bNullable && IsNullable() )
228 SetIsNullable(ColumnValue::NO_NULLS);
229 if ( !_pType->bAutoIncrement && IsAutoIncrement() )
230 SetAutoIncrement(false);
231 SetCurrency( _pType->bCurrency );
232 SetType(_pType);
233 SetTypeName(_pType->aTypeName);
234 }
235
SetName(const OUString & _rName)236 void OFieldDescription::SetName(const OUString& _rName)
237 {
238 try
239 {
240 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_NAME) )
241 m_xDest->setPropertyValue(PROPERTY_NAME,Any(_rName));
242 else
243 m_sName = _rName;
244 }
245 catch(const Exception& )
246 {
247 DBG_UNHANDLED_EXCEPTION("dbaccess");
248 }
249 }
250
SetHelpText(const OUString & _sHelpText)251 void OFieldDescription::SetHelpText(const OUString& _sHelpText)
252 {
253 try
254 {
255 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_HELPTEXT) )
256 m_xDest->setPropertyValue(PROPERTY_HELPTEXT,Any(_sHelpText));
257 else
258 m_sHelpText = _sHelpText;
259 }
260 catch(const Exception& )
261 {
262 DBG_UNHANDLED_EXCEPTION("dbaccess");
263 }
264 }
265
SetDescription(const OUString & _rDescription)266 void OFieldDescription::SetDescription(const OUString& _rDescription)
267 {
268 try
269 {
270 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_DESCRIPTION) )
271 m_xDest->setPropertyValue(PROPERTY_DESCRIPTION,Any(_rDescription));
272 else
273 m_sDescription = _rDescription;
274 }
275 catch(const Exception& )
276 {
277 DBG_UNHANDLED_EXCEPTION("dbaccess");
278 }
279 }
280
SetDefaultValue(const Any & _rDefaultValue)281 void OFieldDescription::SetDefaultValue(const Any& _rDefaultValue)
282 {
283 try
284 {
285 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_DEFAULTVALUE) )
286 m_xDest->setPropertyValue(PROPERTY_DEFAULTVALUE, _rDefaultValue);
287 }
288 catch( const Exception& )
289 {
290 DBG_UNHANDLED_EXCEPTION("dbaccess");
291 }
292 }
293
SetControlDefault(const Any & _rControlDefault)294 void OFieldDescription::SetControlDefault(const Any& _rControlDefault)
295 {
296 try
297 {
298 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_CONTROLDEFAULT) )
299 m_xDest->setPropertyValue(PROPERTY_CONTROLDEFAULT, _rControlDefault);
300 else
301 m_aControlDefault = _rControlDefault;
302 }
303 catch( const Exception& )
304 {
305 DBG_UNHANDLED_EXCEPTION("dbaccess");
306 }
307 }
308
SetAutoIncrementValue(const OUString & _sAutoIncValue)309 void OFieldDescription::SetAutoIncrementValue(const OUString& _sAutoIncValue)
310 {
311 try
312 {
313 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION) )
314 m_xDest->setPropertyValue(PROPERTY_AUTOINCREMENTCREATION,Any(_sAutoIncValue));
315 else
316 m_sAutoIncrementValue = _sAutoIncValue;
317 }
318 catch( const Exception& )
319 {
320 DBG_UNHANDLED_EXCEPTION("dbaccess");
321 }
322 }
323
SetType(const TOTypeInfoSP & _pType)324 void OFieldDescription::SetType(const TOTypeInfoSP& _pType)
325 {
326 m_pType = _pType;
327 if ( !m_pType )
328 return;
329
330 try
331 {
332 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_TYPE) )
333 m_xDest->setPropertyValue(PROPERTY_TYPE,Any(m_pType->nType));
334 else
335 m_nType = m_pType->nType;
336 }
337 catch( const Exception& )
338 {
339 DBG_UNHANDLED_EXCEPTION("dbaccess");
340 }
341 }
342
SetTypeValue(sal_Int32 _nType)343 void OFieldDescription::SetTypeValue(sal_Int32 _nType)
344 {
345 try
346 {
347 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_TYPE) )
348 m_xDest->setPropertyValue(PROPERTY_TYPE,Any(_nType));
349 else
350 {
351 m_nType = _nType;
352 OSL_ENSURE(!m_pType,"Invalid call here!");
353 }
354 }
355 catch( const Exception& )
356 {
357 DBG_UNHANDLED_EXCEPTION("dbaccess");
358 }
359 }
360
SetPrecision(sal_Int32 _rPrecision)361 void OFieldDescription::SetPrecision(sal_Int32 _rPrecision)
362 {
363 try
364 {
365 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_PRECISION) )
366 m_xDest->setPropertyValue(PROPERTY_PRECISION,Any(_rPrecision));
367 else
368 m_nPrecision = _rPrecision;
369 }
370 catch( const Exception& )
371 {
372 DBG_UNHANDLED_EXCEPTION("dbaccess");
373 }
374 }
375
SetScale(sal_Int32 _rScale)376 void OFieldDescription::SetScale(sal_Int32 _rScale)
377 {
378 try
379 {
380 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_SCALE) )
381 m_xDest->setPropertyValue(PROPERTY_SCALE,Any(_rScale));
382 else
383 m_nScale = _rScale;
384 }
385 catch( const Exception& )
386 {
387 DBG_UNHANDLED_EXCEPTION("dbaccess");
388 }
389 }
390
SetIsNullable(sal_Int32 _rIsNullable)391 void OFieldDescription::SetIsNullable(sal_Int32 _rIsNullable)
392 {
393 try
394 {
395 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ISNULLABLE) )
396 m_xDest->setPropertyValue(PROPERTY_ISNULLABLE,Any(_rIsNullable));
397 else
398 m_nIsNullable = _rIsNullable;
399 }
400 catch( const Exception& )
401 {
402 DBG_UNHANDLED_EXCEPTION("dbaccess");
403 }
404 }
405
SetFormatKey(sal_Int32 _rFormatKey)406 void OFieldDescription::SetFormatKey(sal_Int32 _rFormatKey)
407 {
408 try
409 {
410 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_FORMATKEY) )
411 m_xDest->setPropertyValue(PROPERTY_FORMATKEY,Any(_rFormatKey));
412 else
413 m_nFormatKey = _rFormatKey;
414 }
415 catch( const Exception& )
416 {
417 DBG_UNHANDLED_EXCEPTION("dbaccess");
418 }
419 }
420
SetHorJustify(const SvxCellHorJustify & _rHorJustify)421 void OFieldDescription::SetHorJustify(const SvxCellHorJustify& _rHorJustify)
422 {
423 try
424 {
425 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ALIGN) )
426 m_xDest->setPropertyValue(PROPERTY_ALIGN,Any( dbaui::mapTextAlign(_rHorJustify)));
427 else
428 m_eHorJustify = _rHorJustify;
429 }
430 catch( const Exception& )
431 {
432 DBG_UNHANDLED_EXCEPTION("dbaccess");
433 }
434 }
435
SetAutoIncrement(bool _bAuto)436 void OFieldDescription::SetAutoIncrement(bool _bAuto)
437 {
438 try
439 {
440 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ISAUTOINCREMENT) )
441 m_xDest->setPropertyValue(PROPERTY_ISAUTOINCREMENT,Any(_bAuto));
442 else
443 m_bIsAutoIncrement = _bAuto;
444 }
445 catch( const Exception& )
446 {
447 DBG_UNHANDLED_EXCEPTION("dbaccess");
448 }
449 }
450
SetPrimaryKey(bool _bPKey)451 void OFieldDescription::SetPrimaryKey(bool _bPKey)
452 {
453 m_bIsPrimaryKey = _bPKey;
454 if ( _bPKey )
455 SetIsNullable(css::sdbc::ColumnValue::NO_NULLS);
456 }
457
SetCurrency(bool _bIsCurrency)458 void OFieldDescription::SetCurrency(bool _bIsCurrency)
459 {
460 m_bIsCurrency = _bIsCurrency;
461 }
462
GetName() const463 OUString OFieldDescription::GetName() const
464 {
465 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_NAME) )
466 return ::comphelper::getString(m_xDest->getPropertyValue(PROPERTY_NAME));
467 else
468 return m_sName;
469 }
470
GetDescription() const471 OUString OFieldDescription::GetDescription() const
472 {
473 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_DESCRIPTION) )
474 return ::comphelper::getString(m_xDest->getPropertyValue(PROPERTY_DESCRIPTION));
475 else
476 return m_sDescription;
477 }
478
GetHelpText() const479 OUString OFieldDescription::GetHelpText() const
480 {
481 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_HELPTEXT) )
482 return ::comphelper::getString(m_xDest->getPropertyValue(PROPERTY_HELPTEXT));
483 else
484 return m_sHelpText;
485 }
486
GetControlDefault() const487 css::uno::Any OFieldDescription::GetControlDefault() const
488 {
489 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_CONTROLDEFAULT) )
490 return m_xDest->getPropertyValue(PROPERTY_CONTROLDEFAULT);
491 else
492 return m_aControlDefault;
493 }
494
GetAutoIncrementValue() const495 OUString OFieldDescription::GetAutoIncrementValue() const
496 {
497 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION) )
498 return ::comphelper::getString(m_xDest->getPropertyValue(PROPERTY_AUTOINCREMENTCREATION));
499 else
500 return m_sAutoIncrementValue;
501 }
502
GetType() const503 sal_Int32 OFieldDescription::GetType() const
504 {
505 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_TYPE) )
506 return ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_TYPE));
507 else
508 return m_pType ? m_pType->nType : m_nType;
509 }
510
GetTypeName() const511 OUString OFieldDescription::GetTypeName() const
512 {
513 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_TYPENAME) )
514 return ::comphelper::getString(m_xDest->getPropertyValue(PROPERTY_TYPENAME));
515 else
516 return m_pType ? m_pType->aTypeName : m_sTypeName;
517 }
518
GetPrecision() const519 sal_Int32 OFieldDescription::GetPrecision() const
520 {
521 sal_Int32 nPrec = m_nPrecision;
522 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_PRECISION) )
523 nPrec = ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_PRECISION));
524
525 TOTypeInfoSP pTypeInfo = getTypeInfo();
526 if ( pTypeInfo )
527 {
528 switch ( pTypeInfo->nType )
529 {
530 case DataType::TINYINT:
531 case DataType::SMALLINT:
532 case DataType::INTEGER:
533 case DataType::BIGINT:
534 if ( !nPrec )
535 nPrec = pTypeInfo->nPrecision;
536 break;
537 }
538 }
539
540 return nPrec;
541 }
542
GetScale() const543 sal_Int32 OFieldDescription::GetScale() const
544 {
545 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_SCALE) )
546 return ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_SCALE));
547 else
548 return m_nScale;
549 }
550
GetIsNullable() const551 sal_Int32 OFieldDescription::GetIsNullable() const
552 {
553 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ISNULLABLE) )
554 return ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_ISNULLABLE));
555 else
556 return m_nIsNullable;
557 }
558
GetFormatKey() const559 sal_Int32 OFieldDescription::GetFormatKey() const
560 {
561 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_FORMATKEY) )
562 return ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_FORMATKEY));
563 else
564 return m_nFormatKey;
565 }
566
GetHorJustify() const567 SvxCellHorJustify OFieldDescription::GetHorJustify() const
568 {
569 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ALIGN) )
570 return ::dbaui::mapTextJustify(::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_ALIGN)));
571 else
572 return m_eHorJustify;
573 }
574
575
getSpecialTypeInfo() const576 TOTypeInfoSP OFieldDescription::getSpecialTypeInfo() const
577 {
578 TOTypeInfoSP pSpecialType = std::make_shared<OTypeInfo>();
579 *pSpecialType = *m_pType;
580 pSpecialType->nPrecision = GetPrecision();
581 pSpecialType->nMaximumScale = static_cast<sal_Int16>(GetScale());
582 pSpecialType->bAutoIncrement = IsAutoIncrement(); // http://dba.openoffice.org/issues/show_bug.cgi?id=115398 fixed by ludob
583 return pSpecialType;
584 }
585
IsAutoIncrement() const586 bool OFieldDescription::IsAutoIncrement() const
587 {
588 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ISAUTOINCREMENT) )
589 return ::cppu::any2bool(m_xDest->getPropertyValue(PROPERTY_ISAUTOINCREMENT));
590 else
591 return m_bIsAutoIncrement;
592 }
593
594
IsNullable() const595 bool OFieldDescription::IsNullable() const
596 {
597 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_ISNULLABLE) )
598 return ::comphelper::getINT32(m_xDest->getPropertyValue(PROPERTY_ISNULLABLE)) == css::sdbc::ColumnValue::NULLABLE;
599 else
600 return m_nIsNullable == css::sdbc::ColumnValue::NULLABLE;
601 }
602
SetTypeName(const OUString & _sTypeName)603 void OFieldDescription::SetTypeName(const OUString& _sTypeName)
604 {
605 try
606 {
607 if ( m_xDest.is() && m_xDestInfo->hasPropertyByName(PROPERTY_TYPENAME) )
608 m_xDest->setPropertyValue(PROPERTY_TYPENAME,Any(_sTypeName));
609 else
610 m_sTypeName = _sTypeName;
611 }
612 catch( const Exception& )
613 {
614 DBG_UNHANDLED_EXCEPTION("dbaccess");
615 }
616 }
617
copyColumnSettingsTo(const Reference<XPropertySet> & _rxColumn)618 void OFieldDescription::copyColumnSettingsTo(const Reference< XPropertySet >& _rxColumn)
619 {
620 if ( !_rxColumn.is() )
621 return;
622
623 Reference<XPropertySetInfo> xInfo = _rxColumn->getPropertySetInfo();
624
625 if ( GetFormatKey() != NumberFormat::ALL && xInfo->hasPropertyByName(PROPERTY_FORMATKEY) )
626 _rxColumn->setPropertyValue(PROPERTY_FORMATKEY,Any(GetFormatKey()));
627 if ( GetHorJustify() != SvxCellHorJustify::Standard && xInfo->hasPropertyByName(PROPERTY_ALIGN) )
628 _rxColumn->setPropertyValue(PROPERTY_ALIGN,Any(dbaui::mapTextAlign(GetHorJustify())));
629 if ( !GetHelpText().isEmpty() && xInfo->hasPropertyByName(PROPERTY_HELPTEXT) )
630 _rxColumn->setPropertyValue(PROPERTY_HELPTEXT,Any(GetHelpText()));
631 if ( GetControlDefault().hasValue() && xInfo->hasPropertyByName(PROPERTY_CONTROLDEFAULT) )
632 _rxColumn->setPropertyValue(PROPERTY_CONTROLDEFAULT,GetControlDefault());
633
634 if(xInfo->hasPropertyByName(PROPERTY_RELATIVEPOSITION))
635 _rxColumn->setPropertyValue(PROPERTY_RELATIVEPOSITION,m_aRelativePosition);
636 if(xInfo->hasPropertyByName(PROPERTY_WIDTH))
637 _rxColumn->setPropertyValue(PROPERTY_WIDTH,m_aWidth);
638 if(xInfo->hasPropertyByName(PROPERTY_HIDDEN))
639 _rxColumn->setPropertyValue(PROPERTY_HIDDEN,Any(m_bHidden));
640 }
641
642 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
643