@@ -62,37 +62,6 @@ public void Teardown() throws SQLException {
6262 stmt .execute (SQL_DROP_TABLE );
6363 }
6464
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-
9665 /**
9766 * Prepared statement, 1 tuple insert, with no column specification.
9867 */
@@ -144,7 +113,7 @@ public void testPS_1Tuple_CS_1() throws SQLException {
144113 */
145114
146115 // Currently fails. See #1197
147- // @Test
116+ @ Test
148117 public void testPS_1Tuple_CS_2 () throws SQLException {
149118
150119 String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (?, ?, ?);" ;
@@ -168,7 +137,7 @@ public void testPS_1Tuple_CS_2() throws SQLException {
168137 */
169138
170139 // Currently fails. See #1197
171- // @Test
140+ @ Test
172141 public void testPS_1Tuple_CS_3 () throws SQLException {
173142
174143 String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (?, 1, ?);" ;
@@ -232,7 +201,33 @@ public void testPS_1Tuple_CS_5() throws SQLException {
232201 new int [] {1 , 2 , 3 });
233202 assertNoMoreRows (rs );
234203 }
204+
205+ /**
206+ * Prepared statement, 1 tuple insert, all constants
207+ */
208+ // Works, due to use of insert rather than push back
235209
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+
236231 /* --------------------------------------------
237232 * 2 tuple insertions
238233 * ---------------------------------------------
@@ -301,13 +296,13 @@ public void testPS_2Tuple_CS_1() throws SQLException {
301296 * in different order from schema.
302297 */
303298 // Currently fails. See #1197
304- // @Test
299+ @ Test
305300 public void testPS_2Tuple_CS_2 () throws SQLException {
306301
307302 String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (?, ?, ?);" ;
308303 PreparedStatement pstmt = conn .prepareStatement (sql );
309304
310- setValues (pstmt , new int [] {3 , 2 , 1 });
305+ setValues (pstmt , new int [] {3 , 1 , 2 });
311306 pstmt .addBatch ();
312307
313308 setValues (pstmt , new int [] {13 , 11 , 12 });
@@ -331,12 +326,42 @@ public void testPS_2Tuple_CS_2() throws SQLException {
331326 * in different order from schema, with one constant column.
332327 */
333328 // Currently fails. See #1197
334- // @Test
329+ @ Test
335330 public void testPS_2Tuple_CS_3 () throws SQLException {
336331
337- String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (?, 1 , ?);" ;
332+ String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (3, ? , ?);" ;
338333 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 });
340365 pstmt .addBatch ();
341366
342367 setValues (pstmt , new int [] {13 , 12 });
@@ -351,7 +376,7 @@ public void testPS_2Tuple_CS_3() throws SQLException {
351376 rs .next ();
352377 checkRow (rs ,
353378 new String [] {"c1" , "c2" , "c3" },
354- new int [] {1 , 12 , 13 });
379+ new int [] {12 , 2 , 13 });
355380 assertNoMoreRows (rs );
356381 }
357382
@@ -360,7 +385,7 @@ public void testPS_2Tuple_CS_3() throws SQLException {
360385 * in schema order, with 2nd column missing.
361386 */
362387 // Currently failing. See comments in #1197
363- // @Test
388+ @ Test
364389 public void testPS_2Tuple_CS_4 () throws SQLException {
365390
366391 String sql = "INSERT INTO tbl (c1, c3) VALUES (?, ?);" ;
0 commit comments