1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MacabPreparedStatement.cxx,v $
10 * $Revision: 1.3.56.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
34 #include "MacabPreparedStatement.hxx"
35 #include "MacabAddressBook.hxx"
36 #include "propertyids.hxx"
37 #include <connectivity/dbexception.hxx>
38 #include "connectivity/dbtools.hxx"
39 #include "resource/macab_res.hrc"
40 #include "resource/sharedresources.hxx"
42 using namespace connectivity::macab
;
43 using namespace com::sun::star::uno
;
44 using namespace com::sun::star::lang
;
45 using namespace com::sun::star::sdbc
;
46 using namespace com::sun::star::util
;
48 IMPLEMENT_SERVICE_INFO(MacabPreparedStatement
, "com.sun.star.sdbc.drivers.MacabPreparedStatement", "com.sun.star.sdbc.PreparedStatement");
49 // -------------------------------------------------------------------------
50 void MacabPreparedStatement::checkAndResizeParameters(sal_Int32 nParams
) throw(SQLException
)
52 if ( !m_aParameterRow
.isValid() )
53 m_aParameterRow
= new OValueVector();
56 ::dbtools::throwInvalidIndexException(*(MacabPreparedStatement
*) this,Any());
58 if (nParams
>= (sal_Int32
) (m_aParameterRow
->get()).size())
59 (m_aParameterRow
->get()).resize(nParams
);
61 // -------------------------------------------------------------------------
62 void MacabPreparedStatement::setMacabFields() const throw(SQLException
)
64 ::vos::ORef
<connectivity::OSQLColumns
> xColumns
; // selected columns
66 xColumns
= m_aSQLIterator
.getSelectColumns();
67 if (!xColumns
.isValid())
69 ::connectivity::SharedResources aResources
;
70 const ::rtl::OUString
sError( aResources
.getResourceString(
71 STR_INVALID_COLUMN_SELECTION
73 ::dbtools::throwGenericSQLException(sError
,NULL
);
75 m_xMetaData
->setMacabFields(xColumns
);
77 // -------------------------------------------------------------------------
78 void MacabPreparedStatement::resetParameters() const throw(SQLException
)
80 m_nParameterIndex
= 0;
82 // -------------------------------------------------------------------------
83 void MacabPreparedStatement::getNextParameter(::rtl::OUString
&rParameter
) const throw(SQLException
)
85 if (m_nParameterIndex
>= (sal_Int32
) (m_aParameterRow
->get()).size())
87 ::connectivity::SharedResources aResources
;
88 const ::rtl::OUString
sError( aResources
.getResourceString(
89 STR_INVALID_PARA_COUNT
91 ::dbtools::throwGenericSQLException(sError
,*(MacabPreparedStatement
*) this);
94 rParameter
= (m_aParameterRow
->get())[m_nParameterIndex
];
98 // -------------------------------------------------------------------------
99 MacabPreparedStatement::MacabPreparedStatement(
100 MacabConnection
* _pConnection
,
101 const ::rtl::OUString
& sql
)
102 : MacabPreparedStatement_BASE(_pConnection
),
103 m_sSqlStatement(sql
),
104 m_bPrepared(sal_False
),
105 m_nParameterIndex(0),
110 // -------------------------------------------------------------------------
111 MacabPreparedStatement::~MacabPreparedStatement()
114 // -------------------------------------------------------------------------
115 void MacabPreparedStatement::disposing()
117 MacabPreparedStatement_BASE::disposing();
119 if (m_aParameterRow
.isValid())
121 m_aParameterRow
->get().clear();
122 m_aParameterRow
= NULL
;
125 // -------------------------------------------------------------------------
126 Reference
< XResultSetMetaData
> SAL_CALL
MacabPreparedStatement::getMetaData() throw(SQLException
, RuntimeException
)
128 ::osl::MutexGuard
aGuard( m_aMutex
);
129 checkDisposed(MacabCommonStatement_BASE::rBHelper
.bDisposed
);
131 if (!m_xMetaData
.is())
133 const OSQLTables
& xTabs
= m_aSQLIterator
.getTables();
134 ::rtl::OUString sTableName
= MacabAddressBook::getDefaultTableName();
139 // can only deal with one table at a time
140 if(xTabs
.size() == 1 && !m_aSQLIterator
.hasErrors() )
141 sTableName
= xTabs
.begin()->first
;
144 m_xMetaData
= new MacabResultSetMetaData(getOwnConnection(),sTableName
);
147 Reference
< XResultSetMetaData
> xMetaData
= m_xMetaData
.get();
150 // -------------------------------------------------------------------------
151 void SAL_CALL
MacabPreparedStatement::close() throw(SQLException
, RuntimeException
)
153 ::osl::MutexGuard
aGuard( m_aMutex
);
154 checkDisposed(MacabCommonStatement_BASE::rBHelper
.bDisposed
);
156 // Reset last warning message
159 MacabCommonStatement::close();
161 catch (SQLException
&) {
162 // If we get an error, ignore
165 // Remove this Statement object from the Connection object's
168 // -------------------------------------------------------------------------
169 sal_Bool SAL_CALL
MacabPreparedStatement::execute() throw(SQLException
, RuntimeException
)
171 ::osl::MutexGuard
aGuard( m_aMutex
);
172 checkDisposed(MacabCommonStatement_BASE::rBHelper
.bDisposed
);
174 Reference
< XResultSet
> xRS
= MacabCommonStatement::executeQuery(m_sSqlStatement
);
178 // -------------------------------------------------------------------------
179 sal_Int32 SAL_CALL
MacabPreparedStatement::executeUpdate() throw(SQLException
, RuntimeException
)
181 ::osl::MutexGuard
aGuard( m_aMutex
);
182 checkDisposed(MacabCommonStatement_BASE::rBHelper
.bDisposed
);
184 // same as in statement with the difference that this statement also can contain parameter
187 // -------------------------------------------------------------------------
188 Reference
< XConnection
> SAL_CALL
MacabPreparedStatement::getConnection() throw(SQLException
, RuntimeException
)
190 ::osl::MutexGuard
aGuard( m_aMutex
);
191 checkDisposed(MacabCommonStatement_BASE::rBHelper
.bDisposed
);
193 return (Reference
< XConnection
>) m_pConnection
;
195 // -------------------------------------------------------------------------
196 Reference
< XResultSet
> SAL_CALL
MacabPreparedStatement::executeQuery() throw(SQLException
, RuntimeException
)
198 ::osl::MutexGuard
aGuard( m_aMutex
);
199 checkDisposed(MacabCommonStatement_BASE::rBHelper
.bDisposed
);
201 Reference
< XResultSet
> rs
= MacabCommonStatement::executeQuery(m_sSqlStatement
);
205 // -------------------------------------------------------------------------
206 void SAL_CALL
MacabPreparedStatement::setNull(sal_Int32 parameterIndex
, sal_Int32
) throw(SQLException
, RuntimeException
)
208 ::osl::MutexGuard
aGuard( m_aMutex
);
209 checkDisposed(MacabCommonStatement_BASE::rBHelper
.bDisposed
);
211 checkAndResizeParameters(parameterIndex
);
213 (m_aParameterRow
->get())[parameterIndex
- 1].setNull();
215 // -------------------------------------------------------------------------
216 void SAL_CALL
MacabPreparedStatement::setObjectNull(sal_Int32
, sal_Int32
, const ::rtl::OUString
&) throw(SQLException
, RuntimeException
)
221 ::dbtools::throwFunctionNotSupportedException("setObjectNull", NULL
);
223 // -------------------------------------------------------------------------
224 void SAL_CALL
MacabPreparedStatement::setBoolean(sal_Int32
, sal_Bool
) throw(SQLException
, RuntimeException
)
229 ::dbtools::throwFunctionNotSupportedException("setBoolean", NULL
);
231 // -------------------------------------------------------------------------
232 void SAL_CALL
MacabPreparedStatement::setByte(sal_Int32
, sal_Int8
) throw(SQLException
, RuntimeException
)
237 ::dbtools::throwFunctionNotSupportedException("setByte", NULL
);
239 // -------------------------------------------------------------------------
240 void SAL_CALL
MacabPreparedStatement::setShort(sal_Int32
, sal_Int16
) throw(SQLException
, RuntimeException
)
245 ::dbtools::throwFunctionNotSupportedException("setShort", NULL
);
247 // -------------------------------------------------------------------------
248 void SAL_CALL
MacabPreparedStatement::setInt(sal_Int32
, sal_Int32
) throw(SQLException
, RuntimeException
)
253 ::dbtools::throwFunctionNotSupportedException("setInt", NULL
);
255 // -------------------------------------------------------------------------
256 void SAL_CALL
MacabPreparedStatement::setLong(sal_Int32
, sal_Int64
) throw(SQLException
, RuntimeException
)
261 ::dbtools::throwFunctionNotSupportedException("setLong", NULL
);
263 // -------------------------------------------------------------------------
264 void SAL_CALL
MacabPreparedStatement::setFloat(sal_Int32
, float) throw(SQLException
, RuntimeException
)
269 ::dbtools::throwFunctionNotSupportedException("setFloat", NULL
);
271 // -------------------------------------------------------------------------
272 void SAL_CALL
MacabPreparedStatement::setDouble(sal_Int32
, double) throw(SQLException
, RuntimeException
)
277 ::dbtools::throwFunctionNotSupportedException("setDouble", NULL
);
279 // -------------------------------------------------------------------------
280 void SAL_CALL
MacabPreparedStatement::setString(sal_Int32 parameterIndex
, const ::rtl::OUString
&x
) throw(SQLException
, RuntimeException
)
282 ::osl::MutexGuard
aGuard( m_aMutex
);
283 checkDisposed(MacabCommonStatement_BASE::rBHelper
.bDisposed
);
285 checkAndResizeParameters(parameterIndex
);
287 (m_aParameterRow
->get())[parameterIndex
- 1] = x
;
289 // -------------------------------------------------------------------------
290 void SAL_CALL
MacabPreparedStatement::setBytes(sal_Int32
, const Sequence
< sal_Int8
>&) throw(SQLException
, RuntimeException
)
295 ::dbtools::throwFunctionNotSupportedException("setBytes", NULL
);
297 // -------------------------------------------------------------------------
298 void SAL_CALL
MacabPreparedStatement::setDate(sal_Int32
, const Date
&) throw(SQLException
, RuntimeException
)
303 ::dbtools::throwFunctionNotSupportedException("setDate", NULL
);
305 // -------------------------------------------------------------------------
306 void SAL_CALL
MacabPreparedStatement::setTime(sal_Int32
, const Time
&) throw(SQLException
, RuntimeException
)
311 ::dbtools::throwFunctionNotSupportedException("setTime", NULL
);
313 // -------------------------------------------------------------------------
314 void SAL_CALL
MacabPreparedStatement::setTimestamp(sal_Int32
, const DateTime
&) throw(SQLException
, RuntimeException
)
319 ::dbtools::throwFunctionNotSupportedException("setTimestamp", NULL
);
321 // -------------------------------------------------------------------------
322 void SAL_CALL
MacabPreparedStatement::setBinaryStream(sal_Int32
, const Reference
< ::com::sun::star::io::XInputStream
>&, sal_Int32
) throw(SQLException
, RuntimeException
)
327 ::dbtools::throwFunctionNotSupportedException("setBinaryStream", NULL
);
329 // -------------------------------------------------------------------------
330 void SAL_CALL
MacabPreparedStatement::setCharacterStream(sal_Int32
, const Reference
< ::com::sun::star::io::XInputStream
>&, sal_Int32
) throw(SQLException
, RuntimeException
)
335 ::dbtools::throwFunctionNotSupportedException("setCharacterStream", NULL
);
337 // -------------------------------------------------------------------------
338 void SAL_CALL
MacabPreparedStatement::setObject(sal_Int32 parameterIndex
, const Any
& x
) throw(SQLException
, RuntimeException
)
340 if(!::dbtools::implSetObject(this,parameterIndex
,x
))
342 const ::rtl::OUString
sError( m_pConnection
->getResources().getResourceStringWithSubstitution(
343 STR_UNKNOWN_PARA_TYPE
,
344 "$position$", ::rtl::OUString::valueOf(parameterIndex
)
346 ::dbtools::throwGenericSQLException(sError
,*this);
349 // -------------------------------------------------------------------------
350 void SAL_CALL
MacabPreparedStatement::setObjectWithInfo(sal_Int32
, const Any
&, sal_Int32
, sal_Int32
) throw(SQLException
, RuntimeException
)
355 ::dbtools::throwFunctionNotSupportedException("setObjectWithInfo", NULL
);
357 // -------------------------------------------------------------------------
358 void SAL_CALL
MacabPreparedStatement::setRef(sal_Int32
, const Reference
< XRef
>&) throw(SQLException
, RuntimeException
)
363 ::dbtools::throwFunctionNotSupportedException("setRef", NULL
);
365 // -------------------------------------------------------------------------
366 void SAL_CALL
MacabPreparedStatement::setBlob(sal_Int32
, const Reference
< XBlob
>&) throw(SQLException
, RuntimeException
)
371 ::dbtools::throwFunctionNotSupportedException("setBlob", NULL
);
373 // -------------------------------------------------------------------------
374 void SAL_CALL
MacabPreparedStatement::setClob(sal_Int32
, const Reference
< XClob
>&) throw(SQLException
, RuntimeException
)
379 ::dbtools::throwFunctionNotSupportedException("setClob", NULL
);
381 // -------------------------------------------------------------------------
382 void SAL_CALL
MacabPreparedStatement::setArray(sal_Int32
, const Reference
< XArray
>&) throw(SQLException
, RuntimeException
)
387 ::dbtools::throwFunctionNotSupportedException("setArray", NULL
);
389 // -------------------------------------------------------------------------
390 void SAL_CALL
MacabPreparedStatement::clearParameters() throw(SQLException
, RuntimeException
)
392 ::dbtools::throwFunctionNotSupportedException("clearParameters", NULL
);
394 // -------------------------------------------------------------------------
395 void MacabPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
) throw (Exception
)
399 case PROPERTY_ID_RESULTSETCONCURRENCY
:
401 case PROPERTY_ID_RESULTSETTYPE
:
403 case PROPERTY_ID_FETCHDIRECTION
:
405 case PROPERTY_ID_USEBOOKMARKS
:
408 MacabCommonStatement::setFastPropertyValue_NoBroadcast(nHandle
,rValue
);