1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 #include "ado/ACallableStatement.hxx"
31 #include <connectivity/dbexception.hxx>
32 
33 using namespace connectivity::ado;
34 using namespace com::sun::star::uno;
35 using namespace com::sun::star::lang;
36 using namespace com::sun::star::beans;
37 using namespace com::sun::star::sdbc;
38 using namespace com::sun::star::container;
39 using namespace com::sun::star::lang;
40 
41 IMPLEMENT_SERVICE_INFO(OCallableStatement,"com.sun.star.sdbcx.ACallableStatement","com.sun.star.sdbc.CallableStatement");
42 
43 #define GET_PARAM()													\
44 	ADOParameter* pParam = NULL;									\
45 	m_pParameters->get_Item(OLEVariant(sal_Int32(columnIndex-1)),&pParam);		\
46 	if(pParam)														\
47 		pParam->get_Value(&m_aValue);
48 //**************************************************************
49 //************ Class: java.sql.CallableStatement
50 //**************************************************************
51 OCallableStatement::OCallableStatement( OConnection* _pConnection,const OTypeInfoMap& _TypeInfo,const ::rtl::OUString& sql )
52 				: OPreparedStatement( _pConnection, _TypeInfo, sql )
53 {
54 	m_Command.put_CommandType(adCmdStoredProc);
55 }
56 // -------------------------------------------------------------------------
57 
58 Any SAL_CALL OCallableStatement::queryInterface( const Type & rType ) throw(RuntimeException)
59 {
60 	Any aRet = OPreparedStatement::queryInterface(rType);
61 	return aRet.hasValue() ? aRet : ::cppu::queryInterface(rType,static_cast< XRow*>(this));
62 }
63 // -------------------------------------------------------------------------
64 
65 
66 sal_Bool SAL_CALL OCallableStatement::wasNull(  ) throw(SQLException, RuntimeException)
67 {
68 	return m_aValue.isNull();
69 }
70 // -------------------------------------------------------------------------
71 
72 sal_Bool SAL_CALL OCallableStatement::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
73 {
74 	GET_PARAM()
75 	return m_aValue;
76 }
77 // -------------------------------------------------------------------------
78 sal_Int8 SAL_CALL OCallableStatement::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
79 {
80 	GET_PARAM()
81 	return m_aValue;
82 }
83 // -------------------------------------------------------------------------
84 Sequence< sal_Int8 > SAL_CALL OCallableStatement::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
85 {
86 	GET_PARAM()
87 	return m_aValue;
88 }
89 // -------------------------------------------------------------------------
90 ::com::sun::star::util::Date SAL_CALL OCallableStatement::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
91 {
92 	GET_PARAM()
93 	return m_aValue;
94 }
95 // -------------------------------------------------------------------------
96 double SAL_CALL OCallableStatement::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
97 {
98 	GET_PARAM()
99 	return m_aValue;
100 }
101 // -------------------------------------------------------------------------
102 
103 float SAL_CALL OCallableStatement::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
104 {
105 	GET_PARAM()
106 	return m_aValue;
107 }
108 // -------------------------------------------------------------------------
109 
110 sal_Int32 SAL_CALL OCallableStatement::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
111 {
112 	GET_PARAM()
113 	return m_aValue;
114 }
115 // -------------------------------------------------------------------------
116 
117 sal_Int64 SAL_CALL OCallableStatement::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
118 {
119 	GET_PARAM()
120 	return (sal_Int64)m_aValue.getCurrency().int64;
121 }
122 // -------------------------------------------------------------------------
123 
124 Any SAL_CALL OCallableStatement::getObject( sal_Int32 /*columnIndex*/, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
125 {
126     ::dbtools::throwFeatureNotImplementedException( "XRow::getObject", *this );
127 	return Any();
128 }
129 // -------------------------------------------------------------------------
130 
131 sal_Int16 SAL_CALL OCallableStatement::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
132 {
133 	GET_PARAM()
134 	return m_aValue;
135 }
136 // -------------------------------------------------------------------------
137 
138 ::rtl::OUString SAL_CALL OCallableStatement::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
139 {
140 	GET_PARAM()
141 	return m_aValue;
142 }
143 // -------------------------------------------------------------------------
144 
145  ::com::sun::star::util::Time SAL_CALL OCallableStatement::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
146 {
147 	GET_PARAM()
148 	return m_aValue;
149 }
150 // -------------------------------------------------------------------------
151 
152  ::com::sun::star::util::DateTime SAL_CALL OCallableStatement::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
153 {
154 	GET_PARAM()
155 	return m_aValue;
156 }
157 // -------------------------------------------------------------------------
158 
159 void SAL_CALL OCallableStatement::registerOutParameter( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& /*typeName*/ ) throw(SQLException, RuntimeException)
160 {
161 	ADOParameter* pParam = NULL;
162 	m_pParameters->get_Item(OLEVariant(sal_Int32(parameterIndex-1)),&pParam);
163 	if(pParam)
164 	{
165 		pParam->put_Type(ADOS::MapJdbc2ADOType(sqlType,m_pConnection->getEngineType()));
166 		pParam->put_Direction(adParamOutput);
167 	}
168 }
169 // -------------------------------------------------------------------------
170 void SAL_CALL OCallableStatement::registerNumericOutParameter( sal_Int32 parameterIndex, sal_Int32 sqlType, sal_Int32 scale ) throw(SQLException, RuntimeException)
171 {
172 	ADOParameter* pParam = NULL;
173 	m_pParameters->get_Item(OLEVariant(sal_Int32(parameterIndex-1)),&pParam);
174 	if(pParam)
175 	{
176 		pParam->put_Type(ADOS::MapJdbc2ADOType(sqlType,m_pConnection->getEngineType()));
177 		pParam->put_Direction(adParamOutput);
178 		pParam->put_NumericScale((sal_Int8)scale);
179 	}
180 }
181 // -------------------------------------------------------------------------
182 
183 
184 Reference< ::com::sun::star::io::XInputStream > SAL_CALL OCallableStatement::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
185 {
186     ::dbtools::throwFeatureNotImplementedException( "XRow::getBinaryStream", *this );
187 	return NULL;
188 }
189 // -------------------------------------------------------------------------
190 Reference< ::com::sun::star::io::XInputStream > SAL_CALL OCallableStatement::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
191 {
192     ::dbtools::throwFeatureNotImplementedException( "XRow::getCharacterStream", *this );
193 	return NULL;
194 }
195 // -------------------------------------------------------------------------
196 
197 Reference< XArray > SAL_CALL OCallableStatement::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
198 {
199     ::dbtools::throwFeatureNotImplementedException( "XRow::getArray", *this );
200 	return NULL;
201 }
202 // -------------------------------------------------------------------------
203 
204 Reference< XClob > SAL_CALL OCallableStatement::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
205 {
206     ::dbtools::throwFeatureNotImplementedException( "XRow::getClob", *this );
207 	return NULL;
208 }
209 // -------------------------------------------------------------------------
210 Reference< XBlob > SAL_CALL OCallableStatement::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
211 {
212     ::dbtools::throwFeatureNotImplementedException( "XRow::getBlob", *this );
213 	return NULL;
214 }
215 // -------------------------------------------------------------------------
216 
217 Reference< XRef > SAL_CALL OCallableStatement::getRef( sal_Int32 /*columnIndex*/) throw(SQLException, RuntimeException)
218 {
219     ::dbtools::throwFeatureNotImplementedException( "XRow::getRef", *this );
220 	return NULL;
221 }
222 // -------------------------------------------------------------------------
223 // -----------------------------------------------------------------------------
224 void SAL_CALL OCallableStatement::acquire() throw()
225 {
226 	OPreparedStatement::acquire();
227 }
228 // -----------------------------------------------------------------------------
229 void SAL_CALL OCallableStatement::release() throw()
230 {
231 	OPreparedStatement::release();
232 }
233 // -----------------------------------------------------------------------------
234 
235 
236