Ejemplo n.º 1
0
        public void MySqlDecimal()
        {
            if (Version < new Version(5, 0))
            {
                return;
            }

            execSQL("DROP TABLE IF EXISTS Test");
            execSQL("CREATE TABLE Test (id INT, dec1 DECIMAL(36,2))");
            execSQL("INSERT INTO Test VALUES (1, 9999999999999999999999999999999999.99)");

            MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);

            using (MySqlDataReader reader = cmd.ExecuteReader())
            {
                reader.Read();
                MySqlDecimal dec = reader.GetMySqlDecimal(1);
                string       s   = dec.ToString();
                Assert.AreEqual(9999999999999999999999999999999999.99, dec.ToDouble());
                Assert.AreEqual("9999999999999999999999999999999999.99", dec.ToString());
                try
                {
                    decimal d = dec.Value;
                    Assert.Fail("this should have failed");
                }
                catch (Exception)
                {
                }
            }
        }
Ejemplo n.º 2
0
        public override decimal GetDecimal(int i)
        {
            IMySqlValue fieldValue = this.GetFieldValue(i, true);

            if (fieldValue is MySqlDecimal)
            {
                MySqlDecimal num = (MySqlDecimal)fieldValue;
                return(num.Value);
            }
            return(Convert.ToDecimal(fieldValue.Value));
        }
Ejemplo n.º 3
0
 internal MySqlValue GetValueObject()
 {
     if (this.valueObject == null)
     {
         this.valueObject = MySqlValue.GetMySqlValue(this.mySqlDbType);
         MySqlDecimal mySqlDecimal = this.valueObject as MySqlDecimal;
         if (mySqlDecimal != null)
         {
             mySqlDecimal.Precision = this.precision;
             mySqlDecimal.Scale     = this.scale;
         }
     }
     return(this.valueObject);
 }
Ejemplo n.º 4
0
        internal MySqlValue GetValueObject()
        {
            if (valueObject == null)
            {
                valueObject = MySqlValue.GetMySqlValue(mySqlDbType, IsUnsigned, true);

                MySqlDecimal dec = (valueObject as MySqlDecimal);
                if (dec != null)
                {
                    dec.Precision = precision;
                    dec.Scale     = scale;
                }
            }
            return(valueObject);
        }
Ejemplo n.º 5
0
        private static MySqlSchemaCollection GetDataTypes()
        {
            MySqlSchemaCollection dt = new MySqlSchemaCollection("DataTypes");

            dt.AddColumn("TypeName", typeof(string));
            dt.AddColumn("ProviderDbType", typeof(int));
            dt.AddColumn("ColumnSize", typeof(long));
            dt.AddColumn("CreateFormat", typeof(string));
            dt.AddColumn("CreateParameters", typeof(string));
            dt.AddColumn("DataType", typeof(string));
            dt.AddColumn("IsAutoincrementable", typeof(bool));
            dt.AddColumn("IsBestMatch", typeof(bool));
            dt.AddColumn("IsCaseSensitive", typeof(bool));
            dt.AddColumn("IsFixedLength", typeof(bool));
            dt.AddColumn("IsFixedPrecisionScale", typeof(bool));
            dt.AddColumn("IsLong", typeof(bool));
            dt.AddColumn("IsNullable", typeof(bool));
            dt.AddColumn("IsSearchable", typeof(bool));
            dt.AddColumn("IsSearchableWithLike", typeof(bool));
            dt.AddColumn("IsUnsigned", typeof(bool));
            dt.AddColumn("MaximumScale", typeof(short));
            dt.AddColumn("MinimumScale", typeof(short));
            dt.AddColumn("IsConcurrencyType", typeof(bool));
            dt.AddColumn("IsLiteralSupported", typeof(bool));
            dt.AddColumn("LiteralPrefix", typeof(string));
            dt.AddColumn("LiteralSuffix", typeof(string));
            dt.AddColumn("NativeDataType", typeof(string));

            // have each one of the types contribute to the datatypes collection
            MySqlBit.SetDSInfo(dt);
            MySqlBinary.SetDSInfo(dt);
            MySqlDateTime.SetDSInfo(dt);
            MySqlTimeSpan.SetDSInfo(dt);
            MySqlString.SetDSInfo(dt);
            MySqlDouble.SetDSInfo(dt);
            MySqlSingle.SetDSInfo(dt);
            MySqlByte.SetDSInfo(dt);
            MySqlInt16.SetDSInfo(dt);
            MySqlInt32.SetDSInfo(dt);
            MySqlInt64.SetDSInfo(dt);
            MySqlDecimal.SetDSInfo(dt);
            MySqlUByte.SetDSInfo(dt);
            MySqlUInt16.SetDSInfo(dt);
            MySqlUInt32.SetDSInfo(dt);
            MySqlUInt64.SetDSInfo(dt);

            return(dt);
        }
