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 * Version: MPL 1.1 / GPLv3+ / LGPLv2.1+
33 * The contents of this file are subject to the Mozilla Public License Version
34 * 1.1 (the "License"); you may not use this file except in compliance with
35 * the License or as specified alternatively below. You may obtain a copy of
36 * the License at http://www.mozilla.org/MPL/
38 * Software distributed under the License is distributed on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
40 * for the specific language governing rights and limitations under the
43 * Major Contributor(s):
44 * [ Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu> ]
46 * All Rights Reserved.
48 * For minor contributions see the git repository.
50 * Alternatively, the contents of this file may be used under the terms of
51 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
52 * the GNU Lesser General Public License Version 2.1 or later (the "LGPLv2.1+"),
53 * in which case the provisions of the GPLv3+ or the LGPLv2.1+ are applicable
54 * instead of those above.
56 ************************************************************************/
61 #include <com/sun/star/beans/XPropertySet.hpp>
62 #include <com/sun/star/sdbc/XParameters.hpp>
63 #include <com/sun/star/util/Date.hpp>
64 #include <com/sun/star/util/Time.hpp>
65 #include <com/sun/star/util/DateTime.hpp>
67 #include <rtl/ustrbuf.hxx>
68 #include <rtl/string.hxx>
70 #include <pq_connection.hxx>
71 namespace pq_sdbc_driver
73 bool isWhitespace( sal_Unicode c
);
75 rtl::OUString
date2String( const com::sun::star::util::Date
& date
);
76 com::sun::star::util::Date
string2Date( const rtl::OUString
& str
);
78 rtl::OUString
time2String( const com::sun::star::util::Time
& time
);
79 com::sun::star::util::Time
string2Time( const rtl::OUString
& str
);
81 rtl::OUString
dateTime2String( const com::sun::star::util::DateTime
& dateTime
);
82 com::sun::star::util::DateTime
string2DateTime( const rtl::OUString
& dateTime
);
84 rtl::OUString
concatQualified( const rtl::OUString
& a
, const rtl::OUString
&b
);
86 rtl::OString
OUStringToOString( rtl::OUString str
, ConnectionSettings
*settings
);
88 void bufferQuoteConstant( rtl::OUStringBuffer
& buf
, const rtl::OUString
& str
, ConnectionSettings
*settings
);
89 void bufferQuoteAnyConstant( rtl::OUStringBuffer
& buf
, const com::sun::star::uno::Any
&val
, ConnectionSettings
*settings
);
91 void bufferEscapeConstant( rtl::OUStringBuffer
& buf
, const rtl::OUString
& str
, ConnectionSettings
*settings
);
93 ::rtl::OUString
sqltype2string(
94 const com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySet
> & column
);
97 void bufferQuoteQualifiedIdentifier(
98 rtl::OUStringBuffer
& buf
, const rtl::OUString
&schema
, const rtl::OUString
&name
, ConnectionSettings
*settings
);
100 void bufferQuoteQualifiedIdentifier(
101 rtl::OUStringBuffer
& buf
,
102 const rtl::OUString
&schema
,
103 const rtl::OUString
&name
,
104 const rtl::OUString
&col
,
105 ConnectionSettings
*settings
);
107 void bufferQuoteIdentifier( rtl::OUStringBuffer
& buf
, const rtl::OUString
&toQuote
, ConnectionSettings
*settings
);
108 void bufferKey2TableConstraint(
109 rtl::OUStringBuffer
&buf
,
110 const com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySet
> &key
,
111 ConnectionSettings
*settings
);
113 rtl::OUString
extractStringProperty(
114 const com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySet
> & descriptor
,
115 const rtl::OUString
&name
);
117 sal_Int32
extractIntProperty(
118 const com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySet
> & descriptor
,
119 const rtl::OUString
&name
);
121 sal_Bool
extractBoolProperty(
122 const com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySet
> & descriptor
,
123 const rtl::OUString
&name
);
125 void disposeNoThrow( const com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> & r
);
126 void disposeObject( const com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> & r
);
128 ::rtl::OUString
extractTableFromInsert( const rtl::OUString
& sql
);
129 ::rtl::OString
extractSingleTableFromSelect( const OStringVector
&vec
);
131 void tokenizeSQL( const rtl::OString
& sql
, OStringVector
&vec
);
132 void splitSQL( const rtl::OString
& sql
, OStringVector
&vec
);
133 com::sun::star::uno::Sequence
< sal_Int32
> parseIntArray( const ::rtl::OUString
& str
);
134 com::sun::star::uno::Sequence
< com::sun::star::uno::Any
> parseArray( const ::rtl::OUString
& str
)
135 throw( com::sun::star::sdbc::SQLException
);
137 rtl::OUString
array2String( const com::sun::star::uno::Sequence
< com::sun::star::uno::Any
> &seq
);
139 com::sun::star::uno::Reference
< com::sun::star::sdbc::XConnection
> extractConnectionFromStatement(
140 const com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> & stmt
);
142 void splitConcatenatedIdentifier( const rtl::OUString
& source
, rtl::OUString
*first
, rtl::OUString
*second
);
145 void fillAttnum2attnameMap(
147 const com::sun::star::uno::Reference
< com::sun::star::sdbc::XConnection
> &conn
,
148 const rtl::OUString
&schema
,
149 const rtl::OUString
&table
);
151 com::sun::star::uno::Sequence
< sal_Int32
> string2intarray( const ::rtl::OUString
& str
);
153 com::sun::star::uno::Sequence
< rtl::OUString
> convertMappedIntArray2StringArray(
154 const Int2StringMap
&map
, const com::sun::star::uno::Sequence
< sal_Int32
> &source
);
156 typedef ::boost::unordered_map
161 ::std::equal_to
< rtl::OString
>,
162 Allocator
< ::std::pair
< rtl::OString
, ::rtl::OString
> >
165 rtl::OUString
querySingleValue(
166 const com::sun::star::uno::Reference
< com::sun::star::sdbc::XConnection
> &connection
,
167 const rtl::OUString
&query
);
169 void extractNameValuePairsFromInsert( String2StringMap
& map
, const rtl::OString
& lastQuery
);
170 sal_Int32
typeNameToDataType( const rtl::OUString
&typeName
, const rtl::OUString
&typtype
);
172 // copied from connectivity/source/dbtools, can't use the function directly
173 bool implSetObject( const com::sun::star::uno::Reference
< com::sun::star::sdbc::XParameters
>& _rxParameters
,
174 const sal_Int32 _nColumnIndex
, const com::sun::star::uno::Any
& _rValue
);
178 com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> d
;
180 DisposeGuard(const com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> & r
);
185 class TransactionGuard
187 com::sun::star::uno::Reference
< com::sun::star::sdbc::XStatement
> m_stmt
;
190 /// takes over ownership of given statemet
191 TransactionGuard( const com::sun::star::uno::Reference
< com::sun::star::sdbc::XStatement
> &stmt
);
192 ~TransactionGuard( );
195 void executeUpdate( const rtl::OUString
& sql
);
198 template < typename T
, typename Allocator
> com::sun::star::uno::Sequence
<T
> sequence_of_vector ( const std::vector
<T
, Allocator
> &vec
)
201 return com::sun::star::uno::Sequence
<T
>();
203 return com::sun::star::uno::Sequence
<T
>( &vec
[0], vec
.size());