Move setting of LD_LIBRARY_PATH closer to invocation of cppunittester
[LibreOffice.git] / dbaccess / source / ui / tabledesign / TableRow.cxx
blob02976fb595895b82f4be2a829ead5b540110fc2b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <TableRow.hxx>
21 #include <tools/stream.hxx>
22 #include <FieldDescriptions.hxx>
23 #include <comphelper/types.hxx>
25 using namespace dbaui;
26 using namespace ::com::sun::star::uno;
28 OTableRow::OTableRow()
29 :m_pActFieldDescr( nullptr )
30 ,m_nPos( -1 )
31 ,m_bReadOnly( false )
32 ,m_bOwnsDescriptions(false)
36 OTableRow::OTableRow( const OTableRow& rRow, tools::Long nPosition )
37 :m_pActFieldDescr(nullptr)
38 ,m_nPos( nPosition )
39 ,m_bReadOnly(rRow.IsReadOnly())
40 ,m_bOwnsDescriptions(false)
43 OFieldDescription* pSrcField = rRow.GetActFieldDescr();
44 if(pSrcField)
46 m_pActFieldDescr = new OFieldDescription(*pSrcField);
47 m_bOwnsDescriptions = true;
51 OTableRow::~OTableRow()
53 if(m_bOwnsDescriptions)
54 delete m_pActFieldDescr;
57 void OTableRow::SetPrimaryKey( bool bSet )
59 if(m_pActFieldDescr)
60 m_pActFieldDescr->SetPrimaryKey(bSet);
63 bool OTableRow::IsPrimaryKey() const
65 return m_pActFieldDescr && m_pActFieldDescr->IsPrimaryKey();
68 void OTableRow::SetFieldType( const TOTypeInfoSP& _pType, bool _bForce )
70 if ( _pType )
72 if( !m_pActFieldDescr )
74 m_pActFieldDescr = new OFieldDescription();
75 m_bOwnsDescriptions = true;
77 m_pActFieldDescr->FillFromTypeInfo(_pType,_bForce,true);
79 else
81 delete m_pActFieldDescr;
82 m_pActFieldDescr = nullptr;
86 namespace dbaui
88 SvStream& WriteOTableRow( SvStream& _rStr, const OTableRow& _rRow )
90 _rStr.WriteInt32( _rRow.m_nPos );
91 OFieldDescription* pFieldDesc = _rRow.GetActFieldDescr();
92 if(pFieldDesc)
94 _rStr.WriteInt32( 1 );
95 _rStr.WriteUniOrByteString(pFieldDesc->GetName(), _rStr.GetStreamCharSet());
96 _rStr.WriteUniOrByteString(pFieldDesc->GetDescription(), _rStr.GetStreamCharSet());
97 _rStr.WriteUniOrByteString(pFieldDesc->GetHelpText(), _rStr.GetStreamCharSet());
98 double nValue = 0.0;
99 Any aValue = pFieldDesc->GetControlDefault();
100 if ( aValue >>= nValue )
102 _rStr.WriteInt32( 1 );
103 _rStr.WriteDouble( nValue );
105 else
107 _rStr.WriteInt32( 2 );
108 _rStr.WriteUniOrByteString(::comphelper::getString(aValue), _rStr.GetStreamCharSet());
111 _rStr.WriteInt32( pFieldDesc->GetType() );
113 _rStr.WriteInt32( pFieldDesc->GetPrecision() );
114 _rStr.WriteInt32( pFieldDesc->GetScale() );
115 _rStr.WriteInt32( pFieldDesc->GetIsNullable() );
116 _rStr.WriteInt32( pFieldDesc->GetFormatKey() );
117 _rStr.WriteInt32( static_cast<sal_Int32>(pFieldDesc->GetHorJustify()) );
118 _rStr.WriteInt32( pFieldDesc->IsAutoIncrement() ? 1 : 0 );
119 _rStr.WriteInt32( pFieldDesc->IsPrimaryKey() ? 1 : 0 );
120 _rStr.WriteInt32( pFieldDesc->IsCurrency() ? 1 : 0 );
122 else
123 _rStr.WriteInt32( 0 );
124 return _rStr;
126 SvStream& ReadOTableRow( SvStream& _rStr, OTableRow& _rRow )
128 _rStr.ReadInt32( _rRow.m_nPos );
129 sal_Int32 nValue = 0;
130 _rStr.ReadInt32( nValue );
131 if ( !nValue )
132 return _rStr;
133 OFieldDescription* pFieldDesc = new OFieldDescription();
134 _rRow.m_pActFieldDescr = pFieldDesc;
135 pFieldDesc->SetName(_rStr.ReadUniOrByteString(_rStr.GetStreamCharSet()));
136 pFieldDesc->SetDescription(_rStr.ReadUniOrByteString(_rStr.GetStreamCharSet()));
137 pFieldDesc->SetHelpText(_rStr.ReadUniOrByteString(_rStr.GetStreamCharSet()));
139 _rStr.ReadInt32( nValue );
140 Any aControlDefault;
141 switch ( nValue )
143 case 1:
145 double nControlDefault;
146 _rStr.ReadDouble( nControlDefault );
147 aControlDefault <<= nControlDefault;
148 break;
150 case 2:
151 aControlDefault <<= _rStr.ReadUniOrByteString(_rStr.GetStreamCharSet());
152 break;
155 pFieldDesc->SetControlDefault(aControlDefault);
157 _rStr.ReadInt32( nValue );
158 pFieldDesc->SetTypeValue(nValue);
160 _rStr.ReadInt32( nValue );
161 pFieldDesc->SetPrecision(nValue);
162 _rStr.ReadInt32( nValue );
163 pFieldDesc->SetScale(nValue);
164 _rStr.ReadInt32( nValue );
165 pFieldDesc->SetIsNullable(nValue);
166 _rStr.ReadInt32( nValue );
167 pFieldDesc->SetFormatKey(nValue);
168 _rStr.ReadInt32( nValue );
169 pFieldDesc->SetHorJustify(static_cast<SvxCellHorJustify>(nValue));
171 _rStr.ReadInt32( nValue );
172 pFieldDesc->SetAutoIncrement(nValue != 0);
173 _rStr.ReadInt32( nValue );
174 pFieldDesc->SetPrimaryKey(nValue != 0);
175 _rStr.ReadInt32( nValue );
176 pFieldDesc->SetCurrency(nValue != 0);
177 return _rStr;
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */