Esempio n. 1
0
 public void ConversionInt16FormatException()
 {
     SqlString String9E300 = new SqlString("9E+300");
     SqlInt16  test        = String9E300.ToSqlInt16().Value;
 }
Esempio n. 2
0
        public void ArithmeticOperators()
        {
            SqlInt16 Test24   = new SqlInt16(24);
            SqlInt16 Test64   = new SqlInt16(64);
            SqlInt16 Test2550 = new SqlInt16(2550);
            SqlInt16 Test0    = new SqlInt16(0);

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

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

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

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

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

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

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

            // "%"-operator
            Assert.Equal((SqlInt16)54, Test2550 % Test64);
            Assert.Equal((SqlInt16)24, Test24 % Test64);
            Assert.Equal((SqlInt16)0, new SqlInt16(100) % new SqlInt16(10));
        }
Esempio n. 3
0
    public static void AddTicketItem(SqlInt16 year, SqlInt32 ticketId, SqlInt32 itemId, SqlInt16 quantity,
                                     SqlDouble price, SqlDateTime orderTime, SqlDateTime preparedTime, SqlInt32 parentTicketItemId, out SqlInt32 id)
    {
        string query = "INSERT INTO TicketItem (TicketItemYear, TicketItemTicketId, TicketItemItemId, TicketItemQuantity, TicketItemPendingQuantity, TicketItemPrice, TicketItemOrderTime, TicketItemPreparedTime, TicketItemWhenCanceled, TicketItemIsWasted, TicketItemParentTicketItemId) " +
                       "VALUES (@TicketItemYear, @TicketItemTicketId, @TicketItemItemId, @TicketItemQuantity, NULL, @TicketItemPrice, @TicketItemOrderTime, @TicketItemPreparedTime, NULL, 0, @TicketItemParentTicketItemId);" +
                       "SELECT CAST(scope_identity() AS int)";

        using (SqlConnection conn = new SqlConnection("context connection=true"))
        {
            using (SqlCommand cmd = new SqlCommand(query, conn))
            {
                DatabaseHelper.BuildSqlParameter(cmd, "@TicketItemYear", SqlDbType.SmallInt, year);
                DatabaseHelper.BuildSqlParameter(cmd, "@TicketItemTicketId", SqlDbType.Int, ticketId);
                DatabaseHelper.BuildSqlParameter(cmd, "@TicketItemItemId", SqlDbType.Int, itemId);
                DatabaseHelper.BuildSqlParameter(cmd, "@TicketItemQuantity", SqlDbType.SmallInt, quantity);
                DatabaseHelper.BuildSqlParameter(cmd, "@TicketItemPrice", SqlDbType.Float, price);
                DatabaseHelper.BuildSqlParameter(cmd, "@TicketItemOrderTime", SqlDbType.DateTime, orderTime);
                DatabaseHelper.BuildSqlParameter(cmd, "@TicketItemPreparedTime", SqlDbType.DateTime, preparedTime);
                DatabaseHelper.BuildSqlParameter(cmd, "@TicketItemParentTicketItemId", SqlDbType.Int, parentTicketItemId);
                conn.Open();
                id = new SqlInt32((Int32)cmd.ExecuteScalar());
            }
            conn.Close();
        }
    }
