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 #ifndef _CONNECTIVITY_OBOUNPARAM_HXX_
24 #define _CONNECTIVITY_OBOUNPARAM_HXX_
25 
26 #include <com/sun/star/io/XInputStream.hpp>
27 #include "odbc/odbcbasedllapi.hxx"
28 
29 namespace connectivity
30 {
31 	namespace odbc
32 	{
33 		class OOO_DLLPUBLIC_ODBCBASE OBoundParam
34 		{
35 
36 		public:
OBoundParam()37 			OBoundParam()
38 			{
39 				paramLength = NULL;
40 				binaryData	= NULL;
41 				pA1=0;
42 				pA2=0;
43 				pB1=0;
44 				pB2=0;
45 				pC1=0;
46 				pC2=0;
47 				pS1=0;
48 				pS2=0;
49 			}
~OBoundParam()50 			~OBoundParam()
51 			{
52 				delete [] binaryData;
53 				delete [] paramLength;
54 			}
55 			//--------------------------------------------------------------------
56 			// initialize
57 			// Perform an necessary initialization
58 			//--------------------------------------------------------------------
initialize()59 			void initialize ()
60 			{
61 				// Allocate storage for the length.  Note - the length is
62 				// stored in native format, and will have to be converted
63 				// to a Java sal_Int32.  The jdbcodbc 'C' bridge provides an
64 				// interface to do this.
65 
66 				paramLength = new sal_Int8[4];
67 			}
68 
69 			//--------------------------------------------------------------------
70 			// allocBindDataBuffer
71 			// Allocates and returns a new bind data buffer of the specified
72 			// length
73 			//--------------------------------------------------------------------
allocBindDataBuffer(sal_Int32 bufLen)74 			sal_Int8* allocBindDataBuffer (sal_Int32 bufLen)
75 			{
76                 if ( binaryData )
77                     delete [] binaryData;
78 				binaryData = new sal_Int8[bufLen];
79 
80 				// Reset the input stream, we are doing a new bind
81 				setInputStream (NULL, 0);
82 
83 				return binaryData;
84 			}
85 
86 			//--------------------------------------------------------------------
87 			// getBindDataBuffer
88 			// Returns the data buffer to be used when binding to a parameter
89 			//--------------------------------------------------------------------
getBindDataBuffer()90 			sal_Int8* getBindDataBuffer ()
91 			{
92 				return binaryData;
93 			}
94 
95 			//--------------------------------------------------------------------
96 			// getBindLengthBuffer
97 			// Returns the length buffer to be used when binding to a parameter
98 			//--------------------------------------------------------------------
getBindLengthBuffer()99 			sal_Int8* getBindLengthBuffer ()
100 			{
101 				return paramLength;
102 			}
103 
104 			//--------------------------------------------------------------------
105 			// setInputStream
106 			// Sets the input stream for the bound parameter
107 			//--------------------------------------------------------------------
setInputStream(const::com::sun::star::uno::Reference<::com::sun::star::io::XInputStream> & inputStream,sal_Int32 len)108             void setInputStream(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream>& inputStream,
109 								sal_Int32 len)
110 			{
111 				paramInputStream = inputStream;
112 				paramInputStreamLen = len;
113 			}
114 
setSequence(const::com::sun::star::uno::Sequence<sal_Int8> & _aSequence)115 			void setSequence(const ::com::sun::star::uno::Sequence< sal_Int8 >& _aSequence)
116 			{
117 				aSequence = _aSequence;
118 			}
119 
120 			//--------------------------------------------------------------------
121 			// getInputStream
122 			// Gets the input stream for the bound parameter
123 			//--------------------------------------------------------------------
getInputStream()124             ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream> getInputStream ()
125 			{
126 				return paramInputStream;
127 			}
128 
129 			//--------------------------------------------------------------------
130 			// getInputStreamLen
131 			// Gets the input stream length for the bound parameter
132 			//--------------------------------------------------------------------
getInputStreamLen()133 			sal_Int32 getInputStreamLen ()
134 			{
135 				return paramInputStreamLen;
136 			}
137 
138 			//--------------------------------------------------------------------
139 			// setSqlType
140 			// Sets the Java sql type used to register an OUT parameter
141 			//--------------------------------------------------------------------
142 
setSqlType(sal_Int32 type)143 			void setSqlType(sal_Int32 type)
144 			{
145 				sqlType = type;
146 			}
147 
148 			//--------------------------------------------------------------------
149 			// getSqlType
150 			// Gets the Java sql type used to register an OUT parameter
151 			//--------------------------------------------------------------------
152 
getSqlType()153 			sal_Int32 getSqlType ()
154 			{
155 				return sqlType;
156 			}
157 
158 			//--------------------------------------------------------------------
159 			// setOutputParameter
160 			// Sets the flag indicating if this is an OUTPUT parameter
161 			//--------------------------------------------------------------------
162 
setOutputParameter(sal_Bool output)163 			void setOutputParameter (sal_Bool output)
164 			{
165 				outputParameter = output;
166 			}
167 
168 			//--------------------------------------------------------------------
169 			// isOutputParameter
170 			// Gets the OUTPUT parameter flag
171 			//--------------------------------------------------------------------
172 
isOutputParameter()173 			sal_Bool isOutputParameter ()
174 			{
175 				return outputParameter;
176 			}
177 
178 		protected:
179 			//====================================================================
180 			// Data attributes
181 			//====================================================================
182 
183 			sal_Int8* binaryData;		// Storage area to be used
184 										// when binding the parameter
185 
186 			sal_Int8* paramLength;		// Storage area to be used
187 										// for the bound length of the
188 										// parameter.  Note that this
189 										// data is in native format.
190 
191             ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream> paramInputStream;
192 			::com::sun::star::uno::Sequence< sal_Int8 > aSequence;
193 										// When an input stream is
194 										// bound to a parameter, the
195 										// input stream is saved
196 										// until needed.
197 
198 			sal_Int32 paramInputStreamLen;	              // Length of input stream
199 
200 			sal_Int32 sqlType;                          // Java SQL type used to
201 															// register an OUT parameter
202 
203 			sal_Bool outputParameter;	// true for OUTPUT parameters
204 
205 
206 			sal_Int32 pA1;              //pointers
207 			sal_Int32 pA2;
208 			sal_Int32 pB1;
209 			sal_Int32 pB2;
210 			sal_Int32 pC1;
211 			sal_Int32 pC2;
212 			sal_Int32 pS1;
213 			sal_Int32 pS2;// reserved for strings(UTFChars)
214 		};
215 	}
216 }
217 #endif // _CONNECTIVITY_OBOUNPARAM_HXX_
218 
219