예제 #1
0
        public static SqlInt64 OnesComplement(SqlInt64 x)
        {
            if (x.IsNull)
            {
                return Null;
            }

            return ~x;
        }
예제 #2
0
 public static SqlInt64 Xor(SqlInt64 x, SqlInt64 y)
 {
     return (x ^ y);
 }
예제 #3
0
파일: SqlBoolean.cs 프로젝트: nlhepler/mono
        public static SqlBoolean op_Explicit(SqlInt64 x)
        {
            if (x.IsNull)
                return SqlBoolean.Null;

            return new SqlBoolean(x.Value != 0L);
        }
예제 #4
0
 public static SqlInt64 Multiply(SqlInt64 x, SqlInt64 y)
 {
     return (x*y);
 }
예제 #5
0
        public void GetXsdTypeTest()
        {
            XmlQualifiedName qualifiedName = SqlInt64.GetXsdType(null);

            Assert.Equal("long", qualifiedName.Name);
        }
예제 #6
0
        public override object Aggregate(int[] records, AggregateType kind)
        {
            bool hasData = false;
            try
            {
                switch (kind)
                {
                    case AggregateType.Sum:
                        SqlInt64 sum = 0;
                        foreach (int record in records)
                        {
                            if (IsNull(record))
                                continue;
                            checked { sum += _values[record]; }
                            hasData = true;
                        }
                        if (hasData)
                        {
                            return sum;
                        }
                        return _nullValue;

                    case AggregateType.Mean:
                        SqlInt64 meanSum = 0;
                        int meanCount = 0;
                        foreach (int record in records)
                        {
                            if (IsNull(record))
                                continue;
                            checked { meanSum += (_values[record]).ToSqlInt64(); }
                            meanCount++;
                            hasData = true;
                        }
                        if (hasData)
                        {
                            SqlInt32 mean = 0;
                            checked { mean = (meanSum / meanCount).ToSqlInt32(); }
                            return mean;
                        }
                        return _nullValue;

                    case AggregateType.Var:
                    case AggregateType.StDev:
                        int count = 0;
                        SqlDouble var = 0;
                        SqlDouble prec = 0;
                        SqlDouble dsum = 0;
                        SqlDouble sqrsum = 0;

                        foreach (int record in records)
                        {
                            if (IsNull(record))
                                continue;
                            dsum += (_values[record]).ToSqlDouble();
                            sqrsum += (_values[record]).ToSqlDouble() * (_values[record]).ToSqlDouble();
                            count++;
                        }

                        if (count > 1)
                        {
                            var = count * sqrsum - (dsum * dsum);
                            prec = var / (dsum * dsum);

                            // we are dealing with the risk of a cancellation error
                            // double is guaranteed only for 15 digits so a difference
                            // with a result less than 1e-15 should be considered as zero

                            if ((prec < 1e-15) || (var < 0))
                                var = 0;
                            else
                                var = var / (count * (count - 1));

                            if (kind == AggregateType.StDev)
                            {
                                return Math.Sqrt(var.Value);
                            }
                            return var;
                        }
                        return _nullValue;

                    case AggregateType.Min:
                        SqlInt32 min = SqlInt32.MaxValue;
                        for (int i = 0; i < records.Length; i++)
                        {
                            int record = records[i];
                            if (IsNull(record))
                                continue;
                            if ((SqlInt32.LessThan(_values[record], min)).IsTrue)
                                min = _values[record];
                            hasData = true;
                        }
                        if (hasData)
                        {
                            return min;
                        }
                        return _nullValue;

                    case AggregateType.Max:
                        SqlInt32 max = SqlInt32.MinValue;
                        for (int i = 0; i < records.Length; i++)
                        {
                            int record = records[i];
                            if (IsNull(record))
                                continue;
                            if ((SqlInt32.GreaterThan(_values[record], max)).IsTrue)
                                max = _values[record];
                            hasData = true;
                        }
                        if (hasData)
                        {
                            return max;
                        }
                        return _nullValue;

                    case AggregateType.First:
                        if (records.Length > 0)
                        {
                            return _values[records[0]];
                        }
                        return null;

                    case AggregateType.Count:
                        count = 0;
                        for (int i = 0; i < records.Length; i++)
                        {
                            if (!IsNull(records[i]))
                                count++;
                        }
                        return count;
                }
            }
            catch (OverflowException)
            {
                throw ExprException.Overflow(typeof(SqlInt32));
            }
            throw ExceptionBuilder.AggregateException(kind, _dataType);
        }
예제 #7
0
        public static object GetComValueFromSqlVariant(object sqlVal)
        {
            object obj2 = null;

            if (!ADP.IsNull(sqlVal))
            {
                if (sqlVal is SqlSingle)
                {
                    SqlSingle num7 = (SqlSingle)sqlVal;
                    return(num7.Value);
                }
                if (sqlVal is SqlString)
                {
                    SqlString str = (SqlString)sqlVal;
                    return(str.Value);
                }
                if (sqlVal is SqlDouble)
                {
                    SqlDouble num6 = (SqlDouble)sqlVal;
                    return(num6.Value);
                }
                if (sqlVal is SqlBinary)
                {
                    SqlBinary binary = (SqlBinary)sqlVal;
                    return(binary.Value);
                }
                if (sqlVal is SqlGuid)
                {
                    SqlGuid guid = (SqlGuid)sqlVal;
                    return(guid.Value);
                }
                if (sqlVal is SqlBoolean)
                {
                    SqlBoolean flag = (SqlBoolean)sqlVal;
                    return(flag.Value);
                }
                if (sqlVal is SqlByte)
                {
                    SqlByte num5 = (SqlByte)sqlVal;
                    return(num5.Value);
                }
                if (sqlVal is SqlInt16)
                {
                    SqlInt16 num4 = (SqlInt16)sqlVal;
                    return(num4.Value);
                }
                if (sqlVal is SqlInt32)
                {
                    SqlInt32 num3 = (SqlInt32)sqlVal;
                    return(num3.Value);
                }
                if (sqlVal is SqlInt64)
                {
                    SqlInt64 num2 = (SqlInt64)sqlVal;
                    return(num2.Value);
                }
                if (sqlVal is SqlDecimal)
                {
                    SqlDecimal num = (SqlDecimal)sqlVal;
                    return(num.Value);
                }
                if (sqlVal is SqlDateTime)
                {
                    SqlDateTime time = (SqlDateTime)sqlVal;
                    return(time.Value);
                }
                if (sqlVal is SqlMoney)
                {
                    SqlMoney money = (SqlMoney)sqlVal;
                    return(money.Value);
                }
                if (sqlVal is SqlXml)
                {
                    obj2 = ((SqlXml)sqlVal).Value;
                }
            }
            return(obj2);
        }
예제 #8
0
 /// <summary>Add or update a value associated with the specified key.</summary>
 /// <param name="key">The key of the value to add or update.</param>
 /// <param name="value">The value to add or update associated with the specified key.</param>
 /// <returns>A fluent SQLNET object.</returns>
 public SQLNET VALUEBIGINT(SqlString key, SqlInt64 value)
 {
     return(ValueBigInt(key, value));
 }
