use of com.alibaba.druid.util.jdbc.ResultSetMetaDataBase.ColumnMetaData in project druid by alibaba.
the class MySqlMockExecuteHandlerImpl method executeQueryFromDual.
public ResultSet executeQueryFromDual(MockStatementBase statement, SQLSelectQueryBlock query) throws SQLException {
MockResultSet rs = statement.getConnection().getDriver().createMockResultSet(statement);
MockResultSetMetaData metaData = rs.getMockMetaData();
Object[] row = new Object[query.getSelectList().size()];
for (int i = 0, size = query.getSelectList().size(); i < size; ++i) {
ColumnMetaData column = new ColumnMetaData();
SQLSelectItem item = query.getSelectList().get(i);
SQLExpr expr = item.getExpr();
if (expr instanceof SQLIntegerExpr) {
row[i] = ((SQLNumericLiteralExpr) expr).getNumber();
column.setColumnType(Types.INTEGER);
} else if (expr instanceof SQLNumberExpr) {
row[i] = ((SQLNumericLiteralExpr) expr).getNumber();
column.setColumnType(Types.DECIMAL);
} else if (expr instanceof SQLCharExpr) {
row[i] = ((SQLCharExpr) expr).getText();
column.setColumnType(Types.VARCHAR);
} else if (expr instanceof SQLNCharExpr) {
row[i] = ((SQLNCharExpr) expr).getText();
column.setColumnType(Types.NVARCHAR);
} else if (expr instanceof SQLBooleanExpr) {
row[i] = ((SQLBooleanExpr) expr).getValue();
column.setColumnType(Types.NVARCHAR);
} else if (expr instanceof SQLNullExpr) {
row[i] = null;
} else if (expr instanceof SQLMethodInvokeExpr) {
SQLMethodInvokeExpr methodInvokeExpr = (SQLMethodInvokeExpr) expr;
if ("NOW".equalsIgnoreCase(methodInvokeExpr.getMethodName())) {
row[i] = new Timestamp(System.currentTimeMillis());
} else {
throw new SQLException("TODO");
}
} else if (expr instanceof SQLVariantRefExpr) {
SQLVariantRefExpr varExpr = (SQLVariantRefExpr) expr;
int varIndex = varExpr.getIndex();
if (statement instanceof MockPreparedStatement) {
MockPreparedStatement mockPstmt = (MockPreparedStatement) statement;
row[i] = mockPstmt.getParameters().get(varIndex);
} else {
row[i] = null;
}
} else {
row[i] = null;
}
metaData.getColumns().add(column);
}
rs.getRows().add(row);
return rs;
}
use of com.alibaba.druid.util.jdbc.ResultSetMetaDataBase.ColumnMetaData in project druid by alibaba.
the class MySqlMockExecuteHandlerImpl method showStatus.
public ResultSet showStatus(MockStatementBase statement) throws SQLException {
MockResultSet rs = new MockResultSet(statement);
MockResultSetMetaData metaData = rs.getMockMetaData();
Object[] row = new Object[] { "on" };
ColumnMetaData column = new ColumnMetaData();
column.setColumnType(Types.NVARCHAR);
metaData.getColumns().add(column);
rs.getRows().add(row);
return rs;
}
use of com.alibaba.druid.util.jdbc.ResultSetMetaDataBase.ColumnMetaData in project druid by alibaba.
the class MockResultSetMetaDataTest method test_resultSet_metadata.
public void test_resultSet_metadata() throws Exception {
MockResultSetMetaData meta = new MockResultSetMetaData();
Assert.assertTrue(meta.isWrapperFor(MockResultSetMetaData.class));
Assert.assertFalse(meta.isWrapperFor(BigDecimal.class));
Assert.assertTrue(meta.unwrap(MockResultSetMetaData.class) instanceof MockResultSetMetaData);
Assert.assertTrue(meta.unwrap(ResultSetMetaDataBase.class) instanceof MockResultSetMetaData);
Assert.assertTrue(meta.unwrap(ResultSetMetaData.class) instanceof MockResultSetMetaData);
Assert.assertTrue(meta.unwrap(null) == null);
Assert.assertTrue(meta.unwrap(java.sql.ResultSetMetaData.class) != null);
Assert.assertTrue(meta.unwrap(Object.class) != null);
Assert.assertTrue(meta.unwrap(Date.class) == null);
ColumnMetaData column = new ColumnMetaData();
meta.getColumns().add(column);
meta.isAutoIncrement(1);
meta.isCaseSensitive(1);
meta.isSearchable(1);
meta.isCurrency(1);
meta.isNullable(1);
meta.isSigned(1);
meta.getColumnDisplaySize(1);
meta.getColumnLabel(1);
meta.getSchemaName(1);
meta.getPrecision(1);
meta.getScale(1);
meta.getTableName(1);
meta.getCatalogName(1);
meta.getColumnTypeName(1);
meta.isReadOnly(1);
meta.isWritable(1);
meta.isDefinitelyWritable(1);
meta.getColumnClassName(1);
}
Aggregations