package com.obidea.semantika.cli2.command;

import static java.lang.String.format;

import java.io.PrintStream;

import com.obidea.semantika.cli2.runtime.ConsoleSession;
import com.obidea.semantika.queryanswer.result.IQueryResult;

public class SelectCommand extends Command
{
   private String mCommand;
   private ConsoleSession mSession;

   public SelectCommand(String command, ConsoleSession session)
   {
      mCommand = command;
      mSession = session;
   }

   @Override
   public Object execute() throws Exception
   {
      String sparql = createSelectQuery();
      return mSession.getQueryEngine().evaluate(sparql);
   }

   private String createSelectQuery()
   {
      StringBuilder sb = new StringBuilder();
      for (String prefix : mSession.getPrefixMapper().keySet()) {
         sb.append(format("PREFIX %s: <%s>", prefix, mSession.getPrefixMapper().get(prefix)));
         sb.append("\n");
      }
      sb.append(mCommand);
      return sb.toString();
   }

   @Override
   public void printOutput(PrintStream out, Object output)
   {
      if (output instanceof IQueryResult) {
         IQueryResult result = (IQueryResult) output;
         out.println(result.toString());
      }
      out.println();
   }
}

@@ -1163,39 +1163,91 @@
     
-out.println(result.toString());
+while (result.next()) %7B%0A            out.println(result.getValueArray());%0A         %7D
 %0A   

Fix the result formatting.