1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 #ifndef DBAUI_TABLEROW_HXX
27 #include "TableRow.hxx"
28 #endif
29 #ifndef _TOOLS_DEBUG_HXX
30 #include <tools/debug.hxx>
31 #endif
32 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
33 #include "FieldDescriptions.hxx"
34 #endif
35 #include <algorithm>
36 #include <comphelper/types.hxx>
37
38 using namespace dbaui;
39 using namespace ::com::sun::star::sdbc;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::beans;
42
43 //========================================================================
44 // class OTableRow
45 //========================================================================
DBG_NAME(OTableRow)46 DBG_NAME(OTableRow)
47 //------------------------------------------------------------------------------
48 OTableRow::OTableRow()
49 :m_pActFieldDescr( NULL )
50 ,m_nPos( -1 )
51 ,m_bReadOnly( false )
52 ,m_bOwnsDescriptions(false)
53 {
54 DBG_CTOR(OTableRow,NULL);
55 }
56 //------------------------------------------------------------------------------
OTableRow(const Reference<XPropertySet> & xAffectedCol)57 OTableRow::OTableRow(const Reference< XPropertySet >& xAffectedCol)
58 :m_pActFieldDescr( NULL )
59 ,m_nPos( -1 )
60 ,m_bReadOnly( false )
61 ,m_bOwnsDescriptions(true)
62 {
63 DBG_CTOR(OTableRow,NULL);
64 m_pActFieldDescr = new OFieldDescription(xAffectedCol);
65 }
66 //------------------------------------------------------------------------------
OTableRow(const OTableRow & rRow,long nPosition)67 OTableRow::OTableRow( const OTableRow& rRow, long nPosition )
68 :m_pActFieldDescr(NULL)
69 ,m_nPos( nPosition )
70 ,m_bReadOnly(rRow.IsReadOnly())
71 ,m_bOwnsDescriptions(false)
72 {
73 DBG_CTOR(OTableRow,NULL);
74
75 OFieldDescription* pSrcField = rRow.GetActFieldDescr();
76 if(pSrcField)
77 {
78 m_pActFieldDescr = new OFieldDescription(*pSrcField);
79 m_bOwnsDescriptions = true;
80 }
81 }
82
83 //------------------------------------------------------------------------------
~OTableRow()84 OTableRow::~OTableRow()
85 {
86 DBG_DTOR(OTableRow,NULL);
87 if(m_bOwnsDescriptions)
88 delete m_pActFieldDescr;
89 }
90
91 //------------------------------------------------------------------------------
SetPrimaryKey(sal_Bool bSet)92 void OTableRow::SetPrimaryKey( sal_Bool bSet )
93 {
94 DBG_CHKTHIS(OTableRow,NULL);
95 if(m_pActFieldDescr)
96 m_pActFieldDescr->SetPrimaryKey(bSet);
97 }
98 // -----------------------------------------------------------------------------
IsPrimaryKey() const99 sal_Bool OTableRow::IsPrimaryKey() const
100 {
101 DBG_CHKTHIS(OTableRow,NULL);
102 return m_pActFieldDescr && m_pActFieldDescr->IsPrimaryKey();
103 }
104 // -----------------------------------------------------------------------------
SetFieldType(const TOTypeInfoSP & _pType,sal_Bool _bForce)105 void OTableRow::SetFieldType( const TOTypeInfoSP& _pType, sal_Bool _bForce )
106 {
107 DBG_CHKTHIS(OTableRow,NULL);
108 if ( _pType.get() )
109 {
110 if( !m_pActFieldDescr )
111 {
112 m_pActFieldDescr = new OFieldDescription();
113 m_bOwnsDescriptions = true;
114 }
115 m_pActFieldDescr->FillFromTypeInfo(_pType,_bForce,sal_True);
116 }
117 else
118 {
119 delete m_pActFieldDescr;
120 m_pActFieldDescr = NULL;
121 }
122 }
123 // -----------------------------------------------------------------------------
124 namespace dbaui
125 {
126 // -----------------------------------------------------------------------------
operator <<(SvStream & _rStr,const OTableRow & _rRow)127 SvStream& operator<<( SvStream& _rStr, const OTableRow& _rRow )
128 {
129 _rStr << _rRow.m_nPos;
130 OFieldDescription* pFieldDesc = _rRow.GetActFieldDescr();
131 if(pFieldDesc)
132 {
133 _rStr << (sal_Int32)1;
134 _rStr.WriteByteString(pFieldDesc->GetName());
135 _rStr.WriteByteString(pFieldDesc->GetDescription());
136 _rStr.WriteByteString(pFieldDesc->GetHelpText());
137 double nValue = 0.0;
138 Any aValue = pFieldDesc->GetControlDefault();
139 if ( aValue >>= nValue )
140 {
141 _rStr << sal_Int32(1);
142 _rStr << nValue;
143 }
144 else
145 {
146 _rStr << sal_Int32(2);
147 _rStr.WriteByteString(::comphelper::getString(aValue));
148 }
149
150 _rStr << pFieldDesc->GetType();
151
152 _rStr << pFieldDesc->GetPrecision();
153 _rStr << pFieldDesc->GetScale();
154 _rStr << pFieldDesc->GetIsNullable();
155 _rStr << pFieldDesc->GetFormatKey();
156 _rStr << (sal_Int32)pFieldDesc->GetHorJustify();
157 _rStr << sal_Int32(pFieldDesc->IsAutoIncrement() ? 1 : 0);
158 _rStr << sal_Int32(pFieldDesc->IsPrimaryKey() ? 1 : 0);
159 _rStr << sal_Int32(pFieldDesc->IsCurrency() ? 1 : 0);
160 } // if(pFieldDesc)
161 else
162 _rStr << (sal_Int32)0;
163 return _rStr;
164 }
165 // -----------------------------------------------------------------------------
operator >>(SvStream & _rStr,OTableRow & _rRow)166 SvStream& operator>>( SvStream& _rStr, OTableRow& _rRow )
167 {
168 _rStr >> _rRow.m_nPos;
169 sal_Int32 nValue = 0;
170 _rStr >> nValue;
171 if ( nValue )
172 {
173 OFieldDescription* pFieldDesc = new OFieldDescription();
174 _rRow.m_pActFieldDescr = pFieldDesc;
175 String sValue;
176 _rStr.ReadByteString(sValue);
177 pFieldDesc->SetName(sValue);
178
179 _rStr.ReadByteString(sValue);
180 pFieldDesc->SetDescription(sValue);
181 _rStr.ReadByteString(sValue);
182 pFieldDesc->SetHelpText(sValue);
183
184 _rStr >> nValue;
185 Any aControlDefault;
186 switch ( nValue )
187 {
188 case 1:
189 {
190 double nControlDefault;
191 _rStr >> nControlDefault;
192 aControlDefault <<= nControlDefault;
193 break;
194 }
195 case 2:
196 _rStr.ReadByteString(sValue);
197 aControlDefault <<= ::rtl::OUString(sValue);
198 break;
199 }
200
201 pFieldDesc->SetControlDefault(aControlDefault);
202
203
204 _rStr >> nValue;
205 pFieldDesc->SetTypeValue(nValue);
206
207 _rStr >> nValue;
208 pFieldDesc->SetPrecision(nValue);
209 _rStr >> nValue;
210 pFieldDesc->SetScale(nValue);
211 _rStr >> nValue;
212 pFieldDesc->SetIsNullable(nValue);
213 _rStr >> nValue;
214 pFieldDesc->SetFormatKey(nValue);
215 _rStr >> nValue;
216 pFieldDesc->SetHorJustify((SvxCellHorJustify)nValue);
217
218 _rStr >> nValue;
219 pFieldDesc->SetAutoIncrement(nValue != 0);
220 _rStr >> nValue;
221 pFieldDesc->SetPrimaryKey(nValue != 0);
222 _rStr >> nValue;
223 pFieldDesc->SetCurrency(nValue != 0);
224 }
225 return _rStr;
226 }
227 // -----------------------------------------------------------------------------
228 }
229
230
231
232