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