コード例 #1
0
        public MyCatGeometry(MyCatDbType type, byte[] val)
        {
            if (val == null)
            {
                throw new ArgumentNullException("val");
            }

            byte[] buffValue = new byte[val.Length];

            for (int i = 0; i < val.Length; i++)
            {
                buffValue[i] = val[i];
            }

            var xIndex = val.Length == GEOMETRY_LENGTH ? 9 : 5;
            var yIndex = val.Length == GEOMETRY_LENGTH ? 17 : 13;

            _valBinary = buffValue;
            _xValue    = BitConverter.ToDouble(val, xIndex);
            _yValue    = BitConverter.ToDouble(val, yIndex);
            this._srid = val.Length == GEOMETRY_LENGTH?BitConverter.ToInt32(val, 0) : 0;

            this._isNull = false;
            this._type   = type;
        }
コード例 #2
0
        internal MyCatGeometry(MyCatDbType type, Double xValue, Double yValue, int srid)
        {
            this._type      = type;
            this._xValue    = xValue;
            this._yValue    = yValue;
            this._isNull    = false;
            this._srid      = srid;
            this._valBinary = new byte[GEOMETRY_LENGTH];

            byte[] sridBinary = BitConverter.GetBytes(srid);

            for (int i = 0; i < sridBinary.Length; i++)
            {
                _valBinary[i] = sridBinary[i];
            }

            long xVal = BitConverter.DoubleToInt64Bits(xValue);
            long yVal = BitConverter.DoubleToInt64Bits(yValue);

            _valBinary[4] = 1;
            _valBinary[5] = 1;

            for (int i = 0; i < 8; i++)
            {
                _valBinary[i + 9] = (byte)(xVal & 0xff);
                xVal >>= 8;
            }

            for (int i = 0; i < 8; i++)
            {
                _valBinary[i + 17] = (byte)(yVal & 0xff);
                yVal >>= 8;
            }
        }
コード例 #3
0
 internal MyCatParameter(string name, MyCatDbType type, ParameterDirection dir, string col, DataRowVersion ver, object val)
     : this(name, type)
 {
     Direction     = dir;
     SourceColumn  = col;
     SourceVersion = ver;
     Value         = val;
 }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MyCatParameter"/> class with the parameter name, the <see cref="MyCatDbType"/>, the size, and the source column name.
        /// </summary>
        /// <param name="parameterName">The name of the parameter to map. </param>
        /// <param name="dbType">One of the <see cref="MyCatDbType"/> values. </param>
        /// <param name="size">The length of the parameter. </param>
        /// <param name="sourceColumn">The name of the source column. </param>
        public MyCatParameter(string parameterName, MyCatDbType dbType, int size, string sourceColumn) : this(parameterName, dbType)
        {
            Size         = size;
            Direction    = ParameterDirection.Input;
            SourceColumn = sourceColumn;
#if NET451
            SourceVersion = DataRowVersion.Current;
#endif
        }
コード例 #5
0
 internal MyCatGeometry(MyCatDbType type, bool isNull)
 {
     this._type   = type;
     isNull       = true;
     _xValue      = 0;
     _yValue      = 0;
     _srid        = 0;
     _valBinary   = null;
     this._isNull = isNull;
 }
コード例 #6
0
 internal MyCatDateTime(MyCatDbType type, DateTime val)
     : this(type, 0, 0, 0, 0, 0, 0, 0)
 {
     this.isNull = false;
     year        = val.Year;
     month       = val.Month;
     day         = val.Day;
     hour        = val.Hour;
     minute      = val.Minute;
     second      = val.Second;
     Microsecond = (int)(val.Ticks % 10000000) / 10;
 }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MyCatParameter"/> class with the parameter name, the type of the parameter, the size of the parameter, a <see cref="ParameterDirection"/>, the precision of the parameter, the scale of the parameter, the source column, a <see cref="DataRowVersion"/> to use, and the value of the parameter.
 /// </summary>
 /// <param name="parameterName">The name of the parameter to map. </param>
 /// <param name="dbType">One of the <see cref="MyCatDbType"/> values. </param>
 /// <param name="size">The length of the parameter. </param>
 /// <param name="direction">One of the <see cref="ParameterDirection"/> values. </param>
 /// <param name="isNullable">true if the value of the field can be null, otherwise false. </param>
 /// <param name="precision">The total number of digits to the left and right of the decimal point to which <see cref="MyCatParameter.Value"/> is resolved.</param>
 /// <param name="scale">The total number of decimal places to which <see cref="MyCatParameter.Value"/> is resolved. </param>
 /// <param name="sourceColumn">The name of the source column. </param>
 /// <param name="sourceVersion">One of the <see cref="DataRowVersion"/> values. </param>
 /// <param name="value">An <see cref="Object"/> that is the value of the <see cref="MyCatParameter"/>. </param>
 /// <exception cref="ArgumentException"/>
 public MyCatParameter(string parameterName, MyCatDbType dbType, int size, ParameterDirection direction,
                       bool isNullable, byte precision, byte scale, string sourceColumn,
                       DataRowVersion sourceVersion,
                       object value)
     : this(parameterName, dbType, size, sourceColumn)
 {
     Direction     = direction;
     SourceVersion = sourceVersion;
     IsNullable    = isNullable;
     Precision     = precision;
     Scale         = scale;
     Value         = value;
 }
コード例 #8
0
 /// <summary>
 /// Constructs a new <b>MyCatDateTime</b> object by copying the current value of the given object.
 /// </summary>
 /// <param name="mdt">The <b>MyCatDateTime</b> object to copy.</param>
 public MyCatDateTime(MyCatDateTime mdt)
 {
     year           = mdt.Year;
     month          = mdt.Month;
     day            = mdt.Day;
     hour           = mdt.Hour;
     minute         = mdt.Minute;
     second         = mdt.Second;
     microsecond    = 0;
     millisecond    = 0;
     type           = MyCatDbType.DateTime;
     isNull         = false;
     TimezoneOffset = 0;
 }
コード例 #9
0
 internal MyCatDateTime(MyCatDbType type, int year, int month, int day, int hour, int minute,
                        int second, int microsecond)
 {
     this.isNull         = false;
     this.type           = type;
     this.year           = year;
     this.month          = month;
     this.day            = day;
     this.hour           = hour;
     this.minute         = minute;
     this.second         = second;
     this.microsecond    = microsecond;
     this.millisecond    = this.microsecond / 1000;
     this.TimezoneOffset = 0;
 }
コード例 #10
0
        private void GetColumnData(MyCatField field)
        {
            stream.Encoding          = Encoding;
            packet                   = stream.ReadPacket();
            field.Encoding           = Encoding;
            field.CatalogName        = packet.ReadLenString();
            field.DatabaseName       = packet.ReadLenString();
            field.TableName          = packet.ReadLenString();
            field.RealTableName      = packet.ReadLenString();
            field.ColumnName         = packet.ReadLenString();
            field.OriginalColumnName = packet.ReadLenString();
            packet.ReadByte();
            field.CharacterSetIndex = packet.ReadInteger(2);
            field.ColumnLength      = packet.ReadInteger(4);
            MyCatDbType type = (MyCatDbType)packet.ReadByte();
            ColumnFlags colFlags;

            if ((connectionFlags & ClientFlags.LONG_FLAG) != 0)
            {
                colFlags = (ColumnFlags)packet.ReadInteger(2);
            }
            else
            {
                colFlags = (ColumnFlags)packet.ReadByte();
            }
            field.Scale = (byte)packet.ReadByte();

            if (packet.HasMoreData)
            {
                packet.ReadInteger(2); // reserved
            }

            if (type == MyCatDbType.Decimal || type == MyCatDbType.NewDecimal)
            {
                field.Precision = (byte)(field.ColumnLength - 2);
                if ((colFlags & ColumnFlags.UNSIGNED) != 0)
                {
                    field.Precision++;
                }
            }

            field.SetTypeAndFlags(type, colFlags);
        }
