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.

566 lines
17 KiB

4 years ago
  1. #if MYSQL_6_10
  2. // Copyright (c) 2004, 2019, 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 System.ComponentModel;
  25. using System.Globalization;
  26. using System.Reflection;
  27. namespace Externals.MySql.Data.MySqlClient
  28. {
  29. /// <summary>
  30. /// Summary description for ClientParam.
  31. /// </summary>
  32. [Flags]
  33. internal enum ClientFlags : ulong
  34. {
  35. LONG_PASSWORD = 1, // new more secure passwords
  36. FOUND_ROWS = 2, // found instead of affected rows
  37. LONG_FLAG = 4, // Get all column flags
  38. CONNECT_WITH_DB = 8, // One can specify db on connect
  39. NO_SCHEMA = 16, // Don't allow db.table.column
  40. COMPRESS = 32, // Client can use compression protocol
  41. ODBC = 64, // ODBC client
  42. LOCAL_FILES = 128, // Can use LOAD DATA LOCAL
  43. IGNORE_SPACE = 256, // Ignore spaces before '('
  44. PROTOCOL_41 = 512, // Support new 4.1 protocol
  45. INTERACTIVE = 1024, // This is an interactive client
  46. SSL = 2048, // Switch to SSL after handshake
  47. IGNORE_SIGPIPE = 4096, // IGNORE sigpipes
  48. TRANSACTIONS = 8192, // Client knows about transactions
  49. RESERVED = 16384, // old 4.1 protocol flag
  50. SECURE_CONNECTION = 32768, // new 4.1 authentication
  51. MULTI_STATEMENTS = 65536, // Allow multi-stmt support
  52. MULTI_RESULTS = 131072, // Allow multiple resultsets
  53. PS_MULTI_RESULTS = 1UL << 18, // allow multi results using PS protocol
  54. PLUGIN_AUTH = (1UL << 19), //Client supports plugin authentication
  55. CONNECT_ATTRS = (1UL << 20), // Allows client connection attributes
  56. CAN_HANDLE_EXPIRED_PASSWORD = (1UL << 22), // Support for password expiration > 5.6.6
  57. CLIENT_SSL_VERIFY_SERVER_CERT = (1UL << 30),
  58. CLIENT_REMEMBER_OPTIONS = (1UL << 31)
  59. }
  60. [Flags]
  61. internal enum ServerStatusFlags
  62. {
  63. InTransaction = 1, // Transaction has started
  64. AutoCommitMode = 2, // Server in auto_commit mode
  65. MoreResults = 4, // More results on server
  66. AnotherQuery = 8, // Multi query - next query exists
  67. BadIndex = 16,
  68. NoIndex = 32,
  69. CursorExists = 64,
  70. LastRowSent = 128,
  71. OutputParameters = 4096
  72. }
  73. /// <summary>
  74. /// DB Operations Code
  75. /// </summary>
  76. internal enum DBCmd : byte
  77. {
  78. SLEEP = 0,
  79. QUIT = 1,
  80. INIT_DB = 2,
  81. QUERY = 3,
  82. FIELD_LIST = 4,
  83. CREATE_DB = 5,
  84. DROP_DB = 6,
  85. RELOAD = 7,
  86. SHUTDOWN = 8,
  87. STATISTICS = 9,
  88. PROCESS_INFO = 10,
  89. CONNECT = 11,
  90. PROCESS_KILL = 12,
  91. DEBUG = 13,
  92. PING = 14,
  93. TIME = 15,
  94. DELAYED_INSERT = 16,
  95. CHANGE_USER = 17,
  96. BINLOG_DUMP = 18,
  97. TABLE_DUMP = 19,
  98. CONNECT_OUT = 20,
  99. REGISTER_SLAVE = 21,
  100. PREPARE = 22,
  101. EXECUTE = 23,
  102. LONG_DATA = 24,
  103. CLOSE_STMT = 25,
  104. RESET_STMT = 26,
  105. SET_OPTION = 27,
  106. FETCH = 28
  107. }
  108. /// <summary>
  109. /// Specifies MySQL specific data type of a field, property, for use in a <see cref="MySqlParameter"/>.
  110. /// </summary>
  111. internal enum MySqlDbType
  112. {
  113. /// <summary>
  114. /// <see cref="Decimal"/>
  115. /// <para>A fixed precision and scale numeric value between -1038
  116. /// -1 and 10 38 -1.</para>
  117. /// </summary>
  118. Decimal = 0,
  119. /// <summary>
  120. /// <see cref="Byte"/><para>The signed range is -128 to 127. The unsigned
  121. /// range is 0 to 255.</para>
  122. /// </summary>
  123. Byte = 1,
  124. /// <summary>
  125. /// <see cref="Int16"/><para>A 16-bit signed integer. The signed range is
  126. /// -32768 to 32767. The unsigned range is 0 to 65535</para>
  127. /// </summary>
  128. Int16 = 2,
  129. /// <summary>
  130. /// Specifies a 24 (3 byte) signed or unsigned value.
  131. /// </summary>
  132. Int24 = 9,
  133. /// <summary>
  134. /// <see cref="Int32"/><para>A 32-bit signed integer</para>
  135. /// </summary>
  136. Int32 = 3,
  137. /// <summary>
  138. /// <see cref="Int64"/><para>A 64-bit signed integer.</para>
  139. /// </summary>
  140. Int64 = 8,
  141. /// <summary>
  142. /// <see cref="Single"/><para>A small (single-precision) floating-point
  143. /// number. Allowable values are -3.402823466E+38 to -1.175494351E-38,
  144. /// 0, and 1.175494351E-38 to 3.402823466E+38.</para>
  145. /// </summary>
  146. Float = 4,
  147. /// <summary>
  148. /// <see cref="Double"/><para>A normal-size (double-precision)
  149. /// floating-point number. Allowable values are -1.7976931348623157E+308
  150. /// to -2.2250738585072014E-308, 0, and 2.2250738585072014E-308 to
  151. /// 1.7976931348623157E+308.</para>
  152. /// </summary>
  153. Double = 5,
  154. /// <summary>
  155. /// A timestamp. The range is '1970-01-01 00:00:00' to sometime in the
  156. /// year 2037
  157. /// </summary>
  158. Timestamp = 7,
  159. ///<summary>
  160. ///Date The supported range is '1000-01-01' to '9999-12-31'.
  161. ///</summary>
  162. Date = 10,
  163. /// <summary>
  164. /// Time <para>The range is '-838:59:59' to '838:59:59'.</para>
  165. /// </summary>
  166. Time = 11,
  167. ///<summary>
  168. ///DateTime The supported range is '1000-01-01 00:00:00' to
  169. ///'9999-12-31 23:59:59'.
  170. ///</summary>
  171. DateTime = 12,
  172. ///<summary>
  173. ///Datetime The supported range is '1000-01-01 00:00:00' to
  174. ///'9999-12-31 23:59:59'.
  175. ///</summary>
  176. [Obsolete("The Datetime enum value is obsolete. Please use DateTime.")]
  177. Datetime = 12,
  178. /// <summary>
  179. /// A year in 2- or 4-digit format (default is 4-digit). The
  180. /// allowable values are 1901 to 2155, 0000 in the 4-digit year
  181. /// format, and 1970-2069 if you use the 2-digit format (70-69).
  182. /// </summary>
  183. Year = 13,
  184. /// <summary>
  185. /// <b>Obsolete</b> Use Datetime or Date type
  186. /// </summary>
  187. Newdate = 14,
  188. /// <summary>
  189. /// A variable-length string containing 0 to 65535 characters
  190. /// </summary>
  191. VarString = 15,
  192. /// <summary>
  193. /// Bit-field data type
  194. /// </summary>
  195. Bit = 16,
  196. /// <summary>
  197. /// JSON
  198. /// </summary>
  199. JSON = 245,
  200. /// <summary>
  201. /// New Decimal
  202. /// </summary>
  203. NewDecimal = 246,
  204. /// <summary>
  205. /// An enumeration. A string object that can have only one value,
  206. /// chosen from the list of values 'value1', 'value2', ..., NULL
  207. /// or the special "" error value. An ENUM can have a maximum of
  208. /// 65535 distinct values
  209. /// </summary>
  210. Enum = 247,
  211. /// <summary>
  212. /// A set. A string object that can have zero or more values, each
  213. /// of which must be chosen from the list of values 'value1', 'value2',
  214. /// ... A SET can have a maximum of 64 members.
  215. /// </summary>
  216. Set = 248,
  217. /// <summary>
  218. /// A binary column with a maximum length of 255 (2^8 - 1)
  219. /// characters
  220. /// </summary>
  221. TinyBlob = 249,
  222. /// <summary>
  223. /// A binary column with a maximum length of 16777215 (2^24 - 1) bytes.
  224. /// </summary>
  225. MediumBlob = 250,
  226. /// <summary>
  227. /// A binary column with a maximum length of 4294967295 or
  228. /// 4G (2^32 - 1) bytes.
  229. /// </summary>
  230. LongBlob = 251,
  231. /// <summary>
  232. /// A binary column with a maximum length of 65535 (2^16 - 1) bytes.
  233. /// </summary>
  234. Blob = 252,
  235. /// <summary>
  236. /// A variable-length string containing 0 to 255 bytes.
  237. /// </summary>
  238. VarChar = 253,
  239. /// <summary>
  240. /// A fixed-length string.
  241. /// </summary>
  242. String = 254,
  243. /// <summary>
  244. /// Geometric (GIS) data type.
  245. /// </summary>
  246. Geometry = 255,
  247. /// <summary>
  248. /// Unsigned 8-bit value.
  249. /// </summary>
  250. UByte = 501,
  251. /// <summary>
  252. /// Unsigned 16-bit value.
  253. /// </summary>
  254. UInt16 = 502,
  255. /// <summary>
  256. /// Unsigned 24-bit value.
  257. /// </summary>
  258. UInt24 = 509,
  259. /// <summary>
  260. /// Unsigned 32-bit value.
  261. /// </summary>
  262. UInt32 = 503,
  263. /// <summary>
  264. /// Unsigned 64-bit value.
  265. /// </summary>
  266. UInt64 = 508,
  267. /// <summary>
  268. /// Fixed length binary string.
  269. /// </summary>
  270. Binary = 754,
  271. /// <summary>
  272. /// Variable length binary string.
  273. /// </summary>
  274. VarBinary = 753,
  275. /// <summary>
  276. /// A text column with a maximum length of 255 (2^8 - 1) characters.
  277. /// </summary>
  278. TinyText = 749,
  279. /// <summary>
  280. /// A text column with a maximum length of 16777215 (2^24 - 1) characters.
  281. /// </summary>
  282. MediumText = 750,
  283. /// <summary>
  284. /// A text column with a maximum length of 4294967295 or
  285. /// 4G (2^32 - 1) characters.
  286. /// </summary>
  287. LongText = 751,
  288. /// <summary>
  289. /// A text column with a maximum length of 65535 (2^16 - 1) characters.
  290. /// </summary>
  291. Text = 752,
  292. /// <summary>
  293. /// A guid column.
  294. /// </summary>
  295. Guid = 854
  296. };
  297. internal enum Field_Type : byte
  298. {
  299. DECIMAL = 0,
  300. BYTE = 1,
  301. SHORT = 2,
  302. LONG = 3,
  303. FLOAT = 4,
  304. DOUBLE = 5,
  305. NULL = 6,
  306. TIMESTAMP = 7,
  307. LONGLONG = 8,
  308. INT24 = 9,
  309. DATE = 10,
  310. TIME = 11,
  311. DATETIME = 12,
  312. YEAR = 13,
  313. NEWDATE = 14,
  314. ENUM = 247,
  315. SET = 248,
  316. TINY_BLOB = 249,
  317. MEDIUM_BLOB = 250,
  318. LONG_BLOB = 251,
  319. BLOB = 252,
  320. VAR_STRING = 253,
  321. STRING = 254,
  322. }
  323. /// <summary>
  324. /// Allows the user to specify the type of connection that should
  325. /// be used.
  326. /// </summary>
  327. internal enum MySqlConnectionProtocol
  328. {
  329. /// <summary>
  330. /// TCP/IP style connection. Works everywhere.
  331. /// </summary>
  332. Sockets = 1,
  333. /// <summary>
  334. /// TCP/IP style connection. Works everywhere.
  335. /// </summary>
  336. Socket = 1,
  337. /// <summary>
  338. /// TCP/IP style connection. Works everywhere.
  339. /// </summary>
  340. Tcp = 1,
  341. /// <summary>
  342. /// Named pipe connection. Works only on Windows systems.
  343. /// </summary>
  344. Pipe = 2,
  345. /// <summary>
  346. /// Named pipe connection. Works only on Windows systems.
  347. /// </summary>
  348. NamedPipe = 2,
  349. /// <summary>
  350. /// Unix domain socket connection. Works only with Unix systems.
  351. /// </summary>
  352. UnixSocket = 3,
  353. /// <summary>
  354. /// Unix domain socket connection. Works only with Unix systems.
  355. /// </summary>
  356. Unix = 3,
  357. /// <summary>
  358. /// Shared memory connection. Currently works only with Windows systems.
  359. /// </summary>
  360. SharedMemory = 4,
  361. /// <summary>
  362. /// Shared memory connection. Currently works only with Windows systems.
  363. /// </summary>
  364. Memory = 4
  365. }
  366. /// <summary>
  367. /// SSL options for connection.
  368. /// </summary>
  369. internal enum MySqlSslMode
  370. {
  371. /// <summary>
  372. /// Do not use SSL.
  373. /// </summary>
  374. None,
  375. /// <summary>
  376. /// Use SSL, if server supports it.
  377. /// </summary>
  378. Preferred,
  379. /// <summary>
  380. /// Use SSL, if server supports it.
  381. /// </summary>
  382. Prefered = Preferred,
  383. /// <summary>
  384. /// Always use SSL. Deny connection if server does not support SSL.
  385. /// Do not perform server certificate validation.
  386. /// This is the default SSL mode when not specified as part of the connection string.
  387. /// </summary>
  388. Required,
  389. /// <summary>
  390. /// Always use SSL. Validate server SSL certificate, but different host name mismatch.
  391. /// </summary>
  392. VerifyCA,
  393. /// <summary>
  394. /// Always use SSL and perform full certificate validation.
  395. /// </summary>
  396. VerifyFull
  397. }
  398. /// <summary>
  399. /// Specifies the connection types supported
  400. /// </summary>
  401. internal enum MySqlDriverType
  402. {
  403. /// <summary>
  404. /// Use TCP/IP sockets.
  405. /// </summary>
  406. Native,
  407. /// <summary>
  408. /// Use client library.
  409. /// </summary>
  410. Client,
  411. /// <summary>
  412. /// Use MySQL embedded server.
  413. /// </summary>
  414. Embedded
  415. }
  416. /// <summary>
  417. /// Defines the location of the certificate store.
  418. /// </summary>
  419. internal enum MySqlCertificateStoreLocation
  420. {
  421. /// <summary>
  422. /// Do not use certificate store.
  423. /// </summary>
  424. None,
  425. /// <summary>
  426. /// Use certificate store for the current user.
  427. /// </summary>
  428. CurrentUser,
  429. /// <summary>
  430. /// User certificate store for the machine.
  431. /// </summary>
  432. LocalMachine
  433. }
  434. internal class MySqlConnectAttrs
  435. {
  436. static string _version;
  437. static string _os;
  438. static string _platform;
  439. static MySqlConnectAttrs()
  440. {
  441. InitVersion();
  442. InitOS();
  443. InitPlatform();
  444. }
  445. [DisplayName("_client_name")]
  446. public string ClientName => "MySql Connector/NET";
  447. [DisplayName("_pid")]
  448. public string PID
  449. {
  450. get
  451. {
  452. string pid = string.Empty;
  453. try
  454. {
  455. pid = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture);
  456. }
  457. catch (Exception ex)
  458. {
  459. System.Diagnostics.Debug.WriteLine(ex.ToString());
  460. }
  461. return pid;
  462. }
  463. }
  464. [DisplayName("_client_version")]
  465. public string ClientVersion
  466. {
  467. get { return _version; }
  468. }
  469. [DisplayName("_os")]
  470. public string OS
  471. {
  472. get { return _os; }
  473. }
  474. [DisplayName("_thread")]
  475. public string Thread
  476. {
  477. get
  478. {
  479. string thread = string.Empty;
  480. try
  481. {
  482. thread = System.Diagnostics.Process.GetCurrentProcess().Threads[0].Id.ToString(CultureInfo.InvariantCulture);
  483. }
  484. catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); }
  485. return thread;
  486. }
  487. }
  488. [DisplayName("_platform")]
  489. public string Platform
  490. {
  491. get { return _platform; }
  492. }
  493. private static void InitVersion()
  494. {
  495. _version = string.Empty;
  496. try
  497. {
  498. _version = typeof(MySqlConnectAttrs).GetTypeInfo().Assembly.GetName().Version.ToString();
  499. }
  500. catch (Exception ex)
  501. {
  502. System.Diagnostics.Debug.WriteLine(ex.ToString());
  503. }
  504. }
  505. private static void InitOS()
  506. {
  507. _os = string.Empty;
  508. try
  509. {
  510. if (Externals.MySql.Data.Common.Platform.IsDotNetCore())
  511. {
  512. _os = ".Net Core";
  513. }
  514. _os = Environment.OSVersion.Platform.ToString();
  515. if (_os == "Win32NT")
  516. {
  517. _os = "Win";
  518. _os += Is64BitOS() ? "64" : "32";
  519. }
  520. }
  521. catch (Exception ex)
  522. {
  523. System.Diagnostics.Debug.WriteLine(ex.ToString());
  524. }
  525. }
  526. private static void InitPlatform()
  527. {
  528. _platform = Is64BitOS() ? "x86_64" : "x86_32";
  529. }
  530. private static bool Is64BitOS()
  531. {
  532. return Environment.Is64BitOperatingSystem;
  533. // return Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") == "AMD64";
  534. }
  535. }
  536. }
  537. #endif