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: MResultSetMetaData.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 "connectivity/dbexception.hxx"
34 #include "connectivity/dbtools.hxx"
35 #include <comphelper/types.hxx>
36 #include <comphelper/extract.hxx>
37 #include <cppuhelper/typeprovider.hxx>
38 #include <tools/diagnose_ex.h>
39 #include "MResultSetMetaData.hxx"
40 #include <com/sun/star/sdbc/DataType.hpp>
42 using namespace connectivity::mozab
;
43 using namespace com::sun::star::uno
;
44 using namespace com::sun::star::lang
;
45 using namespace com::sun::star::sdbc
;
46 using namespace com::sun::star::beans
;
47 using namespace ::dbtools
;
48 using namespace ::comphelper
;
50 // -------------------------------------------------------------------------
51 OResultSetMetaData::~OResultSetMetaData()
56 // -----------------------------------------------------------------------------
57 void OResultSetMetaData::checkColumnIndex(sal_Int32 column
) throw(SQLException
, RuntimeException
)
59 if(column
<= 0 || column
> (sal_Int32
)(sal_Int32
)m_xColumns
->get().size())
60 throwInvalidIndexException(*this);
62 // -------------------------------------------------------------------------
63 sal_Int32 SAL_CALL
OResultSetMetaData::getColumnDisplaySize( sal_Int32 column
) throw(SQLException
, RuntimeException
)
65 return getPrecision(column
);
67 // -------------------------------------------------------------------------
69 sal_Int32 SAL_CALL
OResultSetMetaData::getColumnType( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
71 return DataType::VARCHAR
; // at the moment there exists only this type
73 // -------------------------------------------------------------------------
75 sal_Int32 SAL_CALL
OResultSetMetaData::getColumnCount( ) throw(SQLException
, RuntimeException
)
77 return (m_xColumns
->get()).size();
79 // -------------------------------------------------------------------------
81 sal_Bool SAL_CALL
OResultSetMetaData::isCaseSensitive( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
85 // -------------------------------------------------------------------------
87 ::rtl::OUString SAL_CALL
OResultSetMetaData::getSchemaName( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
89 return ::rtl::OUString();
91 // -------------------------------------------------------------------------
93 ::rtl::OUString SAL_CALL
OResultSetMetaData::getColumnName( sal_Int32 column
) throw(SQLException
, RuntimeException
)
95 checkColumnIndex(column
);
97 ::rtl::OUString sColumnName
;
100 Reference
< XPropertySet
> xColumnProps( (m_xColumns
->get())[column
-1], UNO_QUERY_THROW
);
101 OSL_VERIFY( xColumnProps
->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_NAME
) ) >>= sColumnName
);
103 catch( const Exception
& )
105 DBG_UNHANDLED_EXCEPTION();
109 // -------------------------------------------------------------------------
110 ::rtl::OUString SAL_CALL
OResultSetMetaData::getTableName( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
114 // -------------------------------------------------------------------------
115 ::rtl::OUString SAL_CALL
OResultSetMetaData::getCatalogName( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
117 return ::rtl::OUString();
119 // -------------------------------------------------------------------------
120 ::rtl::OUString SAL_CALL
OResultSetMetaData::getColumnTypeName( sal_Int32 column
) throw(SQLException
, RuntimeException
)
122 checkColumnIndex(column
);
123 return getString((m_xColumns
->get())[column
-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME
)));
125 // -------------------------------------------------------------------------
126 ::rtl::OUString SAL_CALL
OResultSetMetaData::getColumnLabel( sal_Int32 column
) throw(SQLException
, RuntimeException
)
128 return getColumnName(column
);
130 // -------------------------------------------------------------------------
131 ::rtl::OUString SAL_CALL
OResultSetMetaData::getColumnServiceName( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
133 return ::rtl::OUString();
135 // -------------------------------------------------------------------------
137 sal_Bool SAL_CALL
OResultSetMetaData::isCurrency( sal_Int32 column
) throw(SQLException
, RuntimeException
)
139 checkColumnIndex(column
);
140 return getBOOL((m_xColumns
->get())[column
-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY
)));
142 // -------------------------------------------------------------------------
144 sal_Bool SAL_CALL
OResultSetMetaData::isAutoIncrement( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
148 // -------------------------------------------------------------------------
149 sal_Bool SAL_CALL
OResultSetMetaData::isSigned( sal_Int32
/*column*/ ) throw(SQLException
, RuntimeException
)
153 // -------------------------------------------------------------------------
154 sal_Int32 SAL_CALL
OResultSetMetaData::getPrecision( sal_Int32 column
) throw(SQLException
, RuntimeException
)
156 checkColumnIndex(column
);
157 return getINT32((m_xColumns
->get())[column
-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION
)));
159 // -------------------------------------------------------------------------
160 sal_Int32 SAL_CALL
OResultSetMetaData::getScale( sal_Int32 column
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
162 checkColumnIndex(column
);
163 return getINT32((m_xColumns
->get())[column
-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE
)));
165 // -------------------------------------------------------------------------
167 sal_Int32 SAL_CALL
OResultSetMetaData::isNullable( sal_Int32 column
) throw(SQLException
, RuntimeException
)
169 checkColumnIndex(column
);
170 return getINT32((m_xColumns
->get())[column
-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE
)));
172 // -------------------------------------------------------------------------
174 sal_Bool SAL_CALL
OResultSetMetaData::isSearchable( sal_Int32 column
) throw(SQLException
, RuntimeException
)
176 ::rtl::OUString
sColumnName( getColumnName( column
) );
178 if ( !m_pTable
|| !m_pTable
->getConnection() )
180 OSL_ENSURE( false, "OResultSetMetaData::isSearchable: suspicious: called without table or connection!" );
184 if ( m_pTable
->getConnection()->isLDAP() )
186 const OColumnAlias
& aAliases( m_pTable
->getConnection()->getColumnAlias() );
187 if ( !aAliases
.isColumnSearchable( sColumnName
) )
193 // -------------------------------------------------------------------------
195 sal_Bool SAL_CALL
OResultSetMetaData::isReadOnly( sal_Int32 column
) throw(SQLException
, RuntimeException
)
197 checkColumnIndex(column
);
198 sal_Bool bReadOnly
= (m_xColumns
->get())[column
-1]->getPropertySetInfo()->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION
)) &&
199 ::cppu::any2bool((m_xColumns
->get())[column
-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION
)));
201 return m_bReadOnly
|| bReadOnly
|| m_pTable
->isReadOnly();
203 // -------------------------------------------------------------------------
205 sal_Bool SAL_CALL
OResultSetMetaData::isDefinitelyWritable( sal_Int32 column
) throw(SQLException
, RuntimeException
)
207 return !isReadOnly(column
);
209 // -------------------------------------------------------------------------
210 sal_Bool SAL_CALL
OResultSetMetaData::isWritable( sal_Int32 column
) throw(SQLException
, RuntimeException
)
212 return !isReadOnly(column
);
214 // -------------------------------------------------------------------------