提交 7a0eb586 authored 作者: Thomas Mueller's avatar Thomas Mueller

SHOW COLUMNS did not work correctly if there where multiple indexes on the same columns.

上级 e4760bbd
...@@ -812,12 +812,15 @@ public class Parser { ...@@ -812,12 +812,15 @@ public class Parser {
buff.append("C.COLUMN_NAME FIELD, " + buff.append("C.COLUMN_NAME FIELD, " +
"C.TYPE_NAME || '(' || C.NUMERIC_PRECISION || ')' TYPE, " + "C.TYPE_NAME || '(' || C.NUMERIC_PRECISION || ')' TYPE, " +
"C.IS_NULLABLE \"NULL\", " + "C.IS_NULLABLE \"NULL\", " +
"CASE I.INDEX_TYPE_NAME WHEN 'PRIMARY KEY' THEN 'PRI' WHEN 'UNIQUE INDEX' THEN 'UNI' ELSE '' END KEY, " + "CASE (SELECT MAX(I.INDEX_TYPE_NAME) FROM " +
"IFNULL(COLUMN_DEFAULT, 'NULL') DEFAULT " + "INFORMATION_SCHEMA.INDEXES I " +
"FROM INFORMATION_SCHEMA.COLUMNS C LEFT OUTER JOIN INFORMATION_SCHEMA.INDEXES I " + "WHERE I.TABLE_SCHEMA=C.TABLE_SCHEMA " +
"ON I.TABLE_SCHEMA=C.TABLE_SCHEMA " +
"AND I.TABLE_NAME=C.TABLE_NAME " + "AND I.TABLE_NAME=C.TABLE_NAME " +
"AND I.COLUMN_NAME=C.COLUMN_NAME " + "AND I.COLUMN_NAME=C.COLUMN_NAME)" +
"WHEN 'PRIMARY KEY' THEN 'PRI' " +
"WHEN 'UNIQUE INDEX' THEN 'UNI' ELSE '' END KEY, " +
"IFNULL(COLUMN_DEFAULT, 'NULL') DEFAULT " +
"FROM INFORMATION_SCHEMA.COLUMNS C " +
"WHERE C.TABLE_NAME=? AND C.TABLE_SCHEMA=? " + "WHERE C.TABLE_NAME=? AND C.TABLE_SCHEMA=? " +
"ORDER BY C.ORDINAL_POSITION"); "ORDER BY C.ORDINAL_POSITION");
paramValues.add(ValueString.get(schema)); paramValues.add(ValueString.get(schema));
......
--- special grammar and test cases --------------------------------------------------------------------------------------------- --- special grammar and test cases ---------------------------------------------------------------------------------------------
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
drop table test;
> ok
create table a(a int) as select 1; create table a(a int) as select 1;
> ok > ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论