提交 2192c90a authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Move SHOW tests into show.sql

上级 6e18d576
......@@ -70,7 +70,6 @@ import org.h2.test.db.TestSelectCountNonNullColumn;
import org.h2.test.db.TestSequence;
import org.h2.test.db.TestSessionsLocks;
import org.h2.test.db.TestSetCollation;
import org.h2.test.db.TestShow;
import org.h2.test.db.TestSpaceReuse;
import org.h2.test.db.TestSpatial;
import org.h2.test.db.TestSpeed;
......@@ -779,7 +778,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest(new TestSessionsLocks());
addTest(new TestSelectCountNonNullColumn());
addTest(new TestSequence());
addTest(new TestShow());
addTest(new TestSpaceReuse());
addTest(new TestSpatial());
addTest(new TestSpeed());
......
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.db;
import org.h2.test.TestBase;
import org.h2.test.TestDb;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* Test of compatibility for the SHOW statement.
*/
public class TestShow extends TestDb {
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String... a) throws Exception {
TestBase.createCaller().init().test();
}
@Override
public void test() throws SQLException {
testPgCompatibility();
testMysqlCompatibility();
}
private void testPgCompatibility() throws SQLException {
try (Connection conn = getConnection("mem:pg")) {
Statement stat = conn.createStatement();
assertResult("UNICODE", stat, "SHOW CLIENT_ENCODING");
assertResult("read committed", stat, "SHOW DEFAULT_TRANSACTION_ISOLATION");
assertResult("read committed", stat, "SHOW TRANSACTION ISOLATION LEVEL");
assertResult("ISO", stat, "SHOW DATESTYLE");
assertResult("8.2.23", stat, "SHOW SERVER_VERSION");
assertResult("UTF8", stat, "SHOW SERVER_ENCODING");
}
}
private void testMysqlCompatibility() throws SQLException {
try (Connection conn = getConnection("mem:pg")) {
Statement stat = conn.createStatement();
ResultSet rs;
// show tables without a schema
stat.execute("create table person(id int, name varchar)");
rs = stat.executeQuery("SHOW TABLES");
assertTrue(rs.next());
assertEquals("PERSON", rs.getString(1));
assertEquals("PUBLIC", rs.getString(2));
assertFalse(rs.next());
// show tables with a schema
assertResultRowCount(1, stat.executeQuery("SHOW TABLES FROM PUBLIC"));
// columns
assertResultRowCount(2, stat.executeQuery("SHOW COLUMNS FROM person"));
}
}
}
......@@ -129,7 +129,7 @@ public class TestScript extends TestDb {
testScript("ddl/" + s + ".sql");
}
for (String s : new String[] { "error_reporting", "insertIgnore", "merge", "mergeUsing", "replace",
"script", "with" }) {
"script", "show", "with" }) {
testScript("dml/" + s + ".sql");
}
for (String s : new String[] { "help" }) {
......
-- Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
------------------------------
-- PostgreSQL compatibility --
------------------------------
SHOW CLIENT_ENCODING;
> CLIENT_ENCODING
> ---------------
> UNICODE
> rows: 1
SHOW DEFAULT_TRANSACTION_ISOLATION;
> DEFAULT_TRANSACTION_ISOLATION
> -----------------------------
> read committed
> rows: 1
SHOW TRANSACTION ISOLATION LEVEL;
> TRANSACTION_ISOLATION
> ---------------------
> read committed
> rows: 1
SHOW DATESTYLE;
> DATESTYLE
> ---------
> ISO
> rows: 1
SHOW SERVER_VERSION;
> SERVER_VERSION
> --------------
> 8.2.23
> rows: 1
SHOW SERVER_ENCODING;
> SERVER_ENCODING
> ---------------
> UTF8
> rows: 1
-------------------------
-- MySQL compatibility --
-------------------------
CREATE TABLE TEST_P(ID_P INT PRIMARY KEY, U_P VARCHAR(255) UNIQUE, N_P INT DEFAULT 1);
> ok
CREATE SCHEMA SCH;
> ok
CREATE TABLE SCH.TEST_S(ID_S INT PRIMARY KEY, U_S VARCHAR(255) UNIQUE, N_S INT DEFAULT 1);
> ok
SHOW TABLES;
> TABLE_NAME TABLE_SCHEMA
> ---------- ------------
> TEST_P PUBLIC
> rows: 1
SHOW TABLES FROM PUBLIC;
> TABLE_NAME TABLE_SCHEMA
> ---------- ------------
> TEST_P PUBLIC
> rows: 1
SHOW TABLES FROM SCH;
> TABLE_NAME TABLE_SCHEMA
> ---------- ------------
> TEST_S SCH
> rows: 1
SHOW COLUMNS FROM TEST_P;
> FIELD TYPE NULL KEY DEFAULT
> ----- ------------ ---- --- -------
> ID_P INTEGER(10) NO PRI NULL
> N_P INTEGER(10) YES 1
> U_P VARCHAR(255) YES UNI NULL
> rows: 3
SHOW COLUMNS FROM TEST_S FROM SCH;
> FIELD TYPE NULL KEY DEFAULT
> ----- ------------ ---- --- -------
> ID_S INTEGER(10) NO PRI NULL
> N_S INTEGER(10) YES 1
> U_S VARCHAR(255) YES UNI NULL
> rows: 3
SHOW DATABASES;
> SCHEMA_NAME
> ------------------
> INFORMATION_SCHEMA
> PUBLIC
> SCH
> rows: 3
SHOW SCHEMAS;
> SCHEMA_NAME
> ------------------
> INFORMATION_SCHEMA
> PUBLIC
> SCH
> rows: 3
DROP TABLE TEST_P;
> ok
DROP SCHEMA SCH CASCADE;
> ok
......@@ -630,38 +630,6 @@ select count(*) from test where id = 'X1';
drop table test;
> ok
create table test(id int primary key, name varchar(255), x int);
> ok
create unique index idx_name1 on test(name);
> ok
create unique index idx_name2 on test(name);
> ok
show columns from test;
> FIELD TYPE NULL KEY DEFAULT
> ----- ------------ ---- --- -------
> ID INTEGER(10) NO PRI NULL
> NAME VARCHAR(255) YES UNI NULL
> X INTEGER(10) YES NULL
> rows: 3
show columns from catalogs from information_schema;
> FIELD TYPE NULL KEY DEFAULT
> ------------ ------------------- ---- --- -------
> CATALOG_NAME VARCHAR(2147483647) YES NULL
> rows: 1
show columns from information_schema.catalogs;
> FIELD TYPE NULL KEY DEFAULT
> ------------ ------------------- ---- --- -------
> CATALOG_NAME VARCHAR(2147483647) YES NULL
> rows: 1
drop table test;
> ok
create table test(id int, constraint pk primary key(id), constraint x unique(id));
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论