if (updateStmt.getReturningList() != null)
throw JDBCException.wrapped("Statement already has RETURNING");
addAutoGeneratedReturning(updateStmt, autoGeneratedKeys);
}
PlanContext planContext = new ServerPlanContext(this, context);
BasePlannable result = compile(sqlStmt, sqlParams, planContext);
Operator resultOperator = (Operator)result.getPlannable();
JDBCResultSetMetaData resultSetMetaData = null;
if (!result.isUpdate() || ((PhysicalUpdate)result).isReturning()) {
List<ResultColumn> columns = new ArrayList<>();
for (PhysicalResultColumn column : result.getResultColumns()) {
columns.add((ResultColumn)column);
}
resultSetMetaData = new JDBCResultSetMetaData(getTypesTranslator(), columns);
}
JDBCParameterMetaData parameterMetaData = null;
if (result.getParameterTypes() != null) {
List<ParameterType> jdbcParams = new ArrayList<>();
for (BasePlannable.ParameterType paramType : result.getParameterTypes()) {
int jdbcType = Types.OTHER;
DataTypeDescriptor sqlType = paramType.getSQLType();
TInstance type = paramType.getType();
if (type != null) {
jdbcType = TInstance.tClass(type).jdbcType();
}
else if (sqlType != null) {
jdbcType = sqlType.getJDBCTypeId();
}
jdbcParams.add(new ParameterType(sqlType, jdbcType, type));
}
parameterMetaData = new JDBCParameterMetaData(getTypesTranslator(), jdbcParams);
if (getParameterNames) {
// TODO: Only case through here will be ? = CALL fun(?,?,...),
// which will look like SELECT fun(...).
}
}
if (result.isUpdate())
return new ExecutableModifyOperatorStatement(getSchema(),
resultOperator,
resultSetMetaData,
parameterMetaData);
else
return new ExecutableQueryOperatorStatement(getSchema(),
resultOperator,
resultSetMetaData,
parameterMetaData,
result.getCostEstimate());
}