1 5 package org.h2.command.dml; 6 7 import java.sql.SQLException ; 8 9 import org.h2.command.Prepared; 10 import org.h2.engine.Session; 11 import org.h2.expression.ExpressionColumn; 12 import org.h2.result.LocalResult; 13 import org.h2.table.Column; 14 import org.h2.util.ObjectArray; 15 import org.h2.value.Value; 16 import org.h2.value.ValueString; 17 18 public class ExplainPlan extends Prepared { 19 20 private Prepared command; 21 private LocalResult result; 22 23 public ExplainPlan(Session session) { 24 super(session); 25 } 26 27 public void setCommand(Prepared command) { 28 this.command = command; 29 } 30 31 public void prepare() throws SQLException { 32 command.prepare(); 33 } 34 35 public LocalResult query(int maxrows) throws SQLException { 36 ObjectArray expressions = new ObjectArray(); 38 Column column = new Column("PLAN", Value.STRING, 0, 0); 39 ExpressionColumn expr = new ExpressionColumn(session.getDatabase(), null, column); 40 expressions.add(expr); 41 result = new LocalResult(session, expressions, 1); 42 String plan = command.getPlan(); 43 add(plan); 44 result.done(); 45 return result; 46 } 47 48 private void add(String text) throws SQLException { 49 Value[] row = new Value[1]; 50 Value value = ValueString.get(text); 51 row[0] = value; 52 result.addRow(row); 53 } 54 55 public boolean isQuery() { 56 return true; 57 } 58 59 public boolean isTransactional() { 60 return true; 61 } 62 63 public boolean isReadOnly() { 64 return true; 65 } 66 } 67 | Popular Tags |