1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TableRow.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_TABLEROW_HXX
34 #include "TableRow.hxx"
36 #ifndef _TOOLS_DEBUG_HXX
37 #include <tools/debug.hxx>
39 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
40 #include "FieldDescriptions.hxx"
43 #include <comphelper/types.hxx>
45 using namespace dbaui
;
46 using namespace ::com::sun::star::sdbc
;
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::beans
;
50 //========================================================================
52 //========================================================================
54 //------------------------------------------------------------------------------
55 OTableRow::OTableRow()
56 :m_pActFieldDescr( NULL
)
59 ,m_bOwnsDescriptions(false)
61 DBG_CTOR(OTableRow
,NULL
);
63 //------------------------------------------------------------------------------
64 OTableRow::OTableRow(const Reference
< XPropertySet
>& xAffectedCol
)
65 :m_pActFieldDescr( NULL
)
68 ,m_bOwnsDescriptions(true)
70 DBG_CTOR(OTableRow
,NULL
);
71 m_pActFieldDescr
= new OFieldDescription(xAffectedCol
);
73 //------------------------------------------------------------------------------
74 OTableRow::OTableRow( const OTableRow
& rRow
, long nPosition
)
75 :m_pActFieldDescr(NULL
)
77 ,m_bReadOnly(rRow
.IsReadOnly())
78 ,m_bOwnsDescriptions(false)
80 DBG_CTOR(OTableRow
,NULL
);
82 OFieldDescription
* pSrcField
= rRow
.GetActFieldDescr();
85 m_pActFieldDescr
= new OFieldDescription(*pSrcField
);
86 m_bOwnsDescriptions
= true;
90 //------------------------------------------------------------------------------
91 OTableRow::~OTableRow()
93 DBG_DTOR(OTableRow
,NULL
);
94 if(m_bOwnsDescriptions
)
95 delete m_pActFieldDescr
;
98 //------------------------------------------------------------------------------
99 void OTableRow::SetPrimaryKey( sal_Bool bSet
)
101 DBG_CHKTHIS(OTableRow
,NULL
);
103 m_pActFieldDescr
->SetPrimaryKey(bSet
);
105 // -----------------------------------------------------------------------------
106 sal_Bool
OTableRow::IsPrimaryKey() const
108 DBG_CHKTHIS(OTableRow
,NULL
);
109 return m_pActFieldDescr
&& m_pActFieldDescr
->IsPrimaryKey();
111 // -----------------------------------------------------------------------------
112 void OTableRow::SetFieldType( const TOTypeInfoSP
& _pType
, sal_Bool _bForce
)
114 DBG_CHKTHIS(OTableRow
,NULL
);
117 if( !m_pActFieldDescr
)
119 m_pActFieldDescr
= new OFieldDescription();
120 m_bOwnsDescriptions
= true;
122 m_pActFieldDescr
->FillFromTypeInfo(_pType
,_bForce
,sal_True
);
126 delete m_pActFieldDescr
;
127 m_pActFieldDescr
= NULL
;
130 // -----------------------------------------------------------------------------
133 // -----------------------------------------------------------------------------
134 SvStream
& operator<<( SvStream
& _rStr
, const OTableRow
& _rRow
)
136 _rStr
<< _rRow
.m_nPos
;
137 OFieldDescription
* pFieldDesc
= _rRow
.GetActFieldDescr();
140 _rStr
<< (sal_Int32
)1;
141 _rStr
.WriteByteString(pFieldDesc
->GetName());
142 _rStr
.WriteByteString(pFieldDesc
->GetDescription());
144 Any aValue
= pFieldDesc
->GetControlDefault();
145 if ( aValue
>>= nValue
)
147 _rStr
<< sal_Int32(1);
152 _rStr
<< sal_Int32(2);
153 _rStr
.WriteByteString(::comphelper::getString(aValue
));
156 _rStr
<< pFieldDesc
->GetType();
158 _rStr
<< pFieldDesc
->GetPrecision();
159 _rStr
<< pFieldDesc
->GetScale();
160 _rStr
<< pFieldDesc
->GetIsNullable();
161 _rStr
<< pFieldDesc
->GetFormatKey();
162 _rStr
<< (sal_Int32
)pFieldDesc
->GetHorJustify();
163 _rStr
<< sal_Int32(pFieldDesc
->IsAutoIncrement() ? 1 : 0);
164 _rStr
<< sal_Int32(pFieldDesc
->IsPrimaryKey() ? 1 : 0);
165 _rStr
<< sal_Int32(pFieldDesc
->IsCurrency() ? 1 : 0);
168 _rStr
<< (sal_Int32
)0;
171 // -----------------------------------------------------------------------------
172 SvStream
& operator>>( SvStream
& _rStr
, OTableRow
& _rRow
)
174 _rStr
>> _rRow
.m_nPos
;
175 sal_Int32 nValue
= 0;
179 OFieldDescription
* pFieldDesc
= new OFieldDescription();
180 _rRow
.m_pActFieldDescr
= pFieldDesc
;
182 _rStr
.ReadByteString(sValue
);
183 pFieldDesc
->SetName(sValue
);
185 _rStr
.ReadByteString(sValue
);
186 pFieldDesc
->SetDescription(sValue
);
194 double nControlDefault
;
195 _rStr
>> nControlDefault
;
196 aControlDefault
<<= nControlDefault
;
200 _rStr
.ReadByteString(sValue
);
201 aControlDefault
<<= ::rtl::OUString(sValue
);
205 pFieldDesc
->SetControlDefault(aControlDefault
);
209 pFieldDesc
->SetTypeValue(nValue
);
212 pFieldDesc
->SetPrecision(nValue
);
214 pFieldDesc
->SetScale(nValue
);
216 pFieldDesc
->SetIsNullable(nValue
);
218 pFieldDesc
->SetFormatKey(nValue
);
220 pFieldDesc
->SetHorJustify((SvxCellHorJustify
)nValue
);
223 pFieldDesc
->SetAutoIncrement(nValue
!= 0);
225 pFieldDesc
->SetPrimaryKey(nValue
!= 0);
227 pFieldDesc
->SetCurrency(nValue
!= 0);
231 // -----------------------------------------------------------------------------