Exemplo n.º 1
0
 public void tearDown() {
   try {
     Connection con = AllTests.getConnection();
     Statement st = con.createStatement();
     st.execute("drop table " + table);
     st.close();
   } catch (Throwable e) {
     // e.printStackTrace();
   }
 }
Exemplo n.º 2
0
  public void setUp() {
    tearDown();
    try {
      Connection con = AllTests.getConnection();
      Statement st = con.createStatement();
      st.execute(
          "create table " + table + "(a " + testValue.dataType + ", b " + testValue.dataType + ")");
      st.close();
      PreparedStatement pr = con.prepareStatement("INSERT into " + table + "(a,b) Values(?,?)");

      pr.setObject(1, testValue.small);
      pr.setObject(2, testValue.large);
      pr.execute();

      pr.setObject(1, testValue.small);
      pr.setObject(2, testValue.small);
      pr.execute();

      pr.setObject(1, testValue.large);
      pr.setObject(2, testValue.large);
      pr.execute();

      pr.setObject(1, testValue.large);
      pr.setObject(2, testValue.small);
      pr.execute();

      pr.setObject(1, null);
      pr.setObject(2, testValue.small);
      pr.execute();

      pr.setObject(1, testValue.small);
      pr.setObject(2, null);
      pr.execute();

      pr.setObject(1, null);
      pr.setObject(2, null);
      pr.execute();
      pr.close();
    } catch (Throwable e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 3
0
  public void runTest() throws Exception {
    Connection con = AllTests.getConnection();
    Statement st = con.createStatement();
    ResultSet rs;

    rs = st.executeQuery("Select * from " + table + " where 1 = 0");
    assertFalse("To many rows", rs.next());

    rs = st.executeQuery("Select * from " + table + " where a = b");
    assertTrue("To few rows", rs.next());
    assertEqualsObject("Values not equals", rs.getObject(1), rs.getObject(2), false);
    assertTrue("To few rows", rs.next());
    assertEqualsObject("Values not equals", rs.getObject(1), rs.getObject(2), false);
    assertFalse("To many rows", rs.next());

    rs = st.executeQuery("Select * from " + table + " where a <= b and b <= a");
    assertTrue("To few rows", rs.next());
    assertEqualsObject("Values not equals", rs.getObject(1), rs.getObject(2), false);
    assertTrue("To few rows", rs.next());
    assertEqualsObject("Values not equals", rs.getObject(1), rs.getObject(2), false);
    assertFalse("To many rows", rs.next());

    rs = st.executeQuery("Select * from " + table + " where (a > (b))");
    assertTrue("To few rows", rs.next());
    assertFalse("To many rows", rs.next());

    rs = st.executeQuery("Select * from " + table + " where a >= b");
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertFalse("To many rows", rs.next());

    rs = st.executeQuery("Select * from " + table + " where not (a >= b)");
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertFalse("To many rows", rs.next());

    rs = st.executeQuery("Select * from " + table + " where a < b");
    assertTrue("To few rows", rs.next());
    assertFalse("To many rows", rs.next());

    rs = st.executeQuery("Select * from " + table + " where a < b or a>b");
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertFalse("To many rows", rs.next());

    rs = st.executeQuery("Select * from " + table + " where a <= b");
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertFalse("To many rows", rs.next());

    rs = st.executeQuery("Select * from " + table + " where a <> b");
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertFalse("To many rows", rs.next());

    PreparedStatement pr =
        con.prepareStatement("Select * from " + table + " where a between ? and ?");
    pr.setObject(1, testValue.small);
    pr.setObject(2, testValue.large);
    rs = pr.executeQuery();
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertFalse("To many rows", rs.next());
    pr.close();

    pr = con.prepareStatement("Select * from " + table + " where a not between ? and ?");
    pr.setObject(1, testValue.small);
    pr.setObject(2, testValue.large);
    rs = pr.executeQuery();
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertFalse("To many rows", rs.next());
    pr.close();

    pr = con.prepareStatement("Select * from " + table + " where a in(?,?)");
    pr.setObject(1, testValue.small);
    pr.setObject(2, testValue.large);
    rs = pr.executeQuery();
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertFalse("To many rows", rs.next());
    pr.close();

    pr = con.prepareStatement("Select * from " + table + " where a not in(?,?)");
    pr.setObject(1, testValue.small);
    pr.setObject(2, testValue.large);
    rs = pr.executeQuery();
    assertTrue("To few rows", rs.next());
    assertTrue("To few rows", rs.next());
    assertFalse("To many rows", rs.next());
    pr.close();

    st.close();
  }