Line data Source code
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 : #ifndef _PQ_TOOLS_
38 : #define _PQ_TOOLS_
39 :
40 : #include <com/sun/star/beans/XPropertySet.hpp>
41 : #include <com/sun/star/sdbc/XParameters.hpp>
42 : #include <com/sun/star/util/Date.hpp>
43 : #include <com/sun/star/util/Time.hpp>
44 : #include <com/sun/star/util/DateTime.hpp>
45 :
46 : #include <rtl/ustrbuf.hxx>
47 : #include <rtl/string.hxx>
48 :
49 : #include <pq_connection.hxx>
50 : namespace pq_sdbc_driver
51 : {
52 : bool isWhitespace( sal_Unicode c );
53 :
54 : OUString concatQualified( const OUString & a, const OUString &b);
55 :
56 : OString OUStringToOString( const OUString& str, ConnectionSettings *settings);
57 :
58 : void bufferQuoteConstant( OUStringBuffer & buf, const OUString & str, ConnectionSettings *settings );
59 : void bufferQuoteAnyConstant( OUStringBuffer & buf, const com::sun::star::uno::Any &val, ConnectionSettings *settings );
60 :
61 : void bufferEscapeConstant( OUStringBuffer & buf, const OUString & str, ConnectionSettings *settings );
62 :
63 : OUString sqltype2string(
64 : const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > & column );
65 :
66 :
67 : void bufferQuoteQualifiedIdentifier(
68 : OUStringBuffer & buf, const OUString &schema, const OUString &name, ConnectionSettings *settings );
69 :
70 : void bufferQuoteQualifiedIdentifier(
71 : OUStringBuffer & buf,
72 : const OUString &schema,
73 : const OUString &name,
74 : const OUString &col,
75 : ConnectionSettings *settings );
76 :
77 : void bufferQuoteIdentifier( OUStringBuffer & buf, const OUString &toQuote, ConnectionSettings *settings );
78 : void bufferKey2TableConstraint(
79 : OUStringBuffer &buf,
80 : const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > &key,
81 : ConnectionSettings *settings );
82 :
83 : OUString extractStringProperty(
84 : const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > & descriptor,
85 : const OUString &name );
86 :
87 : sal_Int32 extractIntProperty(
88 : const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > & descriptor,
89 : const OUString &name );
90 :
91 : sal_Bool extractBoolProperty(
92 : const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > & descriptor,
93 : const OUString &name );
94 :
95 : void disposeNoThrow( const com::sun::star::uno::Reference< com::sun::star::uno::XInterface > & r );
96 : void disposeObject( const com::sun::star::uno::Reference< com::sun::star::uno::XInterface > & r );
97 :
98 : OUString extractTableFromInsert( const OUString & sql );
99 : OString extractSingleTableFromSelect( const OStringVector &vec );
100 :
101 : void tokenizeSQL( const OString & sql, OStringVector &vec );
102 : void splitSQL( const OString & sql, OStringVector &vec );
103 : com::sun::star::uno::Sequence< sal_Int32 > parseIntArray( const OUString & str );
104 : com::sun::star::uno::Sequence< com::sun::star::uno::Any > parseArray( const OUString & str )
105 : throw( com::sun::star::sdbc::SQLException );
106 :
107 : OUString array2String( const com::sun::star::uno::Sequence< com::sun::star::uno::Any > &seq );
108 :
109 : com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > extractConnectionFromStatement(
110 : const com::sun::star::uno::Reference< com::sun::star::uno::XInterface > & stmt );
111 :
112 : void splitConcatenatedIdentifier( const OUString & source, OUString *first, OUString *second);
113 :
114 :
115 : void fillAttnum2attnameMap(
116 : Int2StringMap &map,
117 : const com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > &conn,
118 : const OUString &schema,
119 : const OUString &table );
120 :
121 : com::sun::star::uno::Sequence< sal_Int32 > string2intarray( const OUString & str );
122 :
123 : com::sun::star::uno::Sequence< OUString > convertMappedIntArray2StringArray(
124 : const Int2StringMap &map, const com::sun::star::uno::Sequence< sal_Int32> &source );
125 :
126 : typedef ::boost::unordered_map
127 : <
128 : OString,
129 : OString,
130 : OStringHash,
131 : ::std::equal_to< OString >,
132 : Allocator< ::std::pair< OString, OString > >
133 : > String2StringMap;
134 :
135 : OUString querySingleValue(
136 : const com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > &connection,
137 : const OUString &query );
138 :
139 : void extractNameValuePairsFromInsert( String2StringMap & map, const OString & lastQuery );
140 : sal_Int32 typeNameToDataType( const OUString &typeName, const OUString &typtype );
141 :
142 : // copied from connectivity/source/dbtools, can't use the function directly
143 : bool implSetObject( const com::sun::star::uno::Reference< com::sun::star::sdbc::XParameters >& _rxParameters,
144 : const sal_Int32 _nColumnIndex, const com::sun::star::uno::Any& _rValue);
145 :
146 : class DisposeGuard
147 : {
148 : com::sun::star::uno::Reference< com::sun::star::uno::XInterface > d;
149 : public:
150 : DisposeGuard(const com::sun::star::uno::Reference< com::sun::star::uno::XInterface > & r );
151 : ~DisposeGuard();
152 :
153 : };
154 :
155 : class TransactionGuard
156 : {
157 : com::sun::star::uno::Reference< com::sun::star::sdbc::XStatement > m_stmt;
158 : sal_Bool m_commited;
159 : public:
160 : /// takes over ownership of given statemet
161 : TransactionGuard( const com::sun::star::uno::Reference< com::sun::star::sdbc::XStatement > &stmt );
162 : ~TransactionGuard( );
163 :
164 : void commit();
165 : void executeUpdate( const OUString & sql );
166 : };
167 :
168 0 : template < typename T, typename Allocator > com::sun::star::uno::Sequence<T> sequence_of_vector ( const std::vector<T, Allocator> &vec )
169 : {
170 0 : if ( vec.empty() )
171 0 : return com::sun::star::uno::Sequence<T>();
172 : else
173 0 : return com::sun::star::uno::Sequence<T>( &vec[0], vec.size());
174 : }
175 :
176 : }
177 :
178 : #endif
179 :
180 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|