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

Documentation.

上级 37dddac6
......@@ -11,6 +11,7 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.table.Column;
import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter;
......@@ -301,6 +302,7 @@ public abstract class Expression {
/**
* If this expression consists of column expressions it should return them.
*
* @param session the session
* @return array of expression columns if applicable, null otherwise
*/
public Expression[] getExpressionColumns(Session session) {
......@@ -332,24 +334,27 @@ public abstract class Expression {
* @param session the session
* @param rs the result set
* @return an array of expression columns
* @throws SQLException
*/
public static Expression[] getExpressionColumns(Session session, ResultSet rs) throws SQLException {
ResultSetMetaData meta = rs.getMetaData();
int columnCount = meta.getColumnCount();
Expression[] expressions = new Expression[columnCount];
Database db = session == null ? null : session.getDatabase();
for (int i = 0; i < columnCount; i++) {
String name = meta.getColumnLabel(i + 1);
int type = DataType.convertSQLTypeToValueType(meta.getColumnType(i + 1));
int precision = meta.getPrecision(i + 1);
int scale = meta.getScale(i + 1);
int displaySize = meta.getColumnDisplaySize(i + 1);
Column col = new Column(name, type, precision, scale, displaySize);
Expression expr = new ExpressionColumn(db, col);
expressions[i] = expr;
public static Expression[] getExpressionColumns(Session session, ResultSet rs) {
try {
ResultSetMetaData meta = rs.getMetaData();
int columnCount = meta.getColumnCount();
Expression[] expressions = new Expression[columnCount];
Database db = session == null ? null : session.getDatabase();
for (int i = 0; i < columnCount; i++) {
String name = meta.getColumnLabel(i + 1);
int type = DataType.convertSQLTypeToValueType(meta.getColumnType(i + 1));
int precision = meta.getPrecision(i + 1);
int scale = meta.getScale(i + 1);
int displaySize = meta.getColumnDisplaySize(i + 1);
Column col = new Column(name, type, precision, scale, displaySize);
Expression expr = new ExpressionColumn(db, col);
expressions[i] = expr;
}
return expressions;
} catch (SQLException e) {
throw DbException.convert(e);
}
return expressions;
}
}
......@@ -6,13 +6,11 @@
*/
package org.h2.expression;
import java.sql.SQLException;
import org.h2.command.Parser;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.engine.FunctionAlias;
import org.h2.engine.Session;
import org.h2.message.DbException;
import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter;
import org.h2.util.StatementBuilder;
......@@ -161,11 +159,7 @@ public class JavaFunction extends Expression implements FunctionCall {
switch (getType()) {
case Value.RESULT_SET:
ValueResultSet rs = getValueForColumnList(session, getArgs());
try {
return getExpressionColumns(session, rs.getResultSet());
} catch (SQLException e) {
throw DbException.convert(e);
}
return getExpressionColumns(session, rs.getResultSet());
case Value.ARRAY:
return getExpressionColumns(session, (ValueArray) getValue(session));
}
......
......@@ -6,7 +6,6 @@
*/
package org.h2.expression;
import java.sql.SQLException;
import java.util.ArrayList;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
......@@ -150,10 +149,7 @@ public class TableFunction extends Function {
}
public Expression[] getExpressionColumns(Session session) {
try {
return getExpressionColumns(session, getTable(session, getArgs(), true, false).getResultSet());
} catch (SQLException e) {
throw DbException.convert(e);
}
return getExpressionColumns(session, getTable(session, getArgs(), true, false).getResultSet());
}
}
......@@ -100,12 +100,21 @@ public class TestCallableStatement extends TestBase {
}
}
public static ResultSet testCall(Connection connect, int a, String b, Timestamp c) throws SQLException {
/**
* This method is called via reflection from the database.
*
* @param conn the connection
* @param a the value a
* @param b the value b
* @param c the value c
* @return a result set
*/
public static ResultSet testCall(Connection conn, int a, String b, Timestamp c) throws SQLException {
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("A", Types.INTEGER, 0, 0);
rs.addColumn("B", Types.VARCHAR, 0, 0);
rs.addColumn("C", Types.TIMESTAMP, 0, 0);
if ("jdbc:columnlist:connection".equals(connect.getMetaData().getURL())) {
if ("jdbc:columnlist:connection".equals(conn.getMetaData().getURL())) {
return rs;
}
rs.addRow(a * 2, b.toUpperCase(), new Timestamp(c.getTime() + 1));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论