Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef _CONNECTIVITY_OBOUNPARAM_HXX_
20 : #define _CONNECTIVITY_OBOUNPARAM_HXX_
21 :
22 : #include <com/sun/star/io/XInputStream.hpp>
23 : #include <com/sun/star/sdbc/DataType.hpp>
24 : #include "odbc/odbcbasedllapi.hxx"
25 :
26 : namespace connectivity
27 : {
28 : namespace odbc
29 : {
30 : class OOO_DLLPUBLIC_ODBCBASE OBoundParam
31 : {
32 :
33 : public:
34 0 : OBoundParam()
35 : : binaryData(NULL)
36 : , paramLength(0)
37 : , paramInputStreamLen(0)
38 : , sqlType(::com::sun::star::sdbc::DataType::SQLNULL)
39 0 : , outputParameter(false)
40 : {
41 0 : }
42 0 : ~OBoundParam()
43 0 : {
44 0 : free(binaryData);
45 0 : }
46 :
47 : // allocBindDataBuffer
48 : // Allocates and returns a new bind data buffer of the specified
49 : // length
50 :
51 0 : void* allocBindDataBuffer (sal_Int32 bufLen)
52 : {
53 : // Reset the input stream and sequence, we are doing a new bind
54 0 : setInputStream (NULL, 0);
55 0 : aSequence.realloc(0);
56 :
57 0 : free(binaryData);
58 0 : binaryData = (bufLen > 0) ? malloc(bufLen) : NULL;
59 :
60 0 : return binaryData;
61 : }
62 :
63 :
64 : // getBindDataBuffer
65 : // Returns the data buffer to be used when binding to a parameter
66 :
67 : void* getBindDataBuffer ()
68 : {
69 : return binaryData;
70 : }
71 :
72 :
73 : // getBindLengthBuffer
74 : // Returns the length buffer to be used when binding to a parameter
75 :
76 0 : SQLLEN* getBindLengthBuffer ()
77 : {
78 0 : return ¶mLength;
79 : }
80 :
81 :
82 : // setInputStream
83 : // Sets the input stream for the bound parameter
84 :
85 0 : void setInputStream(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream>& inputStream,
86 : sal_Int32 len)
87 : {
88 0 : paramInputStream = inputStream;
89 0 : paramInputStreamLen = len;
90 0 : }
91 :
92 0 : void setSequence(const ::com::sun::star::uno::Sequence< sal_Int8 >& _aSequence)
93 : {
94 0 : aSequence = _aSequence;
95 0 : }
96 :
97 :
98 : // getInputStream
99 : // Gets the input stream for the bound parameter
100 :
101 0 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream> getInputStream ()
102 : {
103 0 : return paramInputStream;
104 : }
105 :
106 :
107 : // getInputStreamLen
108 : // Gets the input stream length for the bound parameter
109 :
110 0 : sal_Int32 getInputStreamLen ()
111 : {
112 0 : return paramInputStreamLen;
113 : }
114 :
115 :
116 : // setSqlType
117 : // Sets the Java sql type used to register an OUT parameter
118 :
119 :
120 : void setSqlType(sal_Int32 type)
121 : {
122 : sqlType = type;
123 : }
124 :
125 :
126 : // getSqlType
127 : // Gets the Java sql type used to register an OUT parameter
128 :
129 :
130 : sal_Int32 getSqlType ()
131 : {
132 : return sqlType;
133 : }
134 :
135 :
136 : // setOutputParameter
137 : // Sets the flag indicating if this is an OUTPUT parameter
138 :
139 :
140 : void setOutputParameter (sal_Bool output)
141 : {
142 : outputParameter = output;
143 : }
144 :
145 :
146 : // isOutputParameter
147 : // Gets the OUTPUT parameter flag
148 :
149 :
150 : sal_Bool isOutputParameter ()
151 : {
152 : return outputParameter;
153 : }
154 :
155 : protected:
156 :
157 : // Data attributes
158 :
159 :
160 : void *binaryData; // Storage area to be used
161 : // when binding the parameter
162 :
163 : SQLLEN paramLength; // Storage area to be used
164 : // for the bound length of the
165 : // parameter. Note that this
166 : // data is in native format.
167 :
168 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream> paramInputStream;
169 : ::com::sun::star::uno::Sequence< sal_Int8 > aSequence;
170 : // When an input stream is
171 : // bound to a parameter, a
172 : // reference to the input stream is saved
173 : // until not needed anymore.
174 :
175 : sal_Int32 paramInputStreamLen; // Length of input stream
176 :
177 : sal_Int32 sqlType; // Java SQL type used to
178 : // register an OUT parameter
179 :
180 : sal_Bool outputParameter; // true for OUTPUT parameters
181 : };
182 : }
183 : }
184 : #endif // _CONNECTIVITY_OBOUNPARAM_HXX_
185 :
186 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|