예제 #9
0
    public static SqlInt64 RunningTotalBigIntQueue(SqlInt64 val, SqlByte id, SqlInt32 queueSize, SqlInt64 nullValue, SqlBoolean nullForLessRows)
    {
        string           dataName  = string.Format("MulstiSqlRt_{0}", id.IsNull ? 0 : id.Value);
        string           queueName = dataName + "_q";
        object           lastSum   = CallContext.GetData(dataName);
        Queue <SqlInt64> queue     = (Queue <SqlInt64>)CallContext.GetData(queueName);

        if (queue == null)
        {
            queue = new Queue <SqlInt64>(queueSize.Value);
            CallContext.SetData(queueName, queue);
        }

        SqlInt64 total = lastSum != null ? (SqlInt64)lastSum : SqlInt64.Null;

        if (!val.IsNull)
        {
            total = total.IsNull ? val : total + val;
        }
        else
        {
            total = total.IsNull ? nullValue : (nullValue.IsNull ? total : total + nullValue);
        }

        SqlInt64 lastQueue = queue.Count == queueSize?queue.Dequeue() : SqlInt64.Null;

        queue.Enqueue(total);
        CallContext.SetData(dataName, total);

        if (!lastQueue.IsNull)
        {
            total -= lastQueue;
        }
        else if (nullForLessRows.IsTrue)
        {
            total = SqlInt64.Null;
        }

        return(total);
    }
        override public Object Aggregate(int[] records, AggregateType kind)
        {
            bool hasData = false;

            try {
                switch (kind)
                {
                case AggregateType.Sum:
                    SqlInt64 sum = 0;
                    foreach (int record in records)
                    {
                        if (IsNull(record))
                        {
                            continue;
                        }
                        checked { sum += values[record]; }
                        hasData = true;
                    }
                    if (hasData)
                    {
                        return(sum);
                    }
                    return(NullValue);

                case AggregateType.Mean:
                    SqlInt64 meanSum   = 0;
                    int      meanCount = 0;
                    foreach (int record in records)
                    {
                        if (IsNull(record))
                        {
                            continue;
                        }
                        checked { meanSum += (values[record]).ToSqlInt64(); }
                        meanCount++;
                        hasData = true;
                    }
                    if (hasData)
                    {
                        SqlInt16 mean = 0;
                        checked { mean = (meanSum / (SqlInt64)meanCount).ToSqlInt16(); }
                        return(mean);
                    }
                    return(NullValue);

                case AggregateType.Var:
                case AggregateType.StDev:
                    int       count  = 0;
                    SqlDouble var    = (SqlDouble)0;
                    SqlDouble prec   = (SqlDouble)0;
                    SqlDouble dsum   = (SqlDouble)0;
                    SqlDouble sqrsum = (SqlDouble)0;

                    foreach (int record in records)
                    {
                        if (IsNull(record))
                        {
                            continue;
                        }
                        dsum   += (values[record]).ToSqlDouble();
                        sqrsum += (values[record]).ToSqlDouble() * (values[record]).ToSqlDouble();
                        count++;
                    }

                    if (count > 1)
                    {
                        var  = ((SqlDouble)count * sqrsum - (dsum * dsum));
                        prec = var / (dsum * dsum);

                        // we are dealing with the risk of a cancellation error
                        // double is guaranteed only for 15 digits so a difference
                        // with a result less than 1e-15 should be considered as zero

                        if ((prec < 1e-15) || (var < 0))
                        {
                            var = 0;
                        }
                        else
                        {
                            var = var / (count * (count - 1));
                        }

                        if (kind == AggregateType.StDev)
                        {
                            return(Math.Sqrt(var.Value));
                        }
                        return(var);
                    }
                    return(NullValue);

                case AggregateType.Min:
                    SqlInt16 min = SqlInt16.MaxValue;
                    for (int i = 0; i < records.Length; i++)
                    {
                        int record = records[i];
                        if (IsNull(record))
                        {
                            continue;
                        }
                        if ((SqlInt16.LessThan(values[record], min)).IsTrue)
                        {
                            min = values[record];
                        }
                        hasData = true;
                    }
                    if (hasData)
                    {
                        return(min);
                    }
                    return(NullValue);

                case AggregateType.Max:
                    SqlInt16 max = SqlInt16.MinValue;
                    for (int i = 0; i < records.Length; i++)
                    {
                        int record = records[i];
                        if (IsNull(record))
                        {
                            continue;
                        }
                        if ((SqlInt16.GreaterThan(values[record], max)).IsTrue)
                        {
                            max = values[record];
                        }
                        hasData = true;
                    }
                    if (hasData)
                    {
                        return(max);
                    }
                    return(NullValue);

                case AggregateType.First:
                    if (records.Length > 0)
                    {
                        return(values[records[0]]);
                    }
                    return(null);   // no data => null

                case AggregateType.Count:
                    count = 0;
                    for (int i = 0; i < records.Length; i++)
                    {
                        if (!IsNull(records[i]))
                        {
                            count++;
                        }
                    }
                    return(count);
                }
            }
            catch (OverflowException) {
                throw ExprException.Overflow(typeof(SqlInt16));
            }
            throw ExceptionBuilder.AggregateException(kind, DataType);
        }
