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: AResultSetMetaData.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_connectivity.hxx"
33 #include "ado/AResultSetMetaData.hxx"
34 #include <com/sun/star/sdbc/DataType.hpp>
35 #include <com/sun/star/sdbc/ColumnValue.hpp>
36 #include "ado/Awrapado.hxx"
37 #include "connectivity/dbexception.hxx"
39 using namespace connectivity
;
40 using namespace connectivity::ado
;
41 using namespace com::sun::star::uno
;
42 using namespace com::sun::star::lang
;
43 using namespace com::sun::star::beans
;
44 using namespace com::sun::star::sdbc
;
46 OResultSetMetaData::OResultSetMetaData( ADORecordset
* _pRecordSet
)
47 : m_pRecordSet(_pRecordSet
),
51 m_pRecordSet
->AddRef();
53 // -------------------------------------------------------------------------
54 OResultSetMetaData::~OResultSetMetaData()
57 m_pRecordSet
->Release();
59 // -------------------------------------------------------------------------
60 sal_Int32 SAL_CALL
OResultSetMetaData::getColumnDisplaySize( sal_Int32 column
) throw(SQLException
, RuntimeException
)
62 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
63 if(aField
.IsValid() && aField
.GetActualSize() != -1)
64 return aField
.GetActualSize();
67 // -------------------------------------------------------------------------
69 sal_Int32 SAL_CALL
OResultSetMetaData::getColumnType( sal_Int32 column
) throw(SQLException
, RuntimeException
)
71 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
72 return ADOS::MapADOType2Jdbc(aField
.GetADOType());
74 // -------------------------------------------------------------------------
76 sal_Int32 SAL_CALL
OResultSetMetaData::getColumnCount( ) throw(SQLException
, RuntimeException
)
78 if(m_nColCount
!= -1 )
84 ADOFields
* pFields
= NULL
;
85 m_pRecordSet
->get_Fields(&pFields
);
86 WpOLEAppendCollection
<ADOFields
, ADOField
, WpADOField
> aFields(pFields
);
87 m_nColCount
= aFields
.GetItemCount();
90 // -------------------------------------------------------------------------
92 sal_Bool SAL_CALL
OResultSetMetaData::isCaseSensitive( sal_Int32 column
) throw(SQLException
, RuntimeException
)
94 sal_Bool bRet
= sal_False
;
95 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
96 if ( aField
.IsValid() )
98 WpADOProperties
aProps( aField
.get_Properties() );
99 if ( aProps
.IsValid() )
100 bRet
= OTools::getValue( aProps
, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ISCASESENSITIVE")) );
104 // -------------------------------------------------------------------------
106 ::rtl::OUString SAL_CALL
OResultSetMetaData::getSchemaName( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
108 return ::rtl::OUString();
110 // -------------------------------------------------------------------------
112 ::rtl::OUString SAL_CALL
OResultSetMetaData::getColumnName( sal_Int32 column
) throw(SQLException
, RuntimeException
)
114 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
116 return aField
.GetName();
118 return ::rtl::OUString();
120 // -------------------------------------------------------------------------
121 ::rtl::OUString SAL_CALL
OResultSetMetaData::getTableName( sal_Int32 column
) throw(SQLException
, RuntimeException
)
123 ::rtl::OUString sTableName
;
125 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
126 if ( aField
.IsValid() )
128 WpADOProperties
aProps( aField
.get_Properties() );
129 if ( aProps
.IsValid() )
130 sTableName
= OTools::getValue( aProps
, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BASETABLENAME")) );
134 // -------------------------------------------------------------------------
135 ::rtl::OUString SAL_CALL
OResultSetMetaData::getCatalogName( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
137 return ::rtl::OUString();
139 // -------------------------------------------------------------------------
140 ::rtl::OUString SAL_CALL
OResultSetMetaData::getColumnTypeName( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
142 return ::rtl::OUString();
144 // -------------------------------------------------------------------------
145 ::rtl::OUString SAL_CALL
OResultSetMetaData::getColumnLabel( sal_Int32 column
) throw(SQLException
, RuntimeException
)
147 return getColumnName(column
);
149 // -------------------------------------------------------------------------
150 ::rtl::OUString SAL_CALL
OResultSetMetaData::getColumnServiceName( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
152 return ::rtl::OUString();
154 // -------------------------------------------------------------------------
156 sal_Bool SAL_CALL
OResultSetMetaData::isCurrency( sal_Int32 column
) throw(SQLException
, RuntimeException
)
158 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
161 return ((aField
.GetAttributes() & adFldFixed
) == adFldFixed
) && (aField
.GetADOType() == adCurrency
);
165 // -------------------------------------------------------------------------
167 sal_Bool SAL_CALL
OResultSetMetaData::isAutoIncrement( sal_Int32 column
) throw(SQLException
, RuntimeException
)
169 sal_Bool bRet
= sal_False
;
170 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
171 if ( aField
.IsValid() )
173 WpADOProperties
aProps( aField
.get_Properties() );
174 if ( aProps
.IsValid() )
176 bRet
= OTools::getValue( aProps
, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ISAUTOINCREMENT")) );
177 #if OSL_DEBUG_LEVEL > 0
178 sal_Int32 nCount
= aProps
.GetItemCount();
179 for (sal_Int32 i
= 0; i
<nCount
; ++i
)
181 WpADOProperty aProp
= aProps
.GetItem(i
);
182 ::rtl::OUString sName
= aProp
.GetName();
183 ::rtl::OUString sVal
= aProp
.GetValue();
190 // -------------------------------------------------------------------------
193 sal_Bool SAL_CALL
OResultSetMetaData::isSigned( sal_Int32 column
) throw(SQLException
, RuntimeException
)
195 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
198 DataTypeEnum eType
= aField
.GetADOType();
199 return !(eType
== adUnsignedBigInt
|| eType
== adUnsignedInt
|| eType
== adUnsignedSmallInt
|| eType
== adUnsignedTinyInt
);
203 // -------------------------------------------------------------------------
204 sal_Int32 SAL_CALL
OResultSetMetaData::getPrecision( sal_Int32 column
) throw(SQLException
, RuntimeException
)
206 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
208 return aField
.GetPrecision();
211 // -------------------------------------------------------------------------
212 sal_Int32 SAL_CALL
OResultSetMetaData::getScale( sal_Int32 column
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
214 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
216 return aField
.GetNumericScale();
219 // -------------------------------------------------------------------------
221 sal_Int32 SAL_CALL
OResultSetMetaData::isNullable( sal_Int32 column
) throw(SQLException
, RuntimeException
)
223 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
226 return (aField
.GetAttributes() & adFldIsNullable
) == adFldIsNullable
;
230 // -------------------------------------------------------------------------
232 sal_Bool SAL_CALL
OResultSetMetaData::isSearchable( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
236 // -------------------------------------------------------------------------
238 sal_Bool SAL_CALL
OResultSetMetaData::isReadOnly( sal_Int32 column
) throw(SQLException
, RuntimeException
)
240 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
243 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
247 // -------------------------------------------------------------------------
249 sal_Bool SAL_CALL
OResultSetMetaData::isDefinitelyWritable( sal_Int32 column
) throw(SQLException
, RuntimeException
)
251 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
254 return (aField
.GetAttributes() & adFldUpdatable
) == adFldUpdatable
;
259 // -------------------------------------------------------------------------
260 sal_Bool SAL_CALL
OResultSetMetaData::isWritable( sal_Int32 column
) throw(SQLException
, RuntimeException
)
262 return isDefinitelyWritable(column
);
264 // -------------------------------------------------------------------------