提交 b514ec22 authored 作者: Thomas Mueller's avatar Thomas Mueller

New system table INFORMATION_SCHEMA.SESSION_STATE.

上级 f35a2f43
...@@ -94,7 +94,8 @@ public class MetaTable extends Table { ...@@ -94,7 +94,8 @@ public class MetaTable extends Table {
private static final int TRIGGERS = 24; private static final int TRIGGERS = 24;
private static final int SESSIONS = 25; private static final int SESSIONS = 25;
private static final int LOCKS = 26; private static final int LOCKS = 26;
private static final int META_TABLE_TYPE_COUNT = LOCKS + 1; private static final int SESSION_STATE = 27;
private static final int META_TABLE_TYPE_COUNT = SESSION_STATE + 1;
private final int type; private final int type;
private final int indexColumn; private final int indexColumn;
...@@ -486,6 +487,14 @@ public class MetaTable extends Table { ...@@ -486,6 +487,14 @@ public class MetaTable extends Table {
}); });
break; break;
} }
case SESSION_STATE: {
setObjectName("SESSION_STATE");
cols = createColumns(new String[]{
"KEY",
"SQL",
});
break;
}
default: default:
throw Message.getInternalError("type="+type); throw Message.getInternalError("type="+type);
} }
...@@ -1532,6 +1541,56 @@ public class MetaTable extends Table { ...@@ -1532,6 +1541,56 @@ public class MetaTable extends Table {
} }
break; break;
} }
case SESSION_STATE: {
String[] variableNames = session.getVariableNames();
for (int i = 0; i < variableNames.length; i++) {
String name = variableNames[i];
Value v = session.getVariable(name);
add(rows, new String[] {
// KEY
"@" + name,
// SQL
"SET @" + name + " " + v.getSQL()
});
}
ObjectArray tables = session.getLocalTempTables();
for (int i = 0; i < tables.size(); i++) {
Table table = (Table) tables.get(i);
add(rows, new String[] {
// KEY
"TABLE " + table.getName(),
// SQL
table.getCreateSQL()
});
}
String[] path = session.getSchemaSearchPath();
if (path != null && path.length > 0) {
StringBuffer buff = new StringBuffer();
buff.append("SET SCHEMA_SEARCH_PATH ");
for (int i = 0; i < path.length; i++) {
if (i > 0) {
buff.append(", ");
}
buff.append(StringUtils.quoteIdentifier(path[i]));
}
add(rows, new String[] {
// KEY
"SCHEMA_SEARCH_PATH",
// SQL
buff.toString()
});
}
String schema = session.getCurrentSchemaName();
if (schema != null) {
add(rows, new String[] {
// KEY
"SCHEMA",
// SQL
"SET SCHEMA " + StringUtils.quoteIdentifier(schema)
});
}
break;
}
default: default:
throw Message.getInternalError("type="+type); throw Message.getInternalError("type="+type);
} }
......
...@@ -29,6 +29,15 @@ public class TestMetaData extends TestBase { ...@@ -29,6 +29,15 @@ public class TestMetaData extends TestBase {
private Statement stat; private Statement stat;
private String catalog = "METADATA"; private String catalog = "METADATA";
/**
* Run just this test.
*
* @param a ignored
*/
public static void main(String[] a) throws Exception {
TestBase.createCaller().init().test();
}
public void test() throws SQLException { public void test() throws SQLException {
deleteDb("metaData"); deleteDb("metaData");
conn = getConnection("metaData"); conn = getConnection("metaData");
...@@ -119,6 +128,8 @@ public class TestMetaData extends TestBase { ...@@ -119,6 +128,8 @@ public class TestMetaData extends TestBase {
rs.next(); rs.next();
assertEquals("SESSIONS", rs.getString("TABLE_NAME")); assertEquals("SESSIONS", rs.getString("TABLE_NAME"));
rs.next(); rs.next();
assertEquals("SESSION_STATE", rs.getString("TABLE_NAME"));
rs.next();
assertEquals("SETTINGS", rs.getString("TABLE_NAME")); assertEquals("SETTINGS", rs.getString("TABLE_NAME"));
rs.next(); rs.next();
assertEquals("TABLES", rs.getString("TABLE_NAME")); assertEquals("TABLES", rs.getString("TABLE_NAME"));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论