1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * Effective License of whole file:
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.
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.
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,
20 * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
22 * The Contents of this file are made available subject to the terms of
23 * the GNU Lesser General Public License Version 2.1
25 * Copyright: 2000 by Sun Microsystems, Inc.
27 * Contributor(s): Joerg Budischewski
29 * All parts contributed on or after August 2011:
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/.
35 ************************************************************************/
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>
45 #include <rtl/ustrbuf.hxx>
46 #include <rtl/string.hxx>
48 #include "pq_connection.hxx"
50 #include <string_view>
55 // helper to create one-time deleters
57 using deleter_from_fn
= std::integral_constant
<decltype(fn
), fn
>;
61 namespace pq_sdbc_driver
63 bool isWhitespace( sal_Unicode c
);
65 OUString
concatQualified( std::u16string_view a
, std::u16string_view b
);
67 OString
OUStringToOString( std::u16string_view str
, ConnectionSettings
const *settings
);
69 void bufferQuoteConstant( OUStringBuffer
& buf
, std::u16string_view str
, ConnectionSettings
*settings
);
70 void bufferQuoteAnyConstant( OUStringBuffer
& buf
, const css::uno::Any
&val
, ConnectionSettings
*settings
);
72 void bufferEscapeConstant( OUStringBuffer
& buf
, std::u16string_view str
, ConnectionSettings
*settings
);
74 OUString
sqltype2string(
75 const css::uno::Reference
< css::beans::XPropertySet
> & column
);
78 void bufferQuoteQualifiedIdentifier(
79 OUStringBuffer
& buf
, std::u16string_view schema
, std::u16string_view name
, ConnectionSettings
*settings
);
81 void bufferQuoteQualifiedIdentifier(
83 std::u16string_view schema
,
84 std::u16string_view name
,
85 std::u16string_view col
,
86 ConnectionSettings
*settings
);
88 void bufferQuoteIdentifier( OUStringBuffer
& buf
, std::u16string_view toQuote
, ConnectionSettings
*settings
);
89 void bufferKey2TableConstraint(
91 const css::uno::Reference
< css::beans::XPropertySet
> &key
,
92 ConnectionSettings
*settings
);
94 OUString
extractStringProperty(
95 const css::uno::Reference
< css::beans::XPropertySet
> & descriptor
,
96 const OUString
&name
);
98 sal_Int32
extractIntProperty(
99 const css::uno::Reference
< css::beans::XPropertySet
> & descriptor
,
100 const OUString
&name
);
102 bool extractBoolProperty(
103 const css::uno::Reference
< css::beans::XPropertySet
> & descriptor
,
104 const OUString
&name
);
106 void disposeNoThrow( const css::uno::Reference
< css::uno::XInterface
> & r
);
107 void disposeObject( const css::uno::Reference
< css::uno::XInterface
> & r
);
109 OUString
extractTableFromInsert( std::u16string_view sql
);
110 OString
extractSingleTableFromSelect( const std::vector
< OString
> &vec
);
112 OUString
getColExprForDefaultSettingVal(ConnectionSettings
const *settings
);
114 void tokenizeSQL( const OString
& sql
, std::vector
< OString
> &vec
);
115 void splitSQL( const OString
& sql
, std::vector
< OString
> &vec
);
116 std::vector
< sal_Int32
> parseIntArray( const OUString
& str
);
117 /// @throws css::sdbc::SQLException
118 std::vector
< css::uno::Any
> parseArray( std::u16string_view str
);
120 OUString
array2String( const css::uno::Sequence
< css::uno::Any
> &seq
);
122 css::uno::Reference
< css::sdbc::XConnection
> extractConnectionFromStatement(
123 const css::uno::Reference
< css::uno::XInterface
> & stmt
);
125 void splitConcatenatedIdentifier( std::u16string_view source
, OUString
*first
, OUString
*second
);
128 void fillAttnum2attnameMap(
130 const css::uno::Reference
< css::sdbc::XConnection
> &conn
,
131 const OUString
&schema
,
132 const OUString
&table
);
134 css::uno::Sequence
< sal_Int32
> string2intarray( std::u16string_view str
);
136 css::uno::Sequence
< OUString
> convertMappedIntArray2StringArray(
137 const Int2StringMap
&map
, const css::uno::Sequence
< sal_Int32
> &source
);
139 typedef std::unordered_map
< OString
, OString
> String2StringMap
;
141 OUString
querySingleValue(
142 const css::uno::Reference
< css::sdbc::XConnection
> &connection
,
143 const OUString
&query
);
145 void extractNameValuePairsFromInsert( String2StringMap
& map
, const OString
& lastQuery
);
146 sal_Int32
typeNameToDataType( const OUString
&typeName
, std::u16string_view typtype
);
148 // copied from connectivity/source/dbtools, can't use the function directly
149 bool implSetObject( const css::uno::Reference
< css::sdbc::XParameters
>& _rxParameters
,
150 const sal_Int32 _nColumnIndex
, const css::uno::Any
& _rValue
);
154 css::uno::Reference
< css::uno::XInterface
> d
;
156 explicit DisposeGuard(const css::uno::Reference
< css::uno::XInterface
> & r
);
161 class TransactionGuard
163 css::uno::Reference
< css::sdbc::XStatement
> m_stmt
;
166 /// takes over ownership of given statement
167 explicit TransactionGuard( const css::uno::Reference
< css::sdbc::XStatement
> &stmt
);
168 ~TransactionGuard( );
171 void executeUpdate( const OUString
& sql
);
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */