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.

107 lines
3.2 KiB

4 years ago
  1. #if MYSQL_6_9
  2. // Copyright (c) 2004-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
  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. using Externals.MySql.Data.MySqlClient.Properties;
  26. namespace Externals.MySql.Data.Common
  27. {
  28. /// <summary>
  29. /// Summary description for Version.
  30. /// </summary>
  31. internal struct DBVersion
  32. {
  33. private int major;
  34. private int minor;
  35. private int build;
  36. private string srcString;
  37. public DBVersion(string s, int major, int minor, int build)
  38. {
  39. this.major = major;
  40. this.minor = minor;
  41. this.build = build;
  42. srcString = s;
  43. }
  44. public int Major
  45. {
  46. get { return major; }
  47. }
  48. public int Minor
  49. {
  50. get { return minor; }
  51. }
  52. public int Build
  53. {
  54. get { return build; }
  55. }
  56. public static DBVersion Parse(string versionString)
  57. {
  58. int start = 0;
  59. int index = versionString.IndexOf('.', start);
  60. if (index == -1)
  61. throw new MySqlException(Resources.BadVersionFormat);
  62. string val = versionString.Substring(start, index - start).Trim();
  63. int major = Convert.ToInt32(val, System.Globalization.NumberFormatInfo.InvariantInfo);
  64. start = index + 1;
  65. index = versionString.IndexOf('.', start);
  66. if (index == -1)
  67. throw new MySqlException(Resources.BadVersionFormat);
  68. val = versionString.Substring(start, index - start).Trim();
  69. int minor = Convert.ToInt32(val, System.Globalization.NumberFormatInfo.InvariantInfo);
  70. start = index + 1;
  71. int i = start;
  72. while (i < versionString.Length && Char.IsDigit(versionString, i))
  73. i++;
  74. val = versionString.Substring(start, i - start).Trim();
  75. int build = Convert.ToInt32(val, System.Globalization.NumberFormatInfo.InvariantInfo);
  76. return new DBVersion(versionString, major, minor, build);
  77. }
  78. public bool isAtLeast(int majorNum, int minorNum, int buildNum)
  79. {
  80. if (major > majorNum) return true;
  81. if (major == majorNum && minor > minorNum) return true;
  82. if (major == majorNum && minor == minorNum && build >= buildNum) return true;
  83. return false;
  84. }
  85. public override string ToString()
  86. {
  87. return srcString;
  88. }
  89. }
  90. }
  91. #endif