package org.realityforge.sqlshell;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Logger;

public class SqlShell
{
  private Logger _logger;
  private Driver _driver;
  private String _database;
  private final Properties _dbProperties = new Properties();

  public Logger getLogger()
  {
    return _logger;
  }

  public void setLogger( final Logger logger )
  {
    _logger = logger;
  }

  public Driver getDriver()
  {
    return _driver;
  }

  public void setDriver( final Driver driver )
  {
    _driver = driver;
  }

  public String getDatabase()
  {
    return _database;
  }

  public void setDatabase( final String database )
  {
    _database = database;
  }

  public Properties getDbProperties()
  {
    return _dbProperties;
  }

  public List<Map<String, Object>> query( final String sql )
    throws Exception
  {
    final Connection connection = _driver.connect( _database, _dbProperties );

    final Statement statement = connection.createStatement();
    final ResultSet resultSet = statement.executeQuery( sql );

    final List<Map<String, Object>> results = toList( resultSet );

    connection.close();

    return results;
  }

  private List<Map<String, Object>> toList( final ResultSet resultSet )
    throws SQLException
  {
    final ResultSetMetaData md = resultSet.getMetaData();
    final int columns = md.getColumnCount();
    final ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
    while ( resultSet.next() )
    {
      final HashMap<String, Object> row = new HashMap<String, Object>();
      for ( int i = 1; i <= columns; ++i )
      {
        row.put( md.getColumnName( i ), resultSet.getObject( i ) );
      }
      list.add( row );
    }

    return list;
  }
}

@@ -331,41 +331,8 @@
 ies;
-%0Aimport java.util.logging.Logger;
 %0A%0Apu
@@ -336,16 +336,22 @@
 %0Apublic 
+final 
 class Sq
@@ -363,34 +363,8 @@
 l%0A%7B%0A
-  private Logger _logger;%0A
   pr
@@ -479,143 +479,8 @@
 );%0A%0A
-  public Logger getLogger()%0A  %7B%0A    return _logger;%0A  %7D%0A%0A  public void setLogger( final Logger logger )%0A  %7B%0A    _logger = logger;%0A  %7D%0A%0A
   pu
@@ -1240,16 +1240,345 @@
 s;%0A  %7D%0A%0A
+  public int execute( final String sql )%0A    throws Exception%0A  %7B%0A    final Connection connection = _driver.connect( _database, _dbProperties );%0A    try%0A    %7B%0A      final Statement statement = connection.createStatement();%0A      return statement.executeUpdate( sql );%0A    %7D%0A    finally%0A    %7B%0A      connection.close();%0A    %7D%0A  %7D%0A%0A
   privat

Add execute utility function