コード例 #11
0
        internal static void SetDSInfo(MyCatSchemaCollection sc)
        {
            string[] types = new string[] { "CHAR", "NCHAR", "VARCHAR", "NVARCHAR", "SET",
                                            "ENUM", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT" };
            MyCatDbType[] dbtype = new MyCatDbType[] { MyCatDbType.String, MyCatDbType.String,
                                                       MyCatDbType.VarChar, MyCatDbType.VarChar, MyCatDbType.Set, MyCatDbType.Enum,
                                                       MyCatDbType.TinyText, MyCatDbType.Text, MyCatDbType.MediumText,
                                                       MyCatDbType.LongText };

            // we use name indexing because this method will only be called
            // when GetSchema is called for the DataSourceInformation
            // collection and then it wil be cached.
            for (int x = 0; x < types.Length; x++)
            {
                MyCatSchemaRow row = sc.AddRow();
                row["TypeName"]              = types[x];
                row["ProviderDbType"]        = dbtype[x];
                row["ColumnSize"]            = 0;
                row["CreateFormat"]          = x < 4 ? types[x] + "({0})" : types[x];
                row["CreateParameters"]      = x < 4 ? "size" : null;
                row["DataType"]              = "System.String";
                row["IsAutoincrementable"]   = false;
                row["IsBestMatch"]           = true;
                row["IsCaseSensitive"]       = false;
                row["IsFixedLength"]         = false;
                row["IsFixedPrecisionScale"] = true;
                row["IsLong"]               = false;
                row["IsNullable"]           = true;
                row["IsSearchable"]         = true;
                row["IsSearchableWithLike"] = true;
                row["IsUnsigned"]           = false;
                row["MaximumScale"]         = 0;
                row["MinimumScale"]         = 0;
                row["IsConcurrencyType"]    = DBNull.Value;
                row["IsLiteralSupported"]   = false;
                row["LiteralPrefix"]        = null;
                row["LiteralSuffix"]        = null;
                row["NativeDataType"]       = null;
            }
        }
コード例 #12
0
        public static void SetDSInfo(MyCatSchemaCollection sc)
        {
            string[]      types  = new string[] { "BLOB", "TINYBLOB", "MEDIUMBLOB", "LONGBLOB", "BINARY", "VARBINARY" };
            MyCatDbType[] dbtype = new MyCatDbType[] { MyCatDbType.Blob,
                                                       MyCatDbType.TinyBlob, MyCatDbType.MediumBlob, MyCatDbType.LongBlob, MyCatDbType.Binary, MyCatDbType.VarBinary };
            long[]   sizes  = new long[] { 65535L, 255L, 16777215L, 4294967295L, 255L, 65535L };
            string[] format = new string[] { null, null, null, null, "binary({0})", "varbinary({0})" };
            string[] parms  = new string[] { null, null, null, null, "length", "length" };

            // we use name indexing because this method will only be called
            // when GetSchema is called for the DataSourceInformation
            // collection and then it wil be cached.
            for (int x = 0; x < types.Length; x++)
            {
                MyCatSchemaRow row = sc.AddRow();
                row["TypeName"]              = types[x];
                row["ProviderDbType"]        = dbtype[x];
                row["ColumnSize"]            = sizes[x];
                row["CreateFormat"]          = format[x];
                row["CreateParameters"]      = parms[x];
                row["DataType"]              = "System.Byte[]";
                row["IsAutoincrementable"]   = false;
                row["IsBestMatch"]           = true;
                row["IsCaseSensitive"]       = false;
                row["IsFixedLength"]         = x < 4 ? false : true;
                row["IsFixedPrecisionScale"] = false;
                row["IsLong"]               = sizes[x] > 255;
                row["IsNullable"]           = true;
                row["IsSearchable"]         = false;
                row["IsSearchableWithLike"] = false;
                row["IsUnsigned"]           = DBNull.Value;
                row["MaximumScale"]         = DBNull.Value;
                row["MinimumScale"]         = DBNull.Value;
                row["IsConcurrencyType"]    = DBNull.Value;
                row["IsLiteralSupported"]   = false;
                row["LiteralPrefix"]        = "0x";
                row["LiteralSuffix"]        = DBNull.Value;
                row["NativeDataType"]       = DBNull.Value;
            }
        }
コード例 #13
0
        internal static void SetDSInfo(MyCatSchemaCollection sc)
        {
            string[]      types  = new string[] { "INT", "YEAR", "MEDIUMINT" };
            MyCatDbType[] dbtype = new MyCatDbType[] { MyCatDbType.Int32,
                                                       MyCatDbType.Year, MyCatDbType.Int24 };

            // we use name indexing because this method will only be called
            // when GetSchema is called for the DataSourceInformation
            // collection and then it wil be cached.
            for (int x = 0; x < types.Length; x++)
            {
                MyCatSchemaRow row = sc.AddRow();
                row["TypeName"]              = types[x];
                row["ProviderDbType"]        = dbtype[x];
                row["ColumnSize"]            = 0;
                row["CreateFormat"]          = types[x];
                row["CreateParameters"]      = null;
                row["DataType"]              = "System.Int32";
                row["IsAutoincrementable"]   = dbtype[x] == MyCatDbType.Year ? false : true;
                row["IsBestMatch"]           = true;
                row["IsCaseSensitive"]       = false;
                row["IsFixedLength"]         = true;
                row["IsFixedPrecisionScale"] = true;
                row["IsLong"]               = false;
                row["IsNullable"]           = true;
                row["IsSearchable"]         = true;
                row["IsSearchableWithLike"] = false;
                row["IsUnsigned"]           = false;
                row["MaximumScale"]         = 0;
                row["MinimumScale"]         = 0;
                row["IsConcurrencyType"]    = DBNull.Value;
                row["IsLiteralSupported"]   = false;
                row["LiteralPrefix"]        = null;
                row["LiteralSuffix"]        = null;
                row["NativeDataType"]       = null;
            }
        }
コード例 #14
0
 private void SetMyCatDbType(MyCatDbType mysql_dbtype)
 {
     mySqlDbType = mysql_dbtype;
     ValueObject = MyCatField.GetIMyCatValue(mySqlDbType);
     SetDbTypeFromMyCatDbType();
 }
コード例 #15
0
 public MyCatBinary(MyCatDbType type, bool isNull)
 {
     this.type   = type;
     this.isNull = isNull;
     mValue      = null;
 }
コード例 #16
0
 public MyCatBinary(MyCatDbType type, byte[] val)
 {
     this.type   = type;
     this.isNull = false;
     mValue      = val;
 }
コード例 #17
0
 public MyCatInt32(MyCatDbType type, int val)
     : this(type)
 {
     this.isNull = false;
     mValue      = val;
 }
コード例 #18
0
 public MyCatInt32(MyCatDbType type, bool isNull)
     : this(type)
 {
     this.isNull = isNull;
 }
コード例 #19
0
 private MyCatInt32(MyCatDbType type)
 {
     is24Bit = type == MyCatDbType.Int24 ? true : false;
     isNull  = true;
     mValue  = 0;
 }
コード例 #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MyCatParameter"/> class with the parameter name, the <see cref="MyCatDbType"/>, and the size.
 /// </summary>
 /// <param name="parameterName">The name of the parameter to map. </param>
 /// <param name="dbType">One of the <see cref="MyCatDbType"/> values. </param>
 /// <param name="size">The length of the parameter. </param>
 public MyCatParameter(string parameterName, MyCatDbType dbType, int size) : this(parameterName, dbType)
 {
     Size = size;
 }
コード例 #21
0
        public static IMyCatValue GetIMyCatValue(MyCatDbType type)
        {
            switch (type)
            {
            case MyCatDbType.Byte:
                return(new MyCatByte());

            case MyCatDbType.UByte:
                return(new MyCatUByte());

            case MyCatDbType.Int16:
                return(new MyCatInt16());

            case MyCatDbType.UInt16:
                return(new MyCatUInt16());

            case MyCatDbType.Int24:
            case MyCatDbType.Int32:
            case MyCatDbType.Year:
                return(new MyCatInt32(type, true));

            case MyCatDbType.UInt24:
            case MyCatDbType.UInt32:
                return(new MyCatUInt32(type, true));

            case MyCatDbType.Bit:
                return(new MyCatBit());

            case MyCatDbType.Int64:
                return(new MyCatInt64());

            case MyCatDbType.UInt64:
                return(new MyCatUInt64());

            case MyCatDbType.Time:
                return(new MyCatTimeSpan());

            case MyCatDbType.Date:
            case MyCatDbType.DateTime:
            case MyCatDbType.Newdate:
            case MyCatDbType.Timestamp:
                return(new MyCatDateTime(type, true));

            case MyCatDbType.Decimal:
            case MyCatDbType.NewDecimal:
                return(new MyCatDecimal());

            case MyCatDbType.Float:
                return(new MyCatSingle());

            case MyCatDbType.Double:
                return(new MyCatDouble());

            case MyCatDbType.Set:
            case MyCatDbType.Enum:
            case MyCatDbType.String:
            case MyCatDbType.VarString:
            case MyCatDbType.VarChar:
            case MyCatDbType.Text:
            case MyCatDbType.TinyText:
            case MyCatDbType.MediumText:
            case MyCatDbType.LongText:
            case (MyCatDbType)Field_Type.NULL:
                return(new MyCatString(type, true));

            case MyCatDbType.Geometry:
                return(new MyCatGeometry(type, true));

            case MyCatDbType.Blob:
            case MyCatDbType.MediumBlob:
            case MyCatDbType.LongBlob:
            case MyCatDbType.TinyBlob:
            case MyCatDbType.Binary:
            case MyCatDbType.VarBinary:
                return(new MyCatBinary(type, true));

            case MyCatDbType.Guid:
                return(new MyCatGuid());

            case MyCatDbType.JSON:
                return(new MyCatJson());

            default:
                throw new MyCatException("Unknown data type");
            }
        }
コード例 #22
0
 /// <summary>
 /// Adds a <see cref="MyCatParameter"/> to the <see cref="MyCatParameterCollection"/> given the parameter name and the data type.
 /// </summary>
 /// <param name="parameterName">The name of the parameter.</param>
 /// <param name="dbType">One of the <see cref="MyCatDbType"/> values. </param>
 /// <returns>The newly added <see cref="MyCatParameter"/> object.</returns>
 public MyCatParameter Add(string parameterName, MyCatDbType dbType)
 {
     return(Add(new MyCatParameter(parameterName, dbType)));
 }
コード例 #23
0
 public MyCatString(MyCatDbType type, bool isNull)
 {
     this.type   = type;
     this.isNull = isNull;
     mValue      = String.Empty;
 }
コード例 #24
0
 public MyCatString(MyCatDbType type, string val)
 {
     this.type   = type;
     this.isNull = false;
     mValue      = val;
 }
コード例 #25
0
 internal MyCatDateTime(MyCatDbType type, bool isNull)
     : this(type, 0, 0, 0, 0, 0, 0, 0)
 {
     this.isNull = isNull;
 }
コード例 #26
0
 /// <summary>
 /// Adds a <see cref="MyCatParameter"/> to the <see cref="MyCatParameterCollection"/> with the parameter name, the data type, the column length, and the source column name.
 /// </summary>
 /// <param name="parameterName">The name of the parameter.</param>
 /// <param name="dbType">One of the <see cref="MyCatDbType"/> values. </param>
 /// <param name="size">The length of the column.</param>
 /// <param name="sourceColumn">The name of the source column.</param>
 /// <returns>The newly added <see cref="MyCatParameter"/> object.</returns>
 public MyCatParameter Add(string parameterName, MyCatDbType dbType, int size, string sourceColumn)
 {
     return(Add(new MyCatParameter(parameterName, dbType, size, sourceColumn)));
 }
コード例 #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MyCatParameter"/> class with the parameter name and the data type.
 /// </summary>
 /// <param name="parameterName">The name of the parameter to map. </param>
 /// <param name="dbType">One of the <see cref="MyCatDbType"/> values. </param>
 public MyCatParameter(string parameterName, MyCatDbType dbType) : this(parameterName, null)
 {
     MyCatDbType = dbType;
 }
コード例 #28
0
 internal MyCatTypeMapping([NotNull] string defaultTypeName, [NotNull] Type clrType, MyCatDbType storeType)
     : base(defaultTypeName, clrType)
 {
     StoreType = storeType;
 }
コード例 #29
0
        public void SetTypeAndFlags(MyCatDbType type, ColumnFlags flags)
        {
            colFlags    = flags;
            mySqlDbType = type;

            if (String.IsNullOrEmpty(TableName) && String.IsNullOrEmpty(RealTableName) &&
                IsBinary && driver.Settings.FunctionsReturnString)
            {
                CharacterSetIndex = driver.ConnectionCharSetIndex;
            }

            // if our type is an unsigned number, then we need
            // to bump it up into our unsigned types
            // we're trusting that the server is not going to set the UNSIGNED
            // flag unless we are a number
            if (IsUnsigned)
            {
                switch (type)
                {
                case MyCatDbType.Byte:
                    mySqlDbType = MyCatDbType.UByte;
                    return;

                case MyCatDbType.Int16:
                    mySqlDbType = MyCatDbType.UInt16;
                    return;

                case MyCatDbType.Int24:
                    mySqlDbType = MyCatDbType.UInt24;
                    return;

                case MyCatDbType.Int32:
                    mySqlDbType = MyCatDbType.UInt32;
                    return;

                case MyCatDbType.Int64:
                    mySqlDbType = MyCatDbType.UInt64;
                    return;
                }
            }

            if (IsBlob)
            {
                // handle blob to UTF8 conversion if requested.  This is only activated
                // on binary blobs
                if (IsBinary && driver.Settings.TreatBlobsAsUTF8)
                {
                    bool  convertBlob  = false;
                    Regex includeRegex = driver.Settings.GetBlobAsUTF8IncludeRegex();
                    Regex excludeRegex = driver.Settings.GetBlobAsUTF8ExcludeRegex();
                    if (includeRegex != null && includeRegex.IsMatch(ColumnName))
                    {
                        convertBlob = true;
                    }
                    else if (includeRegex == null && excludeRegex != null &&
                             !excludeRegex.IsMatch(ColumnName))
                    {
                        convertBlob = true;
                    }

                    if (convertBlob)
                    {
                        binaryOk     = false;
                        Encoding     = System.Text.Encoding.GetEncoding("UTF-8");
                        charSetIndex = -1; // lets driver know we are in charge of encoding
                        maxLength    = 4;
                    }
                }

                if (!IsBinary)
                {
                    if (type == MyCatDbType.TinyBlob)
                    {
                        mySqlDbType = MyCatDbType.TinyText;
                    }
                    else if (type == MyCatDbType.MediumBlob)
                    {
                        mySqlDbType = MyCatDbType.MediumText;
                    }
                    else if (type == MyCatDbType.Blob)
                    {
                        mySqlDbType = MyCatDbType.Text;
                    }
                    else if (type == MyCatDbType.LongBlob)
                    {
                        mySqlDbType = MyCatDbType.LongText;
                    }
                }
            }

            // now determine if we really should be binary
            if (driver.Settings.RespectBinaryFlags)
            {
                CheckForExceptions();
            }

            if (Type == MyCatDbType.String && CharacterLength == 36 && !driver.Settings.OldGuids)
            {
                mySqlDbType = MyCatDbType.Guid;
            }

            if (!IsBinary)
            {
                return;
            }

            if (driver.Settings.RespectBinaryFlags)
            {
                if (type == MyCatDbType.String)
                {
                    mySqlDbType = MyCatDbType.Binary;
                }
                else if (type == MyCatDbType.VarChar ||
                         type == MyCatDbType.VarString)
                {
                    mySqlDbType = MyCatDbType.VarBinary;
                }
            }

            if (CharacterSetIndex == 63)
            {
                CharacterSetIndex = driver.ConnectionCharSetIndex;
            }

            if (Type == MyCatDbType.Binary && ColumnLength == 16 && driver.Settings.OldGuids)
            {
                mySqlDbType = MyCatDbType.Guid;
            }
        }