2013-07-22 08:36:52 +02:00
|
|
|
/* -*- 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/.
|
|
|
|
*/
|
|
|
|
|
2014-04-18 18:41:08 +02:00
|
|
|
#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_UTIL_HXX
|
|
|
|
#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_UTIL_HXX
|
2013-07-22 08:36:52 +02:00
|
|
|
|
2013-07-22 13:29:02 +02:00
|
|
|
#include <ibase.h>
|
|
|
|
|
2013-07-22 08:36:52 +02:00
|
|
|
#include <rtl/ustring.hxx>
|
2016-08-11 20:03:18 +02:00
|
|
|
#include <rtl/ustrbuf.hxx>
|
2013-07-22 08:36:52 +02:00
|
|
|
|
|
|
|
#include <com/sun/star/sdbc/DataType.hpp>
|
2013-07-25 16:30:32 +02:00
|
|
|
#include <com/sun/star/sdbc/SQLException.hpp>
|
2013-07-22 08:36:52 +02:00
|
|
|
|
|
|
|
namespace connectivity
|
|
|
|
{
|
|
|
|
namespace firebird
|
|
|
|
{
|
2016-11-12 01:11:42 +01:00
|
|
|
// Type Blob has 2 subtypes values
|
|
|
|
// 0 for BLOB, 1 for CLOB
|
|
|
|
// see http://www.firebirdfaq.org/faq48/
|
2017-12-27 20:25:33 +01:00
|
|
|
// User-defined subtypes are negative.
|
|
|
|
// Use a number for image which is very unlikely to be defined by a
|
|
|
|
// user.
|
2016-11-12 01:11:42 +01:00
|
|
|
enum class BlobSubtype {
|
|
|
|
Blob = 0,
|
2017-12-27 20:25:33 +01:00
|
|
|
Clob = 1,
|
|
|
|
Image = -9546
|
2016-11-12 01:11:42 +01:00
|
|
|
};
|
|
|
|
|
2017-12-16 12:57:43 +01:00
|
|
|
// Numeric and decimal types can be identified by their subtype
|
|
|
|
// 1 for NUMERIC, 2 for DECIMAL
|
|
|
|
enum class NumberSubType {
|
|
|
|
Other = 0,
|
|
|
|
Numeric = 1,
|
|
|
|
Decimal = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
class ColumnTypeInfo {
|
|
|
|
private:
|
|
|
|
short m_aType;
|
|
|
|
short m_aSubType;
|
|
|
|
short m_nScale;
|
|
|
|
OUString m_sCharsetName;
|
|
|
|
public:
|
|
|
|
explicit ColumnTypeInfo( short aType, short aSubType = 0,
|
|
|
|
short nScale = 0, const OUString& sCharset = OUString() )
|
|
|
|
: m_aType(aType)
|
|
|
|
, m_aSubType(aSubType)
|
|
|
|
, m_nScale(nScale)
|
|
|
|
, m_sCharsetName(sCharset) {}
|
|
|
|
explicit ColumnTypeInfo( short aType, const OUString& sCharset )
|
|
|
|
: m_aType(aType)
|
|
|
|
, m_aSubType(0)
|
|
|
|
, m_nScale(0)
|
|
|
|
, m_sCharsetName(sCharset) {}
|
|
|
|
short getType() const { return m_aType; }
|
|
|
|
short getSubType() const { return m_aSubType; }
|
|
|
|
short getScale() const { return m_nScale; }
|
2017-12-29 14:15:54 +02:00
|
|
|
OUString const & getCharacterSet() const { return m_sCharsetName; }
|
2017-12-16 12:57:43 +01:00
|
|
|
|
|
|
|
sal_Int32 getSdbcType() const;
|
|
|
|
::rtl::OUString getColumnTypeName() const;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-07-31 17:22:43 +02:00
|
|
|
/**
|
2017-03-15 16:03:00 +00:00
|
|
|
* Make sure an identifier is safe to use within the database. Currently
|
2013-07-31 17:22:43 +02:00
|
|
|
* firebird seems to return identifiers with 93 character (instead of
|
2013-08-14 09:56:06 +01:00
|
|
|
* 31), whereby the name is simply padded with trailing whitespace.
|
|
|
|
* This removes all trailing whitespace (i.e. if necessary so that
|
|
|
|
* the length is below 31 characters). Firebird automatically compensates
|
|
|
|
* for such shorter strings, however any trailing padding makes the gui
|
|
|
|
* editing of such names harder, hence we remove all trailing whitespace.
|
2013-07-31 17:22:43 +02:00
|
|
|
*/
|
2014-10-13 09:59:00 +01:00
|
|
|
OUString sanitizeIdentifier(const OUString& rIdentifier);
|
|
|
|
|
|
|
|
inline bool IndicatesError(const ISC_STATUS_ARRAY& rStatusVector)
|
|
|
|
{
|
|
|
|
return rStatusVector[0]==1 && rStatusVector[1]; // indicates error;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString StatusVectorToString(const ISC_STATUS_ARRAY& rStatusVector,
|
|
|
|
const OUString& rCause);
|
2013-07-31 17:22:43 +02:00
|
|
|
|
2013-07-25 16:30:32 +02:00
|
|
|
/**
|
|
|
|
* Evaluate a firebird status vector and throw exceptions as necessary.
|
|
|
|
* The content of the status vector is included in the thrown exception.
|
2017-01-19 17:59:45 +01:00
|
|
|
*
|
|
|
|
* @throws css::sdbc::SQLException
|
2013-07-25 16:30:32 +02:00
|
|
|
*/
|
2014-10-13 09:59:00 +01:00
|
|
|
void evaluateStatusVector(const ISC_STATUS_ARRAY& rStatusVector,
|
2013-07-25 16:30:32 +02:00
|
|
|
const ::rtl::OUString& aCause,
|
2017-01-26 12:28:58 +01:00
|
|
|
const css::uno::Reference< css::uno::XInterface >& _rxContext);
|
2013-07-25 16:30:32 +02:00
|
|
|
|
2013-07-22 09:30:30 +02:00
|
|
|
/**
|
|
|
|
* Internally (i.e. in RDB$FIELD_TYPE) firebird stores the data type
|
|
|
|
* for a column as defined in blr_*, however in the firebird
|
|
|
|
* api the SQL_* types are used, hence we need to be able to convert
|
|
|
|
* between the two when retrieving column metadata.
|
|
|
|
*/
|
|
|
|
short getFBTypeFromBlrType(short blrType);
|
2013-07-22 13:29:02 +02:00
|
|
|
|
|
|
|
void mallocSQLVAR(XSQLDA* pSqlda);
|
|
|
|
|
2013-08-15 15:32:17 +01:00
|
|
|
void freeSQLVAR(XSQLDA* pSqlda);
|
2016-08-11 20:03:18 +02:00
|
|
|
|
|
|
|
OUString escapeWith( const OUString& sText, const char aKey, const char aEscapeChar);
|
2016-10-31 16:32:54 +01:00
|
|
|
sal_Int64 pow10Integer( int nDecimalCount );
|
2013-07-22 08:36:52 +02:00
|
|
|
}
|
|
|
|
}
|
2014-04-18 18:41:08 +02:00
|
|
|
#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_UTIL_HXX
|
2013-07-22 08:36:52 +02:00
|
|
|
|
2014-10-13 09:59:00 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|