25
25
26
26
public class Array implements java .sql .Array
27
27
{
28
- private org .postgresql .Connection conn =null ;
29
- private org .postgresql .Field field =null ;
30
- private org .postgresql .jdbc2 .ResultSet rs =null ;
31
- private int idx =0 ;
28
+ private org .postgresql .Connection conn =null ;
29
+ private org .postgresql .Field field =null ;
30
+ private org .postgresql .jdbc2 .ResultSet rs =null ;
31
+ private int idx =0 ;
32
+ private String rawString =null ;
32
33
33
34
/**
34
35
* Create a new Array
@@ -38,11 +39,14 @@ public class Array implements java.sql.Array
38
39
* @param field the Field descriptor for the field to load into this Array
39
40
* @param rs the ResultSet from which to get the data for this Array
40
41
*/
41
- public Array (org .postgresql .Connection conn ,int idx ,Field field ,org .postgresql .jdbc2 .ResultSet rs ) {
42
+ public Array (org .postgresql .Connection conn ,int idx ,Field field ,org .postgresql .jdbc2 .ResultSet rs )
43
+ throws SQLException
44
+ {
42
45
this .conn =conn ;
43
46
this .field =field ;
44
47
this .rs =rs ;
45
48
this .idx =idx ;
49
+ this .rawString =rs .getFixedString (idx );
46
50
}
47
51
48
52
public Object getArray ()throws SQLException {
@@ -66,9 +70,8 @@ public Object getArray(long index, int count, Map map) throws SQLException {
66
70
Object retVal =null ;
67
71
68
72
ArrayList array =new ArrayList ();
69
- String raw =rs .getFixedString (idx );
70
- if (raw !=null ) {
71
- char []chars =raw .toCharArray ();
73
+ if (rawString !=null ) {
74
+ char []chars =rawString .toCharArray ();
72
75
StringBuffer sbuf =new StringBuffer ();
73
76
boolean foundOpen =false ;
74
77
boolean insideString =false ;
@@ -200,8 +203,8 @@ public java.sql.ResultSet getResultSet(long index, int count, java.util.Map map)
200
203
fields [1 ] =new Field (conn ,"VALUE" ,field .getOID ("bool" ),1 );
201
204
for (int i =0 ;i <booleanArray .length ;i ++ ) {
202
205
byte [][]tuple =new byte [2 ][0 ];
203
- tuple [0 ] =Integer .toString ((int )index +i ). getBytes ( );// Index
204
- tuple [1 ] =( booleanArray [i ]?"YES" :"NO" ). getBytes ( );// Value
206
+ tuple [0 ] =conn . getEncoding (). encode ( Integer .toString ((int )index +i ) );// Index
207
+ tuple [1 ] =conn . getEncoding (). encode ( ( booleanArray [i ]?"YES" :"NO" ) );// Value
205
208
rows .addElement (tuple );
206
209
}
207
210
case Types .SMALLINT :
@@ -212,8 +215,8 @@ public java.sql.ResultSet getResultSet(long index, int count, java.util.Map map)
212
215
fields [1 ] =new Field (conn ,"VALUE" ,field .getOID ("int4" ),4 );
213
216
for (int i =0 ;i <intArray .length ;i ++ ) {
214
217
byte [][]tuple =new byte [2 ][0 ];
215
- tuple [0 ] =Integer .toString ((int )index +i ). getBytes ( );// Index
216
- tuple [1 ] =Integer .toString (intArray [i ]). getBytes ( );// Value
218
+ tuple [0 ] =conn . getEncoding (). encode ( Integer .toString ((int )index +i ) );// Index
219
+ tuple [1 ] =conn . getEncoding (). encode ( Integer .toString (intArray [i ]) );// Value
217
220
rows .addElement (tuple );
218
221
}
219
222
break ;
@@ -222,8 +225,8 @@ public java.sql.ResultSet getResultSet(long index, int count, java.util.Map map)
222
225
fields [1 ] =new Field (conn ,"VALUE" ,field .getOID ("int8" ),8 );
223
226
for (int i =0 ;i <longArray .length ;i ++ ) {
224
227
byte [][]tuple =new byte [2 ][0 ];
225
- tuple [0 ] =Integer .toString ((int )index +i ). getBytes ( );// Index
226
- tuple [1 ] =Long .toString (longArray [i ]). getBytes ( );// Value
228
+ tuple [0 ] =conn . getEncoding (). encode ( Integer .toString ((int )index +i ) );// Index
229
+ tuple [1 ] =conn . getEncoding (). encode ( Long .toString (longArray [i ]) );// Value
227
230
rows .addElement (tuple );
228
231
}
229
232
break ;
@@ -232,8 +235,8 @@ public java.sql.ResultSet getResultSet(long index, int count, java.util.Map map)
232
235
fields [1 ] =new Field (conn ,"VALUE" ,field .getOID ("numeric" ), -1 );
233
236
for (int i =0 ;i <bdArray .length ;i ++ ) {
234
237
byte [][]tuple =new byte [2 ][0 ];
235
- tuple [0 ] =Integer .toString ((int )index +i ). getBytes ( );// Index
236
- tuple [1 ] =bdArray [i ].toString (). getBytes ( );// Value
238
+ tuple [0 ] =conn . getEncoding (). encode ( Integer .toString ((int )index +i ) );// Index
239
+ tuple [1 ] =conn . getEncoding (). encode ( bdArray [i ].toString () );// Value
237
240
rows .addElement (tuple );
238
241
}
239
242
break ;
@@ -242,8 +245,8 @@ public java.sql.ResultSet getResultSet(long index, int count, java.util.Map map)
242
245
fields [1 ] =new Field (conn ,"VALUE" ,field .getOID ("float4" ),4 );
243
246
for (int i =0 ;i <floatArray .length ;i ++ ) {
244
247
byte [][]tuple =new byte [2 ][0 ];
245
- tuple [0 ] =Integer .toString ((int )index +i ). getBytes ( );// Index
246
- tuple [1 ] =Float .toString (floatArray [i ]). getBytes ( );// Value
248
+ tuple [0 ] =conn . getEncoding (). encode ( Integer .toString ((int )index +i ) );// Index
249
+ tuple [1 ] =conn . getEncoding (). encode ( Float .toString (floatArray [i ]) );// Value
247
250
rows .addElement (tuple );
248
251
}
249
252
break ;
@@ -252,8 +255,8 @@ public java.sql.ResultSet getResultSet(long index, int count, java.util.Map map)
252
255
fields [1 ] =new Field (conn ,"VALUE" ,field .getOID ("float8" ),8 );
253
256
for (int i =0 ;i <doubleArray .length ;i ++ ) {
254
257
byte [][]tuple =new byte [2 ][0 ];
255
- tuple [0 ] =Integer .toString ((int )index +i ). getBytes ( );// Index
256
- tuple [1 ] =Double .toString (doubleArray [i ]). getBytes ( );// Value
258
+ tuple [0 ] =conn . getEncoding (). encode ( Integer .toString ((int )index +i ) );// Index
259
+ tuple [1 ] =conn . getEncoding (). encode ( Double .toString (doubleArray [i ]) );// Value
257
260
rows .addElement (tuple );
258
261
}
259
262
break ;
@@ -265,8 +268,8 @@ public java.sql.ResultSet getResultSet(long index, int count, java.util.Map map)
265
268
fields [1 ] =new Field (conn ,"VALUE" ,field .getOID ("varchar" ), -1 );
266
269
for (int i =0 ;i <strArray .length ;i ++ ) {
267
270
byte [][]tuple =new byte [2 ][0 ];
268
- tuple [0 ] =Integer .toString ((int )index +i ). getBytes ( );// Index
269
- tuple [1 ] =strArray [i ]. getBytes ( );// Value
271
+ tuple [0 ] =conn . getEncoding (). encode ( Integer .toString ((int )index +i ) );// Index
272
+ tuple [1 ] =conn . getEncoding (). encode ( strArray [i ] );// Value
270
273
rows .addElement (tuple );
271
274
}
272
275
break ;
@@ -275,8 +278,8 @@ public java.sql.ResultSet getResultSet(long index, int count, java.util.Map map)
275
278
fields [1 ] =new Field (conn ,"VALUE" ,field .getOID ("date" ),4 );
276
279
for (int i =0 ;i <dateArray .length ;i ++ ) {
277
280
byte [][]tuple =new byte [2 ][0 ];
278
- tuple [0 ] =Integer .toString ((int )index +i ). getBytes ( );// Index
279
- tuple [1 ] =dateArray [i ].toString (). getBytes ( );// Value
281
+ tuple [0 ] =conn . getEncoding (). encode ( Integer .toString ((int )index +i ) );// Index
282
+ tuple [1 ] =conn . getEncoding (). encode ( dateArray [i ].toString () );// Value
280
283
rows .addElement (tuple );
281
284
}
282
285
break ;
@@ -285,8 +288,8 @@ public java.sql.ResultSet getResultSet(long index, int count, java.util.Map map)
285
288
fields [1 ] =new Field (conn ,"VALUE" ,field .getOID ("time" ),8 );
286
289
for (int i =0 ;i <timeArray .length ;i ++ ) {
287
290
byte [][]tuple =new byte [2 ][0 ];
288
- tuple [0 ] =Integer .toString ((int )index +i ). getBytes ( );// Index
289
- tuple [1 ] =timeArray [i ].toString (). getBytes ( );// Value
291
+ tuple [0 ] =conn . getEncoding (). encode ( Integer .toString ((int )index +i ) );// Index
292
+ tuple [1 ] =conn . getEncoding (). encode ( timeArray [i ].toString () );// Value
290
293
rows .addElement (tuple );
291
294
}
292
295
break ;
@@ -295,8 +298,8 @@ public java.sql.ResultSet getResultSet(long index, int count, java.util.Map map)
295
298
fields [1 ] =new Field (conn ,"VALUE" ,field .getOID ("timestamp" ),8 );
296
299
for (int i =0 ;i <timestampArray .length ;i ++ ) {
297
300
byte [][]tuple =new byte [2 ][0 ];
298
- tuple [0 ] =Integer .toString ((int )index +i ). getBytes ( );// Index
299
- tuple [1 ] =timestampArray [i ].toString (). getBytes ( );// Value
301
+ tuple [0 ] =conn . getEncoding (). encode ( Integer .toString ((int )index +i ) );// Index
302
+ tuple [1 ] =conn . getEncoding (). encode ( timestampArray [i ].toString () );// Value
300
303
rows .addElement (tuple );
301
304
}
302
305
break ;
@@ -308,5 +311,7 @@ public java.sql.ResultSet getResultSet(long index, int count, java.util.Map map)
308
311
}
309
312
return new ResultSet ((org .postgresql .jdbc2 .Connection )conn ,fields ,rows ,"OK" ,1 );
310
313
}
314
+
315
+ public String toString () {return rawString ; }
311
316
}
312
317