Bump for 3.6-28
[LibreOffice.git] / connectivity / source / drivers / mozab / MResultSetMetaData.cxx
blob32f933aeea185d66a24a239319ec96e711d15207
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "connectivity/dbexception.hxx"
30 #include "connectivity/dbtools.hxx"
31 #include <comphelper/types.hxx>
32 #include <comphelper/extract.hxx>
33 #include <cppuhelper/typeprovider.hxx>
34 #include <tools/diagnose_ex.h>
35 #include "MResultSetMetaData.hxx"
36 #include <com/sun/star/sdbc/DataType.hpp>
38 using namespace connectivity::mozab;
39 using namespace com::sun::star::uno;
40 using namespace com::sun::star::lang;
41 using namespace com::sun::star::sdbc;
42 using namespace com::sun::star::beans;
43 using namespace ::dbtools;
44 using namespace ::comphelper;
46 // -------------------------------------------------------------------------
47 OResultSetMetaData::~OResultSetMetaData()
49 m_xColumns = NULL;
52 // -----------------------------------------------------------------------------
53 void OResultSetMetaData::checkColumnIndex(sal_Int32 column) throw(SQLException, RuntimeException)
55 if(column <= 0 || column > (sal_Int32)(sal_Int32)m_xColumns->get().size())
56 throwInvalidIndexException(*this);
58 // -------------------------------------------------------------------------
59 sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException)
61 return getPrecision(column);
63 // -------------------------------------------------------------------------
65 sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
67 return DataType::VARCHAR; // at the moment there exists only this type
69 // -------------------------------------------------------------------------
71 sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException)
73 return static_cast<sal_Int32>((m_xColumns->get()).size());
75 // -------------------------------------------------------------------------
77 sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
79 return sal_False;
81 // -------------------------------------------------------------------------
83 ::rtl::OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
85 return ::rtl::OUString();
87 // -------------------------------------------------------------------------
89 ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException)
91 checkColumnIndex(column);
93 ::rtl::OUString sColumnName;
94 try
96 Reference< XPropertySet > xColumnProps( (m_xColumns->get())[column-1], UNO_QUERY_THROW );
97 OSL_VERIFY( xColumnProps->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_NAME ) ) >>= sColumnName );
99 catch( const Exception& )
101 DBG_UNHANDLED_EXCEPTION();
103 return sColumnName;
105 // -------------------------------------------------------------------------
106 ::rtl::OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
108 return m_aTableName;
110 // -------------------------------------------------------------------------
111 ::rtl::OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
113 return ::rtl::OUString();
115 // -------------------------------------------------------------------------
116 ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 column ) throw(SQLException, RuntimeException)
118 checkColumnIndex(column);
119 return getString((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)));
121 // -------------------------------------------------------------------------
122 ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException)
124 return getColumnName(column);
126 // -------------------------------------------------------------------------
127 ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
129 return ::rtl::OUString();
131 // -------------------------------------------------------------------------
133 sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException)
135 checkColumnIndex(column);
136 return getBOOL((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)));
138 // -------------------------------------------------------------------------
140 sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
142 return sal_False;
144 // -------------------------------------------------------------------------
145 sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
147 return sal_False;
149 // -------------------------------------------------------------------------
150 sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException)
152 checkColumnIndex(column);
153 return getINT32((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)));
155 // -------------------------------------------------------------------------
156 sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
158 checkColumnIndex(column);
159 return getINT32((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)));
161 // -------------------------------------------------------------------------
163 sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException)
165 checkColumnIndex(column);
166 return getINT32((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)));
168 // -------------------------------------------------------------------------
170 sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 column ) throw(SQLException, RuntimeException)
172 ::rtl::OUString sColumnName( getColumnName( column ) );
174 if ( !m_pTable || !m_pTable->getConnection() )
176 OSL_FAIL( "OResultSetMetaData::isSearchable: suspicious: called without table or connection!" );
177 return sal_False;
180 if ( m_pTable->getConnection()->isLDAP() )
182 const OColumnAlias& aAliases( m_pTable->getConnection()->getColumnAlias() );
183 if ( !aAliases.isColumnSearchable( sColumnName ) )
184 return sal_False;
187 return sal_True;
189 // -------------------------------------------------------------------------
191 sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException)
193 checkColumnIndex(column);
194 sal_Bool bReadOnly = (m_xColumns->get())[column-1]->getPropertySetInfo()->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION)) &&
195 ::cppu::any2bool((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION)));
197 return m_bReadOnly || bReadOnly || m_pTable->isReadOnly();
199 // -------------------------------------------------------------------------
201 sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException)
203 return !isReadOnly(column);
205 // -------------------------------------------------------------------------
206 sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException)
208 return !isReadOnly(column);
210 // -------------------------------------------------------------------------
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */