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 "ado/AResultSetMetaData.hxx"
21 #include <com/sun/star/sdbc/DataType.hpp>
22 #include <com/sun/star/sdbc/ColumnValue.hpp>
23 #include "ado/Awrapado.hxx"
24 #include "connectivity/dbexception.hxx"
26 using namespace connectivity
;
27 using namespace connectivity::ado
;
28 using namespace com::sun::star::uno
;
29 using namespace com::sun::star::lang
;
30 using namespace com::sun::star::beans
;
31 using namespace com::sun::star::sdbc
;
33 OResultSetMetaData::OResultSetMetaData( ADORecordset
* _pRecordSet
)
34 : m_pRecordSet(_pRecordSet
),
38 m_pRecordSet
->AddRef();
41 OResultSetMetaData::~OResultSetMetaData()
44 m_pRecordSet
->Release();
47 sal_Int32 SAL_CALL
OResultSetMetaData::getColumnDisplaySize( sal_Int32 column
) throw(SQLException
, RuntimeException
)
49 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
50 if(aField
.IsValid() && aField
.GetActualSize() != -1)
51 return aField
.GetActualSize();
56 sal_Int32 SAL_CALL
OResultSetMetaData::getColumnType( sal_Int32 column
) throw(SQLException
, RuntimeException
)
58 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
59 return ADOS::MapADOType2Jdbc(aField
.GetADOType());
63 sal_Int32 SAL_CALL
OResultSetMetaData::getColumnCount( ) throw(SQLException
, RuntimeException
)
65 if(m_nColCount
!= -1 )
71 ADOFields
* pFields
= NULL
;
72 m_pRecordSet
->get_Fields(&pFields
);
73 WpOLEAppendCollection
<ADOFields
, ADOField
, WpADOField
> aFields(pFields
);
74 m_nColCount
= aFields
.GetItemCount();
79 sal_Bool SAL_CALL
OResultSetMetaData::isCaseSensitive( sal_Int32 column
) throw(SQLException
, RuntimeException
)
81 sal_Bool bRet
= sal_False
;
82 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
83 if ( aField
.IsValid() )
85 WpADOProperties
aProps( aField
.get_Properties() );
86 if ( aProps
.IsValid() )
87 bRet
= OTools::getValue( aProps
, OUString("ISCASESENSITIVE") );
93 OUString SAL_CALL
OResultSetMetaData::getSchemaName( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
99 OUString SAL_CALL
OResultSetMetaData::getColumnName( sal_Int32 column
) throw(SQLException
, RuntimeException
)
101 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
103 return aField
.GetName();
108 OUString SAL_CALL
OResultSetMetaData::getTableName( sal_Int32 column
) throw(SQLException
, RuntimeException
)
112 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
113 if ( aField
.IsValid() )
115 WpADOProperties
aProps( aField
.get_Properties() );
116 if ( aProps
.IsValid() )
117 sTableName
= OTools::getValue( aProps
, OUString("BASETABLENAME") );
122 OUString SAL_CALL
OResultSetMetaData::getCatalogName( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
127 OUString SAL_CALL
OResultSetMetaData::getColumnTypeName( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
132 OUString SAL_CALL
OResultSetMetaData::getColumnLabel( sal_Int32 column
) throw(SQLException
, RuntimeException
)
134 return getColumnName(column
);
137 OUString SAL_CALL
OResultSetMetaData::getColumnServiceName( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
143 sal_Bool SAL_CALL
OResultSetMetaData::isCurrency( sal_Int32 column
) throw(SQLException
, RuntimeException
)
145 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
148 return ((aField
.GetAttributes() & adFldFixed
) == adFldFixed
) && (aField
.GetADOType() == adCurrency
);
154 sal_Bool SAL_CALL
OResultSetMetaData::isAutoIncrement( sal_Int32 column
) throw(SQLException
, RuntimeException
)
156 sal_Bool bRet
= sal_False
;
157 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
158 if ( aField
.IsValid() )
160 WpADOProperties
aProps( aField
.get_Properties() );
161 if ( aProps
.IsValid() )
163 bRet
= OTools::getValue( aProps
, OUString("ISAUTOINCREMENT") );
164 #if OSL_DEBUG_LEVEL > 0
165 sal_Int32 nCount
= aProps
.GetItemCount();
166 for (sal_Int32 i
= 0; i
<nCount
; ++i
)
168 WpADOProperty aProp
= aProps
.GetItem(i
);
169 OUString sName
= aProp
.GetName();
170 OUString sVal
= aProp
.GetValue();
180 sal_Bool SAL_CALL
OResultSetMetaData::isSigned( sal_Int32 column
) throw(SQLException
, RuntimeException
)
182 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
185 DataTypeEnum eType
= aField
.GetADOType();
186 return !(eType
== adUnsignedBigInt
|| eType
== adUnsignedInt
|| eType
== adUnsignedSmallInt
|| eType
== adUnsignedTinyInt
);
191 sal_Int32 SAL_CALL
OResultSetMetaData::getPrecision( sal_Int32 column
) throw(SQLException
, RuntimeException
)
193 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
195 return aField
.GetPrecision();
199 sal_Int32 SAL_CALL
OResultSetMetaData::getScale( sal_Int32 column
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
201 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
203 return aField
.GetNumericScale();
208 sal_Int32 SAL_CALL
OResultSetMetaData::isNullable( sal_Int32 column
) throw(SQLException
, RuntimeException
)
210 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
213 return (aField
.GetAttributes() & adFldIsNullable
) == adFldIsNullable
;
219 sal_Bool SAL_CALL
OResultSetMetaData::isSearchable( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
225 sal_Bool SAL_CALL
OResultSetMetaData::isReadOnly( sal_Int32 column
) throw(SQLException
, RuntimeException
)
227 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
230 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
236 sal_Bool SAL_CALL
OResultSetMetaData::isDefinitelyWritable( sal_Int32 column
) throw(SQLException
, RuntimeException
)
238 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
241 return (aField
.GetAttributes() & adFldUpdatable
) == adFldUpdatable
;
247 sal_Bool SAL_CALL
OResultSetMetaData::isWritable( sal_Int32 column
) throw(SQLException
, RuntimeException
)
249 return isDefinitelyWritable(column
);
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */