forked from cyq1162/cyqdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMySQLDal.cs
86 lines (82 loc) · 2.54 KB
/
MySQLDal.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
using System.Data;
using System.Data.Common;
using CYQ.Data.Cache;
using System.Reflection;
using System.Collections.Generic;
using System;
using System.IO;
namespace CYQ.Data
{
internal class MySQLDal : DbBase
{
private CacheManage _Cache = CacheManage.LocalInstance;//Cache操作
public MySQLDal(ConnObject co)
: base(co)
{
}
public override void AddReturnPara()
{
}
internal static Assembly GetAssembly()
{
object ass = CacheManage.LocalInstance.Get("MySqlClient_Assembly");
if (ass == null)
{
try
{
ass = Assembly.Load("MySql.Data");
CacheManage.LocalInstance.Set("MySqlClient_Assembly", 10080);
}
catch(Exception err)
{
string errMsg = err.Message;
if (!File.Exists(AppConst.RunFolderPath + "MySql.Data.dll"))
{
errMsg = "Can't find the MySql.Data.dll more info : " + errMsg;
}
Error.Throw(errMsg);
}
}
return ass as Assembly;
}
protected override DbProviderFactory GetFactory(string providerName)
{
object factory = _Cache.Get("MySqlClient_Factory");
if (factory == null)
{
Assembly ass = GetAssembly();
factory = ass.CreateInstance("MySql.Data.MySqlClient.MySqlClientFactory");
if (factory == null)
{
throw new System.Exception("Can't Create MySqlClientFactory in MySql.Data.dll");
}
else
{
_Cache.Set("MySqlClient_Factory", factory, 10080);
}
}
return factory as DbProviderFactory;
}
protected override bool IsExistsDbName(string dbName)
{
try
{
IsAllowRecordSql = false;
bool result = ExeScalar("show databases like '" + dbName + "'", false) != null;
IsAllowRecordSql = true;
return result;
}
catch
{
return true;
}
}
public override char Pre
{
get
{
return '?';
}
}
}
}