-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMysqlH.cs
80 lines (65 loc) · 1.91 KB
/
MysqlH.cs
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
public class MySqlH {
public string CS;
public bool ThrowExceptions { get; set; } = false;
public MySqlConnection Connection {
get => new MySqlConnection(CS);
}
public MySqlH(MySqlConnectionStringBuilder sb) {
CS = sb.ToString();
}
public MySqlH(string cs) {
CS = cs;
}
public void NonQuery(MySqlCommand command) {
Run((con) => {
command.Connection = con;
command.ExecuteNonQuery();
});
}
public void NonQuery(string a) {
Run(a, (command) => {
command.ExecuteNonQuery();
});
}
public void QueryR(MySqlCommand command, Action<MySqlDataReader> action) {
Run((con) => {
command.Connection = con;
var r = command.ExecuteReader();
action.Invoke(r);
});
}
public void QueryR(string q, Action<MySqlDataReader> action) {
QueryR(new MySqlCommand(q), action);
}
public void QueryRLoop(MySqlCommand c, Action<MySqlDataReader> action) {
QueryR(c, (r) => {
while (r.Read()) {
action.Invoke(r);
}
});
}
public void QueryRLoop(string c, Action<MySqlDataReader> action) {
MySqlCommand c1 = new MySqlCommand(c);
QueryRLoop(c1, action);
}
public string[] GetColumns (string table_name) {
var list = new List<string>();
QueryRLoop();
return list.ToArray();
}
private void Run(Action<MySqlConnection> action) {
using var connection = new MySqlConnection(CS);
connection.Open();
action(connection);
}
private void Run(string b, Action<MySqlCommand> a) {
Run((c) => {
var command = c.CreateCommand();
command.CommandText = b;
a.Invoke(command);
});
}
}