main
 1using System.Collections.Generic;
 2using System.Data;
 3
 4namespace gorilla.migrations.data
 5{
 6    public class SqlDatabaseCommand : DatabaseCommand
 7    {
 8        readonly IDbConnection connection;
 9
10        public SqlDatabaseCommand(IDbConnection connection)
11        {
12            this.connection = connection;
13			this.connection.Open();
14        }
15
16        public IEnumerable<DataRow> run(string sql)
17        {
18            var table = new DataTable();
19            using (var command = connection.CreateCommand())
20            {
21                command.CommandText = sql;
22                command.CommandType = CommandType.Text;
23                table.Load( command.ExecuteReader());
24            }
25            foreach (DataRow row in table.Rows)
26            {
27                yield return row;
28            }
29        }
30
31        public void run(SqlFile sql)
32        {
33            using (var command = connection.CreateCommand())
34            {
35                command.CommandText = sql.raw_sql();
36                command.CommandType = CommandType.Text;
37                command.ExecuteNonQuery();
38            }
39        }
40
41        public void Dispose()
42        {
43            connection.Close();
44            connection.Dispose();
45        }
46    }
47}