2000-09-18 15:18:56 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-08 05:35:42 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 05:35:42 +00:00
|
|
|
* $RCSfile: OResultSetMetaData.cxx,v $
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2006-06-20 00:56:26 +00:00
|
|
|
* $Revision: 1.18 $
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2006-06-20 00:56:26 +00:00
|
|
|
* last change: $Author: hr $ $Date: 2006-06-20 01:56:26 $
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 05:35:42 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-08 05:35:42 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 05:35:42 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 05:35:42 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 05:35:42 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _CONNECTIVITY_ODBC_ORESULTSETMETADATA_HXX_
|
|
|
|
#include "odbc/OResultSetMetaData.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _CONNECTIVITY_OTOOLS_HXX_
|
|
|
|
#include "odbc/OTools.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace connectivity::odbc;
|
|
|
|
using namespace com::sun::star::uno;
|
|
|
|
using namespace com::sun::star::lang;
|
|
|
|
using namespace com::sun::star::sdbc;
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
OResultSetMetaData::~OResultSetMetaData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
::rtl::OUString OResultSetMetaData::getCharColAttrib(sal_Int32 _column,sal_Int32 ident) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
sal_Int32 column = _column;
|
2001-05-15 07:18:32 +00:00
|
|
|
if(_column <(sal_Int32) m_vMapping.size()) // use mapping
|
2000-09-18 15:18:56 +00:00
|
|
|
column = m_vMapping[_column];
|
|
|
|
|
2001-05-21 13:30:34 +00:00
|
|
|
SQLSMALLINT BUFFER_LEN = 128;
|
2005-01-21 15:43:00 +00:00
|
|
|
char *pName = new char[BUFFER_LEN+1];
|
2000-09-18 15:18:56 +00:00
|
|
|
SQLSMALLINT nRealLen=0;
|
2004-03-02 11:35:14 +00:00
|
|
|
SQLRETURN nRet = N3SQLColAttribute(m_aStatementHandle,
|
2001-05-02 11:57:37 +00:00
|
|
|
(SQLUSMALLINT)column,
|
2001-05-21 13:30:34 +00:00
|
|
|
(SQLUSMALLINT)ident,
|
2000-09-18 15:18:56 +00:00
|
|
|
(SQLPOINTER)pName,
|
|
|
|
BUFFER_LEN,
|
|
|
|
&nRealLen,
|
|
|
|
NULL
|
2004-03-02 11:35:14 +00:00
|
|
|
);
|
|
|
|
::rtl::OUString sValue;
|
|
|
|
if ( nRet == SQL_SUCCESS )
|
|
|
|
sValue = ::rtl::OUString(pName,nRealLen,m_pConnection->getTextEncoding());
|
|
|
|
delete [] pName;
|
|
|
|
OTools::ThrowException(m_pConnection,nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
|
2000-09-18 15:18:56 +00:00
|
|
|
if(nRealLen > BUFFER_LEN)
|
|
|
|
{
|
2005-01-21 15:43:00 +00:00
|
|
|
pName = new char[nRealLen+1];
|
2004-03-02 11:35:14 +00:00
|
|
|
nRet = N3SQLColAttribute(m_aStatementHandle,
|
2001-05-02 11:57:37 +00:00
|
|
|
(SQLUSMALLINT)column,
|
|
|
|
(SQLUSMALLINT)ident,
|
2000-09-18 15:18:56 +00:00
|
|
|
(SQLPOINTER)pName,
|
|
|
|
nRealLen,
|
|
|
|
&nRealLen,
|
|
|
|
NULL
|
2004-03-02 11:35:14 +00:00
|
|
|
);
|
|
|
|
if ( nRet == SQL_SUCCESS )
|
|
|
|
sValue = ::rtl::OUString(pName,nRealLen,m_pConnection->getTextEncoding());
|
|
|
|
delete [] pName;
|
|
|
|
OTools::ThrowException(m_pConnection,nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2001-08-24 05:19:41 +00:00
|
|
|
return sValue;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
sal_Int32 OResultSetMetaData::getNumColAttrib(sal_Int32 _column,sal_Int32 ident) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
sal_Int32 column = _column;
|
2001-05-15 07:18:32 +00:00
|
|
|
if(_column < (sal_Int32)m_vMapping.size()) // use mapping
|
2000-09-18 15:18:56 +00:00
|
|
|
column = m_vMapping[_column];
|
|
|
|
|
|
|
|
sal_Int32 nValue=0;
|
2001-05-15 07:18:32 +00:00
|
|
|
OTools::ThrowException(m_pConnection,N3SQLColAttribute(m_aStatementHandle,
|
2001-05-02 11:57:37 +00:00
|
|
|
(SQLUSMALLINT)column,
|
|
|
|
(SQLUSMALLINT)ident,
|
2000-09-18 15:18:56 +00:00
|
|
|
NULL,
|
2004-02-04 10:50:05 +00:00
|
|
|
0,
|
2000-09-18 15:18:56 +00:00
|
|
|
NULL,
|
|
|
|
&nValue),m_aStatementHandle,SQL_HANDLE_STMT,*this);
|
|
|
|
return nValue;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
return getNumColAttrib(column,SQL_DESC_DISPLAY_SIZE);
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
2000-12-12 14:50:18 +00:00
|
|
|
sal_Int32 nType = 0;
|
2001-08-06 06:41:49 +00:00
|
|
|
if(!m_bUseODBC2Types)
|
2000-12-12 14:50:18 +00:00
|
|
|
{
|
2001-08-06 06:41:49 +00:00
|
|
|
try
|
|
|
|
{
|
2001-12-03 12:33:33 +00:00
|
|
|
nType = getNumColAttrib(column,SQL_DESC_CONCISE_TYPE);
|
2001-08-06 06:41:49 +00:00
|
|
|
if(nType == SQL_UNKNOWN_TYPE)
|
2001-12-03 12:33:33 +00:00
|
|
|
nType = getNumColAttrib(column, SQL_DESC_TYPE);
|
2001-08-06 06:41:49 +00:00
|
|
|
nType = OTools::MapOdbcType2Jdbc(nType);
|
|
|
|
}
|
|
|
|
catch(SQLException& ) // in this case we have an odbc 2.0 driver
|
|
|
|
{
|
|
|
|
m_bUseODBC2Types = sal_True;
|
|
|
|
nType = OTools::MapOdbcType2Jdbc(getNumColAttrib(column,SQL_DESC_CONCISE_TYPE ));
|
|
|
|
}
|
2000-12-12 14:50:18 +00:00
|
|
|
}
|
2001-08-06 06:41:49 +00:00
|
|
|
else
|
2000-12-12 14:50:18 +00:00
|
|
|
nType = OTools::MapOdbcType2Jdbc(getNumColAttrib(column,SQL_DESC_CONCISE_TYPE ));
|
2001-07-12 11:14:47 +00:00
|
|
|
|
|
|
|
|
2000-12-12 14:50:18 +00:00
|
|
|
return nType;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
if(m_nColCount != -1)
|
|
|
|
return m_nColCount;
|
|
|
|
sal_Int16 nNumResultCols=0;
|
2001-05-15 07:18:32 +00:00
|
|
|
OTools::ThrowException(m_pConnection,N3SQLNumResultCols(m_aStatementHandle,&nNumResultCols),m_aStatementHandle,SQL_HANDLE_STMT,*this);
|
2000-09-18 15:18:56 +00:00
|
|
|
return m_nColCount = nNumResultCols;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
return getNumColAttrib(column,SQL_DESC_CASE_SENSITIVE) == SQL_TRUE;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
::rtl::OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
return getCharColAttrib(column,SQL_DESC_SCHEMA_NAME);
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
::rtl::OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
return getCharColAttrib(column,SQL_DESC_NAME);
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
::rtl::OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
return getCharColAttrib(column,SQL_DESC_TABLE_NAME);
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
::rtl::OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
return getCharColAttrib(column,SQL_DESC_CATALOG_NAME);
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
::rtl::OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
2001-08-02 09:41:53 +00:00
|
|
|
return getCharColAttrib(column,SQL_DESC_TYPE_NAME);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
::rtl::OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
return getCharColAttrib(column,SQL_DESC_LABEL);
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
2006-06-20 00:56:26 +00:00
|
|
|
::rtl::OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
return ::rtl::OUString();
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
return getNumColAttrib(column,SQL_DESC_FIXED_PREC_SCALE) == SQL_TRUE;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
return getNumColAttrib(column,SQL_DESC_AUTO_UNIQUE_VALUE) == SQL_TRUE;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
return getNumColAttrib(column,SQL_DESC_UNSIGNED) == SQL_FALSE;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
2002-11-13 11:18:10 +00:00
|
|
|
sal_Int32 nType = 0;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
nType = getNumColAttrib(column,SQL_DESC_PRECISION);
|
|
|
|
}
|
|
|
|
catch(const SQLException& ) // in this case we have an odbc 2.0 driver
|
|
|
|
{
|
|
|
|
m_bUseODBC2Types = sal_True;
|
|
|
|
nType = getNumColAttrib(column,SQL_COLUMN_PRECISION );
|
|
|
|
}
|
|
|
|
return nType;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2001-03-28 10:32:43 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2000-09-18 15:18:56 +00:00
|
|
|
sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
2002-11-13 11:18:10 +00:00
|
|
|
sal_Int32 nType = 0;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
nType = getNumColAttrib(column,SQL_DESC_SCALE);
|
|
|
|
}
|
|
|
|
catch(const SQLException& ) // in this case we have an odbc 2.0 driver
|
|
|
|
{
|
|
|
|
m_bUseODBC2Types = sal_True;
|
|
|
|
nType = getNumColAttrib(column,SQL_COLUMN_SCALE );
|
|
|
|
}
|
|
|
|
return nType;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
return getNumColAttrib(column,SQL_DESC_NULLABLE);
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
return getNumColAttrib(column,SQL_DESC_SEARCHABLE) != SQL_PRED_NONE;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_READONLY;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_WRITE;
|
|
|
|
;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
|
|
|
return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_WRITE;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|