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