You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

737 lines
26 KiB

2 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text.RegularExpressions;
  7. namespace SqlSugar
  8. {
  9. ///<summary>
  10. /// ** description:ActiveX Data Objects
  11. /// ** author:sunkaixuan
  12. /// ** date:2017/1/2
  13. /// ** email:610262374@qq.com
  14. /// </summary>
  15. public abstract partial class AdoProvider : AdoAccessory, IAdo
  16. {
  17. #region Constructor
  18. protected AdoProvider()
  19. {
  20. this.IsEnableLogEvent = false;
  21. this.CommandType = CommandType.Text;
  22. this.IsClearParameters = true;
  23. this.CommandTimeOut = 30000;
  24. }
  25. #endregion Constructor
  26. #region Properties
  27. protected List<IDataParameter> OutputParameters { get; set; }
  28. public virtual string SqlParameterKeyWord { get { return "@"; } }
  29. public IDbTransaction Transaction { get; set; }
  30. public virtual SqlSugarClient Context { get; set; }
  31. internal CommandType OldCommandType { get; set; }
  32. internal bool OldClearParameters { get; set; }
  33. public IDataParameterCollection DataReaderParameters { get; set; }
  34. public virtual IDbBind DbBind
  35. {
  36. get
  37. {
  38. if (base._DbBind == null)
  39. {
  40. var bind = InstanceFactory.GetDbBind(this.Context.CurrentConnectionConfig);
  41. base._DbBind = bind;
  42. bind.Context = this.Context;
  43. }
  44. return base._DbBind;
  45. }
  46. }
  47. public virtual int CommandTimeOut { get; set; }
  48. public virtual CommandType CommandType { get; set; }
  49. public virtual bool IsEnableLogEvent { get; set; }
  50. public virtual bool IsClearParameters { get; set; }
  51. public virtual Action<string, SugarParameter[]> LogEventStarting { get; set; }
  52. public virtual Action<string, SugarParameter[]> LogEventCompleted { get; set; }
  53. public virtual Func<string, SugarParameter[], KeyValuePair<string, SugarParameter[]>> ProcessingEventStartingSQL { get; set; }
  54. protected virtual Func<string, string> FormatSql { get; set; }
  55. public virtual Action<Exception> ErrorEvent { get; set; }
  56. public virtual List<IDbConnection> SlaveConnections { get; set; }
  57. public virtual IDbConnection MasterConnection { get; set; }
  58. #endregion Properties
  59. #region Connection
  60. public virtual void Open()
  61. {
  62. CheckConnection();
  63. }
  64. public virtual void Close()
  65. {
  66. if (this.Transaction != null)
  67. {
  68. this.Transaction = null;
  69. }
  70. if (this.Connection != null && this.Connection.State == ConnectionState.Open)
  71. {
  72. this.Connection.Close();
  73. }
  74. if (this.IsMasterSlaveSeparation && this.SlaveConnections.HasValue())
  75. {
  76. foreach (var slaveConnection in this.SlaveConnections)
  77. {
  78. if (slaveConnection != null && slaveConnection.State == ConnectionState.Open)
  79. {
  80. slaveConnection.Close();
  81. }
  82. }
  83. }
  84. }
  85. public virtual void Dispose()
  86. {
  87. if (this.Transaction != null)
  88. {
  89. this.Transaction.Commit();
  90. this.Transaction = null;
  91. }
  92. if (this.Connection != null && this.Connection.State != ConnectionState.Open)
  93. {
  94. this.Connection.Close();
  95. }
  96. if (this.Connection != null)
  97. {
  98. this.Connection.Dispose();
  99. }
  100. this.Connection = null;
  101. if (this.IsMasterSlaveSeparation)
  102. {
  103. foreach (var slaveConnection in this.SlaveConnections)
  104. {
  105. if (slaveConnection != null && slaveConnection.State == ConnectionState.Open)
  106. {
  107. slaveConnection.Dispose();
  108. }
  109. }
  110. }
  111. }
  112. public virtual void CheckConnection()
  113. {
  114. if (this.Connection.State != ConnectionState.Open)
  115. {
  116. try
  117. {
  118. this.Connection.Open();
  119. }
  120. catch (Exception ex)
  121. {
  122. Check.Exception(true, ErrorMessage.ConnnectionOpen, ex.Message);
  123. }
  124. }
  125. }
  126. #endregion Connection
  127. #region Transaction
  128. public virtual void BeginTran()
  129. {
  130. CheckConnection();
  131. this.Transaction = this.Connection.BeginTransaction();
  132. }
  133. public virtual void BeginTran(IsolationLevel iso)
  134. {
  135. CheckConnection();
  136. this.Transaction = this.Connection.BeginTransaction(iso);
  137. }
  138. public virtual void RollbackTran()
  139. {
  140. if (this.Transaction != null)
  141. {
  142. this.Transaction.Rollback();
  143. this.Transaction = null;
  144. if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection) this.Close();
  145. }
  146. }
  147. public virtual void CommitTran()
  148. {
  149. if (this.Transaction != null)
  150. {
  151. this.Transaction.Commit();
  152. this.Transaction = null;
  153. if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection) this.Close();
  154. }
  155. }
  156. #endregion Transaction
  157. #region abstract
  158. public abstract IDataParameter[] ToIDbDataParameter(params SugarParameter[] pars);
  159. public abstract void SetCommandToAdapter(IDataAdapter adapter, IDbCommand command);
  160. public abstract IDataAdapter GetAdapter();
  161. public abstract IDbCommand GetCommand(string sql, SugarParameter[] pars);
  162. public abstract IDbConnection Connection { get; set; }
  163. public abstract void BeginTran(string transactionName);//Only SqlServer
  164. public abstract void BeginTran(IsolationLevel iso, string transactionName);//Only SqlServer
  165. #endregion abstract
  166. #region Use
  167. public DbResult<bool> UseTran(Action action)
  168. {
  169. var result = new DbResult<bool>();
  170. try
  171. {
  172. this.BeginTran();
  173. action?.Invoke();
  174. this.CommitTran();
  175. result.Data = result.IsSuccess = true;
  176. }
  177. catch (Exception ex)
  178. {
  179. result.ErrorException = ex;
  180. result.ErrorMessage = ex.Message;
  181. result.IsSuccess = false;
  182. this.RollbackTran();
  183. }
  184. return result;
  185. }
  186. public DbResult<T> UseTran<T>(Func<T> action)
  187. {
  188. var result = new DbResult<T>();
  189. try
  190. {
  191. this.BeginTran();
  192. if (action != null)
  193. result.Data = action();
  194. this.CommitTran();
  195. result.IsSuccess = true;
  196. }
  197. catch (Exception ex)
  198. {
  199. result.ErrorException = ex;
  200. result.ErrorMessage = ex.Message;
  201. result.IsSuccess = false;
  202. this.RollbackTran();
  203. }
  204. return result;
  205. }
  206. public void UseStoredProcedure(Action action)
  207. {
  208. var oldCommandType = this.CommandType;
  209. this.CommandType = CommandType.StoredProcedure;
  210. this.IsClearParameters = false;
  211. action?.Invoke();
  212. this.CommandType = oldCommandType;
  213. this.IsClearParameters = true;
  214. }
  215. public T UseStoredProcedure<T>(Func<T> action)
  216. {
  217. var result = default(T);
  218. var oldCommandType = this.CommandType;
  219. this.CommandType = CommandType.StoredProcedure;
  220. this.IsClearParameters = false;
  221. if (action != null)
  222. {
  223. result = action();
  224. }
  225. this.CommandType = oldCommandType;
  226. this.IsClearParameters = true;
  227. return result;
  228. }
  229. public IAdo UseStoredProcedure()
  230. {
  231. this.OldCommandType = this.CommandType;
  232. this.OldClearParameters = this.IsClearParameters;
  233. this.CommandType = CommandType.StoredProcedure;
  234. this.IsClearParameters = false;
  235. return this;
  236. }
  237. #endregion Use
  238. #region Core
  239. public virtual int ExecuteCommand(string sql, params SugarParameter[] parameters)
  240. {
  241. try
  242. {
  243. if (FormatSql != null)
  244. sql = FormatSql(sql);
  245. SetConnectionStart(sql);
  246. if (this.ProcessingEventStartingSQL != null)
  247. ExecuteProcessingSQL(ref sql, parameters);
  248. ExecuteBefore(sql, parameters);
  249. var sqlCommand = GetCommand(sql, parameters);
  250. var count = sqlCommand.ExecuteNonQuery();
  251. if (this.IsClearParameters)
  252. sqlCommand.Parameters.Clear();
  253. ExecuteAfter(sql, parameters);
  254. return count;
  255. }
  256. catch (Exception ex)
  257. {
  258. ErrorEvent?.Invoke(ex);
  259. throw ex;
  260. }
  261. finally
  262. {
  263. if (this.IsAutoClose()) this.Close();
  264. SetConnectionEnd(sql);
  265. }
  266. }
  267. public virtual IDataReader GetDataReader(string sql, params SugarParameter[] parameters)
  268. {
  269. try
  270. {
  271. if (FormatSql != null)
  272. sql = FormatSql(sql);
  273. SetConnectionStart(sql);
  274. var isSp = this.CommandType == CommandType.StoredProcedure;
  275. if (this.ProcessingEventStartingSQL != null)
  276. ExecuteProcessingSQL(ref sql, parameters);
  277. ExecuteBefore(sql, parameters);
  278. var sqlCommand = GetCommand(sql, parameters);
  279. var sqlDataReader = sqlCommand.ExecuteReader(this.IsAutoClose() ? CommandBehavior.CloseConnection : CommandBehavior.Default);
  280. if (isSp)
  281. DataReaderParameters = sqlCommand.Parameters;
  282. if (this.IsClearParameters)
  283. sqlCommand.Parameters.Clear();
  284. ExecuteAfter(sql, parameters);
  285. SetConnectionEnd(sql);
  286. return sqlDataReader;
  287. }
  288. catch (Exception ex)
  289. {
  290. ErrorEvent?.Invoke(ex);
  291. throw ex;
  292. }
  293. }
  294. public virtual DataSet GetDataSetAll(string sql, params SugarParameter[] parameters)
  295. {
  296. try
  297. {
  298. if (FormatSql != null)
  299. sql = FormatSql(sql);
  300. SetConnectionStart(sql);
  301. if (this.ProcessingEventStartingSQL != null)
  302. ExecuteProcessingSQL(ref sql, parameters);
  303. ExecuteBefore(sql, parameters);
  304. var dataAdapter = this.GetAdapter();
  305. var sqlCommand = GetCommand(sql, parameters);
  306. this.SetCommandToAdapter(dataAdapter, sqlCommand);
  307. var ds = new DataSet();
  308. dataAdapter.Fill(ds);
  309. if (this.IsClearParameters)
  310. sqlCommand.Parameters.Clear();
  311. ExecuteAfter(sql, parameters);
  312. return ds;
  313. }
  314. catch (Exception ex)
  315. {
  316. ErrorEvent?.Invoke(ex);
  317. throw ex;
  318. }
  319. finally
  320. {
  321. if (this.IsAutoClose()) this.Close();
  322. SetConnectionEnd(sql);
  323. }
  324. }
  325. public virtual object GetScalar(string sql, params SugarParameter[] parameters)
  326. {
  327. try
  328. {
  329. if (FormatSql != null)
  330. sql = FormatSql(sql);
  331. SetConnectionStart(sql);
  332. if (this.ProcessingEventStartingSQL != null)
  333. ExecuteProcessingSQL(ref sql, parameters);
  334. ExecuteBefore(sql, parameters);
  335. var sqlCommand = GetCommand(sql, parameters);
  336. var scalar = sqlCommand.ExecuteScalar();
  337. //scalar = (scalar == null ? 0 : scalar);
  338. if (this.IsClearParameters)
  339. sqlCommand.Parameters.Clear();
  340. ExecuteAfter(sql, parameters);
  341. return scalar;
  342. }
  343. catch (Exception ex)
  344. {
  345. ErrorEvent?.Invoke(ex);
  346. throw ex;
  347. }
  348. finally
  349. {
  350. if (this.IsAutoClose()) this.Close();
  351. SetConnectionEnd(sql);
  352. }
  353. }
  354. #endregion Core
  355. #region Methods
  356. public virtual string GetString(string sql, object parameters)
  357. {
  358. return GetString(sql, this.GetParameters(parameters));
  359. }
  360. public virtual string GetString(string sql, params SugarParameter[] parameters)
  361. {
  362. return Convert.ToString(GetScalar(sql, parameters));
  363. }
  364. public virtual string GetString(string sql, List<SugarParameter> parameters)
  365. {
  366. return parameters == null ? GetString(sql) : GetString(sql, parameters.ToArray());
  367. }
  368. public virtual int GetInt(string sql, object parameters)
  369. {
  370. return GetInt(sql, this.GetParameters(parameters));
  371. }
  372. public virtual int GetInt(string sql, params SugarParameter[] parameters)
  373. {
  374. return GetScalar(sql, parameters).ObjToInt();
  375. }
  376. public virtual int GetInt(string sql, List<SugarParameter> parameters)
  377. {
  378. return parameters == null ? GetInt(sql) : GetInt(sql, parameters.ToArray());
  379. }
  380. public virtual Double GetDouble(string sql, object parameters)
  381. {
  382. return GetDouble(sql, this.GetParameters(parameters));
  383. }
  384. public virtual Double GetDouble(string sql, params SugarParameter[] parameters)
  385. {
  386. return GetScalar(sql, parameters).ObjToMoney();
  387. }
  388. public virtual Double GetDouble(string sql, List<SugarParameter> parameters)
  389. {
  390. return parameters == null ? GetDouble(sql) : GetDouble(sql, parameters.ToArray());
  391. }
  392. public virtual decimal GetDecimal(string sql, object parameters)
  393. {
  394. return GetDecimal(sql, this.GetParameters(parameters));
  395. }
  396. public virtual decimal GetDecimal(string sql, params SugarParameter[] parameters)
  397. {
  398. return GetScalar(sql, parameters).ObjToDecimal();
  399. }
  400. public virtual decimal GetDecimal(string sql, List<SugarParameter> parameters)
  401. {
  402. return parameters == null ? GetDecimal(sql) : GetDecimal(sql, parameters.ToArray());
  403. }
  404. public virtual DateTime GetDateTime(string sql, object parameters)
  405. {
  406. return GetDateTime(sql, this.GetParameters(parameters));
  407. }
  408. public virtual DateTime GetDateTime(string sql, params SugarParameter[] parameters)
  409. {
  410. return GetScalar(sql, parameters).ObjToDate();
  411. }
  412. public virtual DateTime GetDateTime(string sql, List<SugarParameter> parameters)
  413. {
  414. return parameters == null ? GetDateTime(sql) : GetDateTime(sql, parameters.ToArray());
  415. }
  416. public virtual List<T> SqlQuery<T>(string sql, object parameters = null)
  417. {
  418. var sugarParameters = this.GetParameters(parameters);
  419. return SqlQuery<T>(sql, sugarParameters);
  420. }
  421. public virtual List<T> SqlQuery<T>(string sql, params SugarParameter[] parameters)
  422. {
  423. this.Context.InitMppingInfo<T>();
  424. var builder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig);
  425. builder.SqlQueryBuilder.sql.Append(sql);
  426. if (parameters != null && parameters.Any())
  427. builder.SqlQueryBuilder.Parameters.AddRange(parameters);
  428. var dataReader = this.GetDataReader(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray());
  429. var result = this.DbBind.DataReaderToList<T>(typeof(T), dataReader);
  430. builder.SqlQueryBuilder.Clear();
  431. if (this.Context.Ado.DataReaderParameters != null)
  432. {
  433. foreach (IDataParameter item in this.Context.Ado.DataReaderParameters)
  434. {
  435. var parameter = parameters.FirstOrDefault(it => item.ParameterName.Substring(1) == it.ParameterName.Substring(1));
  436. if (parameter != null)
  437. {
  438. parameter.Value = item.Value;
  439. }
  440. }
  441. this.Context.Ado.DataReaderParameters = null;
  442. }
  443. return result;
  444. }
  445. public virtual List<T> SqlQuery<T>(string sql, List<SugarParameter> parameters)
  446. {
  447. return parameters != null ? SqlQuery<T>(sql, parameters.ToArray()) : SqlQuery<T>(sql);
  448. }
  449. public virtual T SqlQuerySingle<T>(string sql, object parameters = null)
  450. {
  451. var result = SqlQuery<T>(sql, parameters);
  452. return result == null ? default(T) : result.FirstOrDefault();
  453. }
  454. public virtual T SqlQuerySingle<T>(string sql, params SugarParameter[] parameters)
  455. {
  456. var result = SqlQuery<T>(sql, parameters);
  457. return result == null ? default(T) : result.FirstOrDefault();
  458. }
  459. public virtual T SqlQuerySingle<T>(string sql, List<SugarParameter> parameters)
  460. {
  461. var result = SqlQuery<T>(sql, parameters);
  462. return result == null ? default(T) : result.FirstOrDefault();
  463. }
  464. public virtual dynamic SqlQueryDynamic(string sql, object parameters = null)
  465. {
  466. var dt = this.GetDataTable(sql, parameters);
  467. return dt == null ? null : this.Context.Utilities.DataTableToDynamic(dt);
  468. }
  469. public virtual dynamic SqlQueryDynamic(string sql, params SugarParameter[] parameters)
  470. {
  471. var dt = this.GetDataTable(sql, parameters);
  472. return dt == null ? null : this.Context.Utilities.DataTableToDynamic(dt);
  473. }
  474. public dynamic SqlQueryDynamic(string sql, List<SugarParameter> parameters)
  475. {
  476. var dt = this.GetDataTable(sql, parameters);
  477. return dt == null ? null : this.Context.Utilities.DataTableToDynamic(dt);
  478. }
  479. public virtual DataTable GetDataTable(string sql, params SugarParameter[] parameters)
  480. {
  481. var ds = GetDataSetAll(sql, parameters);
  482. if (ds.Tables.Count != 0 && ds.Tables.Count > 0) return ds.Tables[0];
  483. return new DataTable();
  484. }
  485. public virtual DataTable GetDataTable(string sql, object parameters)
  486. {
  487. return GetDataTable(sql, this.GetParameters(parameters));
  488. }
  489. public virtual DataTable GetDataTable(string sql, List<SugarParameter> parameters)
  490. {
  491. return parameters == null ? GetDataTable(sql) : GetDataTable(sql, parameters.ToArray());
  492. }
  493. public virtual DataSet GetDataSetAll(string sql, object parameters)
  494. {
  495. return GetDataSetAll(sql, this.GetParameters(parameters));
  496. }
  497. public virtual DataSet GetDataSetAll(string sql, List<SugarParameter> parameters)
  498. {
  499. return parameters == null ? GetDataSetAll(sql) : GetDataSetAll(sql, parameters.ToArray());
  500. }
  501. public virtual IDataReader GetDataReader(string sql, object parameters)
  502. {
  503. return GetDataReader(sql, this.GetParameters(parameters));
  504. }
  505. public virtual IDataReader GetDataReader(string sql, List<SugarParameter> parameters)
  506. {
  507. return parameters == null ? GetDataReader(sql) : GetDataReader(sql, parameters.ToArray());
  508. }
  509. public virtual object GetScalar(string sql, object parameters)
  510. {
  511. return GetScalar(sql, this.GetParameters(parameters));
  512. }
  513. public virtual object GetScalar(string sql, List<SugarParameter> parameters)
  514. {
  515. return parameters == null ? GetScalar(sql) : GetScalar(sql, parameters.ToArray());
  516. }
  517. public virtual int ExecuteCommand(string sql, object parameters)
  518. {
  519. return ExecuteCommand(sql, GetParameters(parameters));
  520. }
  521. public virtual int ExecuteCommand(string sql, List<SugarParameter> parameters)
  522. {
  523. return parameters == null ? ExecuteCommand(sql) : ExecuteCommand(sql, parameters.ToArray());
  524. }
  525. #endregion Methods
  526. #region Helper
  527. private void ExecuteProcessingSQL(ref string sql, SugarParameter[] parameters)
  528. {
  529. var result = this.ProcessingEventStartingSQL(sql, parameters);
  530. sql = result.Key;
  531. parameters = result.Value;
  532. }
  533. public virtual void ExecuteBefore(string sql, SugarParameter[] parameters)
  534. {
  535. if (this.IsEnableLogEvent)
  536. {
  537. var action = LogEventStarting;
  538. if (action != null)
  539. {
  540. if (parameters == null || parameters.Length == 0)
  541. {
  542. action(sql, new SugarParameter[] { });
  543. }
  544. else
  545. {
  546. action(sql, parameters);
  547. }
  548. }
  549. }
  550. }
  551. public virtual void ExecuteAfter(string sql, SugarParameter[] parameters)
  552. {
  553. var hasParameter = parameters.HasValue();
  554. if (hasParameter)
  555. {
  556. foreach (var outputParameter in parameters.Where(it => it.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput)))
  557. {
  558. var gobalOutputParamter = this.OutputParameters.Single(it => it.ParameterName == outputParameter.ParameterName);
  559. outputParameter.Value = gobalOutputParamter.Value;
  560. this.OutputParameters.Remove(gobalOutputParamter);
  561. }
  562. }
  563. if (this.IsEnableLogEvent)
  564. {
  565. var action = LogEventCompleted;
  566. if (action != null)
  567. {
  568. if (parameters == null || parameters.Length == 0)
  569. {
  570. action(sql, new SugarParameter[] { });
  571. }
  572. else
  573. {
  574. action(sql, parameters);
  575. }
  576. }
  577. }
  578. if (this.OldCommandType != 0)
  579. {
  580. this.CommandType = this.OldCommandType;
  581. this.IsClearParameters = this.OldClearParameters;
  582. this.OldCommandType = 0;
  583. this.OldClearParameters = false;
  584. }
  585. }
  586. public virtual SugarParameter[] GetParameters(object parameters, PropertyInfo[] propertyInfo = null)
  587. {
  588. if (parameters == null) return null;
  589. return base.GetParameters(parameters, propertyInfo, this.SqlParameterKeyWord);
  590. }
  591. private bool IsAutoClose()
  592. {
  593. return this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Transaction == null;
  594. }
  595. private bool IsMasterSlaveSeparation
  596. {
  597. get
  598. {
  599. return this.Context.CurrentConnectionConfig.SlaveConnectionConfigs.HasValue();
  600. }
  601. }
  602. private void SetConnectionStart(string sql)
  603. {
  604. if (this.Transaction == null && this.IsMasterSlaveSeparation && IsRead(sql))
  605. {
  606. if (this.MasterConnection == null)
  607. {
  608. this.MasterConnection = this.Connection;
  609. }
  610. var saves = this.Context.CurrentConnectionConfig.SlaveConnectionConfigs.Where(it => it.HitRate > 0).ToList();
  611. var currentIndex = UtilRandom.GetRandomIndex(saves.ToDictionary(it => saves.ToList().IndexOf(it), it => it.HitRate));
  612. var currentSaveConnection = saves[currentIndex];
  613. this.Connection = null;
  614. this.Context.CurrentConnectionConfig.ConnectionString = currentSaveConnection.ConnectionString;
  615. this.Connection = this.Connection;
  616. if (this.SlaveConnections.IsNullOrEmpty() || !this.SlaveConnections.Any(it => EqualsConnectionString(it.ConnectionString, this.Connection.ConnectionString)))
  617. {
  618. if (this.SlaveConnections == null) this.SlaveConnections = new List<IDbConnection>();
  619. this.SlaveConnections.Add(this.Connection);
  620. }
  621. }
  622. }
  623. private bool EqualsConnectionString(string connectionString1, string connectionString2)
  624. {
  625. var connectionString1Array = connectionString1.Split(';');
  626. var connectionString2Array = connectionString2.Split(';');
  627. var result = connectionString1Array.Except(connectionString2Array);
  628. return result.Count() == 0;
  629. }
  630. private void SetConnectionEnd(string sql)
  631. {
  632. if (this.IsMasterSlaveSeparation && IsRead(sql) && this.Transaction == null)
  633. {
  634. this.Connection = this.MasterConnection;
  635. this.Context.CurrentConnectionConfig.ConnectionString = this.MasterConnection.ConnectionString;
  636. }
  637. }
  638. private bool IsRead(string sql)
  639. {
  640. var sqlLower = sql.ToLower();
  641. var result = Regex.IsMatch(sqlLower, "[ ]*select[ ]") && !Regex.IsMatch(sqlLower, "[ ]*insert[ ]|[ ]*update[ ]|[ ]*delete[ ]");
  642. return result;
  643. }
  644. #endregion Helper
  645. }
  646. }