提交 277312ed authored 作者: Thomas Mueller's avatar Thomas Mueller

Split long lines.

上级 87b97ef0
...@@ -118,11 +118,16 @@ public class BenchA implements Bench { ...@@ -118,11 +118,16 @@ public class BenchA implements Bench {
int branch = random.nextInt(branches); int branch = random.nextInt(branches);
int teller = random.nextInt(tellers); int teller = random.nextInt(tellers);
PreparedStatement updateAccount = database.prepare("UPDATE ACCOUNTS SET ABALANCE=ABALANCE+? WHERE AID=?"); PreparedStatement updateAccount = database.prepare(
PreparedStatement selectBalance = database.prepare("SELECT ABALANCE FROM ACCOUNTS WHERE AID=?"); "UPDATE ACCOUNTS SET ABALANCE=ABALANCE+? WHERE AID=?");
PreparedStatement updateTeller = database.prepare("UPDATE TELLERS SET TBALANCE=TBALANCE+? WHERE TID=?"); PreparedStatement selectBalance = database.prepare(
PreparedStatement updateBranch = database.prepare("UPDATE BRANCHES SET BBALANCE=BBALANCE+? WHERE BID=?"); "SELECT ABALANCE FROM ACCOUNTS WHERE AID=?");
PreparedStatement insertHistory = database.prepare("INSERT INTO HISTORY(AID,TID,BID,DELTA,HTIME,FILLER) VALUES(?,?,?,?,?,?)"); PreparedStatement updateTeller = database.prepare(
"UPDATE TELLERS SET TBALANCE=TBALANCE+? WHERE TID=?");
PreparedStatement updateBranch = database.prepare(
"UPDATE BRANCHES SET BBALANCE=BBALANCE+? WHERE BID=?");
PreparedStatement insertHistory = database.prepare(
"INSERT INTO HISTORY(AID,TID,BID,DELTA,HTIME,FILLER) VALUES(?,?,?,?,?,?)");
int accountsPerBranch = accounts / branches; int accountsPerBranch = accounts / branches;
database.setAutoCommit(false); database.setAutoCommit(false);
......
...@@ -338,7 +338,8 @@ public class TestCases extends TestBase { ...@@ -338,7 +338,8 @@ public class TestCases extends TestBase {
conn.close(); conn.close();
} }
private void testCompareDoubleWithIntColumn(Statement stat, boolean pk, double x, boolean prepared) throws SQLException { private void testCompareDoubleWithIntColumn(Statement stat, boolean pk,
double x, boolean prepared) throws SQLException {
if (pk) { if (pk) {
stat.execute("create table test(id int primary key)"); stat.execute("create table test(id int primary key)");
} else { } else {
...@@ -347,7 +348,8 @@ public class TestCases extends TestBase { ...@@ -347,7 +348,8 @@ public class TestCases extends TestBase {
stat.execute("insert into test values(1)"); stat.execute("insert into test values(1)");
ResultSet rs; ResultSet rs;
if (prepared) { if (prepared) {
PreparedStatement prep = stat.getConnection().prepareStatement("select * from test where id > ?"); PreparedStatement prep = stat.getConnection().prepareStatement(
"select * from test where id > ?");
prep.setDouble(1, x); prep.setDouble(1, x);
rs = prep.executeQuery(); rs = prep.executeQuery();
} else { } else {
...@@ -815,11 +817,12 @@ public class TestCases extends TestBase { ...@@ -815,11 +817,12 @@ public class TestCases extends TestBase {
deleteDb("cases"); deleteDb("cases");
Connection conn = getConnection("cases"); Connection conn = getConnection("cases");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ORDER_ID INT PRIMARY KEY, ORDER_DATE DATETIME, USER_ID INT ," stat.execute("CREATE TABLE TEST(ORDER_ID INT PRIMARY KEY, ORDER_DATE DATETIME, " +
+ "DESCRIPTION VARCHAR, STATE VARCHAR, TRACKING_ID VARCHAR)"); "USER_ID INT, DESCRIPTION VARCHAR, STATE VARCHAR, TRACKING_ID VARCHAR)");
Timestamp orderDate = Timestamp.valueOf("2005-05-21 17:46:00"); Timestamp orderDate = Timestamp.valueOf("2005-05-21 17:46:00");
String sql = "insert into TEST (ORDER_ID,ORDER_DATE,USER_ID,DESCRIPTION,STATE,TRACKING_ID) " String sql = "insert into TEST (ORDER_ID,ORDER_DATE,USER_ID,DESCRIPTION,STATE,TRACKING_ID) " +
+ "select cast(? as int),cast(? as date),cast(? as int),cast(? as varchar),cast(? as varchar),cast(? as varchar) union all select ?,?,?,?,?,?"; "select cast(? as int),cast(? as date),cast(? as int),cast(? as varchar)," +
"cast(? as varchar),cast(? as varchar) union all select ?,?,?,?,?,?";
PreparedStatement ps = conn.prepareStatement(sql); PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, 5555); ps.setInt(1, 5555);
ps.setTimestamp(2, orderDate); ps.setTimestamp(2, orderDate);
......
...@@ -258,7 +258,8 @@ public class TestCsv extends TestBase { ...@@ -258,7 +258,8 @@ public class TestCsv extends TestBase {
Connection conn = getConnection("csv"); Connection conn = getConnection("csv");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("call csvwrite('" + file.getName() + "', 'select NULL as a, '''' as b, ''\\N'' as c, NULL as d', 'UTF8', ',', '\"', NULL, '\\N', '\n')"); stat.execute("call csvwrite('" + file.getName() +
"', 'select NULL as a, '''' as b, ''\\N'' as c, NULL as d', 'UTF8', ',', '\"', NULL, '\\N', '\n')");
InputStreamReader reader = new InputStreamReader(fs.openFileInputStream(fileName)); InputStreamReader reader = new InputStreamReader(fs.openFileInputStream(fileName));
// on read, an empty string is treated like null, // on read, an empty string is treated like null,
// but on write a null is always written with the nullString // but on write a null is always written with the nullString
...@@ -358,8 +359,11 @@ public class TestCsv extends TestBase { ...@@ -358,8 +359,11 @@ public class TestCsv extends TestBase {
assertEquals("It's nice", rs.getString(1)); assertEquals("It's nice", rs.getString(1));
assertEquals("\nHello*\n", rs.getString(2)); assertEquals("\nHello*\n", rs.getString(2));
assertFalse(rs.next()); assertFalse(rs.next());
stat.execute("call csvwrite('" + fileName2 + "', 'select * from csvread(''" + fileName + "'', null, null, '';'', '''''''', ''\\'')', null, '+', '*', '#')"); stat.execute("call csvwrite('" + fileName2 +
rs = stat.executeQuery("select * from csvread('" + fileName2 + "', null, null, '+', '*', '#')"); "', 'select * from csvread(''" + fileName +
"'', null, null, '';'', '''''''', ''\\'')', null, '+', '*', '#')");
rs = stat.executeQuery("select * from csvread('" + fileName2 +
"', null, null, '+', '*', '#')");
meta = rs.getMetaData(); meta = rs.getMetaData();
assertEquals(2, meta.getColumnCount()); assertEquals(2, meta.getColumnCount());
assertEquals("A", meta.getColumnLabel(1)); assertEquals("A", meta.getColumnLabel(1));
...@@ -473,7 +477,8 @@ public class TestCsv extends TestBase { ...@@ -473,7 +477,8 @@ public class TestCsv extends TestBase {
} }
long time; long time;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
Csv.getInstance().write(conn, getBaseDir() + "/testRW.csv", "SELECT X ID, 'Ruebezahl' NAME FROM SYSTEM_RANGE(1, " + len + ")", "UTF8"); Csv.getInstance().write(conn, getBaseDir() + "/testRW.csv",
"SELECT X ID, 'Ruebezahl' NAME FROM SYSTEM_RANGE(1, " + len + ")", "UTF8");
trace("write: " + (System.currentTimeMillis() - time)); trace("write: " + (System.currentTimeMillis() - time));
ResultSet rs; ResultSet rs;
time = System.currentTimeMillis(); time = System.currentTimeMillis();
......
...@@ -122,7 +122,8 @@ public class TestDateStorage extends TestBase { ...@@ -122,7 +122,8 @@ public class TestDateStorage extends TestBase {
} }
private static void test(int year, int month, int day, int hour) { private static void test(int year, int month, int day, int hour) {
DateTimeUtils.parseDateTime(year + "-" + month + "-" + day + " " + hour + ":00:00", Value.TIMESTAMP, ErrorCode.TIMESTAMP_CONSTANT_2); DateTimeUtils.parseDateTime(year + "-" + month + "-" + day + " " + hour + ":00:00",
Value.TIMESTAMP, ErrorCode.TIMESTAMP_CONSTANT_2);
} }
private void testAllTimeZones() throws SQLException { private void testAllTimeZones() throws SQLException {
......
...@@ -446,12 +446,22 @@ public class TestLinkedTable extends TestBase { ...@@ -446,12 +446,22 @@ public class TestLinkedTable extends TestBase {
Connection conn = DriverManager.getConnection(url1, "sa1", "abc abc"); Connection conn = DriverManager.getConnection(url1, "sa1", "abc abc");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TEMP TABLE TEST_TEMP(ID INT PRIMARY KEY)"); stat.execute("CREATE TEMP TABLE TEST_TEMP(ID INT PRIMARY KEY)");
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(200), XT TINYINT, XD DECIMAL(10,2), XTS TIMESTAMP, XBY BINARY(255), XBO BIT, XSM SMALLINT, XBI BIGINT, XBL BLOB, XDA DATE, XTI TIME, XCL CLOB, XDO DOUBLE)"); stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, " +
"NAME VARCHAR(200), XT TINYINT, XD DECIMAL(10,2), " +
"XTS TIMESTAMP, XBY BINARY(255), XBO BIT, XSM SMALLINT, " +
"XBI BIGINT, XBL BLOB, XDA DATE, XTI TIME, XCL CLOB, XDO DOUBLE)");
stat.execute("CREATE INDEX IDXNAME ON TEST(NAME)"); stat.execute("CREATE INDEX IDXNAME ON TEST(NAME)");
stat.execute("INSERT INTO TEST VALUES(0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)"); stat.execute("INSERT INTO TEST VALUES(0, NULL, NULL, NULL, NULL, " +
stat.execute("INSERT INTO TEST VALUES(1, 'Hello', -1, 10.30, '2001-02-03 11:22:33.4455', X'FF0102', TRUE, 3000, 1234567890123456789, X'1122AA', DATE '0002-01-01', TIME '00:00:00', 'J\u00fcrg', 2.25)"); "NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)");
stat.execute("INSERT INTO TEST VALUES(1, 'Hello', -1, 10.30, " +
"'2001-02-03 11:22:33.4455', X'FF0102', TRUE, 3000, " +
"1234567890123456789, X'1122AA', DATE '0002-01-01', " +
"TIME '00:00:00', 'J\u00fcrg', 2.25)");
testRow(stat, "TEST"); testRow(stat, "TEST");
stat.execute("INSERT INTO TEST VALUES(2, 'World', 30, 100.05, '2005-12-31 12:34:56.789', X'FFEECC33', FALSE, 1, -1234567890123456789, X'4455FF', DATE '9999-12-31', TIME '23:59:59', 'George', -2.5)"); stat.execute("INSERT INTO TEST VALUES(2, 'World', 30, 100.05, " +
"'2005-12-31 12:34:56.789', X'FFEECC33', FALSE, 1, " +
"-1234567890123456789, X'4455FF', DATE '9999-12-31', " +
"TIME '23:59:59', 'George', -2.5)");
testRow(stat, "TEST"); testRow(stat, "TEST");
stat.execute("SELECT * FROM TEST_TEMP"); stat.execute("SELECT * FROM TEST_TEMP");
conn.close(); conn.close();
...@@ -483,7 +493,10 @@ public class TestLinkedTable extends TestBase { ...@@ -483,7 +493,10 @@ public class TestLinkedTable extends TestBase {
conn = DriverManager.getConnection(url2, "sa2", "def def"); conn = DriverManager.getConnection(url2, "sa2", "def def");
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("INSERT INTO LINK_TEST VALUES(3, 'Link Test', 30, 100.05, '2005-12-31 12:34:56.789', X'FFEECC33', FALSE, 1, -1234567890123456789, X'4455FF', DATE '9999-12-31', TIME '23:59:59', 'George', -2.5)"); stat.execute("INSERT INTO LINK_TEST VALUES(3, 'Link Test', " +
"30, 100.05, '2005-12-31 12:34:56.789', X'FFEECC33', " +
"FALSE, 1, -1234567890123456789, X'4455FF', " +
"DATE '9999-12-31', TIME '23:59:59', 'George', -2.5)");
rs = stat.executeQuery("SELECT COUNT(*) FROM LINK_TEST"); rs = stat.executeQuery("SELECT COUNT(*) FROM LINK_TEST");
rs.next(); rs.next();
......
...@@ -773,7 +773,8 @@ public class TestLob extends TestBase { ...@@ -773,7 +773,8 @@ public class TestLob extends TestBase {
conn0.getAutoCommit(); conn0.getAutoCommit();
conn0.getAutoCommit(); conn0.getAutoCommit();
PreparedStatement prep2 = conn0 PreparedStatement prep2 = conn0
.prepareStatement("select c_.ID as ID0_0_, c_.DATA as S_, c_.CLOB_DATA as CLOB3_0_0_ from CLOB_ENTITY c_ where c_.ID=?"); .prepareStatement("select c_.ID as ID0_0_, c_.DATA as S_, " +
"c_.CLOB_DATA as CLOB3_0_0_ from CLOB_ENTITY c_ where c_.ID=?");
prep2.setLong(1, 1); prep2.setLong(1, 1);
ResultSet rs1 = prep2.executeQuery(); ResultSet rs1 = prep2.executeQuery();
rs1.next(); rs1.next();
......
...@@ -271,7 +271,8 @@ public class TestOptimizations extends TestBase { ...@@ -271,7 +271,8 @@ public class TestOptimizations extends TestBase {
stat.execute("create view test_view as select a.status, a.tag from accounts a, parent t where a.id = t.id"); stat.execute("create view test_view as select a.status, a.tag from accounts a, parent t where a.id = t.id");
rs = stat.executeQuery("select * from test_view where status='X' and tag in ('A','B')"); rs = stat.executeQuery("select * from test_view where status='X' and tag in ('A','B')");
assertTrue(rs.next()); assertTrue(rs.next());
rs = stat.executeQuery("select * from (select a.status, a.tag from accounts a, parent t where a.id = t.id) x where status='X' and tag in ('A','B')"); rs = stat.executeQuery("select * from (select a.status, a.tag " +
"from accounts a, parent t where a.id = t.id) x where status='X' and tag in ('A','B')");
assertTrue(rs.next()); assertTrue(rs.next());
stat.execute("create table test(id int primary key, name varchar(255))"); stat.execute("create table test(id int primary key, name varchar(255))");
......
...@@ -76,7 +76,8 @@ public class TestReadOnly extends TestBase { ...@@ -76,7 +76,8 @@ public class TestReadOnly extends TestBase {
} catch (SQLException e) { } catch (SQLException e) {
assertKnownException(e); assertKnownException(e);
} }
stat.execute("create local temporary linked table test(null, 'jdbc:h2:mem:test3', 'sa', 'sa', 'INFORMATION_SCHEMA.TABLES')"); stat.execute("create local temporary linked table test(" +
"null, 'jdbc:h2:mem:test3', 'sa', 'sa', 'INFORMATION_SCHEMA.TABLES')");
ResultSet rs = stat.executeQuery("select * from test"); ResultSet rs = stat.executeQuery("select * from test");
assertTrue(rs.next()); assertTrue(rs.next());
conn.close(); conn.close();
......
...@@ -65,7 +65,9 @@ public class TestRecursiveQueries extends TestBase { ...@@ -65,7 +65,9 @@ public class TestRecursiveQueries extends TestBase {
ResultSet rs; ResultSet rs;
stat = conn.createStatement(); stat = conn.createStatement();
rs = stat.executeQuery("with recursive t(n) as (select 1 union all select n+1 from t where n<3) select * from t"); rs = stat.executeQuery("with recursive t(n) as " +
"(select 1 union all select n+1 from t where n<3) " +
"select * from t");
assertTrue(rs.next()); assertTrue(rs.next());
assertEquals(1, rs.getInt(1)); assertEquals(1, rs.getInt(1));
assertTrue(rs.next()); assertTrue(rs.next());
...@@ -74,7 +76,9 @@ public class TestRecursiveQueries extends TestBase { ...@@ -74,7 +76,9 @@ public class TestRecursiveQueries extends TestBase {
assertEquals(3, rs.getInt(1)); assertEquals(3, rs.getInt(1));
assertFalse(rs.next()); assertFalse(rs.next());
prep = conn.prepareStatement("with recursive t(n) as (select 1 union all select n+1 from t where n<3) select * from t where n>?"); prep = conn.prepareStatement("with recursive t(n) as " +
"(select 1 union all select n+1 from t where n<3) " +
"select * from t where n>?");
prep.setInt(1, 2); prep.setInt(1, 2);
rs = prep.executeQuery(); rs = prep.executeQuery();
assertTrue(rs.next()); assertTrue(rs.next());
...@@ -89,7 +93,9 @@ public class TestRecursiveQueries extends TestBase { ...@@ -89,7 +93,9 @@ public class TestRecursiveQueries extends TestBase {
assertEquals(3, rs.getInt(1)); assertEquals(3, rs.getInt(1));
assertFalse(rs.next()); assertFalse(rs.next());
prep = conn.prepareStatement("with recursive t(n) as (select @start union all select n+@inc from t where n<@end) select * from t"); prep = conn.prepareStatement("with recursive t(n) as " +
"(select @start union all select n+@inc from t where n<@end) " +
"select * from t");
prep2 = conn.prepareStatement("select @start:=?, @inc:=?, @end:=?"); prep2 = conn.prepareStatement("select @start:=?, @inc:=?, @end:=?");
prep2.setInt(1, 10); prep2.setInt(1, 10);
prep2.setInt(2, 2); prep2.setInt(2, 2);
......
...@@ -184,12 +184,14 @@ public class TestRunscript extends TestBase implements Trigger { ...@@ -184,12 +184,14 @@ public class TestRunscript extends TestBase implements Trigger {
stat1.execute("create sequence testSeq start with 100 increment by 10"); stat1.execute("create sequence testSeq start with 100 increment by 10");
stat1.execute("create alias myTest for \"" + getClass().getName() + ".test\""); stat1.execute("create alias myTest for \"" + getClass().getName() + ".test\"");
stat1.execute("create trigger myTrigger before insert on test nowait call \"" + getClass().getName() + "\""); stat1.execute("create trigger myTrigger before insert on test nowait call \"" + getClass().getName() + "\"");
stat1.execute("create view testView as select * from test where 1=0 union all select * from test where 0=1"); stat1.execute("create view testView as select * from test where 1=0 union all " +
"select * from test where 0=1");
stat1.execute("create user testAdmin salt '00' hash '01' admin"); stat1.execute("create user testAdmin salt '00' hash '01' admin");
stat1.execute("create schema testSchema authorization testAdmin"); stat1.execute("create schema testSchema authorization testAdmin");
stat1.execute("create table testSchema.parent(id int primary key, name varchar)"); stat1.execute("create table testSchema.parent(id int primary key, name varchar)");
stat1.execute("create index idxname on testSchema.parent(name)"); stat1.execute("create index idxname on testSchema.parent(name)");
stat1.execute("create table testSchema.child(id int primary key, parentId int, name varchar, foreign key(parentId) references parent(id))"); stat1.execute("create table testSchema.child(id int primary key, " +
"parentId int, name varchar, foreign key(parentId) references parent(id))");
stat1.execute("create user testUser salt '02' hash '03'"); stat1.execute("create user testUser salt '02' hash '03'");
stat1.execute("create role testRole"); stat1.execute("create role testRole");
stat1.execute("grant all on testSchema.child to testUser"); stat1.execute("grant all on testSchema.child to testUser");
......
...@@ -260,8 +260,10 @@ public class TestTransaction extends TestBase { ...@@ -260,8 +260,10 @@ public class TestTransaction extends TestBase {
Statement s1 = c1.createStatement(); Statement s1 = c1.createStatement();
s1.execute("drop table if exists a"); s1.execute("drop table if exists a");
s1.execute("drop table if exists b"); s1.execute("drop table if exists b");
s1.execute("create table a (id integer identity not null, code varchar(10) not null, primary key(id))"); s1.execute("create table a (id integer identity not null, " +
s1.execute("create table b (name varchar(100) not null, a integer, primary key(name), foreign key(a) references a(id))"); "code varchar(10) not null, primary key(id))");
s1.execute("create table b (name varchar(100) not null, a integer, " +
"primary key(name), foreign key(a) references a(id))");
Connection c2 = getConnection("transaction"); Connection c2 = getConnection("transaction");
c2.setAutoCommit(false); c2.setAutoCommit(false);
s1.executeUpdate("insert into A(code) values('one')"); s1.executeUpdate("insert into A(code) values('one')");
......
...@@ -151,7 +151,8 @@ public class TestTriggersConstraints extends TestBase implements Trigger { ...@@ -151,7 +151,8 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
stat.execute("drop table if exists test"); stat.execute("drop table if exists test");
stat.execute("create table test(id int)"); stat.execute("create table test(id int)");
stat.execute("create view test_view as select * from test"); stat.execute("create view test_view as select * from test");
stat.execute("create trigger test_view_insert instead of insert on test_view for each row call \"" + TestView.class.getName() + "\""); stat.execute("create trigger test_view_insert " +
"instead of insert on test_view for each row call \"" + TestView.class.getName() + "\"");
if (!config.memory) { if (!config.memory) {
conn.close(); conn.close();
conn = getConnection("trigger"); conn = getConnection("trigger");
...@@ -219,7 +220,8 @@ public class TestTriggersConstraints extends TestBase implements Trigger { ...@@ -219,7 +220,8 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("drop table if exists meta_tables"); stat.execute("drop table if exists meta_tables");
stat.execute("create table meta_tables(name varchar)"); stat.execute("create table meta_tables(name varchar)");
stat.execute("create trigger meta_tables_select before select on meta_tables call \"" + TestSelect.class.getName() + "\""); stat.execute("create trigger meta_tables_select " +
"before select on meta_tables call \"" + TestSelect.class.getName() + "\"");
ResultSet rs; ResultSet rs;
rs = stat.executeQuery("select * from meta_tables"); rs = stat.executeQuery("select * from meta_tables");
assertTrue(rs.next()); assertTrue(rs.next());
...@@ -319,7 +321,8 @@ public class TestTriggersConstraints extends TestBase implements Trigger { ...@@ -319,7 +321,8 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("DROP TABLE IF EXISTS TEST"); stat.execute("DROP TABLE IF EXISTS TEST");
stat.execute("create table test(id int primary key, parent int)"); stat.execute("create table test(id int primary key, parent int)");
stat.execute("alter table test add constraint test_parent_id foreign key(parent) references test (id) on delete cascade"); stat.execute("alter table test add constraint test_parent_id " +
"foreign key(parent) references test (id) on delete cascade");
stat.execute("insert into test select x, x/2 from system_range(0, 100)"); stat.execute("insert into test select x, x/2 from system_range(0, 100)");
stat.execute("delete from test"); stat.execute("delete from test");
assertSingleValue(stat, "select count(*) from test", 0); assertSingleValue(stat, "select count(*) from test", 0);
...@@ -336,28 +339,37 @@ public class TestTriggersConstraints extends TestBase implements Trigger { ...@@ -336,28 +339,37 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
// CREATE TRIGGER trigger {BEFORE|AFTER} // CREATE TRIGGER trigger {BEFORE|AFTER}
// {INSERT|UPDATE|DELETE|ROLLBACK} ON table // {INSERT|UPDATE|DELETE|ROLLBACK} ON table
// [FOR EACH ROW] [QUEUE n] [NOWAIT] CALL triggeredClass // [FOR EACH ROW] [QUEUE n] [NOWAIT] CALL triggeredClass
stat.execute("CREATE TRIGGER IF NOT EXISTS INS_BEFORE BEFORE INSERT ON TEST FOR EACH ROW NOWAIT CALL \"" stat.execute("CREATE TRIGGER IF NOT EXISTS INS_BEFORE " +
+ getClass().getName() + "\""); "BEFORE INSERT ON TEST " +
stat.execute("CREATE TRIGGER IF NOT EXISTS INS_BEFORE BEFORE INSERT ON TEST FOR EACH ROW NOWAIT CALL \"" "FOR EACH ROW NOWAIT CALL \"" + getClass().getName() + "\"");
+ getClass().getName() + "\""); stat.execute("CREATE TRIGGER IF NOT EXISTS INS_BEFORE " +
stat.execute("CREATE TRIGGER INS_AFTER AFTER INSERT ON TEST FOR EACH ROW NOWAIT CALL \"" + getClass().getName() "BEFORE INSERT ON TEST " +
+ "\""); "FOR EACH ROW NOWAIT CALL \"" + getClass().getName() + "\"");
stat.execute("CREATE TRIGGER UPD_BEFORE BEFORE UPDATE ON TEST FOR EACH ROW NOWAIT CALL \"" stat.execute("CREATE TRIGGER INS_AFTER " + "" +
+ getClass().getName() + "\""); "AFTER INSERT ON TEST " +
stat.execute("CREATE TRIGGER INS_AFTER_ROLLBACK AFTER INSERT, ROLLBACK ON TEST FOR EACH ROW NOWAIT CALL \"" + getClass().getName() "FOR EACH ROW NOWAIT CALL \"" + getClass().getName() + "\"");
+ "\""); stat.execute("CREATE TRIGGER UPD_BEFORE " +
"BEFORE UPDATE ON TEST " +
"FOR EACH ROW NOWAIT CALL \"" + getClass().getName() + "\"");
stat.execute("CREATE TRIGGER INS_AFTER_ROLLBACK " +
"AFTER INSERT, ROLLBACK ON TEST " +
"FOR EACH ROW NOWAIT CALL \"" + getClass().getName() + "\"");
stat.execute("INSERT INTO TEST VALUES(1, 'Hello')"); stat.execute("INSERT INTO TEST VALUES(1, 'Hello')");
ResultSet rs; ResultSet rs;
rs = stat.executeQuery("SCRIPT"); rs = stat.executeQuery("SCRIPT");
checkRows(rs, new String[] { checkRows(rs, new String[] {
"CREATE FORCE TRIGGER PUBLIC.INS_BEFORE BEFORE INSERT ON PUBLIC.TEST FOR EACH ROW NOWAIT CALL \"" "CREATE FORCE TRIGGER PUBLIC.INS_BEFORE " +
+ getClass().getName() + "\";", "BEFORE INSERT ON PUBLIC.TEST " +
"CREATE FORCE TRIGGER PUBLIC.INS_AFTER AFTER INSERT ON PUBLIC.TEST FOR EACH ROW NOWAIT CALL \"" "FOR EACH ROW NOWAIT CALL \"" + getClass().getName() + "\";",
+ getClass().getName() + "\";", "CREATE FORCE TRIGGER PUBLIC.INS_AFTER " +
"CREATE FORCE TRIGGER PUBLIC.UPD_BEFORE BEFORE UPDATE ON PUBLIC.TEST FOR EACH ROW NOWAIT CALL \"" "AFTER INSERT ON PUBLIC.TEST " +
+ getClass().getName() + "\";", "FOR EACH ROW NOWAIT CALL \"" + getClass().getName() + "\";",
"CREATE FORCE TRIGGER PUBLIC.INS_AFTER_ROLLBACK AFTER INSERT, ROLLBACK ON PUBLIC.TEST FOR EACH ROW NOWAIT CALL \"" "CREATE FORCE TRIGGER PUBLIC.UPD_BEFORE " +
+ getClass().getName() + "\";", "BEFORE UPDATE ON PUBLIC.TEST " +
"FOR EACH ROW NOWAIT CALL \"" + getClass().getName() + "\";",
"CREATE FORCE TRIGGER PUBLIC.INS_AFTER_ROLLBACK " +
"AFTER INSERT, ROLLBACK ON PUBLIC.TEST " +
"FOR EACH ROW NOWAIT CALL \"" + getClass().getName() + "\";",
}); });
while (rs.next()) { while (rs.next()) {
String sql = rs.getString(1); String sql = rs.getString(1);
...@@ -468,10 +480,13 @@ public class TestTriggersConstraints extends TestBase implements Trigger { ...@@ -468,10 +480,13 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
if (!"TEST".equals(tableName)) { if (!"TEST".equals(tableName)) {
throw new AssertionError("supposed to be TEST"); throw new AssertionError("supposed to be TEST");
} }
if ((trigger.endsWith("AFTER") && before) || (trigger.endsWith("BEFORE") && !before)) { if ((trigger.endsWith("AFTER") && before) ||
(trigger.endsWith("BEFORE") && !before)) {
throw new AssertionError("triggerName: " + trigger + " before:" + before); throw new AssertionError("triggerName: " + trigger + " before:" + before);
} }
if ((trigger.startsWith("UPD") && type != UPDATE) || (trigger.startsWith("INS") && type != INSERT) || (trigger.startsWith("DEL") && type != DELETE)) { if ((trigger.startsWith("UPD") && type != UPDATE) ||
(trigger.startsWith("INS") && type != INSERT) ||
(trigger.startsWith("DEL") && type != DELETE)) {
throw new AssertionError("triggerName: " + trigger + " type:" + type); throw new AssertionError("triggerName: " + trigger + " type:" + type);
} }
} }
......
...@@ -46,7 +46,8 @@ public class TestUpgrade extends TestBase { ...@@ -46,7 +46,8 @@ public class TestUpgrade extends TestBase {
private void testLobs() throws Exception { private void testLobs() throws Exception {
deleteDb("upgrade"); deleteDb("upgrade");
Connection conn; Connection conn;
conn = DriverManager.getConnection("jdbc:h2v1_1:" + getBaseDir() + "/upgrade;PAGE_STORE=FALSE", getUser(), getPassword()); conn = DriverManager.getConnection("jdbc:h2v1_1:" +
getBaseDir() + "/upgrade;PAGE_STORE=FALSE", getUser(), getPassword());
conn.createStatement().execute("create table test(data clob) as select space(100000)"); conn.createStatement().execute("create table test(data clob) as select space(100000)");
conn.close(); conn.close();
assertTrue(IOUtils.exists(getBaseDir() + "/upgrade.data.db")); assertTrue(IOUtils.exists(getBaseDir() + "/upgrade.data.db"));
...@@ -105,9 +106,11 @@ public class TestUpgrade extends TestBase { ...@@ -105,9 +106,11 @@ public class TestUpgrade extends TestBase {
// Create old db // Create old db
Utils.callStaticMethod("org.h2.upgrade.v1_1.Driver.load"); Utils.callStaticMethod("org.h2.upgrade.v1_1.Driver.load");
Connection connOld = DriverManager.getConnection("jdbc:h2v1_1:" + getBaseDir() + "/upgradeOld;PAGE_STORE=FALSE" + additionalParameters); Connection connOld = DriverManager.getConnection("jdbc:h2v1_1:" +
getBaseDir() + "/upgradeOld;PAGE_STORE=FALSE" + additionalParameters);
// Test auto server, too // Test auto server, too
Connection connOld2 = DriverManager.getConnection("jdbc:h2v1_1:" + getBaseDir() + "/upgradeOld;PAGE_STORE=FALSE" + additionalParameters); Connection connOld2 = DriverManager.getConnection("jdbc:h2v1_1:" +
getBaseDir() + "/upgradeOld;PAGE_STORE=FALSE" + additionalParameters);
Statement statOld = connOld.createStatement(); Statement statOld = connOld.createStatement();
statOld.execute("create table testOld(id int)"); statOld.execute("create table testOld(id int)");
connOld.close(); connOld.close();
...@@ -115,24 +118,32 @@ public class TestUpgrade extends TestBase { ...@@ -115,24 +118,32 @@ public class TestUpgrade extends TestBase {
assertTrue(IOUtils.exists(getBaseDir() + "/upgradeOld.data.db")); assertTrue(IOUtils.exists(getBaseDir() + "/upgradeOld.data.db"));
// Create new DB // Create new DB
Connection connNew = DriverManager.getConnection("jdbc:h2:" + getBaseDir() + "/upgrade" + additionalParameters); Connection connNew = DriverManager.getConnection("jdbc:h2:" +
Connection connNew2 = DriverManager.getConnection("jdbc:h2:" + getBaseDir() + "/upgrade" + additionalParameters); getBaseDir() + "/upgrade" + additionalParameters);
Connection connNew2 = DriverManager.getConnection("jdbc:h2:" +
getBaseDir() + "/upgrade" + additionalParameters);
Statement statNew = connNew.createStatement(); Statement statNew = connNew.createStatement();
statNew.execute("create table test(id int)"); statNew.execute("create table test(id int)");
// Link to old DB without upgrade // Link to old DB without upgrade
statNew.executeUpdate("CREATE LOCAL TEMPORARY LINKED TABLE linkedTestOld('org.h2.Driver', 'jdbc:h2v1_1:" + getBaseDir() + "/upgradeOld" + additionalParameters + "', '', '', 'TestOld')"); statNew.executeUpdate("CREATE LOCAL TEMPORARY LINKED TABLE " +
"linkedTestOld('org.h2.Driver', 'jdbc:h2v1_1:" +
getBaseDir() + "/upgradeOld" + additionalParameters + "', '', '', 'TestOld')");
statNew.executeQuery("select * from linkedTestOld"); statNew.executeQuery("select * from linkedTestOld");
connNew.close(); connNew.close();
connNew2.close(); connNew2.close();
assertTrue(IOUtils.exists(getBaseDir() + "/upgradeOld.data.db")); assertTrue(IOUtils.exists(getBaseDir() + "/upgradeOld.data.db"));
assertTrue(IOUtils.exists(getBaseDir() + "/upgrade.h2.db")); assertTrue(IOUtils.exists(getBaseDir() + "/upgrade.h2.db"));
connNew = DriverManager.getConnection("jdbc:h2:" + getBaseDir() + "/upgrade" + additionalParameters); connNew = DriverManager.getConnection("jdbc:h2:" +
connNew2 = DriverManager.getConnection("jdbc:h2:" + getBaseDir() + "/upgrade" + additionalParameters); getBaseDir() + "/upgrade" + additionalParameters);
connNew2 = DriverManager.getConnection("jdbc:h2:" +
getBaseDir() + "/upgrade" + additionalParameters);
statNew = connNew.createStatement(); statNew = connNew.createStatement();
// Link to old DB with upgrade // Link to old DB with upgrade
statNew.executeUpdate("CREATE LOCAL TEMPORARY LINKED TABLE linkedTestOld('org.h2.Driver', 'jdbc:h2:" + getBaseDir() + "/upgradeOld" + additionalParameters + "', '', '', 'TestOld')"); statNew.executeUpdate("CREATE LOCAL TEMPORARY LINKED TABLE " +
"linkedTestOld('org.h2.Driver', 'jdbc:h2:" +
getBaseDir() + "/upgradeOld" + additionalParameters + "', '', '', 'TestOld')");
statNew.executeQuery("select * from linkedTestOld"); statNew.executeQuery("select * from linkedTestOld");
connNew.close(); connNew.close();
connNew2.close(); connNew2.close();
...@@ -172,14 +183,16 @@ public class TestUpgrade extends TestBase { ...@@ -172,14 +183,16 @@ public class TestUpgrade extends TestBase {
// Create old db // Create old db
Utils.callStaticMethod("org.h2.upgrade.v1_1.Driver.load"); Utils.callStaticMethod("org.h2.upgrade.v1_1.Driver.load");
Connection conn = DriverManager.getConnection("jdbc:h2v1_1:" + getBaseDir() + "/upgrade;PAGE_STORE=FALSE;CIPHER=AES", "abc", "abc abc"); Connection conn = DriverManager.getConnection("jdbc:h2v1_1:" +
getBaseDir() + "/upgrade;PAGE_STORE=FALSE;CIPHER=AES", "abc", "abc abc");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("create table test(id int)"); stat.execute("create table test(id int)");
conn.close(); conn.close();
assertTrue(IOUtils.exists(getBaseDir() + "/upgrade.data.db")); assertTrue(IOUtils.exists(getBaseDir() + "/upgrade.data.db"));
// Connect to old DB with upgrade // Connect to old DB with upgrade
conn = DriverManager.getConnection("jdbc:h2:" + getBaseDir() + "/upgrade;CIPHER=AES", "abc", "abc abc"); conn = DriverManager.getConnection("jdbc:h2:" +
getBaseDir() + "/upgrade;CIPHER=AES", "abc", "abc abc");
stat = conn.createStatement(); stat = conn.createStatement();
stat.executeQuery("select * from test"); stat.executeQuery("select * from test");
conn.close(); conn.close();
...@@ -191,7 +204,8 @@ public class TestUpgrade extends TestBase { ...@@ -191,7 +204,8 @@ public class TestUpgrade extends TestBase {
public void deleteDb(String dbName) { public void deleteDb(String dbName) {
super.deleteDb(dbName); super.deleteDb(dbName);
try { try {
Utils.callStaticMethod("org.h2.upgrade.v1_1.tools.DeleteDbFiles.execute", getBaseDir(), dbName, true); Utils.callStaticMethod("org.h2.upgrade.v1_1.tools.DeleteDbFiles.execute",
getBaseDir(), dbName, true);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(e.getMessage());
} }
......
...@@ -81,13 +81,18 @@ public class TestCallableStatement extends TestBase { ...@@ -81,13 +81,18 @@ public class TestCallableStatement extends TestBase {
call.setInt(1, 1); call.setInt(1, 1);
call.setString(2, "Hello"); call.setString(2, "Hello");
call.execute(); call.execute();
call = conn.prepareCall("SELECT * FROM TEST", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); call = conn.prepareCall("SELECT * FROM TEST",
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
rs = call.executeQuery(); rs = call.executeQuery();
rs.next(); rs.next();
assertEquals(1, rs.getInt(1)); assertEquals(1, rs.getInt(1));
assertEquals("Hello", rs.getString(2)); assertEquals("Hello", rs.getString(2));
assertFalse(rs.next()); assertFalse(rs.next());
call = conn.prepareCall("SELECT * FROM TEST", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); call = conn.prepareCall("SELECT * FROM TEST",
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY,
ResultSet.HOLD_CURSORS_OVER_COMMIT);
rs = call.executeQuery(); rs = call.executeQuery();
rs.next(); rs.next();
assertEquals(1, rs.getInt(1)); assertEquals(1, rs.getInt(1));
......
...@@ -345,7 +345,8 @@ public class TestMetaData extends TestBase { ...@@ -345,7 +345,8 @@ public class TestMetaData extends TestBase {
ResultSet rs; ResultSet rs;
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("CREATE TABLE PARENT(A INT, B INT, PRIMARY KEY(A, B))"); stat.execute("CREATE TABLE PARENT(A INT, B INT, PRIMARY KEY(A, B))");
stat.execute("CREATE TABLE CHILD(ID INT PRIMARY KEY, PA INT, PB INT, CONSTRAINT AB FOREIGN KEY(PA, PB) REFERENCES PARENT(A, B))"); stat.execute("CREATE TABLE CHILD(ID INT PRIMARY KEY, PA INT, PB INT, " +
"CONSTRAINT AB FOREIGN KEY(PA, PB) REFERENCES PARENT(A, B))");
rs = meta.getCrossReference(null, "PUBLIC", "PARENT", null, "PUBLIC", "CHILD"); rs = meta.getCrossReference(null, "PUBLIC", "PARENT", null, "PUBLIC", "CHILD");
checkCrossRef(rs); checkCrossRef(rs);
rs = meta.getImportedKeys(null, "PUBLIC", "CHILD"); rs = meta.getImportedKeys(null, "PUBLIC", "CHILD");
......
...@@ -565,7 +565,8 @@ public class TestPreparedStatement extends TestBase { ...@@ -565,7 +565,8 @@ public class TestPreparedStatement extends TestBase {
stat.execute("DROP TABLE TEST3"); stat.execute("DROP TABLE TEST3");
} }
private void checkParameter(PreparedStatement prep, int index, String className, int type, String typeName, int precision, int scale) throws SQLException { private void checkParameter(PreparedStatement prep, int index,
String className, int type, String typeName, int precision, int scale) throws SQLException {
ParameterMetaData meta = prep.getParameterMetaData(); ParameterMetaData meta = prep.getParameterMetaData();
assertEquals(className, meta.getParameterClassName(index)); assertEquals(className, meta.getParameterClassName(index));
assertEquals(type, meta.getParameterType(index)); assertEquals(type, meta.getParameterType(index));
...@@ -616,7 +617,8 @@ public class TestPreparedStatement extends TestBase { ...@@ -616,7 +617,8 @@ public class TestPreparedStatement extends TestBase {
stat.execute("INSERT INTO TEST VALUES(1),(2),(3)"); stat.execute("INSERT INTO TEST VALUES(1),(2),(3)");
PreparedStatement prep; PreparedStatement prep;
ResultSet rs; ResultSet rs;
prep = conn.prepareStatement("EXPLAIN SELECT COUNT(*) FROM TEST WHERE CASEWHEN(ID=1, ID, ID)=? GROUP BY ID"); prep = conn.prepareStatement("EXPLAIN SELECT COUNT(*) FROM TEST " +
"WHERE CASEWHEN(ID=1, ID, ID)=? GROUP BY ID");
prep.setInt(1, 1); prep.setInt(1, 1);
rs = prep.executeQuery(); rs = prep.executeQuery();
rs.next(); rs.next();
...@@ -624,7 +626,8 @@ public class TestPreparedStatement extends TestBase { ...@@ -624,7 +626,8 @@ public class TestPreparedStatement extends TestBase {
trace(plan); trace(plan);
rs.close(); rs.close();
prep = conn prep = conn
.prepareStatement("EXPLAIN SELECT COUNT(*) FROM TEST WHERE CASE ID WHEN 1 THEN ID WHEN 2 THEN ID ELSE ID END=? GROUP BY ID"); .prepareStatement("EXPLAIN SELECT COUNT(*) FROM TEST " +
"WHERE CASE ID WHEN 1 THEN ID WHEN 2 THEN ID ELSE ID END=? GROUP BY ID");
prep.setInt(1, 1); prep.setInt(1, 1);
rs = prep.executeQuery(); rs = prep.executeQuery();
rs.next(); rs.next();
......
...@@ -215,7 +215,9 @@ public class TestResultSet extends TestBase { ...@@ -215,7 +215,9 @@ public class TestResultSet extends TestBase {
private void testOwnUpdates() throws SQLException { private void testOwnUpdates() throws SQLException {
DatabaseMetaData meta = conn.getMetaData(); DatabaseMetaData meta = conn.getMetaData();
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
int type = i == 0 ? ResultSet.TYPE_FORWARD_ONLY : i == 1 ? ResultSet.TYPE_SCROLL_INSENSITIVE : ResultSet.TYPE_SCROLL_SENSITIVE; int type = i == 0 ? ResultSet.TYPE_FORWARD_ONLY :
i == 1 ? ResultSet.TYPE_SCROLL_INSENSITIVE :
ResultSet.TYPE_SCROLL_SENSITIVE;
assertTrue(meta.ownUpdatesAreVisible(type)); assertTrue(meta.ownUpdatesAreVisible(type));
assertFalse(meta.ownDeletesAreVisible(type)); assertFalse(meta.ownDeletesAreVisible(type));
assertFalse(meta.ownInsertsAreVisible(type)); assertFalse(meta.ownInsertsAreVisible(type));
......
...@@ -173,7 +173,10 @@ public class TestStatement extends TestBase { ...@@ -173,7 +173,10 @@ public class TestStatement extends TestBase {
stat.setFetchSize(0); stat.setFetchSize(0);
assertEquals(SysProperties.SERVER_RESULT_SET_FETCH_SIZE, stat.getFetchSize()); assertEquals(SysProperties.SERVER_RESULT_SET_FETCH_SIZE, stat.getFetchSize());
assertEquals(ResultSet.TYPE_FORWARD_ONLY, stat.getResultSetType()); assertEquals(ResultSet.TYPE_FORWARD_ONLY, stat.getResultSetType());
Statement stat2 = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); Statement stat2 = conn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY,
ResultSet.HOLD_CURSORS_OVER_COMMIT);
assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, stat2.getResultSetType()); assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, stat2.getResultSetType());
assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, stat2.getResultSetHoldability()); assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, stat2.getResultSetHoldability());
assertEquals(ResultSet.CONCUR_READ_ONLY, stat2.getResultSetConcurrency()); assertEquals(ResultSet.CONCUR_READ_ONLY, stat2.getResultSetConcurrency());
......
...@@ -541,7 +541,8 @@ public class TestUpdatableResultSet extends TestBase { ...@@ -541,7 +541,8 @@ public class TestUpdatableResultSet extends TestBase {
} }
} }
private void assertState(ResultSet rs, boolean beforeFirst, boolean first, boolean last, boolean afterLast) throws SQLException { private void assertState(ResultSet rs, boolean beforeFirst,
boolean first, boolean last, boolean afterLast) throws SQLException {
assertEquals(beforeFirst, rs.isBeforeFirst()); assertEquals(beforeFirst, rs.isBeforeFirst());
assertEquals(first, rs.isFirst()); assertEquals(first, rs.isFirst());
assertEquals(last, rs.isLast()); assertEquals(last, rs.isLast());
......
...@@ -107,8 +107,10 @@ public class TestMvcc1 extends TestBase { ...@@ -107,8 +107,10 @@ public class TestMvcc1 extends TestBase {
c2.commit(); c2.commit();
// referential integrity problem // referential integrity problem
s1.execute("create table a (id integer identity not null, code varchar(10) not null, primary key(id))"); s1.execute("create table a (id integer identity not null, " +
s1.execute("create table b (name varchar(100) not null, a integer, primary key(name), foreign key(a) references a(id))"); "code varchar(10) not null, primary key(id))");
s1.execute("create table b (name varchar(100) not null, a integer, " +
"primary key(name), foreign key(a) references a(id))");
s1.execute("insert into a(code) values('one')"); s1.execute("insert into a(code) values('one')");
try { try {
s2.execute("insert into b values('un B', 1)"); s2.execute("insert into b values('un B', 1)");
......
...@@ -78,7 +78,8 @@ public class TestRecover { ...@@ -78,7 +78,8 @@ public class TestRecover {
testLoop(); testLoop();
} }
private static File backup(String sourcePath, String targetPath, String basePath, int max, String node) throws IOException { private static File backup(String sourcePath, String targetPath,
String basePath, int max, String node) throws IOException {
File root = new File(targetPath); File root = new File(targetPath);
if (!root.exists()) { if (!root.exists()) {
root.mkdirs(); root.mkdirs();
......
...@@ -106,19 +106,25 @@ public class TestWeb extends TestBase { ...@@ -106,19 +106,25 @@ public class TestWeb extends TestBase {
client.readSessionId(result); client.readSessionId(result);
result = client.get(url, "tools.jsp"); result = client.get(url, "tools.jsp");
IOUtils.delete(getBaseDir() + "/backup.zip"); IOUtils.delete(getBaseDir() + "/backup.zip");
result = client.get(url, "tools.do?tool=Backup&args=-dir," + getBaseDir() + ",-db,web,-file," + getBaseDir() + "/backup.zip"); result = client.get(url, "tools.do?tool=Backup&args=-dir," +
getBaseDir() + ",-db,web,-file," + getBaseDir() + "/backup.zip");
deleteDb("web"); deleteDb("web");
assertTrue(IOUtils.exists(getBaseDir() + "/backup.zip")); assertTrue(IOUtils.exists(getBaseDir() + "/backup.zip"));
result = client.get(url, "tools.do?tool=DeleteDbFiles&args=-dir," + getBaseDir() + ",-db,web"); result = client.get(url, "tools.do?tool=DeleteDbFiles&args=-dir," +
getBaseDir() + ",-db,web");
assertFalse(IOUtils.exists(getBaseDir() + "/web.h2.db")); assertFalse(IOUtils.exists(getBaseDir() + "/web.h2.db"));
result = client.get(url, "tools.do?tool=Restore&args=-dir," + getBaseDir() + ",-db,web,-file," + getBaseDir() + "/backup.zip"); result = client.get(url, "tools.do?tool=Restore&args=-dir," +
getBaseDir() + ",-db,web,-file," + getBaseDir() + "/backup.zip");
assertTrue(IOUtils.exists(getBaseDir() + "/web.h2.db")); assertTrue(IOUtils.exists(getBaseDir() + "/web.h2.db"));
IOUtils.delete(getBaseDir() + "/web.h2.sql"); IOUtils.delete(getBaseDir() + "/web.h2.sql");
IOUtils.delete(getBaseDir() + "/backup.zip"); IOUtils.delete(getBaseDir() + "/backup.zip");
result = client.get(url, "tools.do?tool=Recover&args=-dir," + getBaseDir() + ",-db,web"); result = client.get(url, "tools.do?tool=Recover&args=-dir," +
getBaseDir() + ",-db,web");
assertTrue(IOUtils.exists(getBaseDir() + "/web.h2.sql")); assertTrue(IOUtils.exists(getBaseDir() + "/web.h2.sql"));
IOUtils.delete(getBaseDir() + "/web.h2.sql"); IOUtils.delete(getBaseDir() + "/web.h2.sql");
result = client.get(url, "tools.do?tool=RunScript&args=-script," + getBaseDir() + "/web.h2.sql,-url," + getURL("web", true) + ",-user," + getUser() + ",-password," + getPassword()); result = client.get(url, "tools.do?tool=RunScript&args=-script," +
getBaseDir() + "/web.h2.sql,-url," + getURL("web", true) +
",-user," + getUser() + ",-password," + getPassword());
IOUtils.delete(getBaseDir() + "/web.h2.sql"); IOUtils.delete(getBaseDir() + "/web.h2.sql");
assertTrue(IOUtils.exists(getBaseDir() + "/web.h2.db")); assertTrue(IOUtils.exists(getBaseDir() + "/web.h2.db"));
deleteDb("web"); deleteDb("web");
...@@ -218,7 +224,8 @@ public class TestWeb extends TestBase { ...@@ -218,7 +224,8 @@ public class TestWeb extends TestBase {
assertTrue(result.indexOf("Exception") < 0); assertTrue(result.indexOf("Exception") < 0);
result = client.get(url, "login.do?driver=org.h2.Driver&url=jdbc:h2:mem:web&user=sa&password=sa&name=_test_"); result = client.get(url, "login.do?driver=org.h2.Driver&url=jdbc:h2:mem:web&user=sa&password=sa&name=_test_");
result = client.get(url, "header.jsp"); result = client.get(url, "header.jsp");
result = client.get(url, "query.do?sql=create table test(id int primary key, name varchar);insert into test values(1, 'Hello')"); result = client.get(url, "query.do?sql=create table test(id int primary key, name varchar);" +
"insert into test values(1, 'Hello')");
result = client.get(url, "query.do?sql=create sequence test_sequence"); result = client.get(url, "query.do?sql=create sequence test_sequence");
result = client.get(url, "query.do?sql=create schema test_schema"); result = client.get(url, "query.do?sql=create schema test_schema");
result = client.get(url, "query.do?sql=create view test_view as select * from test"); result = client.get(url, "query.do?sql=create view test_view as select * from test");
......
...@@ -96,7 +96,8 @@ public class TestFuzzOptimizations extends TestBase { ...@@ -96,7 +96,8 @@ public class TestFuzzOptimizations extends TestBase {
Random seedGenerator = new Random(); Random seedGenerator = new Random();
String[] columns = new String[] { "a", "b", "c" }; String[] columns = new String[] { "a", "b", "c" };
String[] values = new String[] { null, "0", "0", "1", "2", "10", "a", "?" }; String[] values = new String[] { null, "0", "0", "1", "2", "10", "a", "?" };
String[] compares = new String[] { "in(", "not in(", "=", "=", ">", "<", ">=", "<=", "<>", "in(select", "not in(select" }; String[] compares = new String[] { "in(", "not in(", "=", "=", ">",
"<", ">=", "<=", "<>", "in(select", "not in(select" };
int size = getSize(100, 1000); int size = getSize(100, 1000);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
long seed = seedGenerator.nextLong(); long seed = seedGenerator.nextLong();
......
...@@ -87,7 +87,9 @@ public class TestKill extends TestBase { ...@@ -87,7 +87,9 @@ public class TestKill extends TestBase {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE TABLE IF NOT EXISTS ACCOUNT(ID INT PRIMARY KEY, SUM INT)"); stat.execute("CREATE TABLE IF NOT EXISTS ACCOUNT(ID INT PRIMARY KEY, SUM INT)");
stat stat
.execute("CREATE TABLE IF NOT EXISTS LOG(ID IDENTITY, ACCOUNTID INT, AMOUNT INT, FOREIGN KEY(ACCOUNTID) REFERENCES ACCOUNT(ID))"); .execute("CREATE TABLE IF NOT EXISTS LOG(" +
"ID IDENTITY, ACCOUNTID INT, AMOUNT INT, " +
"FOREIGN KEY(ACCOUNTID) REFERENCES ACCOUNT(ID))");
stat.execute("CREATE TABLE IF NOT EXISTS TEST_A(ID INT PRIMARY KEY, DATA VARCHAR)"); stat.execute("CREATE TABLE IF NOT EXISTS TEST_A(ID INT PRIMARY KEY, DATA VARCHAR)");
stat.execute("CREATE TABLE IF NOT EXISTS TEST_B(ID INT PRIMARY KEY, DATA VARCHAR)"); stat.execute("CREATE TABLE IF NOT EXISTS TEST_B(ID INT PRIMARY KEY, DATA VARCHAR)");
} }
......
...@@ -310,11 +310,13 @@ public class TestNestedJoins extends TestBase { ...@@ -310,11 +310,13 @@ public class TestNestedJoins extends TestBase {
stat.execute("create table test(id int primary key, x int) as select x, x from system_range(1, 10)"); stat.execute("create table test(id int primary key, x int) as select x, x from system_range(1, 10)");
stat.execute("create index on test(x)"); stat.execute("create index on test(x)");
stat.execute("create table o(id int primary key) as select x from system_range(1, 10)"); stat.execute("create table o(id int primary key) as select x from system_range(1, 10)");
rs = stat.executeQuery("explain select * from test a inner join test b on a.id=b.id inner join o on o.id=a.id where b.x=1"); rs = stat.executeQuery("explain select * from test a inner join " +
"test b on a.id=b.id inner join o on o.id=a.id where b.x=1");
assertTrue(rs.next()); assertTrue(rs.next());
sql = rs.getString(1); sql = rs.getString(1);
assertTrue("using table scan", sql.indexOf("tableScan") < 0); assertTrue("using table scan", sql.indexOf("tableScan") < 0);
rs = stat.executeQuery("explain select * from test a inner join test b on a.id=b.id left outer join o on o.id=a.id where b.x=1"); rs = stat.executeQuery("explain select * from test a inner join " +
"test b on a.id=b.id left outer join o on o.id=a.id where b.x=1");
assertTrue(rs.next()); assertTrue(rs.next());
sql = rs.getString(1); sql = rs.getString(1);
// TODO Support optimizing queries with both inner and outer joins // TODO Support optimizing queries with both inner and outer joins
...@@ -331,7 +333,8 @@ public class TestNestedJoins extends TestBase { ...@@ -331,7 +333,8 @@ public class TestNestedJoins extends TestBase {
*/ */
stat.execute("create table test(id int primary key)"); stat.execute("create table test(id int primary key)");
stat.execute("insert into test values(1)"); stat.execute("insert into test values(1)");
rs = stat.executeQuery("select b.id from test a left outer join test b on a.id = b.id and not exists (select * from test c where c.id = b.id)"); rs = stat.executeQuery("select b.id from test a left outer join " +
"test b on a.id = b.id and not exists (select * from test c where c.id = b.id)");
assertTrue(rs.next()); assertTrue(rs.next());
sql = rs.getString(1); sql = rs.getString(1);
assertEquals(null, sql); assertEquals(null, sql);
...@@ -370,11 +373,15 @@ public class TestNestedJoins extends TestBase { ...@@ -370,11 +373,15 @@ public class TestNestedJoins extends TestBase {
stat.execute("insert into t2 values(1,1), (2,2)"); stat.execute("insert into t2 values(1,1), (2,2)");
stat.execute("insert into t3 values(1,1), (3,3)"); stat.execute("insert into t3 values(1,1), (3,3)");
stat.execute("insert into t4 values(1,1), (2,2), (3,3), (4,4)"); stat.execute("insert into t4 values(1,1), (2,2), (3,3), (4,4)");
rs = stat.executeQuery("explain select distinct t1.a, t2.a, t3.a from t1 right outer join t3 on t1.b=t3.a right outer join t2 on t2.b=t1.a"); rs = stat.executeQuery("explain select distinct t1.a, t2.a, t3.a from t1 " +
"right outer join t3 on t1.b=t3.a right outer join t2 on t2.b=t1.a");
assertTrue(rs.next()); assertTrue(rs.next());
sql = cleanRemarks(rs.getString(1)); sql = cleanRemarks(rs.getString(1));
assertEquals("SELECT DISTINCT T1.A, T2.A, T3.A FROM PUBLIC.T2 LEFT OUTER JOIN ( PUBLIC.T3 LEFT OUTER JOIN ( PUBLIC.T1 ) ON T1.B = T3.A ) ON T2.B = T1.A", sql); assertEquals("SELECT DISTINCT T1.A, T2.A, T3.A FROM PUBLIC.T2 " +
rs = stat.executeQuery("select distinct t1.a, t2.a, t3.a from t1 right outer join t3 on t1.b=t3.a right outer join t2 on t2.b=t1.a"); "LEFT OUTER JOIN ( PUBLIC.T3 LEFT OUTER JOIN ( PUBLIC.T1 ) " +
"ON T1.B = T3.A ) ON T2.B = T1.A", sql);
rs = stat.executeQuery("select distinct t1.a, t2.a, t3.a from t1 " +
"right outer join t3 on t1.b=t3.a right outer join t2 on t2.b=t1.a");
// expected: 1 1 1; null 2 null // expected: 1 1 1; null 2 null
assertTrue(rs.next()); assertTrue(rs.next());
assertEquals("1", rs.getString(1)); assertEquals("1", rs.getString(1));
...@@ -404,11 +411,14 @@ public class TestNestedJoins extends TestBase { ...@@ -404,11 +411,14 @@ public class TestNestedJoins extends TestBase {
stat.execute("insert into a values(1)"); stat.execute("insert into a values(1)");
stat.execute("insert into b values(1)"); stat.execute("insert into b values(1)");
stat.execute("insert into c values(1), (2)"); stat.execute("insert into c values(1), (2)");
rs = stat.executeQuery("explain select a.x, b.x, c.x from a inner join b on a.x = b.x right outer join c on c.x = a.x"); rs = stat.executeQuery("explain select a.x, b.x, c.x from a " +
"inner join b on a.x = b.x right outer join c on c.x = a.x");
assertTrue(rs.next()); assertTrue(rs.next());
sql = cleanRemarks(rs.getString(1)); sql = cleanRemarks(rs.getString(1));
assertEquals("SELECT A.X, B.X, C.X FROM PUBLIC.C LEFT OUTER JOIN ( PUBLIC.A INNER JOIN PUBLIC.B ON A.X = B.X ) ON C.X = A.X", sql); assertEquals("SELECT A.X, B.X, C.X FROM PUBLIC.C LEFT OUTER JOIN " +
rs = stat.executeQuery("select a.x, b.x, c.x from a inner join b on a.x = b.x right outer join c on c.x = a.x"); "( PUBLIC.A INNER JOIN PUBLIC.B ON A.X = B.X ) ON C.X = A.X", sql);
rs = stat.executeQuery("select a.x, b.x, c.x from a inner join b on a.x = b.x " +
"right outer join c on c.x = a.x");
// expected result: 1 1 1; null null 2 // expected result: 1 1 1; null null 2
assertTrue(rs.next()); assertTrue(rs.next());
assertEquals("1", rs.getString(1)); assertEquals("1", rs.getString(1));
......
...@@ -326,11 +326,15 @@ public class TestOuterJoins extends TestBase { ...@@ -326,11 +326,15 @@ public class TestOuterJoins extends TestBase {
stat.execute("insert into t2 values(1,1), (2,2)"); stat.execute("insert into t2 values(1,1), (2,2)");
stat.execute("insert into t3 values(1,1), (3,3)"); stat.execute("insert into t3 values(1,1), (3,3)");
stat.execute("insert into t4 values(1,1), (2,2), (3,3), (4,4)"); stat.execute("insert into t4 values(1,1), (2,2), (3,3), (4,4)");
rs = stat.executeQuery("explain select distinct t1.a, t2.a, t3.a from t1 right outer join t3 on t1.b=t3.a right outer join t2 on t2.b=t1.a"); rs = stat.executeQuery("explain select distinct t1.a, t2.a, t3.a from t1 " +
"right outer join t3 on t1.b=t3.a right outer join t2 on t2.b=t1.a");
assertTrue(rs.next()); assertTrue(rs.next());
sql = cleanRemarks(rs.getString(1)); sql = cleanRemarks(rs.getString(1));
assertEquals("SELECT DISTINCT T1.A, T2.A, T3.A FROM PUBLIC.T2 LEFT OUTER JOIN ( PUBLIC.T3 LEFT OUTER JOIN ( PUBLIC.T1 ) ON T1.B = T3.A ) ON T2.B = T1.A", sql); assertEquals("SELECT DISTINCT T1.A, T2.A, T3.A FROM PUBLIC.T2 " +
rs = stat.executeQuery("select distinct t1.a, t2.a, t3.a from t1 right outer join t3 on t1.b=t3.a right outer join t2 on t2.b=t1.a"); "LEFT OUTER JOIN ( PUBLIC.T3 LEFT OUTER JOIN ( PUBLIC.T1 ) ON T1.B = T3.A ) " +
"ON T2.B = T1.A", sql);
rs = stat.executeQuery("select distinct t1.a, t2.a, t3.a from t1 " +
"right outer join t3 on t1.b=t3.a right outer join t2 on t2.b=t1.a");
// expected: 1 1 1; null 2 null // expected: 1 1 1; null 2 null
assertTrue(rs.next()); assertTrue(rs.next());
assertEquals("1", rs.getString(1)); assertEquals("1", rs.getString(1));
...@@ -360,11 +364,14 @@ public class TestOuterJoins extends TestBase { ...@@ -360,11 +364,14 @@ public class TestOuterJoins extends TestBase {
stat.execute("insert into a values(1)"); stat.execute("insert into a values(1)");
stat.execute("insert into b values(1)"); stat.execute("insert into b values(1)");
stat.execute("insert into c values(1), (2)"); stat.execute("insert into c values(1), (2)");
rs = stat.executeQuery("explain select a.x, b.x, c.x from a inner join b on a.x = b.x right outer join c on c.x = a.x"); rs = stat.executeQuery("explain select a.x, b.x, c.x from a " +
"inner join b on a.x = b.x right outer join c on c.x = a.x");
assertTrue(rs.next()); assertTrue(rs.next());
sql = cleanRemarks(rs.getString(1)); sql = cleanRemarks(rs.getString(1));
assertEquals("SELECT A.X, B.X, C.X FROM PUBLIC.C LEFT OUTER JOIN ( PUBLIC.A INNER JOIN PUBLIC.B ON A.X = B.X ) ON C.X = A.X", sql); assertEquals("SELECT A.X, B.X, C.X FROM PUBLIC.C LEFT OUTER JOIN " +
rs = stat.executeQuery("select a.x, b.x, c.x from a inner join b on a.x = b.x right outer join c on c.x = a.x"); "( PUBLIC.A INNER JOIN PUBLIC.B ON A.X = B.X ) ON C.X = A.X", sql);
rs = stat.executeQuery("select a.x, b.x, c.x from a inner join b on a.x = b.x " +
"right outer join c on c.x = a.x");
// expected result: 1 1 1; null null 2 // expected result: 1 1 1; null null 2
assertTrue(rs.next()); assertTrue(rs.next());
assertEquals("1", rs.getString(1)); assertEquals("1", rs.getString(1));
......
...@@ -38,7 +38,8 @@ public class TestRandomSQL extends TestBase { ...@@ -38,7 +38,8 @@ public class TestRandomSQL extends TestBase {
private void processException(String sql, SQLException e) { private void processException(String sql, SQLException e) {
if (e.getSQLState().equals("HY000")) { if (e.getSQLState().equals("HY000")) {
TestBase.logError("new TestRandomSQL().init(test).testCase(" + seed + "); // FAIL: " + e.toString() + " sql: " + sql, e); TestBase.logError("new TestRandomSQL().init(test).testCase(" + seed + "); " +
"// FAIL: " + e.toString() + " sql: " + sql, e);
if (exitOnError) { if (exitOnError) {
System.exit(0); System.exit(0);
} }
......
...@@ -15,8 +15,10 @@ import org.h2.util.StatementBuilder; ...@@ -15,8 +15,10 @@ import org.h2.util.StatementBuilder;
* Represents a statement. * Represents a statement.
*/ */
class Command { class Command {
private static final int CONNECT = 0, RESET = 1, DISCONNECT = 2, CREATE_TABLE = 3, INSERT = 4, DROP_TABLE = 5, SELECT = 6, private static final int CONNECT = 0, RESET = 1, DISCONNECT = 2,
DELETE = 7, UPDATE = 8, COMMIT = 9, ROLLBACK = 10, AUTOCOMMIT_ON = 11, AUTOCOMMIT_OFF = 12, CREATE_TABLE = 3, INSERT = 4, DROP_TABLE = 5, SELECT = 6,
DELETE = 7, UPDATE = 8, COMMIT = 9, ROLLBACK = 10,
AUTOCOMMIT_ON = 11, AUTOCOMMIT_OFF = 12,
CREATE_INDEX = 13, DROP_INDEX = 14, END = 15; CREATE_INDEX = 13, DROP_INDEX = 14, END = 15;
/** /**
......
...@@ -122,9 +122,13 @@ public class TestMultiOrder extends TestMultiThread { ...@@ -122,9 +122,13 @@ public class TestMultiOrder extends TestMultiThread {
c.createStatement().execute("drop table customer if exists"); c.createStatement().execute("drop table customer if exists");
c.createStatement().execute("drop table orders if exists"); c.createStatement().execute("drop table orders if exists");
c.createStatement().execute("drop table orderLine if exists"); c.createStatement().execute("drop table orderLine if exists");
c.createStatement().execute("create table customer(id int primary key, name varchar, account decimal)"); c.createStatement().execute("create table customer(" +
c.createStatement().execute("create table orders(id int identity primary key, customer_id int, total decimal)"); "id int primary key, name varchar, account decimal)");
c.createStatement().execute("create table orderLine(order_id int, line_id int, text varchar, amount decimal, primary key(order_id, line_id))"); c.createStatement().execute("create table orders(" +
"id int identity primary key, customer_id int, total decimal)");
c.createStatement().execute("create table orderLine(" +
"order_id int, line_id int, text varchar, " +
"amount decimal, primary key(order_id, line_id))");
c.close(); c.close();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论