PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/MySqlBackup.NET/MySqlBackup/MySqlObjects/MySqlFunctionList.cs

http://mysqlbackupnet.codeplex.com
C# | 97 lines | 85 code | 12 blank | 0 comment | 7 complexity | f96c978e593af58284596ba33d26d246 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. namespace MySql.Data.MySqlClient
  6. {
  7. public class MySqlFunctionList : IDisposable
  8. {
  9. List<MySqlFunction> _lst = new List<MySqlFunction>();
  10. string _sqlShowFunctions = "";
  11. bool _allowAccess = true;
  12. public bool AllowAccess { get { return _allowAccess; } }
  13. public string SqlShowFunctions { get { return _sqlShowFunctions; } }
  14. public MySqlFunctionList()
  15. { }
  16. public MySqlFunctionList(MySqlCommand cmd)
  17. {
  18. try
  19. {
  20. string dbname = QueryExpress.ExecuteScalarStr(cmd, "SELECT DATABASE();");
  21. _sqlShowFunctions = string.Format("SHOW FUNCTION STATUS WHERE UPPER(TRIM(Db))= UPPER(TRIM('{0}'));", dbname);
  22. DataTable dt = QueryExpress.GetTable(cmd, _sqlShowFunctions);
  23. foreach (DataRow dr in dt.Rows)
  24. {
  25. _lst.Add(new MySqlFunction(cmd, dr["Name"] + "", dr["Definer"] + ""));
  26. }
  27. }
  28. catch (MySqlException myEx)
  29. {
  30. if (myEx.Message.ToLower().Contains("access denied"))
  31. _allowAccess = false;
  32. }
  33. catch
  34. {
  35. throw;
  36. }
  37. }
  38. public MySqlFunction this[int functionIndex]
  39. {
  40. get
  41. {
  42. return _lst[functionIndex];
  43. }
  44. }
  45. public MySqlFunction this[string functionName]
  46. {
  47. get
  48. {
  49. for (int i = 0; i < _lst.Count; i++)
  50. {
  51. if (_lst[i].Name == functionName)
  52. {
  53. return _lst[i];
  54. }
  55. }
  56. throw new Exception("Function \"" + functionName + "\" is not existed.");
  57. }
  58. }
  59. public int Count
  60. {
  61. get
  62. {
  63. return _lst.Count;
  64. }
  65. }
  66. public bool Contains(string functionName)
  67. {
  68. if (this[functionName] == null)
  69. return false;
  70. return true;
  71. }
  72. public IEnumerator<MySqlFunction> GetEnumerator()
  73. {
  74. return _lst.GetEnumerator();
  75. }
  76. public void Dispose()
  77. {
  78. for (int i = 0; i < _lst.Count; i++)
  79. {
  80. _lst[i] = null;
  81. }
  82. _lst = null;
  83. }
  84. }
  85. }