-
Notifications
You must be signed in to change notification settings - Fork 0
/
MySqlServer.cs
49 lines (44 loc) · 1.24 KB
/
MySqlServer.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
using MySqlConnector;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OutlookToMariadb
{
public class MySqlServer
{
public MySqlConnectionStringBuilder ConnectionBuilder;
public MySqlServer(string server, string user, string password, string database)
{
ConnectionBuilder = new MySqlConnectionStringBuilder()
{
Server = server,
UserID = user,
Password = password,
Database = database,
};
}
public MySqlConnection Connect(bool async = false)
{
var res = new MySqlConnection(ConnectionBuilder.ConnectionString);
if (async)
res.OpenAsync();
else
res.Open();
return res;
}
public void TruncateTable(string name)
{
ExecNonQuery($"truncate table {name}");
}
public void ExecNonQuery(string sql)
{
var conn = Connect();
var cmd = conn.CreateCommand();
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
conn.Close();
}
}
}