diff options
author | Wastack <btomi96@gmail.com> | 2016-10-31 16:32:54 +0100 |
---|---|---|
committer | Lionel Elie Mamane <lionel@mamane.lu> | 2016-11-10 09:37:12 +0000 |
commit | 21cc1826c758bb71bb0cfa055b3bb51a38bc2acb (patch) | |
tree | 7142453461e05a9320d0f15de9dfb12dd336e8b3 /connectivity/source/drivers/firebird/ResultSetMetaData.cxx | |
parent | 9357e99450974a4bea5946129af126469199797b (diff) |
WiP tdf#74172 use DECIMAL and NUMERIC data types
Change-Id: I917cdf6e8d3ebfa7c9e4a52ca61adc5b8707ecfc
Reviewed-on: https://gerrit.libreoffice.org/30447
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Lionel Elie Mamane <lionel@mamane.lu>
Diffstat (limited to 'connectivity/source/drivers/firebird/ResultSetMetaData.cxx')
-rw-r--r-- | connectivity/source/drivers/firebird/ResultSetMetaData.cxx | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/connectivity/source/drivers/firebird/ResultSetMetaData.cxx b/connectivity/source/drivers/firebird/ResultSetMetaData.cxx index 9baadab8fcce..c36148c6c2fa 100644 --- a/connectivity/source/drivers/firebird/ResultSetMetaData.cxx +++ b/connectivity/source/drivers/firebird/ResultSetMetaData.cxx @@ -23,6 +23,7 @@ #include <com/sun/star/sdbc/ColumnValue.hpp> #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> #include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/DataType.hpp> using namespace connectivity::firebird; @@ -62,8 +63,9 @@ sal_Int32 SAL_CALL OResultSetMetaData::getColumnType(sal_Int32 column) verifyValidColumn(column); short aType = m_pSqlda->sqlvar[column-1].sqltype; + short aSubType = m_pSqlda->sqlvar[column-1].sqlsubtype; - return getColumnTypeFromFBType(aType); + return getColumnTypeFromFBType(aType, aSubType); } sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive(sal_Int32 column) @@ -118,8 +120,9 @@ OUString SAL_CALL OResultSetMetaData::getColumnTypeName(sal_Int32 column) verifyValidColumn(column); short aType = m_pSqlda->sqlvar[column-1].sqltype; + short aSubType = m_pSqlda->sqlvar[column-1].sqlsubtype; - return getColumnTypeNameFromFBType(aType); + return getColumnTypeNameFromFBType(aType, aSubType); } OUString SAL_CALL OResultSetMetaData::getColumnLabel(sal_Int32 column) @@ -191,15 +194,44 @@ sal_Bool SAL_CALL OResultSetMetaData::isSigned(sal_Int32 column) sal_Int32 SAL_CALL OResultSetMetaData::getPrecision(sal_Int32 column) throw(SQLException, RuntimeException, std::exception) { - // TODO: implement - (void) column; + sal_Int32 nType = getColumnType(column); + if( (nType == DataType::NUMERIC || nType == DataType::DECIMAL) + && !m_sTableName.isEmpty() ) + { + OUString sColumnName = getColumnName( column ); + + // RDB$FIELD_SOURCE is a unique name of column per database + OUString sSql = "SELECT RDB$FIELD_PRECISION FROM RDB$FIELDS " + " INNER JOIN RDB$RELATION_FIELDS " + " ON RDB$RELATION_FIELDS.RDB$FIELD_SOURCE = RDB$FIELDS.RDB$FIELD_NAME " + "WHERE RDB$RELATION_FIELDS.RDB$RELATION_NAME = '" + + escapeWith(getTableName(column), '\'', '\'') + "' AND " + "RDB$RELATION_FIELDS.RDB$FIELD_NAME = '" + + escapeWith(sColumnName, '\'', '\'') +"'"; + Reference<XStatement> xStmt= m_pConnection->createStatement(); + + Reference<XResultSet> xRes = + xStmt->executeQuery(sSql); + Reference<XRow> xRow ( xRes, UNO_QUERY); + if(xRes->next()) + { + return (sal_Int32) xRow->getShort(1); + } + else + { + SAL_WARN("connectivity.firebird","Column '" + << sColumnName + << "' not found in database"); + return 0; + } + } return 0; } sal_Int32 SAL_CALL OResultSetMetaData::getScale(sal_Int32 column) throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) { - return m_pSqlda->sqlvar[column-1].sqlscale; + return -(m_pSqlda->sqlvar[column-1].sqlscale); // fb stores negative number } sal_Int32 SAL_CALL OResultSetMetaData::isNullable(sal_Int32 column) |