LibreOffice Module dbaccess (master) 1
TableRow.cxx
Go to the documentation of this file.
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 <TableRow.hxx>
21#include <tools/stream.hxx>
22#include <FieldDescriptions.hxx>
23#include <comphelper/types.hxx>
24
25using namespace dbaui;
26using namespace ::com::sun::star::sdbc;
27using namespace ::com::sun::star::uno;
28using namespace ::com::sun::star::beans;
29
30OTableRow::OTableRow()
31 :m_pActFieldDescr( nullptr )
32 ,m_nPos( -1 )
33 ,m_bReadOnly( false )
34 ,m_bOwnsDescriptions(false)
35{
36}
37
39 :m_pActFieldDescr(nullptr)
40 ,m_nPos( nPosition )
41 ,m_bReadOnly(rRow.IsReadOnly())
42 ,m_bOwnsDescriptions(false)
43{
44
45 OFieldDescription* pSrcField = rRow.GetActFieldDescr();
46 if(pSrcField)
47 {
48 m_pActFieldDescr = new OFieldDescription(*pSrcField);
50 }
51}
52
54{
56 delete m_pActFieldDescr;
57}
58
59void OTableRow::SetPrimaryKey( bool bSet )
60{
63}
64
66{
68}
69
70void OTableRow::SetFieldType( const TOTypeInfoSP& _pType, bool _bForce )
71{
72 if ( _pType )
73 {
74 if( !m_pActFieldDescr )
75 {
78 }
79 m_pActFieldDescr->FillFromTypeInfo(_pType,_bForce,true);
80 }
81 else
82 {
83 delete m_pActFieldDescr;
84 m_pActFieldDescr = nullptr;
85 }
86}
87
88namespace dbaui
89{
90 SvStream& WriteOTableRow( SvStream& _rStr, const OTableRow& _rRow )
91 {
92 _rStr.WriteInt32( _rRow.m_nPos );
93 OFieldDescription* pFieldDesc = _rRow.GetActFieldDescr();
94 if(pFieldDesc)
95 {
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());
100 double nValue = 0.0;
101 Any aValue = pFieldDesc->GetControlDefault();
102 if ( aValue >>= nValue )
103 {
104 _rStr.WriteInt32( 1 );
105 _rStr.WriteDouble( nValue );
106 }
107 else
108 {
109 _rStr.WriteInt32( 2 );
110 _rStr.WriteUniOrByteString(::comphelper::getString(aValue), _rStr.GetStreamCharSet());
111 }
112
113 _rStr.WriteInt32( pFieldDesc->GetType() );
114
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 );
123 }
124 else
125 _rStr.WriteInt32( 0 );
126 return _rStr;
127 }
129 {
130 _rStr.ReadInt32( _rRow.m_nPos );
131 sal_Int32 nValue = 0;
132 _rStr.ReadInt32( nValue );
133 if ( !nValue )
134 return _rStr;
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()));
140
141 _rStr.ReadInt32( nValue );
142 Any aControlDefault;
143 switch ( nValue )
144 {
145 case 1:
146 {
147 double nControlDefault;
148 _rStr.ReadDouble( nControlDefault );
149 aControlDefault <<= nControlDefault;
150 break;
151 }
152 case 2:
153 aControlDefault <<= _rStr.ReadUniOrByteString(_rStr.GetStreamCharSet());
154 break;
155 }
156
157 pFieldDesc->SetControlDefault(aControlDefault);
158
159 _rStr.ReadInt32( nValue );
160 pFieldDesc->SetTypeValue(nValue);
161
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));
172
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);
179 return _rStr;
180 }
181}
182
183/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvStream & WriteDouble(const double &rDouble)
SvStream & WriteInt32(sal_Int32 nInt32)
SvStream & WriteUniOrByteString(std::u16string_view rStr, rtl_TextEncoding eDestCharSet)
OUString ReadUniOrByteString(rtl_TextEncoding eSrcCharSet)
SvStream & ReadDouble(double &rDouble)
SvStream & ReadInt32(sal_Int32 &rInt32)
rtl_TextEncoding GetStreamCharSet() const
void SetTypeValue(sal_Int32 _nType)
void SetHelpText(const OUString &_sHelptext)
void SetControlDefault(const css::uno::Any &_rControlDefault)
void SetPrecision(sal_Int32 _rPrecision)
void SetIsNullable(sal_Int32 _rIsNullable)
void SetPrimaryKey(bool _bPKey)
void SetAutoIncrement(bool _bAuto)
void SetName(const OUString &_rName)
sal_Int32 GetFormatKey() const
void SetDescription(const OUString &_rDescription)
void FillFromTypeInfo(const TOTypeInfoSP &_pType, bool _bForce, bool _bReset)
css::uno::Any GetControlDefault() const
SvxCellHorJustify GetHorJustify() const
sal_Int32 GetPrecision() const
void SetCurrency(bool _bIsCurrency)
sal_Int32 GetIsNullable() const
void SetScale(sal_Int32 _rScale)
void SetFormatKey(sal_Int32 _rFormatKey)
void SetHorJustify(const SvxCellHorJustify &_rHorJustify)
void SetPrimaryKey(bool bSet)
Definition: TableRow.cxx:59
OFieldDescription * GetActFieldDescr() const
Definition: TableRow.hxx:43
sal_Int32 m_nPos
Definition: TableRow.hxx:33
bool IsPrimaryKey() const
Definition: TableRow.cxx:65
void SetFieldType(const TOTypeInfoSP &_pType, bool _bForce=false)
Definition: TableRow.cxx:70
bool m_bOwnsDescriptions
Definition: TableRow.hxx:35
OFieldDescription * m_pActFieldDescr
Definition: TableRow.hxx:32
constexpr OUStringLiteral IsReadOnly(u"IsReadOnly")
size_t m_nPos
sal_Int16 nValue
bool m_bReadOnly
SvStream & WriteOTableRow(SvStream &_rStr, const OTableRow &_rRow)
Definition: TableRow.cxx:90
std::shared_ptr< OTypeInfo > TOTypeInfoSP
Definition: TypeInfo.hxx:99
SvStream & ReadOTableRow(SvStream &_rStr, OTableRow &_rRow)
Definition: TableRow.cxx:128
long Long
SvxCellHorJustify