1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5
6 usingETLUtilityDAL.Interfaces;7 usingETLUtilityDAL.Enums;8 usingETLUtilityDAL.Common;9 usingMySql.Data.MySqlClient;10 usingSystem.Data;11 usingSystem.Collections.Specialized;12 usingSystem.IO;13
14 namespaceETLUtilityDAL.Implement15 {16 public classMySqlDBHelper : IDBHelper17 {18 private DatabaseType _dBVender =DatabaseType.MySql;19 private readonly string _tmpBasePath =AppDomain.CurrentDomain.BaseDirectory;20 private readonly string _tmpCSVFilePattern = "Temp\\{0}.csv"; //0表示文件名称
21 private string_dbName;22
23 publicMySqlDBHelper()24 {25 this._dbName = "";26 }27
28 public MySqlDBHelper(stringdbName)29 {30 this._dbName =dbName;31 }32
33 #region IDBHelper 成员
34
35 public int ExecNonQuery(string sqlText, CommandType cmdType, string[] paramNames, object[] paramValues)36 {37 int result = 0;38 using (MySqlConnection mySqlCon = GetConnection ())39 {40 MySqlCommand mySqlCmd = newMySqlCommand(sqlText, mySqlCon);41 mySqlCmd.CommandType =cmdType;42 try
43 {44 fillParameters(mySqlCmd, paramNames, paramValues);45 mySqlCon.Open();46 result =mySqlCmd.ExecuteNonQuery();47 }48 catch(MySqlException mse)49 {50 throwmse;51 }52 }53 return 0;54 }55
56 public T ExecScalar(string sqlText, CommandType cmdType, string[] paramNames, object[] paramValues)57 {58 T result = default(T);59 using (MySqlConnection mySqlCon = GetConnection())60 {61 MySqlCommand mySqlCmd = newMySqlCommand(sqlText, mySqlCon);62 mySqlCmd.CommandType =cmdType;63 try
64 {65 fillParameters(mySqlCmd, paramNames, paramValues);66 mySqlCon.Open();67 result = (T)Convert.ChangeType(mySqlCmd.ExecuteScalar(), typeof(T));68 }69 catch(MySqlException mse)70 {71 throwmse;72 }73 }74 returnresult;75 }76
77 public T ExecReader(string sqlText, CommandType cmdType, string