Esempio n. 4
0
        public void Conversions()
        {
            // ToDouble
            Assert.Equal(6464.6464, _test1.ToDouble());

            // ToSqlBoolean ()
            Assert.Equal(new SqlBoolean(1), _test1.ToSqlBoolean());

            SqlDecimal Test = new SqlDecimal(0);

            Assert.True(!Test.ToSqlBoolean().Value);

            Test = new SqlDecimal(0);
            Assert.True(!Test.ToSqlBoolean().Value);
            Assert.True(SqlDecimal.Null.ToSqlBoolean().IsNull);

            // ToSqlByte ()
            Test = new SqlDecimal(250);
            Assert.Equal((byte)250, Test.ToSqlByte().Value);

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

            // ToSqlDouble ()
            Assert.Equal(6464.6464, _test1.ToSqlDouble());

            // ToSqlInt16 ()
            Assert.Equal((short)1, new SqlDecimal(1).ToSqlInt16().Value);

            try
            {
                SqlInt16 test = SqlDecimal.MaxValue.ToSqlInt16().Value;
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // ToSqlInt32 ()
            // LAMESPEC: 6464.6464 --> 64646464 ??? with windows
            // MS.NET seems to return the first 32 bit integer (i.e.
            // Data [0]) but we don't have to follow such stupidity.
            //			Assert.Equal ((int)64646464, Test1.ToSqlInt32 ().Value);
            //			Assert.Equal ((int)1212, new SqlDecimal(12.12m).ToSqlInt32 ().Value);

            try
            {
                SqlInt32 test = SqlDecimal.MaxValue.ToSqlInt32().Value;
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // ToSqlInt64 ()
            Assert.Equal(6464, _test1.ToSqlInt64().Value);

            // ToSqlMoney ()
            Assert.Equal((decimal)6464.6464, _test1.ToSqlMoney().Value);

            try
            {
                SqlMoney test = SqlDecimal.MaxValue.ToSqlMoney().Value;
                Assert.False(true);
            }
            catch (OverflowException e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // ToSqlSingle ()
            Assert.Equal((float)6464.6464, _test1.ToSqlSingle().Value);

            // ToSqlString ()
            Assert.Equal("6464.6464", _test1.ToSqlString().Value);

            // ToString ()
            Assert.Equal("6464.6464", _test1.ToString());
            // NOT WORKING
            Assert.Equal("792281625142643375935439503350000.00", SqlDecimal.Multiply(_test5, _test2).ToString());
            Assert.Equal(1E+38, SqlDecimal.MaxValue.ToSqlDouble());
        }
Esempio n. 5
0
        public void GetTypeTest()
        {
            SqlInt16 Test = new SqlInt16(84);

            Assert.AreEqual("System.Data.SqlTypes.SqlInt16", Test.GetType().ToString(), "Test#1");
        }
Esempio n. 6
0
        public void SqlTypes_SqlInt16()
        {
            NpgsqlParameter parameter;
            SqlInt16 value = new SqlInt16((short)5);

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

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

            parameter = new NpgsqlParameter();
            parameter.Value = value;
            Assert.AreEqual(NpgsqlDbType.SmallInt, parameter.NpgsqlDbType, "#C:NpgsqlDbType");
#if NET_2_0
            Assert.AreEqual (value, parameter.NpgsqlValue, "#C:NpgsqlValue");
#endif
            Assert.AreEqual(value, parameter.Value, "#C:Value");
        }
Esempio n. 7
0
 public static SqlBoolean LessThan(SqlInt16 x, SqlInt16 y)
 {
     return (x < y);
 }
        /// <summary>
        /// Propósito: Método SELECT. Este método hace Select de una fila existente en la base de datos, basado en la llave primaria.
        /// </summary>
        /// <returns>DataTable object si tuvo éxito, sino genera una Exception. </returns>
        /// <remarks>
        /// Propiedades necesarias para este método:
        /// <UL>
        ///		 <LI>IdCurso</LI>
        /// </UL>
        /// Propiedades actualizadas luego de una llamada exitosa a este método:
        /// <UL>
        ///		 <LI>CodError</LI>
        ///		 <LI>IdCurso</LI>
        ///		 <LI>CodigoCurso</LI>
        ///		 <LI>NombreCurso</LI>
        ///		 <LI>Fk_idGradoAcademinico</LI>
        ///		 <LI>Eliminado</LI>
        /// </UL>
        /// Llena todas las propiedades que corresponden al campo en tabla con el valor de la fila seleccionada.
        /// </remarks>
        public override DataTable SeleccionarUno()
        {
            SqlCommand cmdAEjecutar = new SqlCommand();

            cmdAEjecutar.CommandText = "dbo.[pr_Curso_SeleccionarUno]";
            cmdAEjecutar.CommandType = CommandType.StoredProcedure;
            DataTable      toReturn = new DataTable("Curso");
            SqlDataAdapter adapter  = new SqlDataAdapter(cmdAEjecutar);

            // Usar el objeto conexión de la clase base
            cmdAEjecutar.Connection = _conexionBD;

            try
            {
                cmdAEjecutar.Parameters.Add(new SqlParameter("@iidCurso", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _idCurso));
                cmdAEjecutar.Parameters.Add(new SqlParameter("@iCodError", SqlDbType.Int, 4, ParameterDirection.Output, true, 10, 0, "", DataRowVersion.Proposed, _codError));

                if (_conexionBDEsCreadaLocal)
                {
                    // Abre una conexión.
                    _conexionBD.Open();
                }
                else
                {
                    if (_conexionBDProvider.IsTransactionPending)
                    {
                        cmdAEjecutar.Transaction = _conexionBDProvider.CurrentTransaction;
                    }
                }

                // Ejecuta la consulta.
                adapter.Fill(toReturn);
                _codError = Int32.Parse(cmdAEjecutar.Parameters["@iCodError"].Value.ToString());

                if (_codError != (int)ITCRError.AllOk)
                {
                    // Genera un error.
                    throw new Exception("Procedimiento Almacenado 'pr_Curso_SeleccionarUno' reportó el error Código: " + _codError);
                }

                if (toReturn.Rows.Count > 0)
                {
                    _idCurso               = (Int32)toReturn.Rows[0]["idCurso"];
                    _codigoCurso           = (string)toReturn.Rows[0]["codigoCurso"];
                    _nombreCurso           = (string)toReturn.Rows[0]["nombreCurso"];
                    _fk_idGradoAcademinico = (Int32)toReturn.Rows[0]["fk_idGradoAcademinico"];
                    _eliminado             = (Int16)toReturn.Rows[0]["eliminado"];
                }
                return(toReturn);
            }
            catch (Exception ex)
            {
                // Ocurrió un error. le hace Bubble a quien llama y encapsula el objeto Exception
                throw new Exception("cCursoBase::SeleccionarUno::Ocurrió un error." + ex.Message, ex);
            }
            finally
            {
                if (_conexionBDEsCreadaLocal)
                {
                    // Cierra la conexión.
                    _conexionBD.Close();
                }
                cmdAEjecutar.Dispose();
                adapter.Dispose();
            }
        }
Esempio n. 9
0
 public static SqlBoolean GreaterThan(SqlInt16 x, SqlInt16 y)
 {
     return (x > y);
 }
Esempio n. 10
0
 public static SqlBoolean GreaterThanOrEqual(SqlInt16 x, SqlInt16 y)
 {
     return (x >= y);
 }
Esempio n. 11
0
 public static SqlBoolean Equals(SqlInt16 x, SqlInt16 y)
 {
     return (x == y);
 }
Esempio n. 12
0
 public static SqlInt16 Divide(SqlInt16 x, SqlInt16 y)
 {
     return (x/y);
 }
Esempio n. 13
0
 private int CompareSqlInt16(SqlInt16 value)
 {
     if ((value).IsNull)
     {
         return 1;
     }
     else
     {
         return this.value.CompareTo(value.Value);
     }
 }
Esempio n. 14
0
        public void GetXsdTypeTest()
        {
            XmlQualifiedName qualifiedName = SqlInt16.GetXsdType(null);

            Assert.Equal("short", qualifiedName.Name);
        }
Esempio n. 15
0
 public static SqlBoolean LessThanOrEqual(SqlInt16 x, SqlInt16 y)
 {
     return (x <= y);
 }
Esempio n. 16
0
        public override DataTable SelectOne()
        {
            SqlCommand scmCmdToExecute = new SqlCommand();

            scmCmdToExecute.CommandText = "dbo.[pr_FTP_Files_SelectOne]";
            scmCmdToExecute.CommandType = CommandType.StoredProcedure;
            DataTable      dtToReturn = new DataTable("FTP_Files");
            SqlDataAdapter sdaAdapter = new SqlDataAdapter(scmCmdToExecute);

            // Use base class' connection object
            scmCmdToExecute.Connection = m_scoMainConnection;

            try
            {
                scmCmdToExecute.Parameters.Add(new SqlParameter("@iID_Files", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, m_iID_Files));

                if (m_bMainConnectionIsCreatedLocal)
                {
                    // Open connection.
                    m_scoMainConnection.Open();
                }
                else
                {
                    if (m_cpMainConnectionProvider.IsTransactionPending)
                    {
                        scmCmdToExecute.Transaction = m_cpMainConnectionProvider.CurrentTransaction;
                    }
                }

                // Execute query.
                sdaAdapter.Fill(dtToReturn);
                if (dtToReturn.Rows.Count > 0)
                {
                    m_iID_Files          = (Int32)dtToReturn.Rows[0]["ID_Files"];
                    m_siID_FileType      = (Int16)dtToReturn.Rows[0]["ID_FileType"];
                    m_sFileIdentity      = (string)dtToReturn.Rows[0]["FileIdentity"];
                    m_sFileName          = (string)dtToReturn.Rows[0]["FileName"];
                    m_sFilePath          = (string)dtToReturn.Rows[0]["FilePath"];
                    m_siTaiKhoan_Lap     = (Int16)dtToReturn.Rows[0]["TaiKhoan_Lap"];
                    m_daNgay_Lap         = (DateTime)dtToReturn.Rows[0]["Ngay_Lap"];
                    m_siTaiKhoan_SuaCuoi = (Int16)dtToReturn.Rows[0]["TaiKhoan_SuaCuoi"];
                    m_daNgay_SuaCuoi     = (DateTime)dtToReturn.Rows[0]["Ngay_SuaCuoi"];
                    m_sGhiChu            = dtToReturn.Rows[0]["GhiChu"] == System.DBNull.Value ? SqlString.Null : (string)dtToReturn.Rows[0]["GhiChu"];
                    m_bTonTai            = (bool)dtToReturn.Rows[0]["TonTai"];
                }
                return(dtToReturn);
            }
            catch (Exception ex)
            {
                // some error occured. Bubble it to caller and encapsulate Exception object
                throw new Exception("clsFTP_Files::SelectOne::Error occured.", ex);
            }
            finally
            {
                if (m_bMainConnectionIsCreatedLocal)
                {
                    // Close connection.
                    m_scoMainConnection.Close();
                }
                scmCmdToExecute.Dispose();
                sdaAdapter.Dispose();
            }
        }
Esempio n. 17
0
 public static SqlInt16 Modulus(SqlInt16 x, SqlInt16 y)
 {
     return (x%y);
 }
Esempio n. 18
0
        public void Conversions()
        {
            SqlMoney TestMoney100 = new SqlMoney(100);

            // ToDecimal
            Assert.AreEqual((decimal)6464.6464, Test1.ToDecimal(), "#M01");

            // ToDouble
            Assert.AreEqual((double)6464.6464, Test1.ToDouble(), "#M02");

            // ToInt32
            Assert.AreEqual((int)90000, Test2.ToInt32(), "#M03");
            Assert.AreEqual((int)6465, Test1.ToInt32(), "#M04");

            // ToInt64
            Assert.AreEqual((long)90000, Test2.ToInt64(), "#M05");
            Assert.AreEqual((long)6465, Test1.ToInt64(), "#M06");

            // ToSqlBoolean ()
            Assert.IsTrue(Test1.ToSqlBoolean().Value, "#M07");
            Assert.IsTrue(!SqlMoney.Zero.ToSqlBoolean().Value, "#M08");
            Assert.IsTrue(SqlMoney.Null.ToSqlBoolean().IsNull, "#M09");

            // ToSqlByte ()
            Assert.AreEqual((byte)100, TestMoney100.ToSqlByte().Value, "#M10");

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

            // ToSqlDecimal ()
            Assert.AreEqual((decimal)6464.6464, Test1.ToSqlDecimal().Value, "#M13");
            Assert.AreEqual(-45000.0000m, Test4.ToSqlDecimal().Value, "#M14");

            // ToSqlInt16 ()
            Assert.AreEqual((short)6465, Test1.ToSqlInt16().Value, "#M15");

            try
            {
                SqlInt16 test = SqlMoney.MaxValue.ToSqlInt16().Value;
                Assert.Fail("#M17");
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M18");
            }

            // ToSqlInt32 ()
            Assert.AreEqual((int)6465, Test1.ToSqlInt32().Value, "#M19");
            Assert.AreEqual((int)(-45000), Test4.ToSqlInt32().Value, "#M20");

            try
            {
                SqlInt32 test = SqlMoney.MaxValue.ToSqlInt32().Value;
                Assert.Fail("#M21");
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M22");
            }

            // ToSqlInt64 ()
            Assert.AreEqual((long)6465, Test1.ToSqlInt64().Value, "#M23");
            Assert.AreEqual((long)(-45000), Test4.ToSqlInt64().Value, "#M24");

            // ToSqlSingle ()
            Assert.AreEqual((float)6464.6464, Test1.ToSqlSingle().Value, "#M25");

            // ToSqlString ()
            Assert.AreEqual("6464.6464", Test1.ToSqlString().Value, "#M26");
            Assert.AreEqual("90000.0000", Test2.ToSqlString().Value, "#M27");

            // ToString ()
            Assert.AreEqual("6464.6464", Test1.ToString(), "#M28");
            Assert.AreEqual("90000.0000", Test2.ToString(), "#M29");
        }
Esempio n. 19
0
 public static SqlInt16 Multiply(SqlInt16 x, SqlInt16 y)
 {
     return (x*y);
 }
Esempio n. 20
0
        public void GetXsdTypeTest()
        {
            XmlQualifiedName qualifiedName = SqlInt16.GetXsdType(null);

            NUnit.Framework.Assert.AreEqual("short", qualifiedName.Name, "#A01");
        }
Esempio n. 21
0
 public static SqlBoolean NotEquals(SqlInt16 x, SqlInt16 y)
 {
     return (x != y);
 }
Esempio n. 22
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 System.Byte[])
                {
                    sqlVal = new SqlBinary((byte[])comVal);
                }
                else if (comVal is System.Char)
                {
                    sqlVal = new SqlString(((char)comVal).ToString());
                }
                else if (comVal is System.Char[])
                {
                    sqlVal = new SqlChars((System.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 Int16)
                {
                    sqlVal = new SqlInt16((Int16)comVal);
                }
                else if (comVal is Int32)
                {
                    sqlVal = new SqlInt32((Int32)comVal);
                }
                else if (comVal is Int64)
                {
                    sqlVal = new SqlInt64((Int64)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.Assert(false, "unknown SqlType class stored in sqlVal");
                }
#endif
            }
            return(sqlVal);
        }
Esempio n. 23
0
        public static SqlInt16 OnesComplement(SqlInt16 x)
        {
            if (x.IsNull)
            {
                return Null;
            }

            return ~x;
        }
Esempio n. 24
0
 public int CompareTo(SqlInt16 value)
 {
     return this.CompareSqlInt16(value);
 }
Esempio n. 25
0
 public static SqlInt16 Subtract(SqlInt16 x, SqlInt16 y)
 {
     return (x - y);
 }
Esempio n. 26
0
    /// <summary>
    ///  Checks whether given string is a certain type of "numeric"
    /// </summary>
    /// <param name="field">Varchar string</param>
    /// <param name="sqltype">A type to compare</param>
    /// <returns></returns>
    public static SqlBoolean fnIsNumeric(SqlString field, string sqltype)
    {
        var    result       = new SqlBoolean(0); // default False
        string errorMessage = string.Empty;

        // Determine base type and any decimal precision parameters
        if (sqltype == null)
        {
            return(result);
        }
        var type          = sqltype.ToString().Trim().ToLower();
        var typePrecision = string.Empty;

        if (type.Contains("("))
        {
            typePrecision = type.Substring(type.IndexOf("(") + 1).Replace(")", "").Trim();
            type          = type.Substring(0, type.IndexOf("("));
        }

        try
        {
            switch (type)
            {
            case "bigint":
                var sqlBigInt = new SqlInt64();
                sqlBigInt = field.ToSqlInt64();
                if (sqlBigInt.IsNull == false)
                {
                    result = true;
                }
                break;

            case "bit":
                if (field.Value.Contains("+") || field.Value.Contains("-"))
                {
                    result = false;
                }
                else
                {
                    var sqlBit = new SqlByte();
                    sqlBit = field.ToSqlByte();
                    if (sqlBit.IsNull == false && (sqlBit == 0 || sqlBit == 1))
                    {
                        result = true;
                    }
                }
                break;

            case "decimal":
            case "numeric":
                // Support format decimal(x,0) or decimal(x,y) where true only if number fits in precision x,y
                // Precision = maximum number of digits to the left of the decimal point
                // If decimal(x,y) supplied, maximum precision = x - y
                var sqlDecimal = new SqlDecimal();
                sqlDecimal = field.ToSqlDecimal();
                if (sqlDecimal.IsNull == false)
                {
                    result = true;
                    if (typePrecision.Length > 0)
                    {
                        var parameters = typePrecision.Split(",".ToCharArray());
                        if (parameters.Length > 0)
                        {
                            int precision = 0;
                            int.TryParse(parameters[0], out precision);
                            if (precision > 0)
                            {
                                if (parameters.Length > 1)
                                {
                                    int scale = 0;
                                    int.TryParse(parameters[1], out scale);
                                    precision = precision - scale;
                                }
                                var    x = " " + sqlDecimal.Value.ToString().Replace("-", "") + ".";
                                string decPrecisionDigitCount = x.Substring(0, x.IndexOf(".")).Trim();
                                if (decPrecisionDigitCount.Length > precision)
                                {
                                    result = false;
                                }
                            }
                        }
                    }
                }
                break;

            case "float":
                var sqlFloat = new SqlDouble();
                sqlFloat = field.ToSqlDouble();
                if (sqlFloat.IsNull == false)
                {
                    result = true;
                }
                break;

            case "int":
                var sqlInt = new SqlInt32();
                sqlInt = field.ToSqlInt32();
                if (sqlInt.IsNull == false)
                {
                    result = true;
                }
                break;

            case "money":
                var sqlMoney = new SqlMoney();
                sqlMoney = field.ToSqlMoney();
                if (sqlMoney.IsNull == false)
                {
                    result = true;
                }
                break;

            case "real":
                var SqlSingle = new SqlSingle();
                SqlSingle = field.ToSqlSingle();
                if (SqlSingle.IsNull == false)
                {
                    result = true;
                }
                break;

            case "smallint":
                var sqlSmallInt = new SqlInt16();
                sqlSmallInt = field.ToSqlInt16();
                if (sqlSmallInt.IsNull == false)
                {
                    result = true;
                }
                break;

            case "smallmoney":
                var sqlSmallMoney = new SqlMoney();
                sqlSmallMoney = field.ToSqlMoney();
                if (sqlSmallMoney.IsNull == false)
                {
                    // Ensure that it will fit in a 4-byte small money
                    if (sqlSmallMoney.Value >= -214748.3648m && sqlSmallMoney.Value <= 214748.3647m)
                    {
                        result = true;
                    }
                }
                break;

            case "tinyint":
                var sqlTinyInt = new SqlByte();
                sqlTinyInt = field.ToSqlByte();
                if (sqlTinyInt.IsNull == false)
                {
                    result = true;
                }
                break;

            default:
                errorMessage = "Unrecognized format";
                break;
            }
        }
        catch (Exception)
        {
            if (string.IsNullOrEmpty(errorMessage) == false)
            {
                result = SqlBoolean.Null;
            }
        }
        return(result);
    }
Esempio n. 27
0
 public static SqlInt16 Xor(SqlInt16 x, SqlInt16 y)
 {
     return (x ^ y);
 }
Esempio n. 28
0
        public void Conversions()
        {
            SqlInt16 Test12   = new SqlInt16(12);
            SqlInt16 Test0    = new SqlInt16(0);
            SqlInt16 TestNull = SqlInt16.Null;
            SqlInt16 Test1000 = new SqlInt16(1000);
            SqlInt16 Test288  = new SqlInt16(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);

            // ToSqlInt64 ()
            Assert.Equal(12, Test12.ToSqlInt64().Value);
            Assert.Equal(0, Test0.ToSqlInt64().Value);
            Assert.Equal(288, Test288.ToSqlInt64().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());
        }
Esempio n. 29
0
 public static SqlInt16 Add(SqlInt16 x, SqlInt16 y)
 {
     return (x + y);
 }
Esempio n. 30
0
        public void ArithmeticMethods()
        {
            SqlInt16 Test64  = new SqlInt16(64);
            SqlInt16 Test0   = new SqlInt16(0);
            SqlInt16 Test164 = new SqlInt16(164);
            SqlInt16 TestMax = new SqlInt16(SqlInt16.MaxValue.Value);

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

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

            // Divide()
            Assert.Equal((short)2, SqlInt16.Divide(Test164, Test64).Value);
            Assert.Equal((short)0, SqlInt16.Divide(Test64, Test164).Value);
            try
            {
                SqlInt16.Divide(Test64, Test0);
                Assert.False(true);
            }
            catch (DivideByZeroException e)
            {
                Assert.Equal(typeof(DivideByZeroException), e.GetType());
            }

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

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

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

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

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

            // Modulus ()
            Assert.Equal((SqlInt16)36, SqlInt16.Modulus(Test164, Test64));
            Assert.Equal((SqlInt16)64, SqlInt16.Modulus(Test64, Test164));
        }
Esempio n. 31
0
 public static SqlInt16 BitwiseAnd(SqlInt16 x, SqlInt16 y)
 {
     return (x & y);
 }
Esempio n. 32
0
    public static void Transposing
    (
        SqlString Query,                                                       // the query or the stored procedure name. Calling a stored procedure always should begin with keyword EXEC.
        [SqlFacet(IsNullable = true, MaxSize = 4000)] SqlString Params,        // the query or the stored procedure parameters
        [SqlFacet(IsNullable = true, MaxSize = 4)] SqlInt16 Rco,               // rotate column ordinal
        [SqlFacet(IsNullable = true, MaxSize = 4)] SqlInt16 KeyValueOption,    // do we use key value option
        [SqlFacet(IsNullable = true, MaxSize = 4000)] SqlString ColumnMapping, // columns mappings
        [SqlFacet(IsNullable = true, MaxSize = 256)] SqlString TableName       // temp(permanent) table name

    )
    {
        DataSet ds          = null;
        string  errorString = "";

        try
        {
            bool           mySp         = false;
            string         queryValue   = Query.Value.ToString();
            SqlParameter[] listOfParams = null;
            string[]       splitQueries = queryValue.Split(';');

            //
            // Make parameters
            //
            if (Params.IsNull == false && Params.Value.ToString().Equals(string.Empty) == false)
            {
                listOfParams = DataAccess.MakeParams(Params.Value, ref errorString);
            }

            //
            // Quit if any errors
            //
            if (errorString.Equals(string.Empty) == false)
            {
                SqlContext.Pipe.Send("There is an error when trying to determine parameters ! Error :" + errorString);
                return;
            }


            //
            // Determine the dataset object
            //
            ds = DataAccess.GetDataSet(
                queryValue,
                mySp,
                listOfParams,
                ref errorString
                );

            //
            // Quit if any errors
            //
            if (errorString.Equals(string.Empty) == false)
            {
                SqlContext.Pipe.Send("There is an error when trying to determine the dataset ! Error :" + errorString);
                return;
            }


            //
            // Let's iterate through the table collection
            //
            foreach (DataTable t in ds.Tables)
            {
                DataTable tblCopy = t;

                //
                // Temporary limitation to MAX_COLS
                //
                if (t.Rows.Count > MAX_COLS)
                {
                    SqlContext.Pipe.Send("You are trying to generate table with more then : " + MAX_COLS.ToString() +
                                         " columns! I will display first " + MAX_COLS.ToString() + " columns !");
                    tblCopy = t.Clone();

                    //
                    // Use the ImportRow method to copy from original table to its clone
                    //
                    for (int i = 0; i <= MAX_COLS; ++i)
                    {
                        tblCopy.ImportRow(t.Rows[i]);
                    }
                }
                DataTable tblRt = null;
                if (KeyValueOption.Value == 0)
                {
                    tblRt = TableManipulation.RotateTable(tblCopy, Rco.Value);
                }
                else
                {
                    tblRt = TableManipulation.RotateTableWithKeyValue(tblCopy, ColumnMapping.IsNull ? null : ColumnMapping.Value);
                }

                //
                // If we want to save our results
                //
                if (TableName.IsNull == false)
                {
                    string[] fullName         = TableName.Value.Split('.');
                    string   partialTableName = fullName[fullName.Length - 1];

                    //
                    // First we build T-SQL to create the table
                    //
                    string cmdToExecute = DataAccess.CreateTABLE(TableName.Value, tblRt);
                    //
                    // Then build T-SQL to create the table value type ( SQL 2008+ )
                    //
                    cmdToExecute += ";\n" + DataAccess.CreateTYPE(partialTableName, tblRt);

                    DataAccess.ExecuteNonQuery(cmdToExecute);

                    DataAccess.SaveResult(TableName.Value, tblRt);
                    //
                    // Drop the type
                    //
                    DataAccess.ExecuteNonQuery("DROP TYPE MATRIX.TVP_" + partialTableName);
                }
                //
                // Send the result to the client
                //
                PipeUtilities.PipeDataTable(tblRt);
            }
        }
        catch (Exception ex)
        {
            errorString = ex.Message;

            if (ex.InnerException != null)
            {
                errorString += "\r\n" + ex.InnerException.Message;
            }

            SqlContext.Pipe.Send("There is an error in the stored procedure : " + errorString);
        }
        finally
        {
            ds = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
    }
Esempio n. 33
0
 public static SqlInt16 BitwiseOr(SqlInt16 x, SqlInt16 y)
 {
     return (x | y);
 }
Esempio n. 34
0
        public static object ChangeTypeForXML(object value, Type type)
        {
            StorageType storageType = DataStorageHelper.GetStorageType(type);
            StorageType type3       = DataStorageHelper.GetStorageType(value.GetType());

            switch (storageType)
            {
            case StorageType.Boolean:
                if ("1" != ((string)value))
                {
                    if ("0" == ((string)value))
                    {
                        return(false);
                    }
                    return(XmlConvert.ToBoolean((string)value));
                }
                return(true);

            case StorageType.Char:
                return(XmlConvert.ToChar((string)value));

            case StorageType.SByte:
                return(XmlConvert.ToSByte((string)value));

            case StorageType.Byte:
                return(XmlConvert.ToByte((string)value));

            case StorageType.Int16:
                return(XmlConvert.ToInt16((string)value));

            case StorageType.UInt16:
                return(XmlConvert.ToUInt16((string)value));

            case StorageType.Int32:
                return(XmlConvert.ToInt32((string)value));

            case StorageType.UInt32:
                return(XmlConvert.ToUInt32((string)value));

            case StorageType.Int64:
                return(XmlConvert.ToInt64((string)value));

            case StorageType.UInt64:
                return(XmlConvert.ToUInt64((string)value));

            case StorageType.Single:
                return(XmlConvert.ToSingle((string)value));

            case StorageType.Double:
                return(XmlConvert.ToDouble((string)value));

            case StorageType.Decimal:
                return(XmlConvert.ToDecimal((string)value));

            case StorageType.DateTime:
                return(XmlConvert.ToDateTime((string)value, XmlDateTimeSerializationMode.RoundtripKind));

            case StorageType.TimeSpan:
            {
                StorageType type2 = type3;
                switch (type2)
                {
                case StorageType.Int32:
                    return(new TimeSpan((long)((int)value)));

                case StorageType.Int64:
                    return(new TimeSpan((long)value));
                }
                if (type2 != StorageType.String)
                {
                    break;
                }
                return(XmlConvert.ToTimeSpan((string)value));
            }

            case StorageType.Guid:
                return(XmlConvert.ToGuid((string)value));

            case StorageType.Uri:
                return(new Uri((string)value));

            case StorageType.SqlBinary:
                return(new SqlBinary(Convert.FromBase64String((string)value)));

            case StorageType.SqlBoolean:
                return(new SqlBoolean(XmlConvert.ToBoolean((string)value)));

            case StorageType.SqlByte:
                return(new SqlByte(XmlConvert.ToByte((string)value)));

            case StorageType.SqlBytes:
                return(new SqlBytes(Convert.FromBase64String((string)value)));

            case StorageType.SqlChars:
                return(new SqlChars(((string)value).ToCharArray()));

            case StorageType.SqlDateTime:
                return(new SqlDateTime(XmlConvert.ToDateTime((string)value, XmlDateTimeSerializationMode.RoundtripKind)));

            case StorageType.SqlDecimal:
                return(SqlDecimal.Parse((string)value));

            case StorageType.SqlDouble:
                return(new SqlDouble(XmlConvert.ToDouble((string)value)));

            case StorageType.SqlGuid:
                return(new SqlGuid(XmlConvert.ToGuid((string)value)));

            case StorageType.SqlInt16:
                return(new SqlInt16(XmlConvert.ToInt16((string)value)));

            case StorageType.SqlInt32:
                return(new SqlInt32(XmlConvert.ToInt32((string)value)));

            case StorageType.SqlInt64:
                return(new SqlInt64(XmlConvert.ToInt64((string)value)));

            case StorageType.SqlMoney:
                return(new SqlMoney(XmlConvert.ToDecimal((string)value)));

            case StorageType.SqlSingle:
                return(new SqlSingle(XmlConvert.ToSingle((string)value)));

            case StorageType.SqlString:
                return(new SqlString((string)value));

            default:
            {
                if ((DBNull.Value == value) || (value == null))
                {
                    return(DBNull.Value);
                }
                switch (type3)
                {
                case StorageType.Boolean:
                    return(XmlConvert.ToString((bool)value));

                case StorageType.Char:
                    return(XmlConvert.ToString((char)value));

                case StorageType.SByte:
                    return(XmlConvert.ToString((sbyte)value));

                case StorageType.Byte:
                    return(XmlConvert.ToString((byte)value));

                case StorageType.Int16:
                    return(XmlConvert.ToString((short)value));

                case StorageType.UInt16:
                    return(XmlConvert.ToString((ushort)value));

                case StorageType.Int32:
                    return(XmlConvert.ToString((int)value));

                case StorageType.UInt32:
                    return(XmlConvert.ToString((uint)value));

                case StorageType.Int64:
                    return(XmlConvert.ToString((long)value));

                case StorageType.UInt64:
                    return(XmlConvert.ToString((ulong)value));

                case StorageType.Single:
                    return(XmlConvert.ToString((float)value));

                case StorageType.Double:
                    return(XmlConvert.ToString((double)value));

                case StorageType.Decimal:
                    return(XmlConvert.ToString((decimal)value));

                case StorageType.DateTime:
                    return(XmlConvert.ToString((DateTime)value, XmlDateTimeSerializationMode.RoundtripKind));

                case StorageType.TimeSpan:
                    return(XmlConvert.ToString((TimeSpan)value));

                case StorageType.String:
                    return((string)value);

                case StorageType.Guid:
                    return(XmlConvert.ToString((Guid)value));

                case StorageType.CharArray:
                    return(new string((char[])value));

                case StorageType.SqlBinary:
                {
                    SqlBinary binary = (SqlBinary)value;
                    return(Convert.ToBase64String(binary.Value));
                }

                case StorageType.SqlBoolean:
                {
                    SqlBoolean flag = (SqlBoolean)value;
                    return(XmlConvert.ToString(flag.Value));
                }

                case StorageType.SqlByte:
                {
                    SqlByte num7 = (SqlByte)value;
                    return(XmlConvert.ToString(num7.Value));
                }

                case StorageType.SqlBytes:
                    return(Convert.ToBase64String(((SqlBytes)value).Value));

                case StorageType.SqlChars:
                    return(new string(((SqlChars)value).Value));

                case StorageType.SqlDateTime:
                {
                    SqlDateTime time = (SqlDateTime)value;
                    return(XmlConvert.ToString(time.Value, XmlDateTimeSerializationMode.RoundtripKind));
                }

                case StorageType.SqlDecimal:
                {
                    SqlDecimal num6 = (SqlDecimal)value;
                    return(num6.ToString());
                }

                case StorageType.SqlDouble:
                {
                    SqlDouble num5 = (SqlDouble)value;
                    return(XmlConvert.ToString(num5.Value));
                }

                case StorageType.SqlGuid:
                {
                    SqlGuid guid = (SqlGuid)value;
                    return(XmlConvert.ToString(guid.Value));
                }

                case StorageType.SqlInt16:
                {
                    SqlInt16 num4 = (SqlInt16)value;
                    return(XmlConvert.ToString(num4.Value));
                }

                case StorageType.SqlInt32:
                {
                    SqlInt32 num3 = (SqlInt32)value;
                    return(XmlConvert.ToString(num3.Value));
                }

                case StorageType.SqlInt64:
                {
                    SqlInt64 num2 = (SqlInt64)value;
                    return(XmlConvert.ToString(num2.Value));
                }

                case StorageType.SqlMoney:
                {
                    SqlMoney money = (SqlMoney)value;
                    return(XmlConvert.ToString(money.Value));
                }

                case StorageType.SqlSingle:
                {
                    SqlSingle num = (SqlSingle)value;
                    return(XmlConvert.ToString(num.Value));
                }

                case StorageType.SqlString:
                {
                    SqlString text = (SqlString)value;
                    return(text.Value);
                }
                }
                IConvertible convertible = value as IConvertible;
                if (convertible != null)
                {
                    return(convertible.ToString(CultureInfo.InvariantCulture));
                }
                IFormattable formattable = value as IFormattable;
                if (formattable != null)
                {
                    return(formattable.ToString(null, CultureInfo.InvariantCulture));
                }
                return(value.ToString());
            }
            }
            return((TimeSpan)value);
        }
Esempio n. 35
0
 public override void SetSqlInt16(object o, int index, SqlInt16 value)
 {
     this[index].SetSqlInt16(o, value);
 }
Esempio n. 36
0
 /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SetSqlInt16/*' />
 public virtual void SetSqlInt16(int ordinal, SqlInt16 value) => ValueUtilsSmi.SetSqlInt16(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value);
Esempio n. 37
0
        public void SqlInt16ToSqlInt64()
        {
            SqlInt16 Test64 = new SqlInt16(64);

            Assert.AreEqual((long)64, ((SqlInt64)Test64).Value, "#AC01");
        }
Esempio n. 38
0
        public void Conversions()
        {
            SqlMoney TestMoney100 = new SqlMoney(100);

            // ToDecimal
            Assert.Equal((decimal)6464.6464, _test1.ToDecimal());

            // ToDouble
            Assert.Equal(6464.6464, _test1.ToDouble());

            // ToInt32
            Assert.Equal(90000, _test2.ToInt32());
            Assert.Equal(6465, _test1.ToInt32());

            // ToInt64
            Assert.Equal(90000, _test2.ToInt64());
            Assert.Equal(6465, _test1.ToInt64());

            // ToSqlBoolean ()
            Assert.True(_test1.ToSqlBoolean().Value);
            Assert.True(!SqlMoney.Zero.ToSqlBoolean().Value);
            Assert.True(SqlMoney.Null.ToSqlBoolean().IsNull);

            // ToSqlByte ()
            Assert.Equal((byte)100, TestMoney100.ToSqlByte().Value);

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

            // ToSqlDecimal ()
            Assert.Equal((decimal)6464.6464, _test1.ToSqlDecimal().Value);
            Assert.Equal(-45000.0000m, _test4.ToSqlDecimal().Value);

            // ToSqlInt16 ()
            Assert.Equal((short)6465, _test1.ToSqlInt16().Value);

            try
            {
                SqlInt16 test = SqlMoney.MaxValue.ToSqlInt16().Value;
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // ToSqlInt32 ()
            Assert.Equal(6465, _test1.ToSqlInt32().Value);
            Assert.Equal(-45000, _test4.ToSqlInt32().Value);

            try
            {
                SqlInt32 test = SqlMoney.MaxValue.ToSqlInt32().Value;
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // ToSqlInt64 ()
            Assert.Equal(6465, _test1.ToSqlInt64().Value);
            Assert.Equal(-45000, _test4.ToSqlInt64().Value);

            // ToSqlSingle ()
            Assert.Equal((float)6464.6464, _test1.ToSqlSingle().Value);

            // ToSqlString ()
            Assert.Equal(6464.6464.ToString(), _test1.ToSqlString().Value);
            Assert.Equal(90000.00m.ToString(), _test2.ToSqlString().Value);

            // ToString ()
            Assert.Equal(6464.6464.ToString(), _test1.ToString());
            Assert.Equal(90000.00m.ToString(), _test2.ToString());
        }
Esempio n. 39
0
 public PInt16(short value)
 {
     _sql      = value;
     ValueType = PValueType.Value;
 }
Esempio n. 40
0
        public void Conversions()
        {
            SqlInt16 Test12   = new SqlInt16(12);
            SqlInt16 Test0    = new SqlInt16(0);
            SqlInt16 TestNull = SqlInt16.Null;
            SqlInt16 Test1000 = new SqlInt16(1000);
            SqlInt16 Test288  = new SqlInt16(288);

            // ToSqlBoolean ()
            Assert.IsTrue(Test12.ToSqlBoolean().Value, "TestA#1");
            Assert.IsTrue(!Test0.ToSqlBoolean().Value, "TestA#2");
            Assert.IsTrue(TestNull.ToSqlBoolean().IsNull, "TestA#3");

            // ToSqlByte ()
            Assert.AreEqual((byte)12, Test12.ToSqlByte().Value, "TestB#1");
            Assert.AreEqual((byte)0, Test0.ToSqlByte().Value, "TestB#2");

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

            // ToSqlDecimal ()
            Assert.AreEqual((decimal)12, Test12.ToSqlDecimal().Value, "TestC#1");
            Assert.AreEqual((decimal)0, Test0.ToSqlDecimal().Value, "TestC#2");
            Assert.AreEqual((decimal)288, Test288.ToSqlDecimal().Value, "TestC#3");

            // ToSqlDouble ()
            Assert.AreEqual((double)12, Test12.ToSqlDouble().Value, "TestD#1");
            Assert.AreEqual((double)0, Test0.ToSqlDouble().Value, "TestD#2");
            Assert.AreEqual((double)1000, Test1000.ToSqlDouble().Value, "TestD#3");

            // ToSqlInt32 ()
            Assert.AreEqual((int)12, Test12.ToSqlInt32().Value, "TestE#1");
            Assert.AreEqual((int)0, Test0.ToSqlInt32().Value, "TestE#2");
            Assert.AreEqual((int)288, Test288.ToSqlInt32().Value, "TestE#3");

            // ToSqlInt64 ()
            Assert.AreEqual((long)12, Test12.ToSqlInt64().Value, "TestF#1");
            Assert.AreEqual((long)0, Test0.ToSqlInt64().Value, "TestF#2");
            Assert.AreEqual((long)288, Test288.ToSqlInt64().Value, "TestF#3");

            // ToSqlMoney ()
            Assert.AreEqual(12.0000M, Test12.ToSqlMoney().Value, "TestG#1");
            Assert.AreEqual((decimal)0, Test0.ToSqlMoney().Value, "TestG#2");
            Assert.AreEqual(288.0000M, Test288.ToSqlMoney().Value, "TestG#3");

            // ToSqlSingle ()
            Assert.AreEqual((float)12, Test12.ToSqlSingle().Value, "TestH#1");
            Assert.AreEqual((float)0, Test0.ToSqlSingle().Value, "TestH#2");
            Assert.AreEqual((float)288, Test288.ToSqlSingle().Value, "TestH#3");

            // ToSqlString ()
            Assert.AreEqual("12", Test12.ToSqlString().Value, "TestI#1");
            Assert.AreEqual("0", Test0.ToSqlString().Value, "TestI#2");
            Assert.AreEqual("288", Test288.ToSqlString().Value, "TestI#3");

            // ToString ()
            Assert.AreEqual("12", Test12.ToString(), "TestJ#1");
            Assert.AreEqual("0", Test0.ToString(), "TestJ#2");
            Assert.AreEqual("288", Test288.ToString(), "TestJ#3");
        }
Esempio n. 41
0
 public PInt16(SqlInt16 value)
 {
     _sql      = value;
     ValueType = value.IsNull ? PValueType.Null : PValueType.Value;
 }
Esempio n. 42
0
 public virtual void SetSqlInt16(object o, int index, SqlInt16 value)
 {
     SetValue(o, index, value);
 }
Esempio n. 43
0
 private PInt16(PValueType type)
 {
     ValueType = type;
     _sql      = SqlInt16.Null;
 }
Esempio n. 44
0
 public virtual void SetSqlInt16(int ordinal, SqlInt16 value)
 {
     EnsureSubclassOverride();
     ValueUtilsSmi.SetSqlInt16(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value);
 }
Esempio n. 45
0
        public static PInt16 Parse(string s, PValueType type)
        {
            var sp = string.IsNullOrEmpty(s) ? new PInt16(type) : SqlInt16.Parse(s);

            return(sp);
        }
Esempio n. 46
0
        public void Conversions()
        {
            SqlSingle Test0    = new SqlSingle(0);
            SqlSingle Test1    = new SqlSingle(250);
            SqlSingle Test2    = new SqlSingle(64E+16);
            SqlSingle Test3    = new SqlSingle(64E+30);
            SqlSingle TestNull = SqlSingle.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 (Exception 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 (Exception 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 (Exception 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 (Exception 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 = Test3.ToSqlInt64().Value;
                Assert.Fail("#M03F");
            } catch (Exception 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 = Test3.ToSqlMoney().Value;
                Assert.Fail("#M03G");
            } catch (Exception e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04G");
            }


            // ToSqlString ()
            Assert.AreEqual("250", Test1.ToSqlString().Value, "#M01H");
            Assert.AreEqual("0", Test0.ToSqlString().Value, "#M02H");
            Assert.AreEqual("6.4E+17", Test2.ToSqlString().Value, "#M03H");

            // ToString ()
            Assert.AreEqual("250", Test1.ToString(), "#M01I");
            Assert.AreEqual("0", Test0.ToString(), "#M02I");
            Assert.AreEqual("6.4E+17", Test2.ToString(), "#M03I");
        }
Esempio n. 47
0
 public virtual void SetSqlInt16(int ordinal, SqlInt16 value)
 {
     throw ADP.InternalError(ADP.InternalErrorCode.UnimplementedSMIMethod);
 }
Esempio n. 48
0
    private static TicketItemCouponTempTableModel[] CreateTicketItemCouponTempTable(SqlInt32 ticketId, SqlInt16 year)
    {
        List <TicketItemCouponTempTableModel> list = new List <TicketItemCouponTempTableModel>();
        string query =
            "SELECT TicketCouponCouponId, TicketCouponYear, TicketCouponTicketItemId " +
            "FROM TicketCoupon " +
            "WHERE (TicketCouponYear=@TicketYear AND TicketCouponTicketId=@TicketId);";

        using (SqlConnection conn = new SqlConnection("context connection=true"))
        {
            using (SqlCommand cmd = new SqlCommand(query, conn))
            {
                DatabaseHelper.BuildSqlParameter(cmd, "@TicketYear", SqlDbType.SmallInt, year);
                DatabaseHelper.BuildSqlParameter(cmd, "@TicketId", SqlDbType.Int, ticketId);
                conn.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    list.Add(BuildTicketItemCouponTempTableModel(rdr));
                }
            }
            conn.Close();
        }
        return(list.ToArray());
    }
Esempio n. 49
0
        public static SqlBoolean op_Explicit(SqlInt16 x)
        {
            if (x.IsNull)
                return SqlBoolean.Null;

            return new SqlBoolean(x.Value != 0);
        }