예제 #11
0
        public void SerializeAndDeserializeSqlTypes()
        {
            SqlBoolean sqlBooleanMax = new SqlBoolean(true);

            Assert.StrictEqual <SqlBoolean>(sqlBooleanMax, SerializeAndDeserialize <SqlBoolean>(sqlBooleanMax, "<boolean>true</boolean>"));

            SqlBoolean sqlBooleanMin = new SqlBoolean(false);

            Assert.StrictEqual <SqlBoolean>(sqlBooleanMin, SerializeAndDeserialize <SqlBoolean>(sqlBooleanMin, "<boolean>false</boolean>"));

            SqlByte sqlByteMax = new SqlByte(255);

            Assert.StrictEqual <SqlByte>(sqlByteMax, SerializeAndDeserialize <SqlByte>(sqlByteMax, "<unsignedByte>255</unsignedByte>"));

            SqlByte sqlByteMin = new SqlByte(0);

            Assert.StrictEqual <SqlByte>(sqlByteMin, SerializeAndDeserialize <SqlByte>(sqlByteMin, "<unsignedByte>0</unsignedByte>"));

            SqlDateTime sqlDateTimeMax = new SqlDateTime(9999, 12, 31, 23, 59, 59);

            Assert.StrictEqual <SqlDateTime>(sqlDateTimeMax, SerializeAndDeserialize <SqlDateTime>(sqlDateTimeMax, "<dateTime>9999-12-31T23:59:59.000</dateTime>"));

            SqlDateTime sqlDateTimeMin = new SqlDateTime(1753, 1, 1, 0, 0, 0);

            Assert.StrictEqual <SqlDateTime>(sqlDateTimeMin, SerializeAndDeserialize <SqlDateTime>(sqlDateTimeMin, "<dateTime>1753-01-01T00:00:00.000</dateTime>"));

            SqlDouble sqlDoubleMaxDec = new SqlDouble(0.999999999999999);

            Assert.StrictEqual <SqlDouble>(sqlDoubleMaxDec, SerializeAndDeserialize <SqlDouble>(sqlDoubleMaxDec, "<double>0.999999999999999</double>"));

            SqlDouble sqlDoubleMinDec = new SqlDouble(999999999999999);

            Assert.StrictEqual <SqlDouble>(sqlDoubleMinDec, SerializeAndDeserialize <SqlDouble>(sqlDoubleMinDec, "<double>999999999999999</double>"));

            SqlInt16 sqlInt16Max = new SqlInt16(32767);

            Assert.StrictEqual <SqlInt16>(sqlInt16Max, SerializeAndDeserialize <SqlInt16>(sqlInt16Max, "<short>32767</short>"));

            SqlInt16 sqlInt16Min = new SqlInt16(-32768);

            Assert.StrictEqual <SqlInt16>(sqlInt16Min, SerializeAndDeserialize <SqlInt16>(sqlInt16Min, "<short>-32768</short>"));

            SqlInt32 sqlInt32Max = new SqlInt32(2147483647);

            Assert.StrictEqual <SqlInt32>(sqlInt32Max, SerializeAndDeserialize <SqlInt32>(sqlInt32Max, "<int>2147483647</int>"));

            SqlInt32 sqlInt32Min = new SqlInt32(-2147483648);

            Assert.StrictEqual <SqlInt32>(sqlInt32Min, SerializeAndDeserialize <SqlInt32>(sqlInt32Min, "<int>-2147483648</int>"));

            SqlInt64 sqlInt64Max = new SqlInt64(9223372036854775807);

            Assert.StrictEqual <SqlInt64>(sqlInt64Max, SerializeAndDeserialize <SqlInt64>(sqlInt64Max, "<long>9223372036854775807</long>"));

            SqlInt64 sqlInt64Min = new SqlInt64(-9223372036854775808);

            Assert.StrictEqual <SqlInt64>(sqlInt64Min, SerializeAndDeserialize <SqlInt64>(sqlInt64Min, "<long>-9223372036854775808</long>"));

            SqlString sqlString             = new SqlString("abcdefghijklmnopqrstuvwxyz");
            SqlString sqlStringDeserialized = SerializeAndDeserialize <SqlString>(sqlString, "<string>abcdefghijklmnopqrstuvwxyz</string>");

            // Cannot use StrictEqual because information such as LCID is lost when the SqlString is serialized
            Assert.Equal(sqlString.Value, sqlStringDeserialized.Value);
        }
예제 #12
0
    public static SqlBoolean InitMethod([SqlFacet(MaxSize = -1)] SqlString sqlDataValue, SqlString sqlDataType)
    {
        String          dataValue     = sqlDataValue.ToString().Trim();
        String          dataType      = sqlDataType.ToString().Trim();
        GroupCollection typeGroups    = splitType.Match(dataType).Groups;
        String          typeText      = typeGroups["type"].Value;
        String          typePrecision = typeGroups["precision"].Value;
        String          typeScale     = typeGroups["scale"].Value;

        try {
            switch (typeText.ToLower())
            {
            case "bit":
                SqlBoolean.Parse(dataValue);
                break;

            case "tinyint":
                SqlByte.Parse(dataValue);
                break;

            case "smallint":
                SqlInt16.Parse(dataValue);
                break;

            case "int":
                SqlInt32.Parse(dataValue);
                break;

            case "bigint":
                SqlInt64.Parse(dataValue);
                break;

            case "smallmoney":
                if (NumberOfDecimals(dataValue) > 4)
                {
                    throw new OverflowException();
                }
                SqlMoney smallmoneyValue = SqlMoney.Parse(dataValue);
                if (SqlMoney.LessThan(smallmoneyValue, smallmoneyMinValue) || SqlMoney.GreaterThan(smallmoneyValue, smallmoneyMaxValue))
                {
                    throw new OverflowException();
                }
                break;

            case "money":
                if (NumberOfDecimals(dataValue) > 4)
                {
                    throw new OverflowException();
                }
                SqlMoney.Parse(dataValue);
                break;

            case "decimal":
            case "numeric":
                if (NumberOfDecimals(dataValue) > Convert.ToInt32(typeScale))
                {
                    throw new OverflowException();
                }
                SqlDecimal.Parse(dataValue);
                break;

            case "real":
                SqlSingle singleValue = SqlSingle.Parse(dataValue);
                if (singleValue.ToString().Length != dataValue.Length + (NumberOfWholes(dataValue) == 0 ? 1 : 0))
                {
                    throw new OverflowException();
                }
                break;

            case "float":
                SqlDouble doubleValue = SqlDouble.Parse(dataValue);
                if (doubleValue.ToString().Length != dataValue.Length + (NumberOfWholes(dataValue) == 0 ? 1 : 0))
                {
                    throw new OverflowException();
                }
                break;

            case "date":
            case "datetime":
            case "datetime2":
                SqlDateTime.Parse(dataValue);
                break;

            case "char":
            case "varchar":
            case "nchar":
            case "nvarchar":
                if (typePrecision != "max" && dataValue.Length > Convert.ToInt32(typePrecision))
                {
                    throw new OverflowException();
                }
                break;

            case "uniqueidentifier":
                SqlGuid.Parse(dataValue);
                break;

            case "geometry":
                SqlGeometry.Parse(dataValue);
                break;

            case "geography":
                SqlGeography.Parse(dataValue);
                break;

            // we do not handle these at this time
            case "xml":
            case "time":
            case "datetimeoffset":
            case "hierarchyid":
            case "image":
            case "text":
            case "ntext":
            case "rowversion":
            case "sql_variant":
            case "table":
            case "timestamp":
            case "varbinary":
            default:
                break;
            }
            return(SqlBoolean.True);
        }
        catch {
            return(SqlBoolean.False);
        }
    }
예제 #13
0
        // devnote: This method should not be used with SqlDbType.Date and SqlDbType.DateTime2.
        //          With these types the values should be used directly as CLR types instead of being converted to a SqlValue
        internal static object GetSqlValueFromComVariant(object comVal)
        {
            object sqlVal = null;

            if ((null != comVal) && (DBNull.Value != comVal))
            {
                if (comVal is float)
                {
                    sqlVal = new SqlSingle((float)comVal);
                }
                else if (comVal is string)
                {
                    sqlVal = new SqlString((string)comVal);
                }
                else if (comVal is double)
                {
                    sqlVal = new SqlDouble((double)comVal);
                }
                else if (comVal is byte[])
                {
                    sqlVal = new SqlBinary((byte[])comVal);
                }
                else if (comVal is char)
                {
                    sqlVal = new SqlString(((char)comVal).ToString());
                }
                else if (comVal is char[])
                {
                    sqlVal = new SqlChars((char[])comVal);
                }
                else if (comVal is System.Guid)
                {
                    sqlVal = new SqlGuid((Guid)comVal);
                }
                else if (comVal is bool)
                {
                    sqlVal = new SqlBoolean((bool)comVal);
                }
                else if (comVal is byte)
                {
                    sqlVal = new SqlByte((byte)comVal);
                }
                else if (comVal is short)
                {
                    sqlVal = new SqlInt16((short)comVal);
                }
                else if (comVal is int)
                {
                    sqlVal = new SqlInt32((int)comVal);
                }
                else if (comVal is long)
                {
                    sqlVal = new SqlInt64((long)comVal);
                }
                else if (comVal is decimal)
                {
                    sqlVal = new SqlDecimal((decimal)comVal);
                }
                else if (comVal is DateTime)
                {
                    // devnote: Do not use with SqlDbType.Date and SqlDbType.DateTime2. See comment at top of method.
                    sqlVal = new SqlDateTime((DateTime)comVal);
                }
                else if (comVal is XmlReader)
                {
                    sqlVal = new SqlXml((XmlReader)comVal);
                }
                else if (comVal is TimeSpan || comVal is DateTimeOffset)
                {
                    sqlVal = comVal;
                }
#if DEBUG
                else
                {
                    Debug.Fail("unknown SqlType class stored in sqlVal");
                }
#endif
            }
            return(sqlVal);
        }
