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/debug.hxx>
22 #include "FieldDescriptions.hxx"
24 #include <comphelper/types.hxx>
26 using namespace dbaui
;
27 using namespace ::com::sun::star::sdbc
;
28 using namespace ::com::sun::star::uno
;
29 using namespace ::com::sun::star::beans
;
32 OTableRow::OTableRow()
33 :m_pActFieldDescr( NULL
)
36 ,m_bOwnsDescriptions(false)
40 OTableRow::OTableRow(const Reference
< XPropertySet
>& xAffectedCol
)
41 :m_pActFieldDescr( NULL
)
44 ,m_bOwnsDescriptions(true)
46 m_pActFieldDescr
= new OFieldDescription(xAffectedCol
);
49 OTableRow::OTableRow( const OTableRow
& rRow
, long nPosition
)
50 :m_pActFieldDescr(NULL
)
52 ,m_bReadOnly(rRow
.IsReadOnly())
53 ,m_bOwnsDescriptions(false)
56 OFieldDescription
* pSrcField
= rRow
.GetActFieldDescr();
59 m_pActFieldDescr
= new OFieldDescription(*pSrcField
);
60 m_bOwnsDescriptions
= true;
64 OTableRow::~OTableRow()
66 if(m_bOwnsDescriptions
)
67 delete m_pActFieldDescr
;
70 void OTableRow::SetPrimaryKey( bool bSet
)
73 m_pActFieldDescr
->SetPrimaryKey(bSet
);
76 bool OTableRow::IsPrimaryKey() const
78 return m_pActFieldDescr
&& m_pActFieldDescr
->IsPrimaryKey();
81 void OTableRow::SetFieldType( const TOTypeInfoSP
& _pType
, bool _bForce
)
85 if( !m_pActFieldDescr
)
87 m_pActFieldDescr
= new OFieldDescription();
88 m_bOwnsDescriptions
= true;
90 m_pActFieldDescr
->FillFromTypeInfo(_pType
,_bForce
,true);
94 delete m_pActFieldDescr
;
95 m_pActFieldDescr
= NULL
;
101 SvStream
& WriteOTableRow( SvStream
& _rStr
, const OTableRow
& _rRow
)
103 _rStr
.WriteInt32( _rRow
.m_nPos
);
104 OFieldDescription
* pFieldDesc
= _rRow
.GetActFieldDescr();
107 _rStr
.WriteInt32( 1 );
108 _rStr
.WriteUniOrByteString(pFieldDesc
->GetName(), _rStr
.GetStreamCharSet());
109 _rStr
.WriteUniOrByteString(pFieldDesc
->GetDescription(), _rStr
.GetStreamCharSet());
110 _rStr
.WriteUniOrByteString(pFieldDesc
->GetHelpText(), _rStr
.GetStreamCharSet());
112 Any aValue
= pFieldDesc
->GetControlDefault();
113 if ( aValue
>>= nValue
)
115 _rStr
.WriteInt32( 1 );
116 _rStr
.WriteDouble( nValue
);
120 _rStr
.WriteInt32( 2 );
121 _rStr
.WriteUniOrByteString(::comphelper::getString(aValue
), _rStr
.GetStreamCharSet());
124 _rStr
.WriteInt32( pFieldDesc
->GetType() );
126 _rStr
.WriteInt32( pFieldDesc
->GetPrecision() );
127 _rStr
.WriteInt32( pFieldDesc
->GetScale() );
128 _rStr
.WriteInt32( pFieldDesc
->GetIsNullable() );
129 _rStr
.WriteInt32( pFieldDesc
->GetFormatKey() );
130 _rStr
.WriteInt32( pFieldDesc
->GetHorJustify() );
131 _rStr
.WriteInt32( pFieldDesc
->IsAutoIncrement() ? 1 : 0 );
132 _rStr
.WriteInt32( pFieldDesc
->IsPrimaryKey() ? 1 : 0 );
133 _rStr
.WriteInt32( pFieldDesc
->IsCurrency() ? 1 : 0 );
136 _rStr
.WriteInt32( 0 );
139 SvStream
& ReadOTableRow( SvStream
& _rStr
, OTableRow
& _rRow
)
141 _rStr
.ReadInt32( _rRow
.m_nPos
);
142 sal_Int32 nValue
= 0;
143 _rStr
.ReadInt32( nValue
);
146 OFieldDescription
* pFieldDesc
= new OFieldDescription();
147 _rRow
.m_pActFieldDescr
= pFieldDesc
;
148 OUString sValue
= _rStr
.ReadUniOrByteString(_rStr
.GetStreamCharSet());
149 pFieldDesc
->SetName(sValue
);
151 sValue
= _rStr
.ReadUniOrByteString(_rStr
.GetStreamCharSet());
152 pFieldDesc
->SetDescription(sValue
);
153 sValue
= _rStr
.ReadUniOrByteString(_rStr
.GetStreamCharSet());
154 pFieldDesc
->SetHelpText(sValue
);
156 _rStr
.ReadInt32( nValue
);
162 double nControlDefault
;
163 _rStr
.ReadDouble( nControlDefault
);
164 aControlDefault
<<= nControlDefault
;
168 sValue
= _rStr
.ReadUniOrByteString(_rStr
.GetStreamCharSet());
169 aControlDefault
<<= OUString(sValue
);
173 pFieldDesc
->SetControlDefault(aControlDefault
);
175 _rStr
.ReadInt32( nValue
);
176 pFieldDesc
->SetTypeValue(nValue
);
178 _rStr
.ReadInt32( nValue
);
179 pFieldDesc
->SetPrecision(nValue
);
180 _rStr
.ReadInt32( nValue
);
181 pFieldDesc
->SetScale(nValue
);
182 _rStr
.ReadInt32( nValue
);
183 pFieldDesc
->SetIsNullable(nValue
);
184 _rStr
.ReadInt32( nValue
);
185 pFieldDesc
->SetFormatKey(nValue
);
186 _rStr
.ReadInt32( nValue
);
187 pFieldDesc
->SetHorJustify((SvxCellHorJustify
)nValue
);
189 _rStr
.ReadInt32( nValue
);
190 pFieldDesc
->SetAutoIncrement(nValue
!= 0);
191 _rStr
.ReadInt32( nValue
);
192 pFieldDesc
->SetPrimaryKey(nValue
!= 0);
193 _rStr
.ReadInt32( nValue
);
194 pFieldDesc
->SetCurrency(nValue
!= 0);
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */