1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 
27 #include <stdio.h>
28 #include <osl/diagnose.h>
29 #include "NPreparedStatement.hxx"
30 #include <com/sun/star/sdbc/DataType.hpp>
31 #include <cppuhelper/typeprovider.hxx>
32 #include <com/sun/star/lang/DisposedException.hpp>
33 #include "propertyids.hxx"
34 #include <connectivity/dbexception.hxx>
35 #include <connectivity/dbtools.hxx>
36 #include <tools/diagnose_ex.h>
37 
38 #include "resource/common_res.hrc"
39 
40 using namespace connectivity::evoab;
41 using namespace com::sun::star::uno;
42 using namespace com::sun::star::lang;
43 using namespace com::sun::star::beans;
44 using namespace com::sun::star::sdbc;
45 using namespace com::sun::star::container;
46 using namespace com::sun::star::io;
47 using namespace com::sun::star::util;
48 
49 IMPLEMENT_SERVICE_INFO(OEvoabPreparedStatement,"com.sun.star.sdbcx.evoab.PreparedStatement","com.sun.star.sdbc.PreparedStatement");
50 
51 
OEvoabPreparedStatement(OEvoabConnection * _pConnection)52 OEvoabPreparedStatement::OEvoabPreparedStatement( OEvoabConnection* _pConnection )
53     :OCommonStatement(_pConnection)
54     ,m_sSqlStatement()
55     ,m_xMetaData()
56 {
57 }
58 
59 // -----------------------------------------------------------------------------
construct(const::rtl::OUString & _sql)60 void OEvoabPreparedStatement::construct( const ::rtl::OUString& _sql )
61 {
62     m_sSqlStatement = _sql;
63 
64     m_aQueryData = impl_getEBookQuery_throw( m_sSqlStatement );
65     ENSURE_OR_THROW( m_aQueryData.getQuery(), "no EBookQuery" );
66     ENSURE_OR_THROW( m_aQueryData.xSelectColumns.isValid(), "no SelectColumn" );
67 
68     // create our meta data
69     OEvoabResultSetMetaData* pMeta = new OEvoabResultSetMetaData( m_aQueryData.sTable );
70 	m_xMetaData = pMeta;
71 	pMeta->setEvoabFields( m_aQueryData.xSelectColumns );
72 }
73 
74 // -----------------------------------------------------------------------------
~OEvoabPreparedStatement()75 OEvoabPreparedStatement::~OEvoabPreparedStatement()
76 {
77 }
78 
79 // -----------------------------------------------------------------------------
acquire()80 void SAL_CALL OEvoabPreparedStatement::acquire() throw()
81 {
82     OCommonStatement::acquire();
83 }
84 
85 // -----------------------------------------------------------------------------
release()86 void SAL_CALL OEvoabPreparedStatement::release() throw()
87 {
88     OCommonStatement::release();
89 }
90 
91 // -----------------------------------------------------------------------------
queryInterface(const Type & rType)92 Any SAL_CALL OEvoabPreparedStatement::queryInterface( const Type & rType ) throw(RuntimeException)
93 {
94     Any aRet = OCommonStatement::queryInterface(rType);
95     if(!aRet.hasValue())
96         aRet = OPreparedStatement_BASE::queryInterface(rType);
97     return aRet;
98 }
99 // -------------------------------------------------------------------------
getTypes()100 Sequence< Type > SAL_CALL OEvoabPreparedStatement::getTypes(  ) throw(RuntimeException)
101 {
102     return ::comphelper::concatSequences(OPreparedStatement_BASE::getTypes(),OCommonStatement::getTypes());
103 }
104 // -------------------------------------------------------------------------
105 
getMetaData()106 Reference< XResultSetMetaData > SAL_CALL OEvoabPreparedStatement::getMetaData(  ) throw(SQLException, RuntimeException)
107 {
108     ::osl::MutexGuard aGuard( m_aMutex );
109     checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
110 
111     // the meta data should have been created at construction time
112     ENSURE_OR_THROW( m_xMetaData.is(), "internal error: no meta data" );
113     return m_xMetaData;
114 }
115 // -------------------------------------------------------------------------
116 
close()117 void SAL_CALL OEvoabPreparedStatement::close(  ) throw(SQLException, RuntimeException)
118 {
119     ::osl::MutexGuard aGuard( m_aMutex );
120     checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
121 
122     free_column_resources();
123     // Reset last warning message
124     try {
125         clearWarnings ();
126         OCommonStatement::close();
127     }
128     catch (SQLException &) {
129         // If we get an error, ignore
130     }
131 
132 }
133 // -------------------------------------------------------------------------
134 
execute()135 sal_Bool SAL_CALL OEvoabPreparedStatement::execute(  ) throw(SQLException, RuntimeException)
136 {
137     ::osl::MutexGuard aGuard( m_aMutex );
138     checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
139 
140     Reference< XResultSet> xRS = impl_executeQuery_throw( m_aQueryData );
141     return xRS.is();
142 }
143 // -------------------------------------------------------------------------
144 
executeUpdate()145 sal_Int32 SAL_CALL OEvoabPreparedStatement::executeUpdate(  ) throw(SQLException, RuntimeException)
146 {
147     ::osl::MutexGuard aGuard( m_aMutex );
148     checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
149     ::dbtools::throwFeatureNotImplementedException( "XStatement::executeUpdate", *this );
150     return 0;
151 }
152 // -------------------------------------------------------------------------
153 
setString(sal_Int32,const::rtl::OUString &)154 void SAL_CALL OEvoabPreparedStatement::setString( sal_Int32 /*parameterIndex*/, const ::rtl::OUString& /*x*/ ) throw(SQLException, RuntimeException)
155 {
156     ::dbtools::throwFunctionNotSupportedException( "XParameters::setString", *this );
157 }
158 // -------------------------------------------------------------------------
159 
getConnection()160 Reference< XConnection > SAL_CALL OEvoabPreparedStatement::getConnection(  ) throw(SQLException, RuntimeException)
161 {
162     ::osl::MutexGuard aGuard( m_aMutex );
163     checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
164 
165     return impl_getConnection();
166 }
167 // -------------------------------------------------------------------------
168 
executeQuery()169 Reference< XResultSet > SAL_CALL OEvoabPreparedStatement::executeQuery(  ) throw(SQLException, RuntimeException)
170 {
171     ::osl::MutexGuard aGuard( m_aMutex );
172     checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
173 
174     return impl_executeQuery_throw( m_aQueryData );
175 }
176 // -------------------------------------------------------------------------
177 
setBoolean(sal_Int32,sal_Bool)178 void SAL_CALL OEvoabPreparedStatement::setBoolean( sal_Int32 /*parameterIndex*/, sal_Bool /*x*/ ) throw(SQLException, RuntimeException)
179 {
180     ::dbtools::throwFunctionNotSupportedException( "XParameters::setBoolean", *this );
181 
182 }
183 // -------------------------------------------------------------------------
setByte(sal_Int32,sal_Int8)184 void SAL_CALL OEvoabPreparedStatement::setByte( sal_Int32 /*parameterIndex*/, sal_Int8 /*x*/ ) throw(SQLException, RuntimeException)
185 {
186     ::dbtools::throwFunctionNotSupportedException( "XParameters::setByte", *this );
187 }
188 // -------------------------------------------------------------------------
189 
setDate(sal_Int32,const Date &)190 void SAL_CALL OEvoabPreparedStatement::setDate( sal_Int32 /*parameterIndex*/, const Date& /*aData*/ ) throw(SQLException, RuntimeException)
191 {
192     ::dbtools::throwFunctionNotSupportedException( "XParameters::setDate", *this );
193 }
194 // -------------------------------------------------------------------------
195 
setTime(sal_Int32,const Time &)196 void SAL_CALL OEvoabPreparedStatement::setTime( sal_Int32 /*parameterIndex*/, const Time& /*aVal*/ ) throw(SQLException, RuntimeException)
197 {
198     ::dbtools::throwFunctionNotSupportedException( "XParameters::setTime", *this );
199 }
200 // -------------------------------------------------------------------------
201 
setTimestamp(sal_Int32,const DateTime &)202 void SAL_CALL OEvoabPreparedStatement::setTimestamp( sal_Int32 /*parameterIndex*/, const DateTime& /*aVal*/ ) throw(SQLException, RuntimeException)
203 {
204     ::dbtools::throwFunctionNotSupportedException( "XParameters::setTimestamp", *this );
205 }
206 // -------------------------------------------------------------------------
207 
setDouble(sal_Int32,double)208 void SAL_CALL OEvoabPreparedStatement::setDouble( sal_Int32 /*parameterIndex*/, double /*x*/ ) throw(SQLException, RuntimeException)
209 {
210     ::dbtools::throwFunctionNotSupportedException( "XParameters::setDouble", *this );
211 }
212 
213 // -------------------------------------------------------------------------
214 
setFloat(sal_Int32,float)215 void SAL_CALL OEvoabPreparedStatement::setFloat( sal_Int32 /*parameterIndex*/, float /*x*/ ) throw(SQLException, RuntimeException)
216 {
217     ::dbtools::throwFunctionNotSupportedException( "XParameters::setFloat", *this );
218 }
219 // -------------------------------------------------------------------------
220 
setInt(sal_Int32,sal_Int32)221 void SAL_CALL OEvoabPreparedStatement::setInt( sal_Int32 /*parameterIndex*/, sal_Int32 /*x*/ ) throw(SQLException, RuntimeException)
222 {
223     ::dbtools::throwFunctionNotSupportedException( "XParameters::setInt", *this );
224 }
225 // -------------------------------------------------------------------------
226 
setLong(sal_Int32,sal_Int64)227 void SAL_CALL OEvoabPreparedStatement::setLong( sal_Int32 /*parameterIndex*/, sal_Int64 /*aVal*/ ) throw(SQLException, RuntimeException)
228 {
229     ::dbtools::throwFunctionNotSupportedException( "XParameters::setLong", *this );
230 }
231 // -------------------------------------------------------------------------
232 
setNull(sal_Int32,sal_Int32)233 void SAL_CALL OEvoabPreparedStatement::setNull( sal_Int32 /*parameterIndex*/, sal_Int32 /*sqlType*/ ) throw(SQLException, RuntimeException)
234 {
235     ::dbtools::throwFunctionNotSupportedException( "XParameters::setNull", *this );
236 }
237 // -------------------------------------------------------------------------
238 
setClob(sal_Int32,const Reference<XClob> &)239 void SAL_CALL OEvoabPreparedStatement::setClob( sal_Int32 /*parameterIndex*/, const Reference< XClob >& /*x*/ ) throw(SQLException, RuntimeException)
240 {
241     ::dbtools::throwFunctionNotSupportedException( "XParameters::setClob", *this );
242 }
243 // -------------------------------------------------------------------------
244 
setBlob(sal_Int32,const Reference<XBlob> &)245 void SAL_CALL OEvoabPreparedStatement::setBlob( sal_Int32 /*parameterIndex*/, const Reference< XBlob >& /*x*/ ) throw(SQLException, RuntimeException)
246 {
247     ::dbtools::throwFunctionNotSupportedException( "XParameters::setBlob", *this );
248 }
249 // -------------------------------------------------------------------------
250 
setArray(sal_Int32,const Reference<XArray> &)251 void SAL_CALL OEvoabPreparedStatement::setArray( sal_Int32 /*parameterIndex*/, const Reference< XArray >& /*x*/ ) throw(SQLException, RuntimeException)
252 {
253     ::dbtools::throwFunctionNotSupportedException( "XParameters::setArray", *this );
254 }
255 // -------------------------------------------------------------------------
256 
setRef(sal_Int32,const Reference<XRef> &)257 void SAL_CALL OEvoabPreparedStatement::setRef( sal_Int32 /*parameterIndex*/, const Reference< XRef >& /*x*/ ) throw(SQLException, RuntimeException)
258 {
259     ::dbtools::throwFunctionNotSupportedException( "XParameters::setRef", *this );
260 }
261 // -------------------------------------------------------------------------
262 
setObjectWithInfo(sal_Int32,const Any &,sal_Int32,sal_Int32)263 void SAL_CALL OEvoabPreparedStatement::setObjectWithInfo( sal_Int32 /*parameterIndex*/, const Any& /*x*/, sal_Int32 /*sqlType*/, sal_Int32 /*scale*/ ) throw(SQLException, RuntimeException)
264 {
265     ::dbtools::throwFunctionNotSupportedException( "XParameters::setObjectWithInfo", *this );
266 }
267 // -------------------------------------------------------------------------
268 
setObjectNull(sal_Int32,sal_Int32,const::rtl::OUString &)269 void SAL_CALL OEvoabPreparedStatement::setObjectNull( sal_Int32 /*parameterIndex*/, sal_Int32 /*sqlType*/, const ::rtl::OUString& /*typeName*/ ) throw(SQLException, RuntimeException)
270 {
271     ::dbtools::throwFunctionNotSupportedException( "XParameters::setObjectNull", *this );
272 }
273 // -------------------------------------------------------------------------
274 
setObject(sal_Int32 parameterIndex,const Any & x)275 void SAL_CALL OEvoabPreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException)
276 {
277     if(!::dbtools::implSetObject(this,parameterIndex,x))
278     {
279         const ::rtl::OUString sError( getOwnConnection()->getResources().getResourceStringWithSubstitution(
280                 STR_UNKNOWN_PARA_TYPE,
281                 "$position$", ::rtl::OUString::valueOf(parameterIndex)
282              ) );
283         ::dbtools::throwGenericSQLException(sError,*this);
284     }
285 }
286 // -------------------------------------------------------------------------
287 
setShort(sal_Int32,sal_Int16)288 void SAL_CALL OEvoabPreparedStatement::setShort( sal_Int32 /*parameterIndex*/, sal_Int16 /*x*/ ) throw(SQLException, RuntimeException)
289 {
290     ::dbtools::throwFunctionNotSupportedException( "XParameters::setShort", *this );
291 }
292 // -------------------------------------------------------------------------
293 
setBytes(sal_Int32,const Sequence<sal_Int8> &)294 void SAL_CALL OEvoabPreparedStatement::setBytes( sal_Int32 /*parameterIndex*/, const Sequence< sal_Int8 >& /*x*/ ) throw(SQLException, RuntimeException)
295 {
296     ::dbtools::throwFunctionNotSupportedException( "XParameters::setBytes", *this );
297 }
298 // -------------------------------------------------------------------------
299 
300 
setCharacterStream(sal_Int32,const Reference<XInputStream> &,sal_Int32)301 void SAL_CALL OEvoabPreparedStatement::setCharacterStream( sal_Int32 /*parameterIndex*/, const Reference< XInputStream >& /*x*/, sal_Int32 /*length*/ ) throw(SQLException, RuntimeException)
302 {
303     ::dbtools::throwFunctionNotSupportedException( "XParameters::setCharacterStream", *this );
304 }
305 // -------------------------------------------------------------------------
306 
setBinaryStream(sal_Int32,const Reference<XInputStream> &,sal_Int32)307 void SAL_CALL OEvoabPreparedStatement::setBinaryStream( sal_Int32 /*parameterIndex*/, const Reference< XInputStream >& /*x*/, sal_Int32 /*length*/ ) throw(SQLException, RuntimeException)
308 {
309     ::dbtools::throwFunctionNotSupportedException( "XParameters::setBinaryStream", *this );
310 }
311 // -------------------------------------------------------------------------
312 
clearParameters()313 void SAL_CALL OEvoabPreparedStatement::clearParameters(  ) throw(SQLException, RuntimeException)
314 {
315 }
316 // -----------------------------------------------------------------------------
getResultSet()317 Reference< XResultSet > SAL_CALL OEvoabPreparedStatement::getResultSet(  ) throw(SQLException, RuntimeException)
318 {
319     return NULL;
320 }
321 // -----------------------------------------------------------------------------
getUpdateCount()322 sal_Int32 SAL_CALL OEvoabPreparedStatement::getUpdateCount(  ) throw(SQLException, RuntimeException)
323 {
324     return 0;
325 }
326 // -----------------------------------------------------------------------------
getMoreResults()327 sal_Bool SAL_CALL OEvoabPreparedStatement::getMoreResults(  ) throw(SQLException, RuntimeException)
328 {
329     return sal_False;
330 }
331 // -----------------------------------------------------------------------------
332