1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 )
32 ,m_bOwnsDescriptions(false)
36 OTableRow::OTableRow( const OTableRow
& rRow
, tools::Long nPosition
)
37 :m_pActFieldDescr(nullptr)
39 ,m_bReadOnly(rRow
.IsReadOnly())
40 ,m_bOwnsDescriptions(false)
43 OFieldDescription
* pSrcField
= rRow
.GetActFieldDescr();
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
)
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
)
72 if( !m_pActFieldDescr
)
74 m_pActFieldDescr
= new OFieldDescription();
75 m_bOwnsDescriptions
= true;
77 m_pActFieldDescr
->FillFromTypeInfo(_pType
,_bForce
,true);
81 delete m_pActFieldDescr
;
82 m_pActFieldDescr
= nullptr;
88 SvStream
& WriteOTableRow( SvStream
& _rStr
, const OTableRow
& _rRow
)
90 _rStr
.WriteInt32( _rRow
.m_nPos
);
91 OFieldDescription
* pFieldDesc
= _rRow
.GetActFieldDescr();
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());
99 Any aValue
= pFieldDesc
->GetControlDefault();
100 if ( aValue
>>= nValue
)
102 _rStr
.WriteInt32( 1 );
103 _rStr
.WriteDouble( nValue
);
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 );
123 _rStr
.WriteInt32( 0 );
126 SvStream
& ReadOTableRow( SvStream
& _rStr
, OTableRow
& _rRow
)
128 _rStr
.ReadInt32( _rRow
.m_nPos
);
129 sal_Int32 nValue
= 0;
130 _rStr
.ReadInt32( nValue
);
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
);
145 double nControlDefault
;
146 _rStr
.ReadDouble( nControlDefault
);
147 aControlDefault
<<= nControlDefault
;
151 aControlDefault
<<= _rStr
.ReadUniOrByteString(_rStr
.GetStreamCharSet());
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);
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */