1 25 package testsuite.regression; 26 27 import java.sql.CallableStatement ; 28 import java.sql.Connection ; 29 import java.sql.SQLException ; 30 import java.sql.Types ; 31 32 import com.mysql.jdbc.DatabaseMetaData; 33 import com.mysql.jdbc.SQLError; 34 35 import testsuite.BaseTestCase; 36 37 43 public class CallableStatementRegressionTest extends BaseTestCase { 44 49 public CallableStatementRegressionTest(String name) { 50 super(name); 51 52 } 54 55 61 public static void main(String [] args) { 62 junit.textui.TestRunner.run(CallableStatementRegressionTest.class); 63 } 64 65 72 public void testBug3539() throws Exception { 73 if (versionMeetsMinimum(5, 0)) { 74 try { 75 this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug3539"); 76 this.stmt.executeUpdate("CREATE PROCEDURE testBug3539()\n" 77 + "BEGIN\n" + "SELECT 1;" + "end\n"); 78 79 this.rs = this.conn.getMetaData().getProcedures(null, null, 80 "testBug3539"); 81 82 assertTrue(this.rs.next()); 83 assertTrue("testBug3539".equals(this.rs.getString(3))); 84 } finally { 85 this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug3539"); 86 } 87 } 88 } 89 90 97 public void testBug3540() throws Exception { 98 if (versionMeetsMinimum(5, 0)) { 99 try { 100 this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug3540"); 101 this.stmt 102 .executeUpdate("CREATE PROCEDURE testBug3540(x int, out y int)\n" 103 + "BEGIN\n" + "SELECT 1;" + "end\n"); 104 105 this.rs = this.conn.getMetaData().getProcedureColumns(null, 106 null, "testBug3540%", "%"); 107 108 assertTrue(this.rs.next()); 109 assertTrue("testBug3540".equals(this.rs.getString(3))); 110 assertTrue("x".equals(this.rs.getString(4))); 111 112 assertTrue(this.rs.next()); 113 assertTrue("testBug3540".equals(this.rs.getString(3))); 114 assertTrue("y".equals(this.rs.getString(4))); 115 116 assertTrue(!this.rs.next()); 117 } finally { 118 this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug3540"); 119 } 120 } 121 } 122 123 130 public void testBug7026() throws Exception { 131 if (versionMeetsMinimum(5, 0)) { 132 try { 133 this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug7026"); 134 this.stmt 135 .executeUpdate("CREATE PROCEDURE testBug7026(x int, out y int)\n" 136 + "BEGIN\n" + "SELECT 1;" + "end\n"); 137 138 this.rs = this.conn.getMetaData().getProcedures( 142 this.conn.getCatalog(), null, "testBug7026"); 143 144 assertTrue(this.rs.next()); 145 assertTrue("testBug7026".equals(this.rs.getString(3))); 146 147 assertTrue(!this.rs.next()); 148 149 this.rs = this.conn.getMetaData().getProcedures("abfgerfg", 154 null, "testBug7026"); 155 assertTrue(!this.rs.next()); 156 157 this.rs = this.conn.getMetaData().getProcedures(null, null, 162 "testBug7026"); 163 164 assertTrue(this.rs.next()); 165 assertTrue("testBug7026".equals(this.rs.getString(3))); 166 167 assertTrue(!this.rs.next()); 168 } finally { 169 this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug7026"); 170 } 171 } 172 } 173 174 182 public void testBug9319() throws Exception { 183 boolean doASelect = true; 187 if (versionMeetsMinimum(5, 0, 2)) { 188 if (isAdminConnectionConfigured()) { 189 Connection db2Connection = null; 190 Connection db1Connection = null; 191 192 try { 193 db2Connection = getAdminConnection(); 194 db1Connection = getAdminConnection(); 195 196 db2Connection.createStatement().executeUpdate( 197 "CREATE DATABASE IF NOT EXISTS db_9319_2"); 198 db2Connection.setCatalog("db_9319_2"); 199 200 db2Connection.createStatement().executeUpdate( 201 "DROP PROCEDURE IF EXISTS COMPROVAR_USUARI"); 202 203 db2Connection 204 .createStatement() 205 .executeUpdate( 206 "CREATE PROCEDURE COMPROVAR_USUARI(IN p_CodiUsuari VARCHAR(10)," 207 + "\nIN p_contrasenya VARCHAR(10)," 208 + "\nOUT p_userId INTEGER," 209 + "\nOUT p_userName VARCHAR(30)," 210 + "\nOUT p_administrador VARCHAR(1)," 211 + "\nOUT p_idioma VARCHAR(2))" 212 + "\nBEGIN" 213 214 + (doASelect ? "\nselect 2;" 215 : "\nSELECT 2 INTO p_administrador;") 216 + "\nEND"); 217 218 db1Connection.createStatement().executeUpdate( 219 "CREATE DATABASE IF NOT EXISTS db_9319_1"); 220 db1Connection.setCatalog("db_9319_1"); 221 222 db1Connection.createStatement().executeUpdate( 223 "DROP PROCEDURE IF EXISTS COMPROVAR_USUARI"); 224 db1Connection 225 .createStatement() 226 .executeUpdate( 227 "CREATE PROCEDURE COMPROVAR_USUARI(IN p_CodiUsuari VARCHAR(10)," 228 + "\nIN p_contrasenya VARCHAR(10)," 229 + "\nOUT p_userId INTEGER," 230 + "\nOUT p_userName VARCHAR(30)," 231 + "\nOUT p_administrador VARCHAR(1))" 232 + "\nBEGIN" 233 + (doASelect ? "\nselect 1;" 234 : "\nSELECT 1 INTO p_administrador;") 235 + "\nEND"); 236 237 CallableStatement cstmt = db2Connection 238 .prepareCall("{ call COMPROVAR_USUARI(?, ?, ?, ?, ?, ?) }"); 239 cstmt.setString(1, "abc"); 240 cstmt.setString(2, "def"); 241 cstmt.registerOutParameter(3, java.sql.Types.INTEGER); 242 cstmt.registerOutParameter(4, java.sql.Types.VARCHAR); 243 cstmt.registerOutParameter(5, java.sql.Types.VARCHAR); 244 245 cstmt.registerOutParameter(6, java.sql.Types.VARCHAR); 246 247 cstmt.execute(); 248 249 if (doASelect) { 250 this.rs = cstmt.getResultSet(); 251 assertTrue(this.rs.next()); 252 assertEquals(2, this.rs.getInt(1)); 253 } else { 254 assertEquals(2, cstmt.getInt(5)); 255 } 256 257 cstmt = db1Connection 258 .prepareCall("{ call COMPROVAR_USUARI(?, ?, ?, ?, ?, ?) }"); 259 cstmt.setString(1, "abc"); 260 cstmt.setString(2, "def"); 261 cstmt.registerOutParameter(3, java.sql.Types.INTEGER); 262 cstmt.registerOutParameter(4, java.sql.Types.VARCHAR); 263 cstmt.registerOutParameter(5, java.sql.Types.VARCHAR); 264 265 try { 266 cstmt.registerOutParameter(6, java.sql.Types.VARCHAR); 267 fail("Should've thrown an exception"); 268 } catch (SQLException sqlEx) { 269 assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, sqlEx 270 .getSQLState()); 271 } 272 273 cstmt = db1Connection 274 .prepareCall("{ call COMPROVAR_USUARI(?, ?, ?, ?, ?) }"); 275 cstmt.setString(1, "abc"); 276 cstmt.setString(2, "def"); 277 cstmt.registerOutParameter(3, java.sql.Types.INTEGER); 278 cstmt.registerOutParameter(4, java.sql.Types.VARCHAR); 279 cstmt.registerOutParameter(5, java.sql.Types.VARCHAR); 280 281 cstmt.execute(); 282 283 if (doASelect) { 284 this.rs = cstmt.getResultSet(); 285 assertTrue(this.rs.next()); 286 assertEquals(1, this.rs.getInt(1)); 287 } else { 288 assertEquals(1, cstmt.getInt(5)); 289 } 290 291 String quoteChar = db2Connection.getMetaData() 292 .getIdentifierQuoteString(); 293 294 cstmt = db2Connection.prepareCall("{ call " + quoteChar 295 + db1Connection.getCatalog() + quoteChar + "." 296 + quoteChar + "COMPROVAR_USUARI" + quoteChar 297 + "(?, ?, ?, ?, ?) }"); 298 cstmt.setString(1, "abc"); 299 cstmt.setString(2, "def"); 300 cstmt.registerOutParameter(3, java.sql.Types.INTEGER); 301 cstmt.registerOutParameter(4, java.sql.Types.VARCHAR); 302 cstmt.registerOutParameter(5, java.sql.Types.VARCHAR); 303 304 cstmt.execute(); 305 306 if (doASelect) { 307 this.rs = cstmt.getResultSet(); 308 assertTrue(this.rs.next()); 309 assertEquals(1, this.rs.getInt(1)); 310 } else { 311 assertEquals(1, cstmt.getInt(5)); 312 } 313 } finally { 314 if (db2Connection != null) { 315 db2Connection.createStatement().executeUpdate( 316 "DROP PROCEDURE IF EXISTS COMPROVAR_USUARI"); 317 db2Connection.createStatement().executeUpdate( 318 "DROP DATABASE IF EXISTS db_9319_2"); 319 } 320 321 if (db1Connection != null) { 322 db1Connection.createStatement().executeUpdate( 323 "DROP PROCEDURE IF EXISTS COMPROVAR_USUARI"); 324 db1Connection.createStatement().executeUpdate( 325 "DROP DATABASE IF EXISTS db_9319_1"); 326 } 327 } 328 } 329 } 330 } 331 332 423 424 431 public void testBug9682() throws Exception { 432 if (versionMeetsMinimum(5, 0)) { 433 CallableStatement cStmt = null; 434 435 try { 436 this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug9682"); 437 this.stmt 438 .executeUpdate("CREATE PROCEDURE testBug9682(decimalParam DECIMAL(18,0))" 439 + "\nBEGIN" + "\n SELECT 1;" + "\nEND"); 440 cStmt = this.conn.prepareCall("Call testBug9682(?)"); 441 cStmt.setDouble(1, 18.0); 442 cStmt.execute(); 443 } finally { 444 if (cStmt != null) { 445 cStmt.close(); 446 } 447 448 this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug9682"); 449 } 450 } 451 } 452 453 461 public void testBug10310() throws Exception { 462 if (versionMeetsMinimum(5, 0)) { 463 CallableStatement cStmt = null; 464 465 try { 466 this.stmt.executeUpdate("DROP FUNCTION IF EXISTS testBug10310"); 467 this.stmt 468 .executeUpdate("CREATE FUNCTION testBug10310(a float) RETURNS INT" 469 + "\nBEGIN" + "\nRETURN a;" + "\nEND"); 470 cStmt = this.conn.prepareCall("{? = CALL testBug10310(?)}"); 471 cStmt.registerOutParameter(1, Types.INTEGER); 472 cStmt.setFloat(1, 2); 473 assertFalse(cStmt.execute()); 474 assertEquals(2f, cStmt.getInt(1), .001); 475 assertEquals("java.lang.Integer", cStmt.getObject(1).getClass() 476 .getName()); 477 478 assertEquals(-1, cStmt.executeUpdate()); 479 assertEquals(2f, cStmt.getInt(1), .001); 480 assertEquals("java.lang.Integer", cStmt.getObject(1).getClass() 481 .getName()); 482 483 485 java.sql.DatabaseMetaData dbmd = this.conn.getMetaData(); 486 487 this.rs = dbmd.getProcedures(this.conn.getCatalog(), null, 488 "testBug10310"); 489 this.rs.next(); 490 assertEquals("testBug10310", this.rs 491 .getString("PROCEDURE_NAME")); 492 assertEquals(DatabaseMetaData.procedureReturnsResult, this.rs 493 .getShort("PROCEDURE_TYPE")); 494 cStmt.setNull(1, Types.FLOAT); 495 496 assertFalse(cStmt.execute()); 497 assertEquals(0f, cStmt.getInt(1), .001); 498 assertEquals(true, cStmt.wasNull()); 499 assertEquals(null, cStmt.getObject(1)); 500 assertEquals(true, cStmt.wasNull()); 501 502 assertEquals(-1, cStmt.executeUpdate()); 503 assertEquals(0f, cStmt.getInt(1), .001); 504 assertEquals(true, cStmt.wasNull()); 505 assertEquals(null, cStmt.getObject(1)); 506 assertEquals(true, cStmt.wasNull()); 507 508 } finally { 509 if (this.rs != null) { 510 this.rs.close(); 511 this.rs = null; 512 } 513 514 if (cStmt != null) { 515 cStmt.close(); 516 } 517 518 this.stmt.executeUpdate("DROP FUNCTION IF EXISTS testBug10310"); 519 } 520 } 521 } 522 } 523 | Popular Tags |