예제 #14
0
 public static SqlInt64 BitwiseAnd(SqlInt64 x, SqlInt64 y)
 {
     return (x & y);
 }
예제 #15
0
        public void Conversions()
        {
            SqlDouble Test0    = new SqlDouble(0);
            SqlDouble Test1    = new SqlDouble(250);
            SqlDouble Test2    = new SqlDouble(64e64);
            SqlDouble Test3    = new SqlDouble(64e164);
            SqlDouble TestNull = SqlDouble.Null;

            // ToSqlBoolean ()
            Assert.IsTrue(Test1.ToSqlBoolean().Value, "#M01A");
            Assert.IsTrue(!Test0.ToSqlBoolean().Value, "#M02A");
            Assert.IsTrue(TestNull.ToSqlBoolean().IsNull, "#M03A");

            // ToSqlByte ()
            Assert.AreEqual((byte)250, Test1.ToSqlByte().Value, "#M01B");
            Assert.AreEqual((byte)0, Test0.ToSqlByte().Value, "#M02B");

            try {
                SqlByte b = (byte)Test2.ToSqlByte();
                Assert.Fail("#M03B");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04B");
            }

            // ToSqlDecimal ()
            Assert.AreEqual(250.00000000000000M, Test1.ToSqlDecimal().Value, "#M01C");
            Assert.AreEqual((decimal)0, Test0.ToSqlDecimal().Value, "#M02C");

            try {
                SqlDecimal test = Test3.ToSqlDecimal().Value;
                Assert.Fail("#M03C");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04C");
            }

            // ToSqlInt16 ()
            Assert.AreEqual((short)250, Test1.ToSqlInt16().Value, "#M01D");
            Assert.AreEqual((short)0, Test0.ToSqlInt16().Value, "#M02D");

            try {
                SqlInt16 test = Test2.ToSqlInt16().Value;
                Assert.Fail("#M03D");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04D");
            }

            // ToSqlInt32 ()
            Assert.AreEqual((int)250, Test1.ToSqlInt32().Value, "#M01E");
            Assert.AreEqual((int)0, Test0.ToSqlInt32().Value, "#M02E");

            try {
                SqlInt32 test = Test2.ToSqlInt32().Value;
                Assert.Fail("#M03E");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04E");
            }

            // ToSqlInt64 ()
            Assert.AreEqual((long)250, Test1.ToSqlInt64().Value, "#M01F");
            Assert.AreEqual((long)0, Test0.ToSqlInt64().Value, "#M02F");

            try {
                SqlInt64 test = Test2.ToSqlInt64().Value;
                Assert.Fail("#M03F");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04F");
            }

            // ToSqlMoney ()
            Assert.AreEqual(250.0000M, Test1.ToSqlMoney().Value, "#M01G");
            Assert.AreEqual((decimal)0, Test0.ToSqlMoney().Value, "#M02G");

            try {
                SqlMoney test = Test2.ToSqlMoney().Value;
                Assert.Fail("#M03G");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04G");
            }

            // ToSqlSingle ()
            Assert.AreEqual((float)250, Test1.ToSqlSingle().Value, "#M01H");
            Assert.AreEqual((float)0, Test0.ToSqlSingle().Value, "#M02H");

            try {
                SqlSingle test = Test2.ToSqlSingle().Value;
                Assert.Fail("#MO3H");
            } catch (OverflowException e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04H");
            }

            // ToSqlString ()
            Assert.AreEqual("250", Test1.ToSqlString().Value, "#M01I");
            Assert.AreEqual("0", Test0.ToSqlString().Value, "#M02I");
            Assert.AreEqual("6.4E+65", Test2.ToSqlString().Value, "#M03I");

            // ToString ()
            Assert.AreEqual("250", Test1.ToString(), "#M01J");
            Assert.AreEqual("0", Test0.ToString(), "#M02J");
            Assert.AreEqual("6.4E+65", Test2.ToString(), "#M03J");
        }
예제 #16
0
 /// <summary>Add or update a value associated with the specified key.</summary>
 /// <param name="key">The key of the value to add or update.</param>
 /// <param name="value">The value to add or update associated with the specified key.</param>
 /// <returns>A fluent SQLNET object.</returns>
 public SQLNET ValueBigInt(SqlString key, SqlInt64 value)
 {
     return(InternalValue(key, typeof(long), value.Value));
 }
 public static SqlDouble FromYPixelToLatitude(SqlInt64 pixelY, SqlDouble zoomLevel)
 {
     return(FromYPixelToLat((long)pixelY, (double)zoomLevel));
 }
