1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
|
/*
Derby - Class org.apache.derbyTesting.functionTests.util.ProcedureTest
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.apache.derbyTesting.functionTests.util;
import org.apache.derbyTesting.functionTests.util.Formatters;
import java.sql.*;
import java.math.BigDecimal;
/**
Java procedures for the procedure.sql test.
*/
public abstract class ProcedureTest extends SimpleProcedureTest implements ResultSet {
public static void zeroArg() {
System.out.println("zeroArg() called");
}
public static void insertRow(int p1) throws SQLException {
insertRow(p1, "int");
}
public static void insertRow(int p1, String p2) throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("insert into t1 values (?, ?)");
ps.setInt(1, p1);
ps.setString(2, p2);
ps.executeUpdate();
ps.close();
conn.close();
}
public static void updateRow(int p1) throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("update t1 set i=i+?");
ps.setInt(1, p1);
ps.executeUpdate();
ps.close();
conn.close();
}
public static void deleteRow(int p1) throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("delete from t1 where i=?");
ps.setInt(1, p1);
ps.executeUpdate();
ps.close();
conn.close();
}
public static void alterTable() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("alter table t1 add column test integer");
ps.execute();
ps.close();
conn.close();
}
public static void dropTable() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("drop table t1");
ps.execute();
ps.close();
conn.close();
}
public static void createIndex() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("create index ix on t1(i,b)");
ps.execute();
ps.close();
conn.close();
}
public static void dropIndex() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("drop index ix");
ps.execute();
ps.close();
conn.close();
}
public static void createTrigger() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("create trigger test_trig" +
" AFTER delete on t1 for each STATEMENT insert into" +
" t1 values(20, 'twenty')");
ps.execute();
ps.close();
conn.close();
}
public static void dropTrigger() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("drop trigger test_trig");
ps.execute();
ps.close();
conn.close();
}
public static int selectFromSpecificSchema(int p1) throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("select * from mamta1.t12RoutineTest");
ps.executeQuery();
ps.close();
conn.close();
return (1);
}
private static void insertInBig(Connection conn, String A, String B, String C, String D) throws SQLException {
PreparedStatement ps = conn.prepareStatement("insert into big values (?, ?, ?, ?)");
ps.setString(1, A);
ps.setString(2, B);
ps.setString(3, C);
ps.setString(4, D);
ps.executeUpdate();
ps.close();
}
public static void bigTestData(int i) throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
switch (i)
{
case 1:
String largeStringA10000 = new String(Formatters.repeatChar("a",10000));
String largeStringB10000 = new String(Formatters.repeatChar("b",10000));
String largeStringC10000 = new String(Formatters.repeatChar("c",10000));
String largeStringD10000 = new String(Formatters.repeatChar("d",10000));
insertInBig(conn, largeStringA10000, largeStringB10000, largeStringC10000, largeStringD10000);
break;
case 2:
largeStringA10000 = new String(Formatters.repeatChar("e",10000));
largeStringB10000 = new String(Formatters.repeatChar("f",10000));
largeStringC10000 = new String(Formatters.repeatChar("g",10000));
largeStringD10000 = new String(Formatters.repeatChar("h",10000));
insertInBig(conn, largeStringA10000, largeStringB10000, largeStringC10000, largeStringD10000);
break;
case 3:
largeStringA10000 = new String(Formatters.repeatChar("i",10000));
largeStringB10000 = new String(Formatters.repeatChar("j",10000));
largeStringC10000 = new String(Formatters.repeatChar("k",10000));
largeStringD10000 = new String(Formatters.repeatChar("l",10000));
insertInBig(conn, largeStringA10000, largeStringB10000, largeStringC10000, largeStringD10000);
break;
case 4:
largeStringA10000 = new String(Formatters.repeatChar("m",10000));
largeStringB10000 = new String(Formatters.repeatChar("n",10000));
largeStringC10000 = new String(Formatters.repeatChar("o",10000));
largeStringD10000 = new String(Formatters.repeatChar("p",10000));
insertInBig(conn, largeStringA10000, largeStringB10000, largeStringC10000, largeStringD10000);
break;
case 5:
String largeStringA30000 = new String(Formatters.repeatChar("a",30000));
String largeStringB2752 = new String(Formatters.repeatChar("b",2752));
PreparedStatement ps = conn.prepareStatement("insert into big values (?, ?)");
ps.setString(1, largeStringA30000);
ps.setString(2, largeStringB2752);
ps.executeUpdate();
ps.close();
break;
case 6:
largeStringA30000 = new String(Formatters.repeatChar("a",30000));
String largeStringB2750 = new String(Formatters.repeatChar("b",2750));
ps = conn.prepareStatement("insert into big values (?, ?)");
ps.setString(1, largeStringA30000);
ps.setString(2, largeStringB2750);
ps.executeUpdate();
ps.close();
break;
case 7:
String largeStringA40000 = new String(Formatters.repeatChar("a",40000));
ps = conn.prepareStatement("insert into big values (?)");
ps.setString(1, largeStringA40000);
ps.executeUpdate();
ps.close();
break;
case 8:
largeStringA40000 = new String(Formatters.repeatChar("a",40000));
String largeStringB40000 = new String(Formatters.repeatChar("b",40000));
String largeStringC40000 = new String(Formatters.repeatChar("c",40000));
ps = conn.prepareStatement("insert into big values (?, ?, ?)");
ps.setString(1, largeStringA40000);
ps.setString(2, largeStringB40000);
ps.setString(3, largeStringC40000);
ps.executeUpdate();
largeStringA40000 = new String(Formatters.repeatChar("d",40000));
largeStringB40000 = new String(Formatters.repeatChar("e",40000));
largeStringC40000 = new String(Formatters.repeatChar("f",40000));
ps.setString(1, largeStringA40000);
ps.setString(2, largeStringB40000);
ps.setString(3, largeStringC40000);
ps.executeUpdate();
ps.close();
break;
case 9:
String lStringA32672 = new String(Formatters.repeatChar("a",32672));
String lStringB32672 = new String(Formatters.repeatChar("b",32672));
String lStringC32672 = new String(Formatters.repeatChar("c",32672));
String lStringD32672 = new String(Formatters.repeatChar("d",32672));
insertInBig(conn, lStringA32672, lStringB32672, lStringC32672, lStringD32672);
break;
}
conn.close();
}
//public static void selectRows_coll(int p1, java.util.Collection rs) throws SQLException {
// ResultSet[] d1 = new ResultSet[1];
// selectRows(p1, d1);
// rs.add(d1[0]);
//}
public static void selectRows(int p1, ResultSet[] data) throws SQLException {
System.out.println("selectRows - 1 arg - 1 rs");
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("select * from t1 where i = ?");
ps.setInt(1, p1);
data[0] = ps.executeQuery();
conn.close();
}
public static void selectRows(int p1, int p2, ResultSet[] data1, ResultSet[] data2) throws SQLException {
System.out.println("selectRows - 2 arg - 2 rs");
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("select * from t1 where i = ?");
ps.setInt(1, p1);
data1[0] = ps.executeQuery();
ps = conn.prepareStatement("select * from t1 where i >= ?");
ps.setInt(1, p2);
data2[0] = ps.executeQuery();
if (p2 == 99)
data2[0].close();
// return no results
if (p2 == 199) {
data1[0].close();
data1[0] = null;
data2[0].close();
data2[0] = null;
}
// swap results
if (p2 == 299) {
ResultSet rs = data1[0];
data1[0] = data2[0];
data2[0] = rs;
}
conn.close();
}
// select all rows from a table
public static void selectRows(String table, ResultSet[] rs)
throws SQLException
{
Connection conn = DriverManager.getConnection("jdbc:default:connection");
Statement stmt = conn.createStatement();
rs[0] = stmt.executeQuery("SELECT * FROM " + table);
conn.close();
}
public static void fivejp(ResultSet[] data1, ResultSet[] data2, ResultSet[] data3, ResultSet[] data4, ResultSet[] data5) throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps1 = conn.prepareStatement("select * from MRS.FIVERS where i > ?");
ps1.setInt(1, 1);
data1[0] = ps1.executeQuery();
PreparedStatement ps2 = conn.prepareStatement("select * from MRS.FIVERS where i > ?");
ps2.setInt(1, 2);
data2[0] = ps2.executeQuery();
PreparedStatement ps3 = conn.prepareStatement("select * from MRS.FIVERS where i > ?");
ps3.setInt(1, 3);
data3[0] = ps3.executeQuery();
PreparedStatement ps4 = conn.prepareStatement("select * from MRS.FIVERS where i > ?");
ps4.setInt(1, 4);
data4[0] = ps4.executeQuery();
PreparedStatement ps5 = conn.prepareStatement("select * from MRS.FIVERS where i > ?");
ps5.setInt(1, 5);
data5[0] = ps5.executeQuery();
conn.close();
}
public static void parameter1(int a, String b, String c, java.sql.ResultSet[] rs) throws SQLException {
System.out.print("PT1 a=" + a);
if (b == null)
System.out.println(" b = null");
else
System.out.print(" b=<"+b+">("+b.length()+")");
if (c == null)
System.out.println(" c = null");
else
System.out.print(" c=<"+c+">("+c.length()+")");
System.out.println("");
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("insert into PT1 values (?, ?, ?)");
ps.setInt(1, a);
ps.setString(2, b);
ps.setString(3, c);
ps.executeUpdate();
ps.close();
ps = conn.prepareStatement("select a,b, length(b), c, length(c) from PT1 where a = ?");
ps.setInt(1, a);
rs[0] = ps.executeQuery();
conn.close();
}
public static void parameter2(int a, java.math.BigDecimal b, java.math.BigDecimal c, java.sql.ResultSet[] rs) throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("insert into PT1 values (?, ?, ?)");
ps.setInt(1, a);
ps.setString(2, b.toString());
ps.setString(3, c.toString());
ps.executeUpdate();
ps.close();
ps = conn.prepareStatement("select a,b,c from PT1 where a = ?");
ps.setInt(1, a);
rs[0] = ps.executeQuery();
conn.close();
}
public static void outparams1(int[] p1, int p2) {
p1[0] = p2 * 2;
}
// Test for CLOB being returned.
public static void clobselect (ResultSet[] results,
ResultSet[] results1,
ResultSet[] results2
)
throws Exception
{
Connection conn = DriverManager.getConnection(
"jdbc:default:connection");
PreparedStatement st = conn.prepareStatement("select * from lobCheckOne");
results[0] = st.executeQuery();
// Just some regular data
PreparedStatement st1 = conn.prepareStatement("select count(*) from lobCheckOne");
results1[0] = st1.executeQuery();
// Now more Clobs
PreparedStatement st2 = conn.prepareStatement("select * from lobCheckOne");
results2[0] = st2.executeQuery();
conn.close();
return;
}
// Test for BLOB being returned.
public static void blobselect (ResultSet[] results)
throws Exception
{
Connection conn = DriverManager.getConnection(
"jdbc:default:connection");
PreparedStatement st = conn.prepareStatement("select * from lobCheckTwo");
results[0] = st.executeQuery();
conn.close();
return;
}
public static void inoutparams2(int[] p1, int p2) {
p1[0] = p1[0] + (p2 * 2);
}
public static void inoutparams3(String[] p1, int p2) {
if (p1[0] == null)
System.out.println("p1 is NULL");
else
System.out.println("p1= >" + p1[0] + "< length " + p1[0].length());
if (p2 == 8)
p1[0] = "nad";
else if (p2 == 9)
p1[0] = null;
else if (p2 == 10)
p1[0] = "abcdefghijklmnopqrstuvwzyz";
}
public static void inoutparams4(java.math.BigDecimal[] p1, String p2) {
if (p2 == null)
p1[0] = null;
else {
if (p1[0] == null)
p1[0] = new BigDecimal(p2).add(new BigDecimal("17"));
else
p1[0] = new BigDecimal(p2).add(p1[0]);
}
}
public static void ambigious1(int p1, String p2, ResultSet[] data1, ResultSet[] data2) {}
public static void ambigious1(int p1, String p2, ResultSet[] data1) {}
public static void ambigious2(int p1, Integer p2) {
System.out.println("ambigious2(int,Integer) called");
};
public static void ambigious2(Integer p1, int p2) {
System.out.println("ambigious2(Integer,int) called");
};
public static void missingDynamicParameter(int p1) {}
public static void missingDynamicParameter(int p1, Object p2) {}
public static void badDynamicParameter(int p1, ProcedureTest[] data) {}
public static void zeroArgDynamicResult(ResultSet[] data1, ResultSet[] data2, ResultSet[] data3, ResultSet[] data4) {
System.out.println("zeroArgDynamicResult called");
}
public static void sqlControl(String[] e1, String[] e2, String[] e3, String[] e4, String[] e5, String[] e6, String[] e7)
throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
Statement s = conn.createStatement();
executeStatement(s, "CREATE TABLE SQLCONTROL_DDL (I INT)", e1);
executeStatement(s, "ALTER TABLE SQLC.SQLCONTROL_DML ADD COLUMN B INT DEFAULT NULL", e2);
executeStatement(s, "INSERT INTO SQLC.SQLCONTROL_DML(I) VALUES (1)", e3);
executeStatement(s, "UPDATE SQLC.SQLCONTROL_DML SET I = I + 11", e4);
executeStatement(s, "SELECT * FROM SQLC.SQLCONTROL_DML", e5);
executeStatement(s, "DELETE FROM SQLC.SQLCONTROL_DML", e6);
executeStatement(s, "DROP TABLE SQLC.SQLCONTROL_DML", e7);
conn.close();
}
public static void sqlControl2(String[] e1, String[] e2, String[] e3, String[] e4, String[] e5, String[] e6, String[] e7)
throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
Statement s = conn.createStatement();
executeStatement(s, "CREATE VIEW SQLCONTROL_VIEW AS SELECT * FROM SQLC.SQLCONTROL_DML", e1);
executeStatement(s, "DROP VIEW SQLCONTROL_VIEW", e2);
executeStatement(s, "LOCK TABLE SQLC.SQLCONTROL_DML IN EXCLUSIVE MODE", e3);
executeStatement(s, "VALUES 1,2,3", e4);
executeStatement(s, "SET SCHEMA SQLC", e5);
executeStatement(s, "CREATE SCHEMA SQLC_M", e6);
executeStatement(s, "DROP SCHEMA SQLC_M RESTRICT", e7);
conn.close();
}
public static void sqlControl3(String[] e1, String[] e2, String[] e3, String[] e4, String[] e5, String[] e6, String[] e7)
throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
Statement s = conn.createStatement();
e1[0] = "IBM CS FEATURE";
e2[0] = "IBM CS FEATURE";
executeStatement(s, "SET ISOLATION CS", e3);
executeStatement(s, "SET RUNTIMESTATISTICS OFF", e4);
executeStatement(s, "SET STATISTICS TIMING OFF", e5);
executeStatement(s, "VALUES 1", e6);
executeStatement(s, "VALUES 1", e7);
conn.close();
}
public static void sqlControl4(int sqlc, String[] e1, String[] e2, String[] e3, String[] e4, String[] e5, String[] e6, String[] e7, String[] e8)
throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
Statement s = conn.createStatement();
String sql = "CALL SQLC.SQLCONTROL2_"+sqlc+" (?, ?, ?, ?, ?, ?, ?) ";
e1[0] = sql;
CallableStatement cs1 = conn.prepareCall(sql);
try {
for (int rop = 1; rop <= 7; rop++) {
cs1.registerOutParameter(rop, Types.VARCHAR);
}
cs1.execute();
e2[0] = cs1.getString(1);
e3[0] = cs1.getString(2);
e4[0] = cs1.getString(3);
e5[0] = cs1.getString(4);
e6[0] = cs1.getString(5);
e7[0] = cs1.getString(6);
e8[0] = cs1.getString(7);
} catch (SQLException sqle) {
StringBuffer sb = new StringBuffer(128);
sb.append("STATE");
do {
sb.append("-");
String ss = sqle.getSQLState();
if (ss == null)
ss= "?????";
sb.append(ss);
sqle = sqle.getNextException();
} while (sqle != null);
e2[0] = sb.toString();
}
cs1.close();
conn.close();
}
private static void executeStatement(Statement s, String sql, String[] result) {
StringBuffer sb = new StringBuffer(128);
int len = sql.length();
if (len > 15)
len = 15;
sb.append(sql.substring(0, len));
try {
if (s.execute(sql)) {
ResultSet rs = s.getResultSet();
while (rs.next())
sb.append("- ROW(" + rs.getString(1) + ")");
rs.close();
} else {
sb.append("-UPDATE " + s.getUpdateCount());
}
sb.append("-EXECUTE OK");
} catch (SQLException sqle) {
do {
sb.append("-");
String ss = sqle.getSQLState();
if (ss == null)
ss= "?????";
sb.append(ss);
sqle = sqle.getNextException();
} while (sqle != null);
}
result[0] = sb.toString();
}
public static void oBOOLEAN(Boolean in, Boolean[] inout, Boolean[] out) throws SQLException {
if (out[0] != null)
throw new SQLException ("oBOOLEAN expected out[] to be null");
out[0] = in;
if (in == null)
inout[0] = null;
else
inout[0] = inout[0].booleanValue() && in.booleanValue();
}
public static void pBOOLEAN(boolean in, boolean[] inout, boolean[] out) throws SQLException {
if (out[0] != false)
throw new SQLException ("pBOOLEAN expected out[] to be null");
out[0] = in;
inout[0] =inout[0] && in;
}
public static void oALLINT(Integer in, Integer[] inout, Integer[] out) throws SQLException {
if (out[0] != null)
throw new SQLException ("oALLINT expected out[] to be null");
out[0] = in;
if (in == null)
;//inout[0] = null;
else if (inout[0] == null)
inout[0] = 3 * in.intValue();
else
inout[0] = inout[0].intValue() + in.intValue();
}
public static void pTINYINT(byte in, byte[] inout, byte[] out) throws SQLException {
out[0] = in;
inout[0] += in;
}
public static void pSMALLINT(short in, short[] inout, short[] out) throws SQLException {
out[0] = in;
inout[0] += in;
}
/*
** Procedures for testing literals passed to procedures as IN parameters
*/
public static void literalTest(int p1, String[] p2) {
p2[0] = ">" + Integer.toString(p1) + "<";
}
public static void literalTest(long p1, String[] p2) {
p2[0] = ">" + Long.toString(p1) + "<";
}
public static void literalTest(float p1, String[] p2) {
p2[0] = ">" + Float.toString(p1) + "<";
}
public static void literalTest(double p1, String[] p2) {
p2[0] = ">" + Double.toString(p1) + "<";
}
public static void literalTest(BigDecimal p1, String[] p2) {
String s = p1 == null ? "NULL" : p1.toString();
p2[0] = ">" + s + "<";
}
public static void literalTest(String p1, String[] p2) {
String s = p1 == null ? "NULL" : p1.toString();
p2[0] = ">" + s + "<";
}
public static void literalTest(java.sql.Date p1, String[] p2) {
String s = p1 == null ? "NULL" : p1.toString();
p2[0] = ">" + s + "<";
}
public static void literalTest(java.sql.Time p1, String[] p2) {
String s = p1 == null ? "NULL" : p1.toString();
p2[0] = ">" + s + "<";
}
public static void literalTest(java.sql.Timestamp p1, String[] p2) {
String s = p1 == null ? "NULL" : p1.toString();
p2[0] = ">" + s + "<";
}
/*
** Procedure which uses BigDecimal - for parameter mapping testing.
*/
public static void pmap(BigDecimal in, BigDecimal[] inout, BigDecimal[] out) {
inout[0] = inout[0].add(new BigDecimal(2.3));
out[0] = new BigDecimal(84.1);
}
public static int countRows(String schema, String table) throws SQLException
{
Connection conn = DriverManager.getConnection("jdbc:default:connection");
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM " + schema + "." + table);
rs.next();
int count = rs.getInt(1);
rs.close();
s.close();
conn.close();
return count;
}
/**
* Procedure installed to test multiple ResultSets in the lang/procedure.java
* test class.
*
* @param p1 Number parameter for the first ResultSet
* @param p2 Number parameter for the second ResultSet
* @param data1 The first ResultSet to be returned.
* @param data2 The Second ResultSet to be returned
* @throws SQLException
*/
public static void multiResult(int p1, int p2, ResultSet[] data1, ResultSet[] data2)
throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("select * from AutoCommitTable where num = ?");
ps.setInt(1, p1);
data1[0] = ps.executeQuery();
ps = conn.prepareStatement("select * from AutoCommitTable where num = ?");
ps.setInt(1, p2);
data2[0] = ps.executeQuery();
conn.close();
}
// Procedure used by the test for bug JIRA-491. The client side part
// of this test is in lang/procedure.java
public static void BIG_COL_491 (int i, ResultSet [] rs1, ResultSet [] rs2)
throws SQLException
{
Connection conn = DriverManager.getConnection("jdbc:default:connection");
Statement st1 = conn.createStatement();
rs1[0] = st1.executeQuery(
"select int1, varchar32k from jira491 where int1 < " + i + " order by 1");
Statement st2 = conn.createStatement();
rs2[0] = st2.executeQuery(
"select int1, varchar32k from jira491 where int1 > " + i + " order by 1");
}
// Procedure used by the test for bug JIRA-492. The client side part of
// this test is in lang/procedure.java
public static void LOTS_O_COLS_492(ResultSet [] rs)
throws SQLException
{
Connection conn = DriverManager.getConnection("jdbc:default:connection");
Statement st1 = conn.createStatement();
StringBuffer query = new StringBuffer("SELECT ");
for (int i = 0; i < 100; i++)
{
int cno = 1000 + (i * 10);
if (i > 0) query.append(", ");
query.append("id AS col").append(cno).append(", nsi as col").
append(cno+1).append(", ni AS col").append(cno+2).
append(", nbi AS col").append(cno+3).append(", nd AS col").
append(cno+4).append(", nr AS col").append(cno+5).
append(", ndo AS col").append(cno+6).append(" ");
}
query.append("FROM jira492 a WHERE a.id = 0");
rs[0] = st1.executeQuery(query.toString());
}
public static void grantSelect() throws SQLException
{
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("grant select on t1 to user2");
ps.execute();
ps.close();
conn.close();
}
public static void revokeSelect() throws SQLException
{
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps = conn.prepareStatement("revoke select on t1 from user2");
ps.execute();
ps.close();
conn.close();
}
public static void noname(int p1, String p2) {
System.out.println("noname(int,String) called");
}
public static void noname2(Timestamp p1, String p2) {
System.out.println("noname(Timestamp,String) called");
}
}
|