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.

561 lines
15 KiB

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