예제 #18
0
        public void Conversions()
        {
            SqlInt64 Test12   = new SqlInt64(12);
            SqlInt64 Test0    = new SqlInt64(0);
            SqlInt64 TestNull = SqlInt64.Null;
            SqlInt64 Test1000 = new SqlInt64(1000);
            SqlInt64 Test288  = new SqlInt64(288);

            // ToSqlBoolean ()
            Assert.True(Test12.ToSqlBoolean().Value);
            Assert.True(!Test0.ToSqlBoolean().Value);
            Assert.True(TestNull.ToSqlBoolean().IsNull);

            // ToSqlByte ()
            Assert.Equal((byte)12, Test12.ToSqlByte().Value);
            Assert.Equal((byte)0, Test0.ToSqlByte().Value);

            try
            {
                SqlByte b = (byte)Test1000.ToSqlByte();
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // ToSqlDecimal ()
            Assert.Equal(12, Test12.ToSqlDecimal().Value);
            Assert.Equal(0, Test0.ToSqlDecimal().Value);
            Assert.Equal(288, Test288.ToSqlDecimal().Value);

            // ToSqlDouble ()
            Assert.Equal(12, Test12.ToSqlDouble().Value);
            Assert.Equal(0, Test0.ToSqlDouble().Value);
            Assert.Equal(1000, Test1000.ToSqlDouble().Value);

            // ToSqlInt32 ()
            Assert.Equal(12, Test12.ToSqlInt32().Value);
            Assert.Equal(0, Test0.ToSqlInt32().Value);
            Assert.Equal(288, Test288.ToSqlInt32().Value);

            // ToSqlInt16 ()
            Assert.Equal((short)12, Test12.ToSqlInt16().Value);
            Assert.Equal((short)0, Test0.ToSqlInt16().Value);
            Assert.Equal((short)288, Test288.ToSqlInt16().Value);

            // ToSqlMoney ()
            Assert.Equal(12.0000M, Test12.ToSqlMoney().Value);
            Assert.Equal(0, Test0.ToSqlMoney().Value);
            Assert.Equal(288.0000M, Test288.ToSqlMoney().Value);

            // ToSqlSingle ()
            Assert.Equal(12, Test12.ToSqlSingle().Value);
            Assert.Equal(0, Test0.ToSqlSingle().Value);
            Assert.Equal(288, Test288.ToSqlSingle().Value);

            // ToSqlString ()
            Assert.Equal("12", Test12.ToSqlString().Value);
            Assert.Equal("0", Test0.ToSqlString().Value);
            Assert.Equal("288", Test288.ToSqlString().Value);

            // ToString ()
            Assert.Equal("12", Test12.ToString());
            Assert.Equal("0", Test0.ToString());
            Assert.Equal("288", Test288.ToString());
        }
예제 #19
0
        public void Conversions()
        {
            SqlInt64 Test12   = new SqlInt64(12);
            SqlInt64 Test0    = new SqlInt64(0);
            SqlInt64 TestNull = SqlInt64.Null;
            SqlInt64 Test1000 = new SqlInt64(1000);
            SqlInt64 Test288  = new SqlInt64(288);

            // ToSqlBoolean ()
            Assert.IsTrue(Test12.ToSqlBoolean().Value, "#P01");
            Assert.IsTrue(!Test0.ToSqlBoolean().Value, "#P02");
            Assert.IsTrue(TestNull.ToSqlBoolean().IsNull, "#P03");

            // ToSqlByte ()
            Assert.AreEqual((byte)12, Test12.ToSqlByte().Value, "#P04");
            Assert.AreEqual((byte)0, Test0.ToSqlByte().Value, "#P05");

            try
            {
                SqlByte b = (byte)Test1000.ToSqlByte();
                Assert.Fail("#P06");
            }
            catch (OverflowException e)
            {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#P07");
            }

            // ToSqlDecimal ()
            Assert.AreEqual((decimal)12, Test12.ToSqlDecimal().Value, "#P08");
            Assert.AreEqual((decimal)0, Test0.ToSqlDecimal().Value, "#P09");
            Assert.AreEqual((decimal)288, Test288.ToSqlDecimal().Value, "#P10");

            // ToSqlDouble ()
            Assert.AreEqual((double)12, Test12.ToSqlDouble().Value, "#P11");
            Assert.AreEqual((double)0, Test0.ToSqlDouble().Value, "#P12");
            Assert.AreEqual((double)1000, Test1000.ToSqlDouble().Value, "#P13");

            // ToSqlInt32 ()
            Assert.AreEqual((int)12, Test12.ToSqlInt32().Value, "#P14");
            Assert.AreEqual((int)0, Test0.ToSqlInt32().Value, "#P15");
            Assert.AreEqual((int)288, Test288.ToSqlInt32().Value, "#P16");

            // ToSqlInt16 ()
            Assert.AreEqual((short)12, Test12.ToSqlInt16().Value, "#P17");
            Assert.AreEqual((short)0, Test0.ToSqlInt16().Value, "#P18");
            Assert.AreEqual((short)288, Test288.ToSqlInt16().Value, "#P19");

            // ToSqlMoney ()
            Assert.AreEqual(12.0000M, Test12.ToSqlMoney().Value, "#P20");
            Assert.AreEqual((decimal)0, Test0.ToSqlMoney().Value, "#P21");
            Assert.AreEqual(288.0000M, Test288.ToSqlMoney().Value, "#P22");

            // ToSqlSingle ()
            Assert.AreEqual((float)12, Test12.ToSqlSingle().Value, "#P23");
            Assert.AreEqual((float)0, Test0.ToSqlSingle().Value, "#P24");
            Assert.AreEqual((float)288, Test288.ToSqlSingle().Value, "#P25");

            // ToSqlString ()
            Assert.AreEqual("12", Test12.ToSqlString().Value, "#P26");
            Assert.AreEqual("0", Test0.ToSqlString().Value, "#P27");
            Assert.AreEqual("288", Test288.ToSqlString().Value, "#P28");

            // ToString ()
            Assert.AreEqual("12", Test12.ToString(), "#P29");
            Assert.AreEqual("0", Test0.ToString(), "#P30");
            Assert.AreEqual("288", Test288.ToString(), "#P31");
        }
예제 #20
0
 public FileProperties(SqlString fileName, SqlInt64 fileSize, SqlDateTime creationTime)
 {
     FileName     = fileName;
     FileSize     = fileSize;
     CreationTime = creationTime;
 }
예제 #21
0
        public void ArithmeticOperators()
        {
            SqlInt64 Test24   = new SqlInt64(24);
            SqlInt64 Test64   = new SqlInt64(64);
            SqlInt64 Test2550 = new SqlInt64(2550);
            SqlInt64 Test0    = new SqlInt64(0);

            // "+"-operator
            Assert.AreEqual((SqlInt64)2614, Test2550 + Test64, "#R01");
            try
            {
                SqlInt64 result = Test64 + SqlInt64.MaxValue;
                Assert.Fail("#R02");
            }
            catch (OverflowException e)
            {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#R03");
            }

            // "/"-operator
            Assert.AreEqual((SqlInt64)39, Test2550 / Test64, "#R04");
            Assert.AreEqual((SqlInt64)0, Test24 / Test64, "#R05");

            try
            {
                SqlInt64 result = Test2550 / Test0;
                Assert.Fail("#R06");
            }
            catch (DivideByZeroException e)
            {
                Assert.AreEqual(typeof(DivideByZeroException), e.GetType(), "#R07");
            }

            // "*"-operator
            Assert.AreEqual((SqlInt64)1536, Test64 * Test24, "#R08");

            try
            {
                SqlInt64 test = (SqlInt64.MaxValue * Test64);
                Assert.Fail("TestC#2");
            }
            catch (OverflowException e)
            {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#R08");
            }

            // "-"-operator
            Assert.AreEqual((SqlInt64)2526, Test2550 - Test24, "#R09");

            try
            {
                SqlInt64 test = SqlInt64.MinValue - Test64;
                Assert.Fail("#R10");
            }
            catch (OverflowException e)
            {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#R11");
            }

            // "%"-operator
            Assert.AreEqual((SqlInt64)54, Test2550 % Test64, "#R12");
            Assert.AreEqual((SqlInt64)24, Test24 % Test64, "#R13");
            Assert.AreEqual((SqlInt64)0, new SqlInt64(100) % new SqlInt64(10), "#R14");
        }
예제 #22
0
        public void SqlInt64ToSqlString()
        {
            SqlInt64 TestInt = new SqlInt64(10101010);

            Assert.AreEqual("10101010", ((SqlString)TestInt).Value, "#Z01");
        }
예제 #23
0
        public void GetXsdTypeTest()
        {
            XmlQualifiedName qualifiedName = SqlInt64.GetXsdType(null);

            NUnit.Framework.Assert.AreEqual("long", qualifiedName.Name, "#A01");
        }
예제 #24
0
 public void WriteData(AMFWriter writer, object data)
 {
     if ((data is INullable) && (data as INullable).IsNull)
     {
         writer.WriteAMF3Null();
     }
     else if (data is SqlByte)
     {
         SqlByte num = (SqlByte)data;
         writer.WriteAMF3Data(num.Value);
     }
     else if (data is SqlInt16)
     {
         SqlInt16 num2 = (SqlInt16)data;
         writer.WriteAMF3Data(num2.Value);
     }
     else if (data is SqlInt32)
     {
         SqlInt32 num3 = (SqlInt32)data;
         writer.WriteAMF3Data(num3.Value);
     }
     else if (data is SqlInt64)
     {
         SqlInt64 num4 = (SqlInt64)data;
         writer.WriteAMF3Data(num4.Value);
     }
     else if (data is SqlSingle)
     {
         SqlSingle num5 = (SqlSingle)data;
         writer.WriteAMF3Data(num5.Value);
     }
     else if (data is SqlDouble)
     {
         SqlDouble num6 = (SqlDouble)data;
         writer.WriteAMF3Data(num6.Value);
     }
     else if (data is SqlDecimal)
     {
         SqlDecimal num7 = (SqlDecimal)data;
         writer.WriteAMF3Data(num7.Value);
     }
     else if (data is SqlMoney)
     {
         SqlMoney money = (SqlMoney)data;
         writer.WriteAMF3Data(money.Value);
     }
     else if (data is SqlDateTime)
     {
         SqlDateTime time = (SqlDateTime)data;
         writer.WriteAMF3Data(time.Value);
     }
     else if (data is SqlString)
     {
         SqlString str2 = (SqlString)data;
         writer.WriteAMF3String(str2.Value);
     }
     else if (data is SqlGuid)
     {
         SqlGuid guid = (SqlGuid)data;
         writer.WriteAMF3Data(guid.Value.ToString("N"));
     }
     else if (data is SqlBoolean)
     {
         SqlBoolean flag2 = (SqlBoolean)data;
         writer.WriteAMF3Bool(flag2.Value);
     }
     else
     {
         string message = string.Format("Could not find serializer for type {0}", data.GetType().FullName);
         if (_log.get_IsErrorEnabled())
         {
             _log.Error(message);
         }
         throw new FluorineException(message);
     }
 }
예제 #25
0
        public void ArithmeticMethods()
        {
            SqlInt64 Test64  = new SqlInt64(64);
            SqlInt64 Test0   = new SqlInt64(0);
            SqlInt64 Test164 = new SqlInt64(164);
            SqlInt64 TestMax = new SqlInt64(SqlInt64.MaxValue.Value);

            // Add()
            Assert.AreEqual((long)64, SqlInt64.Add(Test64, Test0).Value, "#D01");
            Assert.AreEqual((long)228, SqlInt64.Add(Test64, Test164).Value, "#D02");
            Assert.AreEqual((long)164, SqlInt64.Add(Test0, Test164).Value, "#D03");
            Assert.AreEqual((long)SqlInt64.MaxValue, SqlInt64.Add(TestMax, Test0).Value, "#D04");

            try
            {
                SqlInt64.Add(TestMax, Test64);
                Assert.Fail("#D05");
            }
            catch (OverflowException e)
            {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#D06");
            }

            // Divide()
            Assert.AreEqual((long)2, SqlInt64.Divide(Test164, Test64).Value, "#D07");
            Assert.AreEqual((long)0, SqlInt64.Divide(Test64, Test164).Value, "#D08");

            try
            {
                SqlInt64.Divide(Test64, Test0);
                Assert.Fail("#D09");
            }
            catch (DivideByZeroException e)
            {
                Assert.AreEqual(typeof(DivideByZeroException), e.GetType(), "#D10");
            }

            // Mod()
            Assert.AreEqual((SqlInt64)36, SqlInt64.Mod(Test164, Test64), "#D11");
            Assert.AreEqual((SqlInt64)64, SqlInt64.Mod(Test64, Test164), "#D12");

            // Multiply()
            Assert.AreEqual((long)10496, SqlInt64.Multiply(Test64, Test164).Value, "#D13");
            Assert.AreEqual((long)0, SqlInt64.Multiply(Test64, Test0).Value, "#D14");

            try
            {
                SqlInt64.Multiply(TestMax, Test64);
                Assert.Fail("#D15");
            }
            catch (OverflowException e)
            {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#D16");
            }

            // Subtract()
            Assert.AreEqual((long)100, SqlInt64.Subtract(Test164, Test64).Value, "#D17");

            try
            {
                SqlInt64.Subtract(SqlInt64.MinValue, Test164);
                Assert.Fail("#D18");
            }
            catch (OverflowException e)
            {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#D19");
            }

#if NET_2_0
            // Modulus ()
            Assert.AreEqual((SqlInt64)36, SqlInt64.Modulus(Test164, Test64), "#D20");
            Assert.AreEqual((SqlInt64)64, SqlInt64.Modulus(Test64, Test164), "#D21");
#endif
        }
예제 #26
0
 public static SqlBoolean NotEquals(SqlInt64 x, SqlInt64 y)
 {
     return (x != y);
 }
예제 #27
0
 public virtual void SetSqlInt64(int ordinal, SqlInt64 value)
 {
     throw new NotImplementedException();
 }
예제 #28
0
 public static SqlInt64 Subtract(SqlInt64 x, SqlInt64 y)
 {
     return (x - y);
 }
예제 #29
0
    public static SqlInt32 cmd_catchhandler(
        String cmdtext,
        SqlInt32 procid,
        SqlBoolean trycatch,
        SqlString quotechar,
        String server,
        String dbname,
        SqlString username,
        SqlString appname,
        SqlString hostname
        )
    {
        // Replace the quote character with a single quote.
        if (!quotechar.IsNull)
        {
            cmdtext = cmdtext.Replace(quotechar.Value, "'");
        }

        // Instantiate the MessageGatherer class.
        MessageGatherer message_gatherer = new MessageGatherer();

        using (SqlConnection ctx_cn = new SqlConnection("context connection=true"))
        {
            // Open the context connection, and define an event handler for
            // messages with severity < 11. Then set the property with the
            // long name to also divert errors with severity <= 16 to the
            // event handler.
            ctx_cn.Open();
            ctx_cn.InfoMessage += message_gatherer.message_handler;
            ctx_cn.FireInfoMessageEventOnUserErrors = true;

            // Run the command over the context connection. The reason we
            // invoke a data reader and don't use ExecuteAndSend directly, is
            // that the latter is more prone to produce bad TDS which causes
            // errors in SqlClient (but not with ODBC or OLE DB).
            SqlCommand cmd = new SqlCommand(cmdtext, ctx_cn);
            cmd.CommandType = CommandType.Text;
            try {
                using (SqlDataReader reader = cmd.ExecuteReader()) {
                    SqlContext.Pipe.Send(reader);
                }
            }
            catch (SqlException ex) {
                // An exception is an error with severity > 16. Add these
                // messages to the MessageGatherer so that we can handle them
                // all the same.
                message_gatherer.add_messages(ex.Errors);
            }

            // We don't want the event handler any more.
            ctx_cn.InfoMessage -= message_gatherer.message_handler;
            ctx_cn.FireInfoMessageEventOnUserErrors = false;

            // Some variables for the rest of the analysis.
            Int32  retvalue   = 0;            // The return value from the procedure.
            String fullerrmsg = String.Empty; // Used when @reraise = 1.

            // Traverse the message collection. Note that despite the name
            // SqlError, not all messages are necessarily errors.
            foreach (SqlError msgobj in message_gatherer.messages)
            {
                // First mission is to send the message to the client. Before
                // we can do this, we need to augment the message to include
                // the message number. We don't add procedure nmae and line
                // number, because it seems to always be missing in this context.
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                if (msgobj.Class > 0)
                {
                    sb.Append("{");
                    sb.Append(msgobj.Number);
                    sb.Append("} ");
                }
                sb.Append(msgobj.Message);

                // Now we compose the command string which is a single
                // RAISERROR statement.
                SqlCommand raisecmd = new SqlCommand(
                    "RAISERROR('%s', @severity, @state, @msg)", ctx_cn);
                raisecmd.Parameters.Add("@msg", SqlDbType.NVarChar, 2048);
                raisecmd.Parameters["@msg"].Value = sb.ToString();
                raisecmd.Parameters.Add("@severity", SqlDbType.TinyInt);
                raisecmd.Parameters["@severity"].Value =
                    (msgobj.Class <= 18 ? msgobj.Class : (Byte)18);
                raisecmd.Parameters.Add("@state", SqlDbType.TinyInt);
                raisecmd.Parameters["@state"].Value = msgobj.State;

                // And send to client. It seems that a single RAISERROR does
                // not provoke that TDS error in SqlClient and SSMS.
                try {
                    SqlContext.Pipe.ExecuteAndSend(raisecmd);
                }
                // Empty CATCH block, to suppress error from being re-thrown.
                catch  {}

                if (msgobj.Class >= 11)
                {
                    // So this is an error. If the this is the first error, this
                    // sets the return value. Accumulate all error messages in
                    // fullerrmsg.
                    if (retvalue == 0)
                    {
                        fullerrmsg = msgobj.Message;
                        retvalue   = msgobj.Number;
                    }
                    else
                    {
                        fullerrmsg = string.Concat(fullerrmsg, "\r\n",
                                                   msgobj.ToString());
                    }

                    // Log the error to sqleventlog. We always use a loopback
                    // connection for this, in case there is a transaction in
                    // progress. First set up the connection string.
                    SqlConnectionStringBuilder loopback_string =
                        new SqlConnectionStringBuilder();
                    loopback_string.DataSource         = server;
                    loopback_string.InitialCatalog     = dbname;
                    loopback_string.IntegratedSecurity = true;
                    loopback_string.Enlist             = false;

                    using (SqlConnection loop_cn =
                               new SqlConnection(loopback_string.ConnectionString)) {
                        // We call log_insert_sp directly. We can permit this
                        // as we are part of the slog schema.
                        SqlCommand logcmd =
                            new SqlCommand("slog.log_insert_sp", loop_cn);

                        loop_cn.Open();

                        logcmd.CommandType = CommandType.StoredProcedure;

                        logcmd.Parameters.Add("@logid", SqlDbType.BigInt);
                        logcmd.Parameters["@logid"].Direction = ParameterDirection.Output;

                        logcmd.Parameters.Add("@msgid", SqlDbType.VarChar, 36);
                        logcmd.Parameters["@msgid"].Value = DBNull.Value;

                        logcmd.Parameters.Add("@errno", SqlDbType.Int);
                        logcmd.Parameters["@errno"].Value = msgobj.Number;

                        logcmd.Parameters.Add("@severity", SqlDbType.TinyInt);
                        logcmd.Parameters["@severity"].Value = msgobj.Class;

                        logcmd.Parameters.Add("@logprocid", SqlDbType.Int);
                        logcmd.Parameters["@logprocid"].Value = procid;

                        logcmd.Parameters.Add("@msgtext", SqlDbType.NVarChar, 2048);
                        logcmd.Parameters["@msgtext"].Value = msgobj.Message;

                        logcmd.Parameters.Add("@errproc", SqlDbType.NVarChar, 128);
                        logcmd.Parameters["@errproc"].Value = msgobj.Procedure;

                        logcmd.Parameters.Add("@linenum", SqlDbType.Int);
                        logcmd.Parameters["@linenum"].Value = msgobj.LineNumber;

                        logcmd.Parameters.Add("@username", SqlDbType.NVarChar, 128);
                        logcmd.Parameters["@username"].Value = username;

                        logcmd.Parameters.Add("@appname", SqlDbType.NVarChar, 128);
                        logcmd.Parameters["@appname"].Value = appname;

                        logcmd.Parameters.Add("@hostname", SqlDbType.NVarChar, 128);
                        logcmd.Parameters["@hostname"].Value = hostname;

                        logcmd.Parameters.Add("@p1", SqlDbType.NVarChar, 400);
                        logcmd.Parameters["@p1"].Value = DBNull.Value;
                        logcmd.Parameters.Add("@p2", SqlDbType.NVarChar, 400);
                        logcmd.Parameters["@p2"].Value = DBNull.Value;
                        logcmd.Parameters.Add("@p3", SqlDbType.NVarChar, 400);
                        logcmd.Parameters["@p3"].Value = DBNull.Value;
                        logcmd.Parameters.Add("@p4", SqlDbType.NVarChar, 400);
                        logcmd.Parameters["@p4"].Value = DBNull.Value;
                        logcmd.Parameters.Add("@p5", SqlDbType.NVarChar, 400);
                        logcmd.Parameters["@p5"].Value = DBNull.Value;
                        logcmd.Parameters.Add("@p6", SqlDbType.NVarChar, 400);
                        logcmd.Parameters["@p6"].Value = DBNull.Value;

                        logcmd.ExecuteNonQuery();

                        // Get the output parameter and update the command text,
                        // which has a separate procedure, as it is an add-on.
                        SqlInt64 logid = new SqlInt64((Int64)logcmd.Parameters["@logid"].Value);

                        logcmd.CommandText = "slog.add_cmdtext_sp";
                        logcmd.Parameters.Clear();
                        logcmd.Parameters.Add("@logid", SqlDbType.BigInt);
                        logcmd.Parameters["@logid"].Value = logid.Value;
                        logcmd.Parameters.Add("@cmdtext", SqlDbType.NVarChar, -1);
                        logcmd.Parameters["@cmdtext"].Value = cmdtext;
                        logcmd.ExecuteNonQuery();
                    }
                }
            }

            // If called from a TRY block, we should throw an error for real
            // to ensure that TRY-CATCH in the calling T-SQL is activated.
            if (trycatch && retvalue != 0)
            {
                throw new Exception(fullerrmsg);
            }

            return(retvalue);
        }
    }
예제 #30
0
 public static SqlInt64 Add(SqlInt64 x, SqlInt64 y)
 {
     return (x + y);
 }
예제 #31
0
 public int CompareTo(SqlInt64 value)
 {
     return this.CompareSqlInt64(value);
 }
예제 #32
0
 public static SqlInt64 BitwiseOr(SqlInt64 x, SqlInt64 y)
 {
     return (x | y);
 }
예제 #33
0
 private int CompareSqlInt64(SqlInt64 value)
 {
     if (value.IsNull)
     {
         return 1;
     }
     else
     {
         return this.value.CompareTo(value.Value);
     }
 }
예제 #34
0
 /// <summary>Add or update a value associated with the specified key.</summary>
 /// <param name="key">The key of the value to add or update.</param>
 /// <param name="value">The value to add or update associated with the specified key.</param>
 /// <returns>A fluent SQLNET object.</returns>
 public SQLNET valuebigint(SqlString key, SqlInt64 value)
 {
     return(ValueBigInt(key, value));
 }
예제 #35
0
 public static SqlInt64 Divide(SqlInt64 x, SqlInt64 y)
 {
     return (x/y);
 }
예제 #36
0
        public void GetTypeTest()
        {
            SqlInt64 Test = new SqlInt64(84);

            Assert.Equal("System.Data.SqlTypes.SqlInt64", Test.GetType().ToString());
        }
예제 #37
0
 public static SqlBoolean Equals(SqlInt64 x, SqlInt64 y)
 {
     return (x == y);
 }
예제 #38
0
        public void ArithmeticOperators()
        {
            SqlInt64 Test24   = new SqlInt64(24);
            SqlInt64 Test64   = new SqlInt64(64);
            SqlInt64 Test2550 = new SqlInt64(2550);
            SqlInt64 Test0    = new SqlInt64(0);

            // "+"-operator
            Assert.Equal(2614, Test2550 + Test64);
            try
            {
                SqlInt64 result = Test64 + SqlInt64.MaxValue;
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // "/"-operator
            Assert.Equal(39, Test2550 / Test64);
            Assert.Equal(0, Test24 / Test64);

            try
            {
                SqlInt64 result = Test2550 / Test0;
                Assert.False(true);
            }
            catch (DivideByZeroException e)
            {
                Assert.Equal(typeof(DivideByZeroException), e.GetType());
            }

            // "*"-operator
            Assert.Equal(1536, Test64 * Test24);

            try
            {
                SqlInt64 test = (SqlInt64.MaxValue * Test64);
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // "-"-operator
            Assert.Equal(2526, Test2550 - Test24);

            try
            {
                SqlInt64 test = SqlInt64.MinValue - Test64;
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // "%"-operator
            Assert.Equal(54, Test2550 % Test64);
            Assert.Equal(24, Test24 % Test64);
            Assert.Equal(0, new SqlInt64(100) % new SqlInt64(10));
        }
예제 #39
0
 public static SqlBoolean GreaterThan(SqlInt64 x, SqlInt64 y)
 {
     return (x > y);
 }
예제 #40
0
        public void ArithmeticMethods()
        {
            SqlInt64 Test64  = new SqlInt64(64);
            SqlInt64 Test0   = new SqlInt64(0);
            SqlInt64 Test164 = new SqlInt64(164);
            SqlInt64 TestMax = new SqlInt64(SqlInt64.MaxValue.Value);

            // Add()
            Assert.Equal(64, SqlInt64.Add(Test64, Test0).Value);
            Assert.Equal(228, SqlInt64.Add(Test64, Test164).Value);
            Assert.Equal(164, SqlInt64.Add(Test0, Test164).Value);
            Assert.Equal((long)SqlInt64.MaxValue, SqlInt64.Add(TestMax, Test0).Value);

            try
            {
                SqlInt64.Add(TestMax, Test64);
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // Divide()
            Assert.Equal(2, SqlInt64.Divide(Test164, Test64).Value);
            Assert.Equal(0, SqlInt64.Divide(Test64, Test164).Value);

            try
            {
                SqlInt64.Divide(Test64, Test0);
                Assert.False(true);
            }
            catch (DivideByZeroException e)
            {
                Assert.Equal(typeof(DivideByZeroException), e.GetType());
            }

            // Mod()
            Assert.Equal(36, SqlInt64.Mod(Test164, Test64));
            Assert.Equal(64, SqlInt64.Mod(Test64, Test164));

            // Multiply()
            Assert.Equal(10496, SqlInt64.Multiply(Test64, Test164).Value);
            Assert.Equal(0, SqlInt64.Multiply(Test64, Test0).Value);

            try
            {
                SqlInt64.Multiply(TestMax, Test64);
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // Subtract()
            Assert.Equal(100, SqlInt64.Subtract(Test164, Test64).Value);

            try
            {
                SqlInt64.Subtract(SqlInt64.MinValue, Test164);
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // Modulus ()
            Assert.Equal(36, SqlInt64.Modulus(Test164, Test64));
            Assert.Equal(64, SqlInt64.Modulus(Test64, Test164));
        }
예제 #41
0
 public static SqlBoolean GreaterThanOrEqual(SqlInt64 x, SqlInt64 y)
 {
     return (x >= y);
 }
예제 #42
0
        public void SqlInt64ToSqlString()
        {
            SqlInt64 testInt = new SqlInt64(10101010);

            Assert.Equal("10101010", ((SqlString)testInt).Value);
        }
예제 #43
0
 public static SqlBoolean LessThan(SqlInt64 x, SqlInt64 y)
 {
     return (x < y);
 }
예제 #44
0
 public void ConversionInt64FormatException()
 {
     SqlString String9E300 = new SqlString("9E+300");
     SqlInt64  test        = String9E300.ToSqlInt64().Value;
 }
예제 #45
0
 public static SqlBoolean LessThanOrEqual(SqlInt64 x, SqlInt64 y)
 {
     return (x <= y);
 }
예제 #46
0
 /// <include file='../../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SetSqlInt64/*' />
 public virtual void SetSqlInt64(int ordinal, SqlInt64 value)
 {
     EnsureSubclassOverride();
     ValueUtilsSmi.SetSqlInt64(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value);
 }
예제 #47
0
 public static SqlInt64 Modulus(SqlInt64 x, SqlInt64 y)
 {
     return (x%y);
 }
예제 #48
0
        public void SqlTypes_SqlInt64()
        {
            NpgsqlParameter parameter;
            SqlInt64 value = new SqlInt64(5L);

#if NET_2_0
            parameter = new NpgsqlParameter ();
            parameter.NpgsqlValue = value;
            Assert.AreEqual (NpgsqlDbType.Bigint, parameter.NpgsqlDbType, "#A:NpgsqlDbType");
            Assert.AreEqual (value, parameter.NpgsqlValue, "#A:NpgsqlValue");
            Assert.AreEqual (value, parameter.Value, "#A:Value");

            parameter = new NpgsqlParameter ();
            parameter.NpgsqlValue = SqlInt64.Null;
            Assert.AreEqual (NpgsqlDbType.Bigint, parameter.NpgsqlDbType, "#B:NpgsqlDbType");
            Assert.AreEqual (SqlInt64.Null, parameter.NpgsqlValue, "#B:NpgsqlValue");
            Assert.AreEqual (SqlInt64.Null, parameter.Value, "#B:Value");
#endif

            parameter = new NpgsqlParameter();
            parameter.Value = value;
            Assert.AreEqual(NpgsqlDbType.Bigint, parameter.NpgsqlDbType, "#C:NpgsqlDbType");
#if NET_2_0
            Assert.AreEqual (value, parameter.NpgsqlValue, "#C:NpgsqlValue");
#endif
            Assert.AreEqual(value, parameter.Value, "#C:Value");
        }
 public override void SetSqlInt64(object o, int index, SqlInt64 value)
 {
     this[index].SetSqlInt64(o, value);
 }