LibreOffice Module connectivity (master) 1
pq_tools.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * Effective License of whole file:
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1, as published by the Free Software Foundation.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 * MA 02111-1307 USA
19 *
20 * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
21 *
22 * The Contents of this file are made available subject to the terms of
23 * the GNU Lesser General Public License Version 2.1
24 *
25 * Copyright: 2000 by Sun Microsystems, Inc.
26 *
27 * Contributor(s): Joerg Budischewski
28 *
29 * All parts contributed on or after August 2011:
30 *
31 * This Source Code Form is subject to the terms of the Mozilla Public
32 * License, v. 2.0. If a copy of the MPL was not distributed with this
33 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
34 *
35 ************************************************************************/
36
37#pragma once
38
39#include <com/sun/star/beans/XPropertySet.hpp>
40#include <com/sun/star/sdbc/XParameters.hpp>
41#include <com/sun/star/util/Date.hpp>
42#include <com/sun/star/util/Time.hpp>
43#include <com/sun/star/util/DateTime.hpp>
44
45#include <rtl/ustrbuf.hxx>
46#include <rtl/string.hxx>
47
48#include "pq_connection.hxx"
49
50#include <string_view>
51#include <vector>
52
53namespace
54{
55// helper to create one-time deleters
56template <auto fn>
57using deleter_from_fn = std::integral_constant<decltype(fn), fn>;
58
59}
60
61namespace pq_sdbc_driver
62{
64
65OUString concatQualified( std::u16string_view a, std::u16string_view b);
66
67OString OUStringToOString( std::u16string_view str, ConnectionSettings const *settings);
68
69void bufferQuoteConstant( OUStringBuffer & buf, std::u16string_view str, ConnectionSettings *settings );
70void bufferQuoteAnyConstant( OUStringBuffer & buf, const css::uno::Any &val, ConnectionSettings *settings );
71
72void bufferEscapeConstant( OUStringBuffer & buf, std::u16string_view str, ConnectionSettings *settings );
73
75 const css::uno::Reference< css::beans::XPropertySet > & column );
76
77
79 OUStringBuffer & buf, std::u16string_view schema, std::u16string_view name, ConnectionSettings *settings );
80
82 OUStringBuffer & buf,
83 std::u16string_view schema,
84 std::u16string_view name,
85 std::u16string_view col,
86 ConnectionSettings *settings );
87
88void bufferQuoteIdentifier( OUStringBuffer & buf, std::u16string_view toQuote, ConnectionSettings *settings );
90 OUStringBuffer &buf,
91 const css::uno::Reference< css::beans::XPropertySet > &key,
92 ConnectionSettings *settings );
93
95 const css::uno::Reference< css::beans::XPropertySet > & descriptor,
96 const OUString &name );
97
99 const css::uno::Reference< css::beans::XPropertySet > & descriptor,
100 const OUString &name );
101
103 const css::uno::Reference< css::beans::XPropertySet > & descriptor,
104 const OUString &name );
105
106void disposeNoThrow( const css::uno::Reference< css::uno::XInterface > & r );
107void disposeObject( const css::uno::Reference< css::uno::XInterface > & r );
108
109OUString extractTableFromInsert( std::u16string_view sql );
110OString extractSingleTableFromSelect( const std::vector< OString > &vec );
111
112OUString getColExprForDefaultSettingVal(ConnectionSettings const *settings);
113
114void tokenizeSQL( const OString & sql, std::vector< OString > &vec );
115void splitSQL( const OString & sql, std::vector< OString > &vec );
116std::vector< sal_Int32 > parseIntArray( const OUString & str );
118std::vector< css::uno::Any > parseArray( std::u16string_view str );
119
120OUString array2String( const css::uno::Sequence< css::uno::Any > &seq );
121
122css::uno::Reference< css::sdbc::XConnection > extractConnectionFromStatement(
123 const css::uno::Reference< css::uno::XInterface > & stmt );
124
125void splitConcatenatedIdentifier( std::u16string_view source, OUString *first, OUString *second);
126
127
129 Int2StringMap &map,
130 const css::uno::Reference< css::sdbc::XConnection > &conn,
131 const OUString &schema,
132 const OUString &table );
133
134css::uno::Sequence< sal_Int32 > string2intarray( const OUString & str );
135
136css::uno::Sequence< OUString > convertMappedIntArray2StringArray(
137 const Int2StringMap &map, const css::uno::Sequence< sal_Int32> &source );
138
139typedef std::unordered_map< OString, OString > String2StringMap;
140
141OUString querySingleValue(
142 const css::uno::Reference< css::sdbc::XConnection > &connection,
143 const OUString &query );
144
145void extractNameValuePairsFromInsert( String2StringMap & map, const OString & lastQuery );
146sal_Int32 typeNameToDataType( const OUString &typeName, std::u16string_view typtype );
147
148// copied from connectivity/source/dbtools, can't use the function directly
149bool implSetObject( const css::uno::Reference< css::sdbc::XParameters >& _rxParameters,
150 const sal_Int32 _nColumnIndex, const css::uno::Any& _rValue);
151
153{
154 css::uno::Reference< css::uno::XInterface > d;
155public:
156 explicit DisposeGuard(const css::uno::Reference< css::uno::XInterface > & r );
158
159};
160
162{
163 css::uno::Reference< css::sdbc::XStatement > m_stmt;
165public:
167 explicit TransactionGuard( const css::uno::Reference< css::sdbc::XStatement > &stmt );
169
170 void commit();
171 void executeUpdate( const OUString & sql );
172};
173
174}
175
176/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::uno::XInterface > d
Definition: pq_tools.hxx:154
DisposeGuard(const css::uno::Reference< css::uno::XInterface > &r)
TransactionGuard(const css::uno::Reference< css::sdbc::XStatement > &stmt)
takes over ownership of given statement
css::uno::Reference< css::sdbc::XStatement > m_stmt
Definition: pq_tools.hxx:163
void executeUpdate(const OUString &sql)
Definition: pq_tools.cxx:292
OString extractSingleTableFromSelect(const std::vector< OString > &vec)
Definition: pq_tools.cxx:732
bool implSetObject(const Reference< XParameters > &_rxParameters, const sal_Int32 _nColumnIndex, const Any &_rValue)
Definition: pq_tools.cxx:1157
void bufferQuoteConstant(OUStringBuffer &buf, std::u16string_view value, ConnectionSettings *settings)
Definition: pq_tools.cxx:138
bool isWhitespace(sal_Unicode c)
Definition: pq_tools.cxx:313
void bufferQuoteQualifiedIdentifier(OUStringBuffer &buf, std::u16string_view schema, std::u16string_view table, ConnectionSettings *settings)
Definition: pq_tools.cxx:181
OUString extractTableFromInsert(std::u16string_view sql)
Definition: pq_tools.cxx:318
OUString concatQualified(std::u16string_view a, std::u16string_view b)
Definition: pq_tools.cxx:90
OUString array2String(const css::uno::Sequence< Any > &seq)
Definition: pq_tools.cxx:569
sal_Int32 extractIntProperty(const Reference< XPropertySet > &descriptor, const OUString &name)
Definition: pq_tools.cxx:220
css::uno::Sequence< sal_Int32 > string2intarray(const OUString &str)
Definition: pq_tools.cxx:843
std::vector< sal_Int32 > parseIntArray(const OUString &str)
Definition: pq_tools.cxx:691
OUString sqltype2string(const Reference< XPropertySet > &desc)
Definition: pq_tools.cxx:932
void tokenizeSQL(const OString &sql, std::vector< OString > &vec)
Definition: pq_tools.cxx:464
void bufferQuoteAnyConstant(OUStringBuffer &buf, const Any &val, ConnectionSettings *settings)
Definition: pq_tools.cxx:143
void extractNameValuePairsFromInsert(String2StringMap &map, const OString &lastQuery)
Definition: pq_tools.cxx:1080
OUString querySingleValue(const css::uno::Reference< css::sdbc::XConnection > &connection, const OUString &query)
Definition: pq_tools.cxx:1141
OUString extractStringProperty(const Reference< XPropertySet > &descriptor, const OUString &name)
Definition: pq_tools.cxx:204
std::unordered_map< OString, OString > String2StringMap
Definition: pq_tools.hxx:139
void splitConcatenatedIdentifier(std::u16string_view source, OUString *first, OUString *second)
Definition: pq_tools.cxx:548
void disposeNoThrow(const css::uno::Reference< css::uno::XInterface > &r)
Definition: pq_tools.cxx:235
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
Definition: pq_tools.cxx:100
OUString getColExprForDefaultSettingVal(ConnectionSettings const *settings)
Definition: pq_tools.cxx:836
Sequence< OUString > convertMappedIntArray2StringArray(const Int2StringMap &map, const Sequence< sal_Int32 > &intArray)
Definition: pq_tools.cxx:917
Reference< XConnection > extractConnectionFromStatement(const Reference< XInterface > &stmt)
Definition: pq_tools.cxx:248
void bufferQuoteIdentifier(OUStringBuffer &buf, std::u16string_view toQuote, ConnectionSettings *settings)
Definition: pq_tools.cxx:175
void bufferEscapeConstant(OUStringBuffer &buf, std::u16string_view value, ConnectionSettings *settings)
Definition: pq_tools.cxx:104
void splitSQL(const OString &sql, std::vector< OString > &vec)
Definition: pq_tools.cxx:404
std::unordered_map< sal_Int32, OUString > Int2StringMap
void bufferKey2TableConstraint(OUStringBuffer &buf, const Reference< XPropertySet > &key, ConnectionSettings *settings)
Definition: pq_tools.cxx:991
bool extractBoolProperty(const Reference< XPropertySet > &descriptor, const OUString &name)
Definition: pq_tools.cxx:212
void disposeObject(const css::uno::Reference< css::uno::XInterface > &r)
Definition: pq_tools.cxx:228
std::vector< Any > parseArray(std::u16string_view str)
Definition: pq_tools.cxx:599
sal_Int32 typeNameToDataType(const OUString &typeName, std::u16string_view typtype)
returns the constant from sdbc.DataType
void fillAttnum2attnameMap(Int2StringMap &map, const Reference< css::sdbc::XConnection > &conn, const OUString &schema, const OUString &table)
Definition: pq_tools.cxx:707
OUString typeName
OUString name
Definition: pq_statics.cxx:74
sal_uInt16 sal_Unicode