diff options
author | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2013-07-22 08:36:52 +0200 |
---|---|---|
committer | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2013-07-22 11:04:04 +0200 |
commit | 734a30a23dd392924a1072172d61a372167529b0 (patch) | |
tree | bfe15c641ef4cf0c0ad659795ed7b51ebcabdebb /connectivity/source | |
parent | abc147410e92f165ec27067e678c75667ede31f1 (diff) |
Move sqltype identification into Util (firebird-sdbc).
Change-Id: I2e3068bf46555fea63c62bc1abc8a467c588a8b5
Diffstat (limited to 'connectivity/source')
-rw-r--r-- | connectivity/source/drivers/firebird/FResultSetMetaData.cxx | 79 | ||||
-rw-r--r-- | connectivity/source/drivers/firebird/Util.cxx | 104 | ||||
-rw-r--r-- | connectivity/source/drivers/firebird/Util.hxx | 27 |
3 files changed, 134 insertions, 76 deletions
diff --git a/connectivity/source/drivers/firebird/FResultSetMetaData.cxx b/connectivity/source/drivers/firebird/FResultSetMetaData.cxx index 3c11fbada0e2..fe087f2d39cc 100644 --- a/connectivity/source/drivers/firebird/FResultSetMetaData.cxx +++ b/connectivity/source/drivers/firebird/FResultSetMetaData.cxx @@ -34,6 +34,7 @@ *************************************************************************/ #include "FResultSetMetaData.hxx" +#include "Util.hxx" #include <com/sun/star/sdbc/ColumnValue.hpp> @@ -74,44 +75,7 @@ sal_Int32 SAL_CALL OResultSetMetaData::getColumnType(sal_Int32 column) int aType = m_pSqlda->sqlvar[column-1].sqltype; - aType &= ~1; // Remove last bit -- it is used to denote whether column - // can store Null, not needed for type determination - switch (aType) - { - case SQL_TEXT: - return DataType::CHAR; - case SQL_VARYING: - return DataType::VARCHAR; - case SQL_SHORT: - return DataType::SMALLINT; - case SQL_LONG: - return DataType::INTEGER; - case SQL_FLOAT: - return DataType::REAL; - case SQL_DOUBLE: - return DataType::DOUBLE; - case SQL_D_FLOAT: - return DataType::FLOAT; - case SQL_TIMESTAMP: - return DataType::TIMESTAMP; - case SQL_BLOB: - return DataType::BLOB; - case SQL_ARRAY: - return DataType::ARRAY; - case SQL_TYPE_TIME: - return DataType::TIME; - case SQL_TYPE_DATE: - return DataType::DATE; - case SQL_INT64: - return DataType::BIGINT; - case SQL_NULL: - return DataType::SQLNULL; - case SQL_QUAD: // Is a "Blob ID" according to the docs - return 0; // TODO: verify - default: - assert(false); // Should never happen - return 0; - } + return getColumnTypeFromFBType(aType); } sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive(sal_Int32 column) @@ -160,44 +124,7 @@ OUString SAL_CALL OResultSetMetaData::getColumnTypeName(sal_Int32 column) int aType = m_pSqlda->sqlvar[column-1].sqltype; - aType &= ~1; // Remove last bit -- it is used to denote whether column - // can store Null, not needed for type determination - switch (aType) - { - case SQL_TEXT: - return OUString("SQL_TEXT"); - case SQL_VARYING: - return OUString("SQL_VARYING"); - case SQL_SHORT: - return OUString("SQL_SHORT"); - case SQL_LONG: - return OUString("SQL_LONG"); - case SQL_FLOAT: - return OUString("SQL_FLOAT"); - case SQL_DOUBLE: - return OUString("SQL_DOUBLE"); - case SQL_D_FLOAT: - return OUString("SQL_D_FLOAT"); - case SQL_TIMESTAMP: - return OUString("SQL_TIMESTAMP"); - case SQL_BLOB: - return OUString("SQL_BLOB"); - case SQL_ARRAY: - return OUString("SQL_ARRAY"); - case SQL_TYPE_TIME: - return OUString("SQL_TYPE_TIME"); - case SQL_TYPE_DATE: - return OUString("SQL_TYPE_DATE"); - case SQL_INT64: - return OUString("SQL_INT64"); - case SQL_NULL: - return OUString("SQL_NULL"); - case SQL_QUAD: - return OUString("SQL_QUAD"); - default: - assert(false); // Should never happen - return OUString(); - } + return getColumnTypeNameFromFBType(aType); } OUString SAL_CALL OResultSetMetaData::getColumnLabel(sal_Int32 column) diff --git a/connectivity/source/drivers/firebird/Util.cxx b/connectivity/source/drivers/firebird/Util.cxx new file mode 100644 index 000000000000..5fd08e3e9408 --- /dev/null +++ b/connectivity/source/drivers/firebird/Util.cxx @@ -0,0 +1,104 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "Util.hxx" + +#include <ibase.h> + +using namespace ::connectivity; + +using namespace ::rtl; + +using namespace ::com::sun::star::sdbc; + +sal_Int32 firebird::getColumnTypeFromFBType(int aType) +{ + aType &= ~1; // Remove last bit -- it is used to denote whether column + // can store Null, not needed for type determination + switch (aType) + { + case SQL_TEXT: + return DataType::CHAR; + case SQL_VARYING: + return DataType::VARCHAR; + case SQL_SHORT: + return DataType::SMALLINT; + case SQL_LONG: + return DataType::INTEGER; + case SQL_FLOAT: + return DataType::REAL; + case SQL_DOUBLE: + return DataType::DOUBLE; + case SQL_D_FLOAT: + return DataType::FLOAT; + case SQL_TIMESTAMP: + return DataType::TIMESTAMP; + case SQL_BLOB: + return DataType::BLOB; + case SQL_ARRAY: + return DataType::ARRAY; + case SQL_TYPE_TIME: + return DataType::TIME; + case SQL_TYPE_DATE: + return DataType::DATE; + case SQL_INT64: + return DataType::BIGINT; + case SQL_NULL: + return DataType::SQLNULL; + case SQL_QUAD: // Is a "Blob ID" according to the docs + return 0; // TODO: verify + default: + assert(false); // Should never happen + return 0; + } +} + +OUString firebird::getColumnTypeNameFromFBType(int aType) +{ + aType &= ~1; // Remove last bit -- it is used to denote whether column + // can store Null, not needed for type determination + switch (aType) + { + case SQL_TEXT: + return OUString("SQL_TEXT"); + case SQL_VARYING: + return OUString("SQL_VARYING"); + case SQL_SHORT: + return OUString("SQL_SHORT"); + case SQL_LONG: + return OUString("SQL_LONG"); + case SQL_FLOAT: + return OUString("SQL_FLOAT"); + case SQL_DOUBLE: + return OUString("SQL_DOUBLE"); + case SQL_D_FLOAT: + return OUString("SQL_D_FLOAT"); + case SQL_TIMESTAMP: + return OUString("SQL_TIMESTAMP"); + case SQL_BLOB: + return OUString("SQL_BLOB"); + case SQL_ARRAY: + return OUString("SQL_ARRAY"); + case SQL_TYPE_TIME: + return OUString("SQL_TYPE_TIME"); + case SQL_TYPE_DATE: + return OUString("SQL_TYPE_DATE"); + case SQL_INT64: + return OUString("SQL_INT64"); + case SQL_NULL: + return OUString("SQL_NULL"); + case SQL_QUAD: + return OUString("SQL_QUAD"); + default: + assert(false); // Should never happen + return OUString(); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file diff --git a/connectivity/source/drivers/firebird/Util.hxx b/connectivity/source/drivers/firebird/Util.hxx new file mode 100644 index 000000000000..532403103ca0 --- /dev/null +++ b/connectivity/source/drivers/firebird/Util.hxx @@ -0,0 +1,27 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef CONNECTIVITY_FIREBIRD_UTIL_HXX +#define CONNECTIVITY_FIREBIRD_UTIL_HXX + +#include <rtl/ustring.hxx> + +#include <com/sun/star/sdbc/DataType.hpp> + +namespace connectivity +{ + namespace firebird + { + sal_Int32 getColumnTypeFromFBType(int aType); + ::rtl::OUString getColumnTypeNameFromFBType(int aType); + } +} +#endif //CONNECTIVITY_FIREBIRD_UTIL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file |