4
4
* Copyright (c) 2004, Open Cloud Limited.
5
5
*
6
6
* IDENTIFICATION
7
- * $PostgreSQL: pgjdbc/org/postgresql/core/v3/SimpleParameterList.java,v 1.7 2005/01/27 22:50:14 oliver Exp $
7
+ * $PostgreSQL: pgjdbc/org/postgresql/core/v3/SimpleParameterList.java,v 1.8 2005/02/01 07:27:54 jurka Exp $
8
8
*
9
9
*-------------------------------------------------------------------------
10
10
*/
27
27
* @author Oliver Jowett ([email protected] )
28
28
*/
29
29
class SimpleParameterList implements V3ParameterList {
30
+
31
+ private final static int IN =1 ;
32
+ private final static int OUT =2 ;
33
+ private final static int INOUT =3 ;
34
+ // this is here to avoid creating objects for copy
35
+ // copy will simply discard them
36
+
37
+
38
+
30
39
SimpleParameterList (int paramCount ) {
31
40
this .paramValues = new Object [paramCount ];
32
41
this .paramTypes = new int [paramCount ];
33
42
this .encoded = new byte [paramCount ][];
43
+ this .direction = new int [paramCount ];
44
+ }
45
+
46
+
47
+ public void registerOutParameter ( int index , int sqlType )
48
+ {
49
+ direction [index -1 ] |= OUT ;
34
50
}
35
51
36
52
private void bind (int index , Object value , int oid ) throws SQLException {
@@ -40,8 +56,9 @@ private void bind(int index, Object value, int oid) throws SQLException {
40
56
--index ;
41
57
42
58
encoded [index ] = null ;
43
- paramValues [index ] = value ;
44
-
59
+ paramValues [index ] = value ;
60
+ direction [index ] |= IN ;
61
+
45
62
// If we are setting something to null, don't overwrite our existing type
46
63
// for it. We don't need the correct type info to send NULL and we
47
64
// don't want to overwrite and require a reparse.
@@ -51,9 +68,22 @@ private void bind(int index, Object value, int oid) throws SQLException {
51
68
paramTypes [index ] = oid ;
52
69
}
53
70
54
- public int getParameterCount () {
71
+ public int getParameterCount ()
72
+ {
55
73
return paramValues .length ;
56
74
}
75
+ public int getInParameterCount ()
76
+ {
77
+ int count =0 ;
78
+ for ( int i =0 ; i < paramTypes .length ;i ++)
79
+ {
80
+ if (direction [i ] != OUT )
81
+ {
82
+ count ++;
83
+ }
84
+ }
85
+ return count ;
86
+ }
57
87
58
88
public void setIntParameter (int index , int value ) throws SQLException {
59
89
byte [] data = new byte [4 ];
@@ -86,7 +116,6 @@ public void setNull(int index, int oid) throws SQLException {
86
116
87
117
public String toString (int index ) {
88
118
--index ;
89
-
90
119
if (paramValues [index ] == null )
91
120
return "?" ;
92
121
else if (paramValues [index ] == NULL_OBJECT )
@@ -98,7 +127,7 @@ else if (paramValues[index] == NULL_OBJECT)
98
127
public void checkAllParametersSet () throws SQLException {
99
128
for (int i = 0 ; i < paramTypes .length ; ++i )
100
129
{
101
- if (paramValues [i ] == null )
130
+ if (direction [ i ] != OUT && paramValues [i ] == null )
102
131
throw new PSQLException (GT .tr ("No value specified for parameter {0}." , new Integer (i + 1 )), PSQLState .INVALID_PARAMETER_VALUE );
103
132
}
104
133
}
@@ -127,11 +156,17 @@ public int[] getTypeOIDs() {
127
156
//
128
157
129
158
int getTypeOID (int index ) {
130
- return paramTypes [index -1 ];
159
+ if (direction [index -1 ] == OUT )
160
+ {
161
+ paramTypes [index -1 ] = Oid .VOID ;
162
+ paramValues [index -1 ] = "null" ;
163
+ }
164
+
165
+ return paramTypes [index -1 ];
131
166
}
132
167
133
168
boolean hasUnresolvedTypes () {
134
- for (int i =0 ; i <paramTypes .length ; i ++) {
169
+ for (int i =0 ; i < paramTypes .length ; i ++) {
135
170
if (paramTypes [i ] == Oid .INVALID )
136
171
return true ;
137
172
}
@@ -148,18 +183,18 @@ void setResolvedType(int index, int oid) {
148
183
}
149
184
150
185
boolean isNull (int index ) {
151
- return (paramValues [index -1 ] == NULL_OBJECT );
186
+ return (paramValues [index -1 ] == NULL_OBJECT );
152
187
}
153
188
154
189
boolean isBinary (int index ) {
155
190
// Currently, only StreamWrapper uses the binary parameter form.
156
- return (paramValues [index -1 ] instanceof StreamWrapper );
191
+ return (paramValues [index -1 ] instanceof StreamWrapper );
157
192
}
158
193
159
194
int getV3Length (int index ) {
160
195
--index ;
161
196
162
- // Null?
197
+ // Null?
163
198
if (paramValues [index ] == NULL_OBJECT )
164
199
throw new IllegalArgumentException ("can't getV3Length() on a null parameter" );
165
200
@@ -208,31 +243,37 @@ void writeV3Value(int index, PGStream pgStream) throws IOException {
208
243
pgStream .Send (encoded [index ]);
209
244
}
210
245
246
+
247
+
211
248
public ParameterList copy () {
212
249
SimpleParameterList newCopy = new SimpleParameterList (paramValues .length );
213
250
System .arraycopy (paramValues , 0 , newCopy .paramValues , 0 , paramValues .length );
214
251
System .arraycopy (paramTypes , 0 , newCopy .paramTypes , 0 , paramTypes .length );
252
+ System .arraycopy (direction , 0 , newCopy .direction , 0 , direction .length );
215
253
return newCopy ;
216
254
}
217
255
218
256
public void clear () {
219
257
Arrays .fill (paramValues , null );
220
258
Arrays .fill (paramTypes , 0 );
221
259
Arrays .fill (encoded , null );
260
+ Arrays .fill (direction , 0 );
222
261
}
223
-
224
262
public SimpleParameterList [] getSubparams () {
225
263
return null ;
226
264
}
227
265
228
266
private final Object [] paramValues ;
229
267
private final int [] paramTypes ;
268
+ private final int [] direction ;
230
269
private final byte [][] encoded ;
231
-
270
+
232
271
/**
233
272
* Marker object representing NULL; this distinguishes
234
273
* "parameter never set" from "parameter set to null".
235
274
*/
236
275
private final static Object NULL_OBJECT = new Object ();
276
+
277
+
237
278
}
238
279
0 commit comments