Unverified 提交 1cd6ee15 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1772 from katzyn/tests

Fix newlines in test scripts
......@@ -5,12 +5,14 @@
*/
package org.h2.test.scripts;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.PrintStream;
import java.io.RandomAccessFile;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
......@@ -47,6 +49,8 @@ public class TestScript extends TestDb {
private static final String BASE_DIR = "org/h2/test/scripts/";
private static final boolean FIX_OUTPUT = false;
private static final Field COMMAND;
private static final Field PREPARED;
......@@ -232,7 +236,16 @@ public class TestScript extends TestDb {
if (statements == null) {
println("Running commands in " + scriptFileName);
}
final String outFile = "test.out.txt";
String outFile;
if (FIX_OUTPUT) {
outFile = scriptFileName;
int idx = outFile.lastIndexOf('/');
if (idx >= 0) {
outFile = outFile.substring(idx + 1);
}
} else {
outFile = "test.out.txt";
}
conn = getConnection("script");
stat = conn.createStatement();
out = new PrintStream(new FileOutputStream(outFile));
......@@ -240,10 +253,31 @@ public class TestScript extends TestDb {
testFile(BASE_DIR + scriptFileName);
conn.close();
out.close();
if (FIX_OUTPUT) {
File file = new File(outFile);
// If there are two trailing newline characters remove one
try (RandomAccessFile r = new RandomAccessFile(file, "rw")) {
byte[] separator = System.lineSeparator().getBytes(StandardCharsets.ISO_8859_1);
int separatorLength = separator.length;
long length = r.length() - (separatorLength * 2);
truncate: if (length >= 0) {
r.seek(length);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < separatorLength; j++) {
if (r.readByte() != separator[j]) {
break truncate;
}
}
}
r.setLength(length + separatorLength);
}
}
file.renameTo(new File("h2/src/test/org/h2/test/scripts/" + scriptFileName));
return;
}
if (errors.length() > 0) {
throw new Exception("errors in " + scriptFileName + " found");
}
// new File(outFile).delete();
}
private String readLine() throws IOException {
......@@ -253,6 +287,7 @@ public class TestScript extends TestDb {
private String readNextLine() throws IOException {
String s;
boolean comment = false;
while ((s = in.readLine()) != null) {
if (s.startsWith("#")) {
int end = s.indexOf('#', 1);
......@@ -276,18 +311,32 @@ public class TestScript extends TestDb {
switch (flag) {
case "mvStore":
if (config.mvStore == val) {
out.print("#" + (val ? '+' : '-') + flag + '#');
break;
} else {
if (FIX_OUTPUT) {
write("#" + (val ? '+' : '-') + flag + '#' + s);
}
continue;
}
default:
fail("Unknown flag \"" + flag + '\"');
}
} else if (s.startsWith("--")) {
write(s);
comment = true;
continue;
}
if (!FIX_OUTPUT) {
s = s.trim();
}
s = s.trim();
if (!s.isEmpty()) {
break;
}
if (comment) {
write("");
comment = false;
}
}
return s;
}
......@@ -322,14 +371,20 @@ public class TestScript extends TestDb {
} else {
switch (sql) {
case "@reconnect":
write(sql);
write("");
if (!config.memory) {
reconnect(conn.getAutoCommit());
}
break;
case "@reconnect on":
write(sql);
write("");
allowReconnect = true;
break;
case "@reconnect off":
write(sql);
write("");
allowReconnect = false;
break;
default:
......
......@@ -24,4 +24,3 @@ INSERT INTO user_group (ID) VALUES (1);
DELETE FROM user_group;
> update count: 1
......@@ -29,7 +29,6 @@ SELECT * FROM TEST ORDER BY ID;
> 3 3000
> rows (ordered): 2
UPDATE TEST SET V = 3 WHERE ID = 3;
> update count: 1
......
......@@ -480,7 +480,6 @@ SELECT G / 10 G1, G / 10 G2, SUM(T.V) S FROM TEST T GROUP BY G / 10, G / 10;
> 2 2 4
> rows: 2
SELECT G / 10 G1, G / 10 G2, SUM(T.V) S FROM TEST T GROUP BY G2;
> G1 G2 S
> -- -- -
......
......@@ -44,7 +44,6 @@ explain with recursive "r"(n) as (
select n from "r";
>> WITH RECURSIVE PUBLIC."r"(N) AS ( (SELECT 1 FROM SYSTEM_RANGE(1, 1) /* PUBLIC.RANGE_INDEX */) UNION ALL (SELECT (N + 1) FROM PUBLIC."r" /* PUBLIC."r".tableScan */ WHERE N < 3) ) SELECT N FROM PUBLIC."r" "r" /* null */
select sum(n) from (
with recursive r(n) as (
(select 1) union all (select n+1 from r where n < 3)
......@@ -80,6 +79,7 @@ select 0 from (
> 0
> -
> rows: 0
with
r0(n,k) as (select -1, 0),
r1(n,k) as ((select 1, 0) union all (select n+1,k+1 from r1 where n <= 3)),
......
......@@ -23,7 +23,6 @@ select count(*), count(*) filter (where v >= 4) from test;
> 13 9
> rows: 1
select count(*), count(*) filter (where v >= 4) from test where v <= 10;
> COUNT(*) COUNT(*) FILTER (WHERE (V >= 4))
> -------- --------------------------------
......
......@@ -14,4 +14,3 @@ select acos(null) vn, acos(-1) r1 from test;
> ---- -----------------
> null 3.141592653589793
> rows: 1
......@@ -14,4 +14,3 @@ select asin(null) vn, asin(-1) r1 from test;
> ---- -------------------
> null -1.5707963267948966
> rows: 1
......@@ -14,4 +14,3 @@ select atan(null) vn, atan(-1) r1 from test;
> ---- -------------------
> null -0.7853981633974483
> rows: 1
......@@ -14,5 +14,3 @@ select atan2(null, null) vn, atan2(10, 1) r1 from test;
> ---- ------------------
> null 1.4711276743037347
> rows: 1
......@@ -14,7 +14,3 @@ select bitand(null, 1) vn, bitand(1, null) vn1, bitand(null, null) vn2, bitand(3
> ---- ---- ---- --
> null null null 2
> rows: 1
......@@ -2,4 +2,3 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
......@@ -14,7 +14,3 @@ select bitor(null, 1) vn, bitor(1, null) vn1, bitor(null, null) vn2, bitor(3, 6)
> ---- ---- ---- --
> null null null 7
> rows: 1
......@@ -14,7 +14,3 @@ select bitxor(null, 1) vn, bitxor(1, null) vn1, bitxor(null, null) vn2, bitxor(3
> ---- ---- ---- --
> null null null 5
> rows: 1
......@@ -14,8 +14,3 @@ select ceil(null) vn, ceil(1) v1, ceiling(1.1) v2, ceil(-1.1) v3, ceiling(1.9) v
> ---- --- --- ---- --- ----
> null 1.0 2.0 -1.0 2.0 -1.0
> rows: 1
......@@ -2,4 +2,3 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
......@@ -14,5 +14,3 @@ select cos(null) vn, cos(-1) r1 from test;
> ---- ------------------
> null 0.5403023058681398
> rows: 1
......@@ -2,4 +2,3 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
......@@ -14,5 +14,3 @@ select cot(null) vn, cot(-1) r1 from test;
> ---- -------------------
> null -0.6420926159343306
> rows: 1
......@@ -14,6 +14,3 @@ select exp(null) vn, left(exp(1), 4) v1, left(exp(1.1), 4) v2, left(exp(-1.1), 4
> ---- ---- ---- ---- ---- ----
> null 2.71 3.00 0.33 6.68 0.14
> rows: 1
......@@ -14,9 +14,3 @@ select floor(null) vn, floor(1) v1, floor(1.1) v2, floor(-1.1) v3, floor(1.9) v4
> ---- --- --- ---- --- ----
> null 1.0 1.0 -2.0 1.0 -2.0
> rows: 1
......@@ -38,8 +38,3 @@ select octet_length(null) en, octet_length('') e0, octet_length('ab') e4 from te
> ---- -- --
> null 0 4
> rows: 1
......@@ -26,9 +26,3 @@ select log(null) vn, log(1) v1, log(1.1) v2, log(-1.1) v3, log(1.9) v4, log(-1.9
> ---- --- ------------------- --- ------------------ ---
> null 0.0 0.09531017980432493 NaN 0.6418538861723947 NaN
> rows: 1
......@@ -14,7 +14,3 @@ select mod(null, 1) vn, mod(1, null) vn1, mod(null, null) vn2, mod(10, 2) e1 fro
> ---- ---- ---- --
> null null null 0
> rows: 1
......@@ -14,7 +14,3 @@ select power(null, null) en, power(2, 3) e8, power(16, 0.5) e4 from test;
> ---- --- ---
> null 8.0 4.0
> rows: 1
......@@ -26,6 +26,3 @@ select roundmagic(null) en, roundmagic(cast(3.11 as double) - 3.1) e001, roundma
> ---- ---- ---- ------
> null 0.01 0.0 2.0E12
> rows: 1
......@@ -14,5 +14,3 @@ select sin(null) vn, sin(-1) r1 from test;
> ---- -------------------
> null -0.8414709848078965
> rows: 1
......@@ -14,6 +14,3 @@ select sqrt(null) vn, sqrt(0) e0, sqrt(1) e1, sqrt(4) e2, sqrt(100) e10, sqrt(0.
> ---- --- --- --- ---- ---
> null 0.0 1.0 2.0 10.0 0.5
> rows: 1
......@@ -14,6 +14,3 @@ select tan(null) vn, tan(-1) r1 from test;
> ---- -------------------
> null -1.5574077246549023
> rows: 1
......@@ -14,7 +14,3 @@ select ascii(null) en, ascii('') en, ascii('Abc') e65 from test;
> ---- ---- ---
> null null 65
> rows: 1
......@@ -14,4 +14,3 @@ select hextoraw(null) en, rawtohex(null) en1, hextoraw(rawtohex('abc')) abc from
> ---- ---- ---
> null null abc
> rows: 1
......@@ -20,4 +20,3 @@ select insert('World', 2, 4, 'e') welt, insert('Hello', 2, 1, 'a') hallo from te
> ---- -----
> We Hallo
> rows: 1
......@@ -28,4 +28,4 @@ select len(null) en, len('MSSQLServer uses the len keyword') e_32 from test;
> rows: 1
SET MODE Regular;
> ok
\ No newline at end of file
> ok
......@@ -9,7 +9,6 @@ create memory table test(id int primary key, name varchar(255));
insert into test values(1, 'Hello');
> update count: 1
select cast(null as varchar(255)) xn, cast(' 10' as int) x10, cast(' 20 ' as int) x20 from test;
> XN X10 X20
> ---- --- ---
......
......@@ -2,4 +2,3 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
......@@ -20,4 +20,3 @@ select isnull(null, '1') x1, isnull(null, null) xn, isnull('a', 'b') xa from tes
> -- ---- --
> 1 null a
> rows: 1
......@@ -15,7 +15,6 @@ select length(curtime())>=8 c1, length(current_time())>=8 c2, substring(curtime(
> TRUE TRUE :
> rows: 1
select length(now())>18 c1, length(current_timestamp())>18 c2, length(now(0))>18 c3, length(now(2))>18 c4 from test;
> C1 C2 C3 C4
> ---- ---- ---- ----
......
......@@ -25,4 +25,4 @@ SELECT CURRENT_DATE = GETDATE();
>> TRUE
SET MODE Regular;
> ok
\ No newline at end of file
> ok
......@@ -372,7 +372,6 @@ SELECT DATE_TRUNC('second', '2015-05-29 00:00:00');
SELECT DATE_TRUNC('SECOND', '2015-05-29 00:00:00');
>> 2015-05-29 00:00:00
--
-- Test time unit 'MINUTE'
--
......@@ -598,7 +597,6 @@ select DATE_TRUNC('day', '2015-05-29 15:14:13');
select DATE_TRUNC('DAY', '2015-05-29 15:14:13');
>> 2015-05-29 00:00:00
--
-- Test time unit 'WEEK'
--
......@@ -818,7 +816,6 @@ SELECT DATE_TRUNC('quarter', '2015-12-29 15:14:13');
SELECT DATE_TRUNC('QUARTER', '2015-12-29 15:14:13');
>> 2015-10-01 00:00:00
--
-- Test time unit 'YEAR'
--
......@@ -1073,4 +1070,3 @@ SELECT DATE_TRUNC('', '');
SELECT DATE_TRUNC('YEAR', '');
> exception INVALID_DATETIME_CONSTANT_2
......@@ -87,7 +87,6 @@ SELECT *,
NTH_VALUE(VALUE, 2) OVER(ORDER BY ID RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) F_U_C,
NTH_VALUE(VALUE, 2) OVER(ORDER BY ID RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) F_C_U,
NTH_VALUE(VALUE, 2) OVER(ORDER BY ID RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) F_U_U,
NTH_VALUE(VALUE, 2) FROM LAST OVER(ORDER BY ID) L,
NTH_VALUE(VALUE, 2) FROM LAST OVER(ORDER BY ID RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) L_U_C,
NTH_VALUE(VALUE, 2) FROM LAST OVER(ORDER BY ID RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) L_C_U,
......
......@@ -22,13 +22,11 @@ SELECT *,
ROW_NUMBER() OVER () RN,
ROUND(PERCENT_RANK() OVER (), 2) PR,
ROUND(CUME_DIST() OVER (), 2) CD,
ROW_NUMBER() OVER (ORDER BY ID) RNO,
RANK() OVER (ORDER BY ID) RKO,
DENSE_RANK() OVER (ORDER BY ID) DRO,
ROUND(PERCENT_RANK() OVER (ORDER BY ID), 2) PRO,
ROUND(CUME_DIST() OVER (ORDER BY ID), 2) CDO
FROM TEST;
> ID CATEGORY VALUE RN PR CD RNO RKO DRO PRO CDO
> -- -------- ----- -- --- --- --- --- --- ---- ----
......
......@@ -744,33 +744,46 @@ DROP TABLE C;
CREATE TABLE T1(X1 INT);
> ok
CREATE TABLE T2(X2 INT);
> ok
CREATE TABLE T3(X3 INT);
> ok
CREATE TABLE T4(X4 INT);
> ok
CREATE TABLE T5(X5 INT);
> ok
INSERT INTO T1 VALUES (1);
> update count: 1
INSERT INTO T1 VALUES (NULL);
> update count: 1
INSERT INTO T2 VALUES (1);
> update count: 1
INSERT INTO T2 VALUES (NULL);
> update count: 1
INSERT INTO T3 VALUES (1);
> update count: 1
INSERT INTO T3 VALUES (NULL);
> update count: 1
INSERT INTO T4 VALUES (1);
> update count: 1
INSERT INTO T4 VALUES (NULL);
> update count: 1
INSERT INTO T5 VALUES (1);
> update count: 1
INSERT INTO T5 VALUES (NULL);
> update count: 1
......
......@@ -2523,6 +2523,7 @@ insert into address(id, name, name2) values(2, 'test@abc', 'test@acme');
> exception CHECK_CONSTRAINT_VIOLATED_1
@reconnect
insert into address(id, name, name2) values(3, 'test_abc', 'test@gmail');
> exception CHECK_CONSTRAINT_VIOLATED_1
......@@ -7954,4 +7955,3 @@ select * from test where year in (select distinct year from test order by year d
drop table test;
> ok
......@@ -4,390 +4,558 @@
--
select 1000L / 10;
>> 100
select * from (select x as y from dual order by y);
>> 1
select a.x from dual a, dual b order by x;
>> 1
select 1 from(select 2 from(select 1) a right join dual b) c;
>> 1
select 1.00 / 3 * 0.00;
>> 0.00000000000000000000000000000
select 1.00000 / 3 * 0.0000;
>> 0.0000000000000000000000000000000000
select 1.0000000 / 3 * 0.00000;
>> 0.0000000000000000000000000000000000000
select 1.0000000 / 3 * 0.000000;
>> 0E-38
create table test(id null);
> ok
drop table test;
> ok
select * from (select group_concat(distinct 1) from system_range(1, 3));
>> 1
select sum(mod(x, 2) = 1) from system_range(1, 10);
>> 5
create table a(x int);
> ok
create table b(x int);
> ok
select count(*) from (select b.x from a left join b);
>> 0
drop table a, b;
> ok
select count(distinct now()) c from system_range(1, 100), system_range(1, 1000);
>> 1
select {fn TIMESTAMPADD(SQL_TSI_DAY, 1, {ts '2011-10-20 20:30:40.001'})};
>> 2011-10-21 20:30:40.001
select {fn TIMESTAMPADD(SQL_TSI_SECOND, 1, cast('2011-10-20 20:30:40.001' as timestamp))};
>> 2011-10-20 20:30:41.001
select N'test';
>> test
select E'test\\test';
>> test\test
create table a(id int) as select null;
> ok
create table b(id int references a(id)) as select null;
> ok
delete from a;
> update count: 1
drop table a, b;
> ok
create table test(a int, b int) as select 2, 0;
> ok
create index idx on test(b, a);
> ok
select count(*) from test where a in(2, 10) and b in(0, null);
>> 1
drop table test;
> ok
create table test(a int, b int) as select 1, 0;
> ok
create index idx on test(b, a);
> ok
select count(*) from test where b in(null, 0) and a in(1, null);
>> 1
drop table test;
> ok
create cached temp table test(id identity) not persistent;
> ok
drop table test;
> ok
create table test(a int, b int, unique(a, b));
> ok
insert into test values(1,1), (1,2);
> update count: 2
select count(*) from test where a in(1,2) and b in(1,2);
>> 2
drop table test;
> ok
create table test(id int);
> ok
alter table test alter column id set default 'x';
> ok
select column_default from information_schema.columns c where c.table_name = 'TEST' and c.column_name = 'ID';
>> 'x'
alter table test alter column id set not null;
> ok
select is_nullable from information_schema.columns c where c.table_name = 'TEST' and c.column_name = 'ID';
>> NO
alter table test alter column id set data type varchar;
> ok
select type_name from information_schema.columns c where c.table_name = 'TEST' and c.column_name = 'ID';
>> VARCHAR
alter table test alter column id type int;
> ok
select type_name from information_schema.columns c where c.table_name = 'TEST' and c.column_name = 'ID';
>> INTEGER
alter table test alter column id drop default;
> ok
select column_default from information_schema.columns c where c.table_name = 'TEST' and c.column_name = 'ID';
>> null
alter table test alter column id drop not null;
> ok
select is_nullable from information_schema.columns c where c.table_name = 'TEST' and c.column_name = 'ID';
>> YES
drop table test;
> ok
select x from (select *, rownum as r from system_range(1, 3)) where r=2;
>> 2
create table test(name varchar(255)) as select 'Hello+World+';
> ok
select count(*) from test where name like 'Hello++World++' escape '+';
>> 1
select count(*) from test where name like '+H+e+l+l+o++World++' escape '+';
>> 1
select count(*) from test where name like 'Hello+World++' escape '+';
>> 0
select count(*) from test where name like 'Hello++World+' escape '+';
>> 0
drop table test;
> ok
select count(*) from system_range(1, 1);
>> 1
select count(*) from system_range(1, -1);
>> 0
select 1 from dual where '\' like '\' escape '';
>> 1
select left(timestamp '2001-02-03 08:20:31+04', 4);
>> 2001
create table t1$2(id int);
> ok
drop table t1$2;
> ok
create table test(id int primary key) as select x from system_range(1, 200);
> ok
delete from test;
> update count: 200
insert into test(id) values(1);
> update count: 1
select * from test order by id;
>> 1
drop table test;
> ok
create memory table test(id int) not persistent as select 1 from dual;
> ok
insert into test values(1);
> update count: 1
select count(1) from test;
>> 2
@reconnect
select count(1) from test;
>> 0
drop table test;
> ok
create table test(t clob) as select 1;
> ok
select distinct t from test;
>> 1
drop table test;
> ok
create table test(id int unique not null);
> ok
drop table test;
> ok
create table test(id int not null unique);
> ok
drop table test;
> ok
select count(*)from((select 1 from dual limit 1)union(select 2 from dual limit 1));
>> 2
select sum(cast(x as int)) from system_range(2147483547, 2147483637);
>> 195421006872
select sum(x) from system_range(9223372036854775707, 9223372036854775797);
>> 839326855353784593432
select sum(cast(100 as tinyint)) from system_range(1, 1000);
>> 100000
select sum(cast(100 as smallint)) from system_range(1, 1000);
>> 100000
select avg(cast(x as int)) from system_range(2147483547, 2147483637);
>> 2147483592
select avg(x) from system_range(9223372036854775707, 9223372036854775797);
>> 9223372036854775752
select avg(cast(100 as tinyint)) from system_range(1, 1000);
>> 100
select avg(cast(100 as smallint)) from system_range(1, 1000);
>> 100
select datediff(yyyy, now(), now());
>> 0
create table t(d date) as select '2008-11-01' union select '2008-11-02';
> ok
select 1 from t group by year(d) order by year(d);
>> 1
drop table t;
> ok
create table t(d int) as select 2001 union select 2002;
> ok
select 1 from t group by d/10 order by d/10;
>> 1
drop table t;
> ok
create schema test;
> ok
create sequence test.report_id_seq;
> ok
select nextval('"test".REPORT_ID_SEQ');
>> 1
select nextval('"test"."report_id_seq"');
>> 2
select nextval('test.report_id_seq');
>> 3
drop schema test cascade;
> ok
create table master(id int primary key);
> ok
create table detail(id int primary key, x bigint, foreign key(x) references master(id) on delete cascade);
> ok
alter table detail alter column x bigint;
> ok
insert into master values(0);
> update count: 1
insert into detail values(0,0);
> update count: 1
delete from master;
> update count: 1
drop table master, detail;
> ok
drop all objects;
> ok
create table test(id int, parent int references test(id) on delete cascade);
> ok
insert into test values(0, 0);
> update count: 1
alter table test rename to test2;
> ok
delete from test2;
> update count: 1
drop table test2;
> ok
SELECT X FROM dual GROUP BY X HAVING X=AVG(X);
>> 1
create view test_view(id,) as select * from dual;
> ok
drop view test_view;
> ok
create table test(id int,);
> ok
insert into test(id,) values(1,);
> update count: 1
merge into test(id,) key(id,) values(1,);
> update count: 1
drop table test;
> ok
SET MODE DB2;
> ok
SELECT * FROM SYSTEM_RANGE(1, 100) OFFSET 99 ROWS;
>> 100
SELECT * FROM SYSTEM_RANGE(1, 100) OFFSET 50 ROWS FETCH FIRST 1 ROW ONLY;
>> 51
SELECT * FROM SYSTEM_RANGE(1, 100) FETCH FIRST 1 ROWS ONLY;
>> 1
SELECT * FROM SYSTEM_RANGE(1, 100) FETCH FIRST ROW ONLY;
>> 1
SET MODE REGULAR;
> ok
create domain email as varchar comment 'e-mail';
> ok
create table test(e email);
> ok
select remarks from INFORMATION_SCHEMA.COLUMNS where table_name='TEST';
>> e-mail
drop table test;
> ok
drop domain email;
> ok
create table test$test(id int);
> ok
drop table test$test;
> ok
create table test$$test(id int);
> ok
drop table test$$test;
> ok
create table test (id varchar(36) as random_uuid() primary key);
> ok
insert into test() values();
> update count: 1
delete from test where id = select id from test;
> update count: 1
drop table test;
> ok
create table test (id varchar(36) as now() primary key);
> ok
insert into test() values();
> update count: 1
delete from test where id = select id from test;
> update count: 1
drop table test;
> ok
SELECT SOME(X>4) FROM SYSTEM_RANGE(1,6);
>> TRUE
SELECT EVERY(X>4) FROM SYSTEM_RANGE(1,6);
>> FALSE
SELECT BOOL_OR(X>4) FROM SYSTEM_RANGE(1,6);
>> TRUE
SELECT BOOL_AND(X>4) FROM SYSTEM_RANGE(1,6);
>> FALSE
SELECT BIT_OR(X) FROM SYSTEM_RANGE(1,6);
>> 7
SELECT BIT_AND(X) FROM SYSTEM_RANGE(1,6);
>> 0
SELECT BIT_AND(X) FROM SYSTEM_RANGE(1,1);
>> 1
CREATE TABLE TEST(ID IDENTITY);
> ok
ALTER TABLE TEST ALTER COLUMN ID RESTART WITH ?;
{
10
};
> update count: 0
INSERT INTO TEST VALUES(NULL);
> update count: 1
SELECT * FROM TEST;
>> 10
DROP TABLE TEST;
> ok
CREATE SEQUENCE TEST_SEQ;
> ok
ALTER SEQUENCE TEST_SEQ RESTART WITH ? INCREMENT BY ?;
{
20, 3
};
> update count: 0
SELECT NEXT VALUE FOR TEST_SEQ;
>> 20
SELECT NEXT VALUE FOR TEST_SEQ;
>> 23
DROP SEQUENCE TEST_SEQ;
> ok
create schema Contact;
> ok
CREATE TABLE Account (id BIGINT);
> ok
CREATE TABLE Person (id BIGINT, FOREIGN KEY (id) REFERENCES Account(id));
> ok
CREATE TABLE Contact.Contact (id BIGINT, FOREIGN KEY (id) REFERENCES public.Person(id));
> ok
drop schema contact cascade;
> ok
drop table account, person;
> ok
create schema Contact;
> ok
CREATE TABLE Account (id BIGINT primary key);
> ok
CREATE TABLE Person (id BIGINT primary key, FOREIGN KEY (id) REFERENCES Account);
> ok
CREATE TABLE Contact.Contact (id BIGINT primary key, FOREIGN KEY (id) REFERENCES public.Person);
> ok
drop schema contact cascade;
> ok
drop table account, person;
> ok
CREATE TABLE TEST(A int NOT NULL, B int NOT NULL, C int) ;
> ok
ALTER TABLE TEST ADD CONSTRAINT CON UNIQUE(A,B);
> ok
ALTER TABLE TEST DROP C;
> ok
ALTER TABLE TEST DROP CONSTRAINT CON;
> ok
ALTER TABLE TEST DROP B;
> ok
DROP TABLE TEST;
> ok
......@@ -396,16 +564,21 @@ select count(d.*) from dual d group by d.x;
create table test(id int);
> ok
select count(*) from (select * from ((select * from test) union (select * from test)) a) b where id = 0;
>> 0
select count(*) from (select * from ((select * from test) union select * from test) a) b where id = 0;
>> 0
select count(*) from (select * from (select * from test union select * from test) a) b where id = 0;
>> 0
select 1 from ((test d1 inner join test d2 on d1.id = d2.id) inner join test d3 on d1.id = d3.id) inner join test d4 on d4.id = d1.id;
> 1
> -
> rows: 0
drop table test;
> ok
......@@ -414,50 +587,67 @@ select replace(lpad('string', 10), ' ', '*');
select count(*) from (select * from dual union select * from dual) where x = 0;
>> 0
select count(*) from (select * from (select * from dual union select * from dual)) where x = 0;
>> 0
select instr('abcisj','s', -1) from dual;
>> 5
CREATE TABLE TEST(ID INT);
> ok
INSERT INTO TEST VALUES(1), (2), (3);
> update count: 3
create index idx_desc on test(id desc);
> ok
select * from test where id between 0 and 1;
>> 1
select * from test where id between 3 and 4;
>> 3
drop table test;
> ok
CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255));
> ok
INSERT INTO TEST VALUES(1, 'Hello'), (2, 'HelloWorld'), (3, 'HelloWorldWorld');
> update count: 3
SELECT COUNT(*) FROM TEST WHERE NAME REGEXP 'World';
>> 2
SELECT NAME FROM TEST WHERE NAME REGEXP 'WorldW';
>> HelloWorldWorld
drop table test;
> ok
select * from (select x from (select x from dual)) where 1=x;
>> 1
CREATE VIEW TEST_VIEW AS SELECT X FROM (SELECT X FROM DUAL);
> ok
SELECT * FROM TEST_VIEW;
>> 1
SELECT * FROM TEST_VIEW;
>> 1
DROP VIEW TEST_VIEW;
> ok
SELECT X FROM (SELECT X, X AS "XY" FROM DUAL) WHERE X=1;
>> 1
SELECT X FROM (SELECT X, X AS "X Y" FROM DUAL) WHERE X=1;
>> 1
SELECT X FROM (SELECT X, X AS "X Y" FROM DUAL AS "D Z") WHERE X=1;
>> 1
......@@ -465,18 +655,25 @@ select * from (select x from dual union select convert(x, int) from dual) where
> X
> -
> rows: 0
create table test(id int);
> ok
insert into script.public.test(id) values(1), (2);
> update count: 2
update test t set t.id=t.id+1;
> update count: 2
update public.test set public.test.id=1;
> update count: 2
select count(script.public.test.id) from script.public.test;
>> 2
update script.public.test set script.public.test.id=1;
> update count: 2
drop table script.public.test;
> ok
......@@ -485,39 +682,55 @@ select year(timestamp '2007-07-26T18:44:26.109000+02:00');
create table test(id int primary key);
> ok
begin;
> ok
insert into test values(1);
> update count: 1
rollback;
> ok
insert into test values(2);
> update count: 1
rollback;
> ok
begin;
> ok
insert into test values(3);
> update count: 1
commit;
> ok
insert into test values(4);
> update count: 1
rollback;
> ok
select group_concat(id order by id) from test;
>> 2,3,4
drop table test;
> ok
create table test();
> ok
insert into test values();
> update count: 1
ALTER TABLE TEST ADD ID INTEGER;
> ok
select count(*) from test;
>> 1
drop table test;
> ok
......@@ -526,62 +739,85 @@ select * from dual where 'a_z' like '%=_%' escape '=';
create table test as select 1 from dual union all select 2 from dual;
> ok
drop table test;
> ok
create table test_table(column_a integer);
> ok
insert into test_table values(1);
> update count: 1
create view test_view AS SELECT * FROM (SELECT DISTINCT * FROM test_table) AS subquery;
> ok
select * FROM test_view;
>> 1
drop view test_view;
> ok
drop table test_table;
> ok
CREATE TABLE TEST(ID INT);
> ok
INSERT INTO TEST VALUES(1);
> update count: 1
CREATE VIEW TEST_VIEW AS SELECT COUNT(ID) X FROM TEST;
> ok
explain SELECT * FROM TEST_VIEW WHERE X>1;
>> SELECT TEST_VIEW.X FROM PUBLIC.TEST_VIEW /* SELECT COUNT(ID) AS X FROM PUBLIC.TEST /++ PUBLIC.TEST.tableScan ++/ HAVING COUNT(ID) >= ?1: X > 1 */ WHERE X > 1
DROP VIEW TEST_VIEW;
> ok
DROP TABLE TEST;
> ok
create table test1(id int);
> ok
insert into test1 values(1), (1), (2), (3);
> update count: 4
select sum(C0) from (select count(*) AS C0 from (select distinct * from test1) as temp);
>> 3
drop table test1;
> ok
create table test(id int primary key check id>1);
> ok
drop table test;
> ok
create table table1(f1 int not null primary key);
> ok
create table table2(f2 int not null references table1(f1) on delete cascade);
> ok
drop table table2;
> ok
drop table table1;
> ok
create table table1(f1 int not null primary key);
> ok
create table table2(f2 int not null primary key references table1(f1));
> ok
drop table table1;
> ok
drop table table2;
> ok
......@@ -593,403 +829,588 @@ select case (1) when 1 then 1 else 2 end;
create table test(id int);
> ok
insert into test values(1);
> update count: 1
select distinct id from test a order by a.id;
>> 1
drop table test;
> ok
create table FOO (ID int, A number(18, 2));
> ok
insert into FOO (ID, A) values (1, 10.0), (2, 20.0);
> update count: 2
select SUM (CASE when ID=1 then 0 ELSE A END) col0 from Foo;
>> 20.00
drop table FOO;
> ok
select (SELECT true)+1 GROUP BY 1;
>> 2
create table FOO (ID int, A number(18, 2));
> ok
insert into FOO (ID, A) values (1, 10.0), (2, 20.0);
> update count: 2
select SUM (CASE when ID=1 then A ELSE 0 END) col0 from Foo;
>> 10.00
drop table FOO;
> ok
create table A ( ID integer, a1 varchar(20) );
> ok
create table B ( ID integer, AID integer, b1 varchar(20));
> ok
create table C ( ID integer, BId integer, c1 varchar(20));
> ok
insert into A (ID, a1) values (1, 'a1');
> update count: 1
insert into A (ID, a1) values (2, 'a2');
> update count: 1
select count(*) from A left outer join (B inner join C on C.BID=B.ID ) on B.AID=A.ID where A.id=1;
>> 1
select count(*) from A left outer join (B left join C on C.BID=B.ID ) on B.AID=A.ID where A.id=1;
>> 1
select count(*) from A left outer join B on B.AID=A.ID inner join C on C.BID=B.ID where A.id=1;
>> 0
select count(*) from (A left outer join B on B.AID=A.ID) inner join C on C.BID=B.ID where A.id=1;
>> 0
drop table a, b, c;
> ok
create schema a;
> ok
create table a.test(id int);
> ok
insert into a.test values(1);
> update count: 1
create schema b;
> ok
create table b.test(id int);
> ok
insert into b.test values(2);
> update count: 1
select a.test.id + b.test.id from a.test, b.test;
>> 3
drop schema a cascade;
> ok
drop schema b cascade;
> ok
select date '+0011-01-01';
>> 0011-01-01
select date'-0010-01-01';
>> -10-01-01
create schema TEST_SCHEMA;
> ok
create table TEST_SCHEMA.test(id int);
> ok
create sequence TEST_SCHEMA.TEST_SEQ;
> ok
select TEST_SCHEMA.TEST_SEQ.CURRVAL;
>> 0
select TEST_SCHEMA.TEST_SEQ.nextval;
>> 1
drop schema TEST_SCHEMA cascade;
> ok
create table test(id int);
> ok
create trigger TEST_TRIGGER before insert on test call "org.h2.test.db.TestTriggersConstraints";
> ok
comment on trigger TEST_TRIGGER is 'just testing';
> ok
select remarks from information_schema.triggers where trigger_name = 'TEST_TRIGGER';
>> just testing
@reconnect
select remarks from information_schema.triggers where trigger_name = 'TEST_TRIGGER';
>> just testing
drop trigger TEST_TRIGGER;
> ok
@reconnect
create alias parse_long for "java.lang.Long.parseLong(java.lang.String)";
> ok
comment on alias parse_long is 'Parse a long with base';
> ok
select remarks from information_schema.function_aliases where alias_name = 'PARSE_LONG';
>> Parse a long with base
@reconnect
select remarks from information_schema.function_aliases where alias_name = 'PARSE_LONG';
>> Parse a long with base
drop alias parse_long;
> ok
@reconnect
create role hr;
> ok
comment on role hr is 'Human Resources';
> ok
select remarks from information_schema.roles where name = 'HR';
>> Human Resources
@reconnect
select remarks from information_schema.roles where name = 'HR';
>> Human Resources
create user abc password 'x';
> ok
grant hr to abc;
> ok
drop role hr;
> ok
@reconnect
drop user abc;
> ok
create domain email as varchar(100) check instr(value, '@') > 0;
> ok
comment on domain email is 'must contain @';
> ok
select remarks from information_schema.domains where domain_name = 'EMAIL';
>> must contain @
@reconnect
select remarks from information_schema.domains where domain_name = 'EMAIL';
>> must contain @
drop domain email;
> ok
@reconnect
create schema tests;
> ok
set schema tests;
> ok
create sequence walk;
> ok
comment on schema tests is 'Test Schema';
> ok
comment on sequence walk is 'Walker';
> ok
select remarks from information_schema.schemata where schema_name = 'TESTS';
>> Test Schema
select remarks from information_schema.sequences where sequence_name = 'WALK';
>> Walker
@reconnect
select remarks from information_schema.schemata where schema_name = 'TESTS';
>> Test Schema
select remarks from information_schema.sequences where sequence_name = 'WALK';
>> Walker
drop schema tests cascade;
> ok
@reconnect
create constant abc value 1;
> ok
comment on constant abc is 'One';
> ok
select remarks from information_schema.constants where constant_name = 'ABC';
>> One
@reconnect
select remarks from information_schema.constants where constant_name = 'ABC';
>> One
drop constant abc;
> ok
drop table test;
> ok
@reconnect
create table test(id int);
> ok
alter table test add constraint const1 unique(id);
> ok
create index IDX_ID on test(id);
> ok
comment on constraint const1 is 'unique id';
> ok
comment on index IDX_ID is 'id_index';
> ok
select remarks from information_schema.constraints where constraint_name = 'CONST1';
>> unique id
select remarks from information_schema.indexes where index_name = 'IDX_ID';
>> id_index
@reconnect
select remarks from information_schema.constraints where constraint_name = 'CONST1';
>> unique id
select remarks from information_schema.indexes where index_name = 'IDX_ID';
>> id_index
drop table test;
> ok
@reconnect
create user sales password '1';
> ok
comment on user sales is 'mr. money';
> ok
select remarks from information_schema.users where name = 'SALES';
>> mr. money
@reconnect
select remarks from information_schema.users where name = 'SALES';
>> mr. money
alter user sales rename to SALES_USER;
> ok
select remarks from information_schema.users where name = 'SALES_USER';
>> mr. money
@reconnect
select remarks from information_schema.users where name = 'SALES_USER';
>> mr. money
create table test(id int);
> ok
create linked table test_link('org.h2.Driver', 'jdbc:h2:mem:', 'sa', 'sa', 'DUAL');
> ok
comment on table test_link is '123';
> ok
select remarks from information_schema.tables where table_name = 'TEST_LINK';
>> 123
@reconnect
select remarks from information_schema.tables where table_name = 'TEST_LINK';
>> 123
comment on table test_link is 'xyz';
> ok
select remarks from information_schema.tables where table_name = 'TEST_LINK';
>> xyz
alter table test_link rename to test_l;
> ok
select remarks from information_schema.tables where table_name = 'TEST_L';
>> xyz
@reconnect
select remarks from information_schema.tables where table_name = 'TEST_L';
>> xyz
drop table test;
> ok
@reconnect
create table test(id int);
> ok
create view test_v as select * from test;
> ok
comment on table test_v is 'abc';
> ok
select remarks from information_schema.tables where table_name = 'TEST_V';
>> abc
@reconnect
select remarks from information_schema.tables where table_name = 'TEST_V';
>> abc
alter table test_v rename to TEST_VIEW;
> ok
select remarks from information_schema.tables where table_name = 'TEST_VIEW';
>> abc
@reconnect
select remarks from information_schema.tables where table_name = 'TEST_VIEW';
>> abc
drop table test cascade;
> ok
@reconnect
create table test(a int);
> ok
comment on table test is 'hi';
> ok
select remarks from information_schema.tables where table_name = 'TEST';
>> hi
alter table test add column b int;
> ok
select remarks from information_schema.tables where table_name = 'TEST';
>> hi
alter table test rename to test1;
> ok
select remarks from information_schema.tables where table_name = 'TEST1';
>> hi
@reconnect
select remarks from information_schema.tables where table_name = 'TEST1';
>> hi
comment on table test1 is 'ho';
> ok
@reconnect
select remarks from information_schema.tables where table_name = 'TEST1';
>> ho
drop table test1;
> ok
create table test(a int, b int);
> ok
comment on column test.b is 'test';
> ok
select remarks from information_schema.columns where table_name = 'TEST' and column_name = 'B';
>> test
@reconnect
select remarks from information_schema.columns where table_name = 'TEST' and column_name = 'B';
>> test
alter table test drop column b;
> ok
@reconnect
comment on column test.a is 'ho';
> ok
select remarks from information_schema.columns where table_name = 'TEST' and column_name = 'A';
>> ho
@reconnect
select remarks from information_schema.columns where table_name = 'TEST' and column_name = 'A';
>> ho
drop table test;
> ok
@reconnect
create table test(a int);
> ok
comment on column test.a is 'test';
> ok
alter table test rename to test2;
> ok
@reconnect
select remarks from information_schema.columns where table_name = 'TEST2';
>> test
@reconnect
select remarks from information_schema.columns where table_name = 'TEST2';
>> test
drop table test2;
> ok
@reconnect
create table test1 (a varchar(10));
> ok
create hash index x1 on test1(a);
> ok
insert into test1 values ('abcaaaa'),('abcbbbb'),('abccccc'),('abcdddd');
> update count: 4
insert into test1 values ('abcaaaa'),('abcbbbb'),('abccccc'),('abcdddd');
> update count: 4
insert into test1 values ('abcaaaa'),('abcbbbb'),('abccccc'),('abcdddd');
> update count: 4
insert into test1 values ('abcaaaa'),('abcbbbb'),('abccccc'),('abcdddd');
> update count: 4
select count(*) from test1 where a='abcaaaa';
>> 4
select count(*) from test1 where a='abcbbbb';
>> 4
@reconnect
select count(*) from test1 where a='abccccc';
>> 4
select count(*) from test1 where a='abcdddd';
>> 4
update test1 set a='abccccc' where a='abcdddd';
> update count: 4
select count(*) from test1 where a='abccccc';
>> 8
select count(*) from test1 where a='abcdddd';
>> 0
delete from test1 where a='abccccc';
> update count: 8
select count(*) from test1 where a='abccccc';
>> 0
truncate table test1;
> ok
insert into test1 values ('abcaaaa');
> update count: 1
insert into test1 values ('abcaaaa');
> update count: 1
delete from test1;
> update count: 2
drop table test1;
> ok
@reconnect
drop table if exists test;
> ok
create table if not exists test(col1 int primary key);
> ok
insert into test values(1);
> update count: 1
insert into test values(2);
> update count: 1
insert into test values(3);
> update count: 1
select count(*) from test;
>> 3
select max(col1) from test;
>> 3
update test set col1 = col1 + 1 order by col1 asc limit 100;
> update count: 3
select count(*) from test;
>> 3
select max(col1) from test;
>> 4
drop table if exists test;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论