// // Field.cs // // Provide definition for the Field class // Part of the C# bindings to MySQL library libMySQL.dll // // Author: // Brad Merrill // Daniel Morgan // // (C)Copyright 2002 Brad Merril // (C)Copyright 2002 Daniel Morgan // // http://www.cybercom.net/~zbrad/DotNet/MySql/ // // Mono has gotten permission from Brad Merrill to include in // the Mono Class Library // his C# bindings to MySQL under the X11 License // // Mono can be found at http://www.go-mono.com/ // The X11/MIT License can be found // at http://www.opensource.org/licenses/mit-license.html // // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // namespace Mono.Data.MySql { using System; using System.Runtime.InteropServices; [Flags] internal enum MySqlFieldFlags : uint { NOT_NULL_FLAG = 1, PRI_KEY_FLAG = 2, UNIQUE_KEY_FLAG = 4, MULTIPLE_KEY_FLAG = 8, BLOB_FLAG = 16, UNSIGNED_FLAG = 32, ZEROFILL_FLAG = 64, BINARY_FLAG = 128, ENUM_FLAG = 256, AUTO_INCREMENT_FLAG = 512, TIMESTAMP_FLAG = 1024, SET_FLAG = 2048, NUM_FLAG = 32768, PART_KEY_FLAG = 16384, GROUP_FLAG = 32768, UNIQUE_FLAG = 65536 } /// /// /// MySql P/Invoke implementation test program /// Brad Merrill /// 3-Mar-2002 /// /// /// This structure contains information about a field, such as the /// field's name, type, and size. Its members are described in more /// detail below. You may obtain the structures for /// each field by calling /// /// repeatedly. /// Field values are not part of this structure; /// they are contained in a Row structure. /// /// [StructLayout(LayoutKind.Sequential)] public class MySqlMarshalledField { ///name of column [MarshalAs(UnmanagedType.LPStr)] public string Name; ///table of column [MarshalAs(UnmanagedType.LPStr)] public string Table; ///default value [MarshalAs(UnmanagedType.LPStr)] public string Def; ///type of field public int FieldType; ///width of column public uint Length; ///max width of selected set public uint MaxLength; ///div flags public uint Flags; ///number of decimals in field public uint Decimals; } internal sealed class MySqlFieldHelper { public static bool IsPrimaryKey(uint fieldFlags) { // if ((SomeEnum)U & SomeEnum.EnumFlagValue) != 0) {...} if(! (((MySqlFieldFlags) fieldFlags) & MySqlFieldFlags.PRI_KEY_FLAG).Equals(0)) return true; else return false; } public static bool IsNotNull(uint fieldFlags) { if(! (((MySqlFieldFlags) fieldFlags) & MySqlFieldFlags.NOT_NULL_FLAG).Equals(0)) return true; else return false; } public static bool IsBlob(uint fieldFlags) { if(! (((MySqlFieldFlags) fieldFlags) & MySqlFieldFlags.BLOB_FLAG).Equals(0)) return true; else return false; } } }