Ejemplo n.º 6
0
        private static DataTable GetDataTypes()
        {
            DataTable dsTable = new DataTable("DataTypes");

            dsTable.Columns.Add(new DataColumn("TypeName", typeof(string)));
            dsTable.Columns.Add(new DataColumn("ProviderDbType", typeof(int)));
            dsTable.Columns.Add(new DataColumn("ColumnSize", typeof(long)));
            dsTable.Columns.Add(new DataColumn("CreateFormat", typeof(string)));
            dsTable.Columns.Add(new DataColumn("CreateParameters", typeof(string)));
            dsTable.Columns.Add(new DataColumn("DataType", typeof(string)));
            dsTable.Columns.Add(new DataColumn("IsAutoincrementable", typeof(bool)));
            dsTable.Columns.Add(new DataColumn("IsBestMatch", typeof(bool)));
            dsTable.Columns.Add(new DataColumn("IsCaseSensitive", typeof(bool)));
            dsTable.Columns.Add(new DataColumn("IsFixedLength", typeof(bool)));
            dsTable.Columns.Add(new DataColumn("IsFixedPrecisionScale", typeof(bool)));
            dsTable.Columns.Add(new DataColumn("IsLong", typeof(bool)));
            dsTable.Columns.Add(new DataColumn("IsNullable", typeof(bool)));
            dsTable.Columns.Add(new DataColumn("IsSearchable", typeof(bool)));
            dsTable.Columns.Add(new DataColumn("IsSearchableWithLike", typeof(bool)));
            dsTable.Columns.Add(new DataColumn("IsUnsigned", typeof(bool)));
            dsTable.Columns.Add(new DataColumn("MaximumScale", typeof(short)));
            dsTable.Columns.Add(new DataColumn("MinimumScale", typeof(short)));
            dsTable.Columns.Add(new DataColumn("IsConcurrencyType", typeof(bool)));
            dsTable.Columns.Add(new DataColumn("IsLiteralsSupported", typeof(bool)));
            dsTable.Columns.Add(new DataColumn("LiteralPrefix", typeof(string)));
            dsTable.Columns.Add(new DataColumn("LiteralSuffix", typeof(string)));
            dsTable.Columns.Add(new DataColumn("NativeDataType", typeof(string)));
            MySqlBit.SetDSInfo(dsTable);
            MySqlBinary.SetDSInfo(dsTable);
            MySqlDateTime.SetDSInfo(dsTable);
            MySqlTimeSpan.SetDSInfo(dsTable);
            MySqlString.SetDSInfo(dsTable);
            MySqlDouble.SetDSInfo(dsTable);
            MySqlSingle.SetDSInfo(dsTable);
            MySqlByte.SetDSInfo(dsTable);
            MySqlInt16.SetDSInfo(dsTable);
            MySqlInt32.SetDSInfo(dsTable);
            MySqlInt64.SetDSInfo(dsTable);
            MySqlDecimal.SetDSInfo(dsTable);
            MySqlUByte.SetDSInfo(dsTable);
            MySqlUInt16.SetDSInfo(dsTable);
            MySqlUInt32.SetDSInfo(dsTable);
            MySqlUInt64.SetDSInfo(dsTable);
            return(dsTable);
        }
Ejemplo n.º 7
0
        public void MySqlDecimal()
        {
            executeSQL("DROP TABLE IF EXISTS Test");
            executeSQL("CREATE TABLE Test (id INT, dec1 DECIMAL(36,2))");
            executeSQL("INSERT INTO Test VALUES (1, 9999999999999999999999999999999999.99)");

            MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", Connection);

            using (MySqlDataReader reader = cmd.ExecuteReader())
            {
                reader.Read();
                MySqlDecimal dec = reader.GetMySqlDecimal(1);
                string       s   = dec.ToString();
                Assert.Equal(9999999999999999999999999999999999.99, dec.ToDouble());
                Assert.Equal("9999999999999999999999999999999999.99", dec.ToString());
                Exception ex = Assert.Throws <OverflowException>(() => dec.Value);
                Assert.Equal(ex.Message, "Value was either too large or too small for a Decimal.");
            }
        }