@@ -62,37 +62,6 @@ public void Teardown() throws SQLException {
62
62
stmt .execute (SQL_DROP_TABLE );
63
63
}
64
64
65
- /**
66
- * Set column values.
67
- *
68
- * @param pstmt prepared statement to receive values
69
- * @param values array of values
70
- */
71
- public void setValues (PreparedStatement pstmt ,
72
- int [] values ) throws SQLException {
73
- int col = 1 ;
74
- for (int i =0 ; i <values .length ; i ++) {
75
- pstmt .setInt (col ++, (int ) values [i ]);
76
- }
77
- }
78
-
79
- /**
80
- * Check a single row of queried values against expected values
81
- *
82
- * @param rs resultset, with cursor at the desired row
83
- * @param columns column names
84
- * @param expected_values expected values of columns
85
- */
86
-
87
- public void checkRow (ResultSet rs ,
88
- String [] columns ,
89
- int [] expected_values ) throws SQLException {
90
- assertEquals (columns .length , expected_values .length );
91
- for (int i =0 ; i <columns .length ; i ++) {
92
- assertEquals (rs .getInt (columns [i ]), expected_values [i ]);
93
- }
94
- }
95
-
96
65
/**
97
66
* Prepared statement, 1 tuple insert, with no column specification.
98
67
*/
@@ -144,7 +113,7 @@ public void testPS_1Tuple_CS_1() throws SQLException {
144
113
*/
145
114
146
115
// Currently fails. See #1197
147
- // @Test
116
+ @ Test
148
117
public void testPS_1Tuple_CS_2 () throws SQLException {
149
118
150
119
String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (?, ?, ?);" ;
@@ -168,7 +137,7 @@ public void testPS_1Tuple_CS_2() throws SQLException {
168
137
*/
169
138
170
139
// Currently fails. See #1197
171
- // @Test
140
+ @ Test
172
141
public void testPS_1Tuple_CS_3 () throws SQLException {
173
142
174
143
String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (?, 1, ?);" ;
@@ -232,7 +201,33 @@ public void testPS_1Tuple_CS_5() throws SQLException {
232
201
new int [] {1 , 2 , 3 });
233
202
assertNoMoreRows (rs );
234
203
}
204
+
205
+ /**
206
+ * Prepared statement, 1 tuple insert, all constants
207
+ */
208
+ // Works, due to use of insert rather than push back
235
209
210
+ @ Test
211
+ public void testPS_1Tuple_CS_6 () throws SQLException {
212
+
213
+ String sql = "INSERT INTO tbl (c1, c2, c3) VALUES (1, 2, 3);" ;
214
+ PreparedStatement pstmt = conn .prepareStatement (sql );
215
+
216
+ // setValues(pstmt, new int [] {});
217
+ // Todo: determine if this is 100% correct. addBatch call required
218
+ // as, internally, SetParameterValues is where the constants
219
+ // are inserted.
220
+ pstmt .addBatch ();
221
+ pstmt .executeBatch ();
222
+
223
+ getResultsPS ();
224
+ rs .next ();
225
+ checkRow (rs ,
226
+ new String [] {"c1" , "c2" , "c3" },
227
+ new int [] {1 , 2 , 3 });
228
+ assertNoMoreRows (rs );
229
+ }
230
+
236
231
/* --------------------------------------------
237
232
* 2 tuple insertions
238
233
* ---------------------------------------------
@@ -301,13 +296,13 @@ public void testPS_2Tuple_CS_1() throws SQLException {
301
296
* in different order from schema.
302
297
*/
303
298
// Currently fails. See #1197
304
- // @Test
299
+ @ Test
305
300
public void testPS_2Tuple_CS_2 () throws SQLException {
306
301
307
302
String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (?, ?, ?);" ;
308
303
PreparedStatement pstmt = conn .prepareStatement (sql );
309
304
310
- setValues (pstmt , new int [] {3 , 2 , 1 });
305
+ setValues (pstmt , new int [] {3 , 1 , 2 });
311
306
pstmt .addBatch ();
312
307
313
308
setValues (pstmt , new int [] {13 , 11 , 12 });
@@ -331,12 +326,42 @@ public void testPS_2Tuple_CS_2() throws SQLException {
331
326
* in different order from schema, with one constant column.
332
327
*/
333
328
// Currently fails. See #1197
334
- // @Test
329
+ @ Test
335
330
public void testPS_2Tuple_CS_3 () throws SQLException {
336
331
337
- String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (?, 1 , ?);" ;
332
+ String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (3, ? , ?);" ;
338
333
PreparedStatement pstmt = conn .prepareStatement (sql );
339
- setValues (pstmt , new int [] {3 , 2 });
334
+ setValues (pstmt , new int [] {1 , 2 });
335
+ pstmt .addBatch ();
336
+
337
+ setValues (pstmt , new int [] {11 , 12 });
338
+ pstmt .addBatch ();
339
+ pstmt .executeBatch ();
340
+
341
+ getResultsPS ();
342
+ rs .next ();
343
+ checkRow (rs ,
344
+ new String [] {"c1" , "c2" , "c3" },
345
+ new int [] {1 , 2 , 3 });
346
+ rs .next ();
347
+ checkRow (rs ,
348
+ new String [] {"c1" , "c2" , "c3" },
349
+ new int [] {11 , 12 , 3 });
350
+ assertNoMoreRows (rs );
351
+ }
352
+
353
+ /**
354
+ * Prepared statement, 2 tuple insert, with columns inserted
355
+ * in different order from schema, with one constant column.
356
+ * Variant of above, with constant column last.
357
+ */
358
+ // Currently fails. See #1197
359
+ @ Test
360
+ public void testPS_2Tuple_CS_3a () throws SQLException {
361
+
362
+ String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (?, ?, 2);" ;
363
+ PreparedStatement pstmt = conn .prepareStatement (sql );
364
+ setValues (pstmt , new int [] {3 , 1 });
340
365
pstmt .addBatch ();
341
366
342
367
setValues (pstmt , new int [] {13 , 12 });
@@ -351,7 +376,7 @@ public void testPS_2Tuple_CS_3() throws SQLException {
351
376
rs .next ();
352
377
checkRow (rs ,
353
378
new String [] {"c1" , "c2" , "c3" },
354
- new int [] {1 , 12 , 13 });
379
+ new int [] {12 , 2 , 13 });
355
380
assertNoMoreRows (rs );
356
381
}
357
382
@@ -360,7 +385,7 @@ public void testPS_2Tuple_CS_3() throws SQLException {
360
385
* in schema order, with 2nd column missing.
361
386
*/
362
387
// Currently failing. See comments in #1197
363
- // @Test
388
+ @ Test
364
389
public void testPS_2Tuple_CS_4 () throws SQLException {
365
390
366
391
String sql = "INSERT INTO tbl (c1, c3) VALUES (?, ?);" ;
0 commit comments