4 // Provide definition for the Field class
5 // Part of the C# bindings to MySQL library libMySQL.dll
8 // Brad Merrill <zbrad@cybercom.net>
9 // Daniel Morgan <danmorg@sc.rr.com>
11 // (C)Copyright 2002 Brad Merril
12 // (C)Copyright 2002 Daniel Morgan
14 // http://www.cybercom.net/~zbrad/DotNet/MySql/
16 // Mono has gotten permission from Brad Merrill to include in
17 // the Mono Class Library
18 // his C# bindings to MySQL under the X11 License
20 // Mono can be found at http://www.go-mono.com/
21 // The X11/MIT License can be found
22 // at http://www.opensource.org/licenses/mit-license.html
26 // Permission is hereby granted, free of charge, to any person obtaining
27 // a copy of this software and associated documentation files (the
28 // "Software"), to deal in the Software without restriction, including
29 // without limitation the rights to use, copy, modify, merge, publish,
30 // distribute, sublicense, and/or sell copies of the Software, and to
31 // permit persons to whom the Software is furnished to do so, subject to
32 // the following conditions:
34 // The above copyright notice and this permission notice shall be
35 // included in all copies or substantial portions of the Software.
37 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
38 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
39 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
40 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
41 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
42 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
43 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
47 namespace Mono.Data.MySql {
49 using System.Runtime.InteropServices;
52 internal enum MySqlFieldFlags : uint {
56 MULTIPLE_KEY_FLAG = 8,
62 AUTO_INCREMENT_FLAG = 512,
63 TIMESTAMP_FLAG = 1024,
66 PART_KEY_FLAG = 16384,
73 /// MySql P/Invoke implementation test program
78 /// This structure contains information about a field, such as the
79 /// field's name, type, and size. Its members are described in more
80 /// detail below. You may obtain the <see cref="Field"/> structures for
81 /// each field by calling
82 /// <see cref="MySql.FetchField"/>
84 /// Field values are not part of this structure;
85 /// they are contained in a Row structure.
88 [StructLayout(LayoutKind.Sequential)]
89 public class MySqlMarshalledField {
91 ///<value>name of column</value>
92 [MarshalAs(UnmanagedType.LPStr)]
94 ///<value>table of column</value>
95 [MarshalAs(UnmanagedType.LPStr)]
97 ///<value>default value</value>
98 [MarshalAs(UnmanagedType.LPStr)]
100 ///<value>type of field</value>
101 public int FieldType;
102 ///<value>width of column</value>
104 ///<value>max width of selected set</value>
105 public uint MaxLength;
106 ///<value>div flags</value>
108 ///<value>number of decimals in field</value>
109 public uint Decimals;
112 internal sealed class MySqlFieldHelper {
114 public static bool IsPrimaryKey(uint fieldFlags) {
115 // if ((SomeEnum)U & SomeEnum.EnumFlagValue) != 0) {...}
116 if(! (((MySqlFieldFlags) fieldFlags) & MySqlFieldFlags.PRI_KEY_FLAG).Equals(0))
122 public static bool IsNotNull(uint fieldFlags) {
124 if(! (((MySqlFieldFlags) fieldFlags) & MySqlFieldFlags.NOT_NULL_FLAG).Equals(0))
130 public static bool IsBlob(uint fieldFlags) {
132 if(! (((MySqlFieldFlags) fieldFlags) & MySqlFieldFlags.BLOB_FLAG).Equals(0))