bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / firebird / Util.hxx
blob46fadebb1a205ccb619e34b8719ec35c71153ec5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #pragma once
12 #include <ibase.h>
14 #include <rtl/ustring.hxx>
16 #include <com/sun/star/uno/XInterface.hpp>
18 namespace connectivity::firebird
20 // Type Blob has 2 subtypes values
21 // 0 for BLOB, 1 for CLOB
22 // see http://www.firebirdfaq.org/faq48/
23 // User-defined subtypes are negative.
24 // Use a number for image which is very unlikely to be defined by a
25 // user.
26 enum class BlobSubtype {
27 Blob = 0,
28 Clob = 1,
29 Image = -9546
32 /**
33 * Numeric and decimal types can be identified by their subtype in
34 * Firebird API. 1 for NUMERIC, 2 for DECIMAL.
36 enum class NumberSubType {
37 Other = 0,
38 Numeric = 1,
39 Decimal = 2
42 class ColumnTypeInfo {
43 private:
44 short m_aType;
45 short m_aSubType;
46 short m_nScale;
47 OUString m_sCharsetName;
48 public:
49 /**
50 * @param tType SQL type of column defined by Firebird (e.g.
51 * SQL_DOUBLE)
52 * @param aSubType SQL sub type as in firebird API. See
53 * NumberSubType.
54 * @param scale: Scale of the number. It is ignored in case it's not
55 * a number. Scale obtained from the Firebird API is negative, so
56 * that should be negated before passing to this constructor.
59 explicit ColumnTypeInfo( short aType, short aSubType = 0,
60 short nScale = 0, const OUString& sCharset = OUString() )
61 : m_aType(aType)
62 , m_aSubType(aSubType)
63 , m_nScale(nScale)
64 , m_sCharsetName(sCharset) {}
65 explicit ColumnTypeInfo( short aType, const OUString& sCharset )
66 : m_aType(aType)
67 , m_aSubType(0)
68 , m_nScale(0)
69 , m_sCharsetName(sCharset) {}
70 short getType() const { return m_aType; }
71 short getSubType() const { return m_aSubType; }
72 short getScale() const { return m_nScale; }
73 OUString const & getCharacterSet() const { return m_sCharsetName; }
75 sal_Int32 getSdbcType() const;
76 OUString getColumnTypeName() const;
80 /**
81 * Make sure an identifier is safe to use within the database. Currently
82 * firebird seems to return identifiers with 93 character (instead of
83 * 31), whereby the name is simply padded with trailing whitespace.
84 * This removes all trailing whitespace (i.e. if necessary so that
85 * the length is below 31 characters). Firebird automatically compensates
86 * for such shorter strings, however any trailing padding makes the gui
87 * editing of such names harder, hence we remove all trailing whitespace.
89 OUString sanitizeIdentifier(const OUString& rIdentifier);
91 inline bool IndicatesError(const ISC_STATUS_ARRAY& rStatusVector)
93 return rStatusVector[0]==1 && rStatusVector[1]; // indicates error;
96 OUString StatusVectorToString(const ISC_STATUS_ARRAY& rStatusVector,
97 std::u16string_view rCause);
99 /**
100 * Evaluate a firebird status vector and throw exceptions as necessary.
101 * The content of the status vector is included in the thrown exception.
103 * @throws css::sdbc::SQLException
105 void evaluateStatusVector(const ISC_STATUS_ARRAY& rStatusVector,
106 std::u16string_view aCause,
107 const css::uno::Reference< css::uno::XInterface >& _rxContext);
110 * Internally (i.e. in RDB$FIELD_TYPE) firebird stores the data type
111 * for a column as defined in blr_*, however in the firebird
112 * api the SQL_* types are used, hence we need to be able to convert
113 * between the two when retrieving column metadata.
115 short getFBTypeFromBlrType(short blrType);
117 void mallocSQLVAR(XSQLDA* pSqlda);
119 void freeSQLVAR(XSQLDA* pSqlda);
121 OUString escapeWith( const OUString& sText, const char aKey, const char aEscapeChar);
122 sal_Int64 pow10Integer( int nDecimalCount );
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */