1 30 31 32 package org.hsqldb.test; 33 34 import java.sql.Connection ; 35 import java.sql.PreparedStatement ; 36 import java.sql.ResultSet ; 37 import java.sql.Statement ; 38 39 import junit.framework.TestCase; 40 import junit.framework.TestResult; 41 42 47 public class TestBug785429 extends TestBase { 48 49 Statement stmt; 50 Connection conn; 51 52 public TestBug785429(String name) { 53 super(name); 54 } 55 56 public void test() throws Exception { 57 58 Connection conn = newConnection(); 59 60 conn.setAutoCommit(false); 61 62 Statement stmt = conn.createStatement(); 63 String sql; 64 String msg; 65 PreparedStatement ps; 66 ResultSet rs; 67 int rowcount = 0; 68 69 stmt.executeUpdate("drop table testA if exists;"); 70 stmt.executeUpdate("drop table testB if exists;"); 71 stmt.executeUpdate( 72 "create table testA(oid binary(2), data integer);"); 73 stmt.executeUpdate( 74 "create table testB(oid binary(2), data integer);"); 75 stmt.executeUpdate("insert into testA values('0001',1);"); 76 stmt.executeUpdate("insert into testB values('0001',1);"); 77 78 sql = "select * from testA as ttt,(select oid,data from testB) as tst " 79 + "where (tst.oid=ttt.oid) and (tst.oid='0001');"; 80 rs = stmt.executeQuery(sql); 81 rowcount = 0; 82 83 while (rs.next()) { 84 rowcount++; 85 } 86 87 msg = sql + ": row count:"; 88 89 assertEquals(msg, 1, rowcount); 90 stmt.execute("drop table testA if exists"); 91 stmt.execute("drop table testB if exists"); 92 stmt.execute("create table testA(oid binary(2), data integer)"); 93 stmt.execute("create table testB(oid binary(2), data integer)"); 94 95 byte[] oid = new byte[] { 96 0, 1 97 }; 98 99 ps = conn.prepareStatement("insert into testA values(?,1)"); 100 101 ps.setBytes(1, oid); 102 ps.execute(); 103 104 ps = conn.prepareStatement("insert into testB values (?,1)"); 105 106 ps.setBytes(1, oid); 107 ps.execute(); 108 109 sql = "select * from testA as ttt,(select oid,data from testB) as tst " 110 + "where (tst.oid=ttt.oid) and (tst.oid=?);"; 111 112 try { 113 ps = conn.prepareStatement(sql); 114 } catch (Exception e) { 115 e.printStackTrace(); 116 } 117 118 ps.setBytes(1, oid); 119 120 rs = ps.executeQuery(); 121 rowcount = 0; 122 123 int colCount = rs.getMetaData().getColumnCount(); 124 125 while (rs.next()) { 126 127 rowcount++; 133 } 134 135 msg = sql + ": row count:"; 136 137 assertEquals(msg, 1, rowcount); 138 } 139 140 public static void main(String [] args) throws Exception { 141 142 TestResult result; 143 TestCase test; 144 java.util.Enumeration exceptions; 145 java.util.Enumeration failures; 146 int count; 147 148 result = new TestResult(); 149 test = new TestBug785429("test"); 150 151 test.run(result); 152 153 count = result.failureCount(); 154 155 System.out.println("TestBug785429 failure count: " + count); 156 157 failures = result.failures(); 158 159 while (failures.hasMoreElements()) { 160 System.out.println(failures.nextElement()); 161 } 162 } 163 } 164 | Popular Tags |