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.

99 lines
3.4 KiB

4 years ago
  1. #if MYSQL_6_10
  2. // Copyright ?2004, 2016 Oracle and/or its affiliates. All rights reserved.
  3. //
  4. // MySQL Connector/NET is licensed under the terms of the GPLv2
  5. // <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
  6. // MySQL Connectors. There are special exceptions to the terms and
  7. // conditions of the GPLv2 as it is applied to this software, see the
  8. // FLOSS License Exception
  9. // <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
  10. //
  11. // This program is free software; you can redistribute it and/or modify
  12. // it under the terms of the GNU General Public License as published
  13. // by the Free Software Foundation; version 2 of the License.
  14. //
  15. // This program is distributed in the hope that it will be useful, but
  16. // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  18. // for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License along
  21. // with this program; if not, write to the Free Software Foundation, Inc.,
  22. // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. using System;
  24. using Externals.MySql.Data.MySqlClient;
  25. namespace Externals.MySql.Data.Common
  26. {
  27. /// <summary>
  28. /// Summary description for Version.
  29. /// </summary>
  30. internal struct DBVersion
  31. {
  32. private readonly string _srcString;
  33. public DBVersion(string s, int major, int minor, int build)
  34. {
  35. Major = major;
  36. Minor = minor;
  37. Build = build;
  38. _srcString = s;
  39. IsEnterprise = s.ToLowerInvariant().Contains("-enterprise-");
  40. }
  41. public int Major { get; }
  42. public int Minor { get; }
  43. public int Build { get; }
  44. public bool IsEnterprise
  45. {
  46. get; private set;
  47. }
  48. public static DBVersion Parse(string versionString)
  49. {
  50. int start = 0;
  51. int index = versionString.IndexOf('.', start);
  52. if (index == -1)
  53. throw new MySqlException(Resources.BadVersionFormat);
  54. string val = versionString.Substring(start, index - start).Trim();
  55. int major = Convert.ToInt32(val, System.Globalization.NumberFormatInfo.InvariantInfo);
  56. start = index + 1;
  57. index = versionString.IndexOf('.', start);
  58. if (index == -1)
  59. throw new MySqlException(Resources.BadVersionFormat);
  60. val = versionString.Substring(start, index - start).Trim();
  61. int minor = Convert.ToInt32(val, System.Globalization.NumberFormatInfo.InvariantInfo);
  62. start = index + 1;
  63. int i = start;
  64. while (i < versionString.Length && Char.IsDigit(versionString, i))
  65. i++;
  66. val = versionString.Substring(start, i - start).Trim();
  67. int build = Convert.ToInt32(val, System.Globalization.NumberFormatInfo.InvariantInfo);
  68. return new DBVersion(versionString, major, minor, build);
  69. }
  70. public bool isAtLeast(int majorNum, int minorNum, int buildNum)
  71. {
  72. if (Major > majorNum) return true;
  73. if (Major == majorNum && Minor > minorNum) return true;
  74. if (Major == majorNum && Minor == minorNum && Build >= buildNum) return true;
  75. return false;
  76. }
  77. public override string ToString()
  78. {
  79. return _srcString;
  80. }
  81. }
  82. }
  83. #endif