1 /*************************************************************************
3 * $RCSfile: pq_tools.hxx,v $
7 * last change: $Author: jbu $ $Date: 2008/07/07 21:37:11 $
9 * The Contents of this file are made available subject to the terms of
10 * either of the following licenses
12 * - GNU Lesser General Public License Version 2.1
13 * - Sun Industry Standards Source License Version 1.1
15 * Sun Microsystems Inc., October, 2000
17 * GNU Lesser General Public License Version 2.1
18 * =============================================
19 * Copyright 2000 by Sun Microsystems, Inc.
20 * 901 San Antonio Road, Palo Alto, CA 94303, USA
22 * This library is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU Lesser General Public
24 * License version 2.1, as published by the Free Software Foundation.
26 * This library is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * Lesser General Public License for more details.
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with this library; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
37 * Sun Industry Standards Source License Version 1.1
38 * =================================================
39 * The contents of this file are subject to the Sun Industry Standards
40 * Source License Version 1.1 (the "License"); You may not use this file
41 * except in compliance with the License. You may obtain a copy of the
42 * License at http://www.openoffice.org/license.html.
44 * Software provided under this License is provided on an "AS IS" basis,
45 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
46 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
47 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
48 * See the License for the specific provisions governing your rights and
49 * obligations concerning the Software.
51 * The Initial Developer of the Original Code is: Joerg Budischewski
53 * Copyright: 2000 by Sun Microsystems, Inc.
55 * All Rights Reserved.
57 * Contributor(s): Joerg Budischewski
60 ************************************************************************/
65 #include <com/sun/star/beans/XPropertySet.hpp>
66 #include <com/sun/star/sdbc/XParameters.hpp>
67 #include <com/sun/star/util/Date.hpp>
68 #include <com/sun/star/util/Time.hpp>
69 #include <com/sun/star/util/DateTime.hpp>
71 #include <rtl/ustrbuf.hxx>
72 #include <rtl/string.hxx>
74 #include <pq_connection.hxx>
75 namespace pq_sdbc_driver
77 bool isWhitespace( sal_Unicode c
);
79 rtl::OUString
date2String( const com::sun::star::util::Date
& date
);
80 com::sun::star::util::Date
string2Date( const rtl::OUString
& str
);
82 rtl::OUString
time2String( const com::sun::star::util::Time
& time
);
83 com::sun::star::util::Time
string2Time( const rtl::OUString
& str
);
85 rtl::OUString
dateTime2String( const com::sun::star::util::DateTime
& dateTime
);
86 com::sun::star::util::DateTime
string2DateTime( const rtl::OUString
& dateTime
);
88 rtl::OUString
concatQualified( const rtl::OUString
& a
, const rtl::OUString
&b
);
90 void bufferQuoteConstant( rtl::OUStringBuffer
& buf
, const rtl::OUString
& str
, sal_Int32 encoding
);
92 void bufferEscapeConstant( rtl::OUStringBuffer
& buf
, const rtl::OUString
& str
, sal_Int32 encoding
);
94 ::rtl::OUString
sqltype2string(
95 const com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySet
> & column
);
98 void bufferQuoteQualifiedIdentifier(
99 rtl::OUStringBuffer
& buf
, const rtl::OUString
&schema
, const rtl::OUString
&name
);
101 void bufferQuoteQualifiedIdentifier(
102 rtl::OUStringBuffer
& buf
,
103 const rtl::OUString
&schema
,
104 const rtl::OUString
&name
,
105 const rtl::OUString
&col
);
107 void bufferQuoteIdentifier( rtl::OUStringBuffer
& buf
, const rtl::OUString
&toQuote
);
108 void bufferKey2TableConstraint(
109 rtl::OUStringBuffer
&buf
,
110 const com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySet
> &key
);
112 rtl::OUString
extractStringProperty(
113 const com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySet
> & descriptor
,
114 const rtl::OUString
&name
);
116 sal_Int32
extractIntProperty(
117 const com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySet
> & descriptor
,
118 const rtl::OUString
&name
);
120 sal_Bool
extractBoolProperty(
121 const com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySet
> & descriptor
,
122 const rtl::OUString
&name
);
124 void disposeNoThrow( const com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> & r
);
125 void disposeObject( const com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> & r
);
127 void rollbackNoThrow( const com::sun::star::uno::Reference
< com::sun::star::sdbc::XConnection
> & r
);
129 ::rtl::OUString
extractTableFromInsert( const rtl::OUString
& sql
);
130 ::rtl::OString
extractSingleTableFromSelect( const OStringVector
&vec
);
132 void tokenizeSQL( const rtl::OString
& sql
, OStringVector
&vec
);
133 void splitSQL( const rtl::OString
& sql
, OStringVector
&vec
);
134 com::sun::star::uno::Sequence
< sal_Int32
> parseIntArray( const ::rtl::OUString
& str
);
135 com::sun::star::uno::Sequence
< com::sun::star::uno::Any
> parseArray( const ::rtl::OUString
& str
)
136 throw( com::sun::star::sdbc::SQLException
);
138 rtl::OUString
array2String( const com::sun::star::uno::Sequence
< com::sun::star::uno::Any
> &seq
);
140 com::sun::star::uno::Reference
< com::sun::star::sdbc::XConnection
> extractConnectionFromStatement(
141 const com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> & stmt
);
143 void splitConcatenatedIdentifier( const rtl::OUString
& source
, rtl::OUString
*first
, rtl::OUString
*second
);
146 void fillAttnum2attnameMap(
148 const com::sun::star::uno::Reference
< com::sun::star::sdbc::XConnection
> &conn
,
149 const rtl::OUString
&schema
,
150 const rtl::OUString
&table
);
152 com::sun::star::uno::Sequence
< sal_Int32
> string2intarray( const ::rtl::OUString
& str
);
154 com::sun::star::uno::Sequence
< rtl::OUString
> convertMappedIntArray2StringArray(
155 const Int2StringMap
&map
, const com::sun::star::uno::Sequence
< sal_Int32
> &source
);
157 typedef std::hash_map
162 ::std::equal_to
< rtl::OString
>,
163 Allocator
< ::std::pair
< rtl::OString
, ::rtl::OString
> >
166 rtl::OUString
querySingleValue(
167 const com::sun::star::uno::Reference
< com::sun::star::sdbc::XConnection
> &connection
,
168 const rtl::OUString
&query
);
170 void extractNameValuePairsFromInsert( String2StringMap
& map
, const rtl::OString
& lastQuery
);
171 sal_Int32
typeNameToDataType( const rtl::OUString
&typeName
, const rtl::OUString
&typtype
);
173 // copied from connectivity/source/dbtools, can't use the function directly
174 bool implSetObject( const com::sun::star::uno::Reference
< com::sun::star::sdbc::XParameters
>& _rxParameters
,
175 const sal_Int32 _nColumnIndex
, const com::sun::star::uno::Any
& _rValue
);
179 com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> d
;
181 DisposeGuard(const com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> & r
);
186 class TransactionGuard
188 com::sun::star::uno::Reference
< com::sun::star::sdbc::XStatement
> m_stmt
;
191 /// takes over ownership of given statemet
192 TransactionGuard( const com::sun::star::uno::Reference
< com::sun::star::sdbc::XStatement
> &stmt
);
193 ~TransactionGuard( );
196 void executeUpdate( const rtl::OUString
& sql
);