Unverified 提交 9f951e0a authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1293 from katzyn/misc

Move HELP and SHOW tests into own files
...@@ -1271,23 +1271,23 @@ public class Parser { ...@@ -1271,23 +1271,23 @@ public class Parser {
} }
private Prepared parseHelp() { private Prepared parseHelp() {
StringBuilder buff = new StringBuilder( Select select = new Select(session);
"SELECT * FROM INFORMATION_SCHEMA.HELP"); select.setWildcard();
int i = 0; Table table = database.getSchema("INFORMATION_SCHEMA").resolveTableOrView(session, "HELP");
ArrayList<Value> paramValues = Utils.newSmallArrayList(); Function function = Function.getFunction(database, "UPPER");
function.setParameter(0, new ExpressionColumn(database, "INFORMATION_SCHEMA", "HELP", "TOPIC"));
function.doneWithParameters();
TableFilter filter = new TableFilter(session, table, null, rightsChecked, select, 0, null);
select.addTableFilter(filter, true);
while (currentTokenType != END) { while (currentTokenType != END) {
String s = currentToken; String s = currentToken;
read(); read();
if (i == 0) { CompareLike like = new CompareLike(database, function,
buff.append(" WHERE "); ValueExpression.get(ValueString.get('%' + s + '%')), null, false);
} else { select.addCondition(like);
buff.append(" AND ");
} }
i++; select.init();
buff.append("UPPER(TOPIC) LIKE ?"); return select;
paramValues.add(ValueString.get("%" + s + "%"));
}
return prepare(session, buff.toString(), paramValues);
} }
private Prepared parseShow() { private Prepared parseShow() {
...@@ -1463,9 +1463,7 @@ public class Parser { ...@@ -1463,9 +1463,7 @@ public class Parser {
command.setSourceTableFilter(sourceTableFilter); command.setSourceTableFilter(sourceTableFilter);
Select preparedQuery = new Select(session); Select preparedQuery = new Select(session);
ArrayList<Expression> expr = new ArrayList<>(1); preparedQuery.setWildcard();
expr.add(new Wildcard(null, null));
preparedQuery.setExpressions(expr);
TableFilter filter = new TableFilter(session, sourceTableFilter.getTable(), TableFilter filter = new TableFilter(session, sourceTableFilter.getTable(),
sourceTableFilter.getTableAlias(), rightsChecked, preparedQuery, 0, null); sourceTableFilter.getTableAlias(), rightsChecked, preparedQuery, 0, null);
preparedQuery.addTableFilter(filter, true); preparedQuery.addTableFilter(filter, true);
...@@ -5130,9 +5128,7 @@ public class Parser { ...@@ -5130,9 +5128,7 @@ public class Parser {
Select command = new Select(session); Select command = new Select(session);
currentSelect = command; currentSelect = command;
TableFilter filter = parseValuesTable(0); TableFilter filter = parseValuesTable(0);
ArrayList<Expression> list = new ArrayList<>(1); command.setWildcard();
list.add(new Wildcard(null, null));
command.setExpressions(list);
command.addTableFilter(filter, true); command.addTableFilter(filter, true);
command.init(); command.init();
return command; return command;
......
...@@ -25,6 +25,7 @@ import org.h2.expression.Expression; ...@@ -25,6 +25,7 @@ import org.h2.expression.Expression;
import org.h2.expression.ExpressionColumn; import org.h2.expression.ExpressionColumn;
import org.h2.expression.ExpressionVisitor; import org.h2.expression.ExpressionVisitor;
import org.h2.expression.Parameter; import org.h2.expression.Parameter;
import org.h2.expression.Wildcard;
import org.h2.index.Cursor; import org.h2.index.Cursor;
import org.h2.index.Index; import org.h2.index.Index;
import org.h2.index.IndexType; import org.h2.index.IndexType;
...@@ -171,6 +172,11 @@ public class Select extends Query { ...@@ -171,6 +172,11 @@ public class Select extends Query {
this.expressions = expressions; this.expressions = expressions;
} }
public void setWildcard() {
expressions = new ArrayList<>(1);
expressions.add(new Wildcard(null, null));
}
/** /**
* Called if this query contains aggregate functions. * Called if this query contains aggregate functions.
*/ */
......
...@@ -70,7 +70,6 @@ import org.h2.test.db.TestSelectCountNonNullColumn; ...@@ -70,7 +70,6 @@ import org.h2.test.db.TestSelectCountNonNullColumn;
import org.h2.test.db.TestSequence; import org.h2.test.db.TestSequence;
import org.h2.test.db.TestSessionsLocks; import org.h2.test.db.TestSessionsLocks;
import org.h2.test.db.TestSetCollation; import org.h2.test.db.TestSetCollation;
import org.h2.test.db.TestShow;
import org.h2.test.db.TestSpaceReuse; import org.h2.test.db.TestSpaceReuse;
import org.h2.test.db.TestSpatial; import org.h2.test.db.TestSpatial;
import org.h2.test.db.TestSpeed; import org.h2.test.db.TestSpeed;
...@@ -779,7 +778,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -779,7 +778,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest(new TestSessionsLocks()); addTest(new TestSessionsLocks());
addTest(new TestSelectCountNonNullColumn()); addTest(new TestSelectCountNonNullColumn());
addTest(new TestSequence()); addTest(new TestSequence());
addTest(new TestShow());
addTest(new TestSpaceReuse()); addTest(new TestSpaceReuse());
addTest(new TestSpatial()); addTest(new TestSpatial());
addTest(new TestSpeed()); 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,9 +129,12 @@ public class TestScript extends TestDb { ...@@ -129,9 +129,12 @@ public class TestScript extends TestDb {
testScript("ddl/" + s + ".sql"); testScript("ddl/" + s + ".sql");
} }
for (String s : new String[] { "error_reporting", "insertIgnore", "merge", "mergeUsing", "replace", for (String s : new String[] { "error_reporting", "insertIgnore", "merge", "mergeUsing", "replace",
"script", "with" }) { "script", "show", "with" }) {
testScript("dml/" + s + ".sql"); testScript("dml/" + s + ".sql");
} }
for (String s : new String[] { "help" }) {
testScript("other/" + s + ".sql");
}
for (String s : new String[] { "avg", "bit-and", "bit-or", "count", for (String s : new String[] { "avg", "bit-and", "bit-or", "count",
"group-concat", "max", "median", "min", "selectivity", "stddev-pop", "group-concat", "max", "median", "min", "selectivity", "stddev-pop",
"stddev-samp", "sum", "var-pop", "var-samp", "array-agg" }) { "stddev-samp", "sum", "var-pop", "var-samp", "array-agg" }) {
......
-- 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
-- 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
--
help abc;
> ID SECTION TOPIC SYNTAX TEXT
> -- ------- ----- ------ ----
> rows: 0
HELP ABCDE EF_GH;
> ID SECTION TOPIC SYNTAX TEXT
> -- ------- ----- ------ ----
> rows: 0
HELP HELP;
> ID SECTION TOPIC SYNTAX TEXT
> -- ---------------- ----- ----------------------- ----------------------------------------------------
> 64 Commands (Other) HELP HELP [ anything [...] ] Displays the help pages of SQL commands or keywords.
> rows: 1
HELP he lp;
> ID SECTION TOPIC SYNTAX TEXT
> -- ---------------- ----- ----------------------- ----------------------------------------------------
> 64 Commands (Other) HELP HELP [ anything [...] ] Displays the help pages of SQL commands or keywords.
> rows: 1
...@@ -630,38 +630,6 @@ select count(*) from test where id = 'X1'; ...@@ -630,38 +630,6 @@ select count(*) from test where id = 'X1';
drop table test; drop table test;
> ok > 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)); create table test(id int, constraint pk primary key(id), constraint x unique(id));
> ok > ok
...@@ -1109,11 +1077,6 @@ drop table test; ...@@ -1109,11 +1077,6 @@ drop table test;
alter table information_schema.help rename to information_schema.help2; alter table information_schema.help rename to information_schema.help2;
> exception FEATURE_NOT_SUPPORTED_1 > exception FEATURE_NOT_SUPPORTED_1
help abc;
> ID SECTION TOPIC SYNTAX TEXT
> -- ------- ----- ------ ----
> rows: 0
CREATE TABLE test (id int(25) NOT NULL auto_increment, name varchar NOT NULL, PRIMARY KEY (id,name)); CREATE TABLE test (id int(25) NOT NULL auto_increment, name varchar NOT NULL, PRIMARY KEY (id,name));
> ok > ok
...@@ -6880,12 +6843,6 @@ DROP INDEX IF EXISTS IDXNAME; ...@@ -6880,12 +6843,6 @@ DROP INDEX IF EXISTS IDXNAME;
DROP TABLE TEST; DROP TABLE TEST;
> ok > ok
--- help ----------------------------------------------------------------------------------------------
HELP ABCDE EF_GH;
> ID SECTION TOPIC SYNTAX TEXT
> -- ------- ----- ------ ----
> rows: 0
--- sequence ---------------------------------------------------------------------------------------------- --- sequence ----------------------------------------------------------------------------------------------
CREATE CACHED TABLE TEST(ID INT PRIMARY KEY); CREATE CACHED TABLE TEST(ID INT PRIMARY KEY);
> ok > ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论