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::sdbc
;
27 using namespace ::com::sun::star::uno
;
28 using namespace ::com::sun::star::beans
;
30 OTableRow::OTableRow()
31 :m_pActFieldDescr( nullptr )
34 ,m_bOwnsDescriptions(false)
38 OTableRow::OTableRow( const OTableRow
& rRow
, tools::Long nPosition
)
39 :m_pActFieldDescr(nullptr)
41 ,m_bReadOnly(rRow
.IsReadOnly())
42 ,m_bOwnsDescriptions(false)
45 OFieldDescription
* pSrcField
= rRow
.GetActFieldDescr();
48 m_pActFieldDescr
= new OFieldDescription(*pSrcField
);
49 m_bOwnsDescriptions
= true;
53 OTableRow::~OTableRow()
55 if(m_bOwnsDescriptions
)
56 delete m_pActFieldDescr
;
59 void OTableRow::SetPrimaryKey( bool bSet
)
62 m_pActFieldDescr
->SetPrimaryKey(bSet
);
65 bool OTableRow::IsPrimaryKey() const
67 return m_pActFieldDescr
&& m_pActFieldDescr
->IsPrimaryKey();
70 void OTableRow::SetFieldType( const TOTypeInfoSP
& _pType
, bool _bForce
)
74 if( !m_pActFieldDescr
)
76 m_pActFieldDescr
= new OFieldDescription();
77 m_bOwnsDescriptions
= true;
79 m_pActFieldDescr
->FillFromTypeInfo(_pType
,_bForce
,true);
83 delete m_pActFieldDescr
;
84 m_pActFieldDescr
= nullptr;
90 SvStream
& WriteOTableRow( SvStream
& _rStr
, const OTableRow
& _rRow
)
92 _rStr
.WriteInt32( _rRow
.m_nPos
);
93 OFieldDescription
* pFieldDesc
= _rRow
.GetActFieldDescr();
96 _rStr
.WriteInt32( 1 );
97 _rStr
.WriteUniOrByteString(pFieldDesc
->GetName(), _rStr
.GetStreamCharSet());
98 _rStr
.WriteUniOrByteString(pFieldDesc
->GetDescription(), _rStr
.GetStreamCharSet());
99 _rStr
.WriteUniOrByteString(pFieldDesc
->GetHelpText(), _rStr
.GetStreamCharSet());
101 Any aValue
= pFieldDesc
->GetControlDefault();
102 if ( aValue
>>= nValue
)
104 _rStr
.WriteInt32( 1 );
105 _rStr
.WriteDouble( nValue
);
109 _rStr
.WriteInt32( 2 );
110 _rStr
.WriteUniOrByteString(::comphelper::getString(aValue
), _rStr
.GetStreamCharSet());
113 _rStr
.WriteInt32( pFieldDesc
->GetType() );
115 _rStr
.WriteInt32( pFieldDesc
->GetPrecision() );
116 _rStr
.WriteInt32( pFieldDesc
->GetScale() );
117 _rStr
.WriteInt32( pFieldDesc
->GetIsNullable() );
118 _rStr
.WriteInt32( pFieldDesc
->GetFormatKey() );
119 _rStr
.WriteInt32( static_cast<sal_Int32
>(pFieldDesc
->GetHorJustify()) );
120 _rStr
.WriteInt32( pFieldDesc
->IsAutoIncrement() ? 1 : 0 );
121 _rStr
.WriteInt32( pFieldDesc
->IsPrimaryKey() ? 1 : 0 );
122 _rStr
.WriteInt32( pFieldDesc
->IsCurrency() ? 1 : 0 );
125 _rStr
.WriteInt32( 0 );
128 SvStream
& ReadOTableRow( SvStream
& _rStr
, OTableRow
& _rRow
)
130 _rStr
.ReadInt32( _rRow
.m_nPos
);
131 sal_Int32 nValue
= 0;
132 _rStr
.ReadInt32( nValue
);
135 OFieldDescription
* pFieldDesc
= new OFieldDescription();
136 _rRow
.m_pActFieldDescr
= pFieldDesc
;
137 pFieldDesc
->SetName(_rStr
.ReadUniOrByteString(_rStr
.GetStreamCharSet()));
138 pFieldDesc
->SetDescription(_rStr
.ReadUniOrByteString(_rStr
.GetStreamCharSet()));
139 pFieldDesc
->SetHelpText(_rStr
.ReadUniOrByteString(_rStr
.GetStreamCharSet()));
141 _rStr
.ReadInt32( nValue
);
147 double nControlDefault
;
148 _rStr
.ReadDouble( nControlDefault
);
149 aControlDefault
<<= nControlDefault
;
153 aControlDefault
<<= _rStr
.ReadUniOrByteString(_rStr
.GetStreamCharSet());
157 pFieldDesc
->SetControlDefault(aControlDefault
);
159 _rStr
.ReadInt32( nValue
);
160 pFieldDesc
->SetTypeValue(nValue
);
162 _rStr
.ReadInt32( nValue
);
163 pFieldDesc
->SetPrecision(nValue
);
164 _rStr
.ReadInt32( nValue
);
165 pFieldDesc
->SetScale(nValue
);
166 _rStr
.ReadInt32( nValue
);
167 pFieldDesc
->SetIsNullable(nValue
);
168 _rStr
.ReadInt32( nValue
);
169 pFieldDesc
->SetFormatKey(nValue
);
170 _rStr
.ReadInt32( nValue
);
171 pFieldDesc
->SetHorJustify(static_cast<SvxCellHorJustify
>(nValue
));
173 _rStr
.ReadInt32( nValue
);
174 pFieldDesc
->SetAutoIncrement(nValue
!= 0);
175 _rStr
.ReadInt32( nValue
);
176 pFieldDesc
->SetPrimaryKey(nValue
!= 0);
177 _rStr
.ReadInt32( nValue
);
178 pFieldDesc
->SetCurrency(nValue
!= 0);
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */