Example #1
0
        /// <summary>
        /// Generates an Array of Parameters for the columns that make up the IType
        /// </summary>
        /// <param name="factory">The SessionFactory to use to get the DbTypes.</param>
        /// <param name="tableAlias">The Alias for the Table.</param>
        /// <param name="columnNames">The names of the Columns that compose the IType</param>
        /// <param name="type">The IType to turn into Parameters</param>
        /// <returns>An Array of <see cref="Parameter"/> objects</returns>
        public static Parameter[] GenerateParameters(IMapping factory, string tableAlias, string[] columnNames, IType type)
        {
            SqlType[] sqlTypes = type.SqlTypes(factory);

            Parameter[] parameters = new Parameter[sqlTypes.Length];

            for (int i = 0; i < sqlTypes.Length; i++)
            {
                if (sqlTypes[i].LengthDefined)
                {
                    ParameterLength param = new ParameterLength(columnNames[i], tableAlias, sqlTypes[i]);
                    parameters[i] = param;
                }
                else if (sqlTypes[i].PrecisionDefined)
                {
                    ParameterPrecisionScale param = new ParameterPrecisionScale(columnNames[i], tableAlias, sqlTypes[i]);
                    parameters[i] = param;
                }
                else
                {
                    parameters[i] = new Parameter(columnNames[i], tableAlias, sqlTypes[i]);
                }
            }

            return(parameters);
        }
Example #2
0
        /// <summary>
        /// Determines wether this instance and the specified object
        /// are the same Type and have the same values.
        /// </summary>
        /// <param name="obj">An object to compare to this instance.</param>
        /// <returns>
        /// <c>true</c> if the object is a <see cref="ParameterLength" /> and has the
        /// same values.
        /// </returns>
        public override bool Equals(object obj)
        {
            ParameterLength rhs = null;

            // Step1: Perform an equals test
            if (obj == this)
            {
                return(true);
            }

            // Step	2: Instance of check - don't need to worry about subclasses
            // getting in here because this class is sealed.
            rhs = obj as ParameterLength;
            if (rhs == null)
            {
                return(false);
            }

            //Step 3: Check each important field

            // isTypeSensitive is false because we want to check the values
            // of the fields - we know the rhs is a subclass of Parameter.
            if (this.Equals(rhs, false) == false)
            {
                return(false);
            }


            return(this.Length == rhs.Length);
        }
		public void EqualsLengthDiffType()
		{
			Parameter x = new Parameter( "name", "alias", new SqlTypes.AnsiStringSqlType(5) );
			ParameterLength y = new ParameterLength( "name", "alias", new SqlTypes.AnsiStringSqlType(5) );
			
			// even though these contain the exact same values - they should not be 
			// equal because they are different types
			Assert.IsFalse( x.Equals(y) );
			Assert.IsFalse( y.Equals(x) );
		}
		public void EqualsLengthType()
		{
			ParameterLength x = new ParameterLength( "name", "alias", new SqlTypes.AnsiStringSqlType(5) );
			ParameterLength y = new ParameterLength( "name", "alias", new SqlTypes.AnsiStringSqlType(5) );
			ParameterLength z = new ParameterLength( "name", "alias", new SqlTypes.AnsiStringSqlType(5) );
			
			Assert.IsTrue( x.Equals(y) );
			Assert.IsTrue( y.Equals(x) );
			Assert.IsTrue( y.Equals(z) );
			Assert.IsTrue( x.Equals(z) );
			Assert.IsFalse( x.Equals(null) );

			y = new ParameterLength( "name2", "alias", new SqlTypes.AnsiStringSqlType(5) );

			Assert.IsFalse( x.Equals(y) );
			Assert.IsFalse( y.Equals(x) );
		}
		/// <summary>
		/// Generates an Array of Parameters for the columns that make up the IType
		/// </summary>
		/// <param name="factory">The SessionFactory to use to get the DbTypes.</param>
		/// <param name="tableAlias">The Alias for the Table.</param>
		/// <param name="columnNames">The names of the Columns that compose the IType</param>
		/// <param name="type">The IType to turn into Parameters</param>
		/// <returns>An Array of <see cref="Parameter"/> objects</returns>
		public static Parameter[ ] GenerateParameters( IMapping factory, string tableAlias, string[ ] columnNames, IType type )
		{
			SqlType[ ] sqlTypes = type.SqlTypes( factory );

			Parameter[ ] parameters = new Parameter[sqlTypes.Length];

			for( int i = 0; i < sqlTypes.Length; i++ )
			{
				if( sqlTypes[ i ].LengthDefined )
				{
					ParameterLength param = new ParameterLength( columnNames[i], tableAlias, sqlTypes[i] );
					parameters[ i ] = param;
				}
				else if( sqlTypes[ i ].PrecisionDefined )
				{
					ParameterPrecisionScale param = new ParameterPrecisionScale( columnNames[i], tableAlias, sqlTypes[i] );
					parameters[ i ] = param;
				}
				else
				{
					parameters[ i ] = new Parameter( columnNames[i], tableAlias, sqlTypes[i] );
				}
			}

			return parameters;
		}
		public void TestParameterLengthClone()
		{
			ParameterLength original = new ParameterLength( "originalName", new SqlTypes.StringSqlType(275) );
			ParameterLength cloned = null;

			cloned = (ParameterLength)original.Clone();

			Assert.IsTrue((original==cloned)==false, "Not the same object by ==");
			Assert.AreEqual(original.SqlType.DbType, cloned.SqlType.DbType, "Same DbType");
			Assert.AreEqual(original.Name, cloned.Name, "Same Name");
			Assert.AreEqual(original.Length, cloned.Length, "Same Length");
		}