-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMySqlDataConnection.cs
101 lines (89 loc) · 3.09 KB
/
MySqlDataConnection.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;
using MySql.Data.MySqlClient;
using FastReport.Data.ConnectionEditors;
using System.Data;
namespace FastReport.Data
{
public class MySqlDataConnection : DataConnectionBase
{
private void GetDBObjectNames(string name, List<string> list)
{
DataTable schema = null;
string databaseName = "";
DbConnection connection = GetConnection();
try
{
OpenConnection(connection);
MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder(ConnectionString);
schema = connection.GetSchema(name);
databaseName = builder.Database;
}
finally
{
DisposeConnection(connection);
}
foreach (DataRow row in schema.Rows)
{
if(String.IsNullOrEmpty(databaseName) || String.Compare(row["TABLE_SCHEMA"].ToString(), databaseName) == 0)
list.Add(row["TABLE_NAME"].ToString());
}
}
public override string[] GetTableNames()
{
List<string> list = new List<string>();
GetDBObjectNames("Tables", list);
GetDBObjectNames("Views", list);
return list.ToArray();
}
public override string QuoteIdentifier(string value, DbConnection connection)
{
return "`" + value + "`";
}
protected override string GetConnectionStringWithLoginInfo(string userName, string password)
{
MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder(ConnectionString);
builder.UserID = userName;
builder.Password = password;
return builder.ToString();
}
public override Type GetConnectionType()
{
return typeof(MySqlConnection);
}
public override DbDataAdapter GetAdapter(string selectCommand, DbConnection connection,
CommandParameterCollection parameters)
{
MySqlDataAdapter adapter = new MySqlDataAdapter(selectCommand, connection as MySqlConnection);
foreach (CommandParameter p in parameters)
{
MySqlParameter parameter = adapter.SelectCommand.Parameters.Add(p.Name, (MySqlDbType)p.DataType, p.Size);
parameter.Value = p.Value;
}
return adapter;
}
public override Type GetParameterType()
{
return typeof(MySqlDbType);
}
public override string GetConnectionId()
{
MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder(ConnectionString);
string info = "";
try
{
info = builder.Database;
}
catch
{
}
return "MySQL: " + info;
}
public override ConnectionEditorBase GetEditor()
{
return new MySqlConnectionEditor();
}
}
}