예제 #1
0
		// Used from SqlServerCeDriver as well
		public static void SetParameterSizes(IDataParameterCollection parameters, SqlType[] parameterTypes)
		{
			for (int i = 0; i < parameters.Count; i++)
			{
				SetVariableLengthParameterSize((IDbDataParameter) parameters[i], parameterTypes[i]);
			}
		}
        private static void SetDefaultParameterSize(IDbDataParameter dbParam, SqlType sqlType)
        {
            switch (dbParam.DbType)
            {
                case DbType.AnsiString:
                case DbType.AnsiStringFixedLength:
                    dbParam.Size = MaxAnsiStringSize;
                    break;

                case DbType.Binary:
                    if (sqlType is BinaryBlobSqlType)
                    {
                        dbParam.Size = MaxBinaryBlobSize;
                    }
                    else
                    {
                        dbParam.Size = MaxBinarySize;
                    }
                    break;
                case DbType.Decimal:
                    dbParam.Precision = MaxPrecision;
                    dbParam.Scale = MaxScale;
                    break;
                case DbType.String:
                case DbType.StringFixedLength:
                    dbParam.Size = IsText(dbParam, sqlType) ? MaxStringClobSize : MaxStringSize;
                    break;
                case DbType.DateTime2:
                    dbParam.Size = MaxDateTime2;
                    break;
                case DbType.DateTimeOffset:
                    dbParam.Size = MaxDateTimeOffset;
                    break;
            }
        }
예제 #3
0
 protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType)
 {
     if (sqlType is NpgsqlExtendedSqlType && dbParam is NpgsqlParameter)
         this.InitializeParameter(dbParam as NpgsqlParameter, name, sqlType as NpgsqlExtendedSqlType);
     else
         base.InitializeParameter(dbParam, name, sqlType);
 }
예제 #4
0
		public override string GetTypeName(SqlType sqlType)
		{
			if (IsUnallowedDecimal(sqlType.DbType, sqlType.Precision))
				return base.GetTypeName(new SqlType(sqlType.DbType, MAX_DECIMAL_PRECISION, sqlType.Scale));

			return base.GetTypeName(sqlType);
		}
		protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType)
		{
			var convertedSqlType = sqlType;
			if (convertedSqlType.DbType == DbType.Currency)
				convertedSqlType = new SqlType(DbType.Decimal);

			base.InitializeParameter(dbParam, name, convertedSqlType);
		}
		public override IDbCommand GenerateCommand(CommandType type, SqlString sqlString, SqlType[] parameterTypes)
		{
			IDbCommand command = base.GenerateCommand(type, sqlString, parameterTypes);

			SetParameterSizes(command.Parameters, parameterTypes);

			return command;
		}
 protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType)
 {
     base.InitializeParameter(dbParam, name, sqlType);
     if (sqlType is StringClobSqlType)
     {
         ((OracleParameter)dbParam).OracleType = OracleType.NClob;
     }
 }
예제 #8
0
		public override string GetTypeName(SqlType sqlType, int length, int precision, int scale)
		{
			var fbDecimalPrecision = precision;
			if (IsUnallowedDecimal(sqlType.DbType, precision))
				fbDecimalPrecision = MAX_DECIMAL_PRECISION;

			return base.GetTypeName(sqlType, length, fbDecimalPrecision, scale);
		}
        protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType)
        {
            base.InitializeParameter(dbParam, name, sqlType);

            if (sqlType.LengthDefined)
            {
                dbParam.Size = sqlType.Length;
            }
        }
예제 #10
0
		public SqlDeleteBuilder AddWhereFragment(string columnName, SqlType type, string op)
		{
			if (!string.IsNullOrEmpty(columnName))
			{
				whereStrings.Add(ToWhereString(columnName, op));
				parameterTypes.Add(type);
			}
			return this;
		}
예제 #11
0
		public override IDbCommand GenerateCommand(CommandType type, SqlString sqlString, SqlType[] parameterTypes)
		{
			IDbCommand command = base.GenerateCommand(type, sqlString, parameterTypes);
			if (IsPrepareSqlEnabled)
			{
				SetParameterSizes(command.Parameters, parameterTypes);
			}
			return command;
		}
        public IDbCommand GenerateCommand(CommandType type, SqlString sqlString, SqlType[] parameterTypes)
        {
            var innerCommand = _innerDriver.GenerateCommand(type, sqlString, parameterTypes);
            if (innerCommand is GlimpseProfileDbCommand)
                return innerCommand;

            var command = new GlimpseProfileDbCommand(innerCommand as DbCommand, _stats);
            return command;
        }
 private static SqlType AdjustSqlType(SqlType sqlType)
 {
     switch (sqlType.DbType)
     {
         case DbType.Guid:
             return GuidSqlType;
         default:
             return sqlType;
     }
 }
예제 #14
0
		public override IDbCommand GenerateCommand(CommandType type, SqlString sqlString, SqlType[] parameterTypes)
		{
			IDbCommand command = base.GenerateCommand(type, sqlString, parameterTypes);
			if (prepareSql)
			{
				SqlClientDriver.SetParameterSizes(command.Parameters, parameterTypes);
			}

			return command;
		}
		/// <remarks>
		/// This adds logic to ensure that a DbType.Boolean parameter is not created since
		/// ODP.NET doesn't support it.
		/// </remarks>
		protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType)
		{
			// if the parameter coming in contains a boolean then we need to convert it 
			// to another type since ODP.NET doesn't support DbType.Boolean
			if (sqlType.DbType == DbType.Boolean)
			{
				sqlType = SqlTypeFactory.Int16;
			}
			base.InitializeParameter(dbParam, name, sqlType);
		}
예제 #16
0
		public IDbCommand Generate(CommandType type, SqlString sqlString, SqlType[] parameterTypes)
		{
			IDbCommand cmd = factory.ConnectionProvider.Driver.GenerateCommand(type, sqlString, parameterTypes);
			LogOpenPreparedCommand();
			if (log.IsDebugEnabled)
			{
				log.Debug("Building an IDbCommand object for the SqlString: " + sqlString.ToString());
			}
			commandsToClose.Add(cmd);
			return cmd;
		}
		protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType)
		{
			if (sqlType.DbType == DbType.Guid)
			{
				base.InitializeParameter(dbParam, name, GuidSqlType);
			}
			else
			{
				base.InitializeParameter(dbParam, name, sqlType);
			}
		}
		public OutputParamReturningDelegate(IPostInsertIdentityPersister persister, ISessionFactoryImplementor factory)
			: base(persister)
		{
			if (Persister.RootTableKeyColumnNames.Length > 1)
			{
				throw new HibernateException("identity-style generator cannot be used with multi-column keys");
			}
			paramType = Persister.IdentifierType.SqlTypes(factory)[0];
			idColumnName = Persister.RootTableKeyColumnNames[0];
			this.factory = factory;
		}
		private static Parameter[ ] GenerateValueParameters( string prefix, SqlType sqlType, int count )
		{
			Parameter[ ] parameters = new Parameter[count];

			for( int i = 0; i < count; i++ )
			{
				string parameterName = StringHelper.Suffix( prefix, StringHelper.Underscore + i.ToString() );
				parameters[ i ] = new Parameter( parameterName, sqlType );
			}

			return parameters;
		}
		/// <summary>
		/// Initializes a new instance of <see cref="Parameter"/> class.
		/// </summary>
		/// <param name="name">The name of the parameter.</param>
		/// <param name="tableAlias">The Alias to use for the table.</param>
		/// <param name="sqlType">The <see cref="SqlType"/> to create the parameter for.</param>
		public Parameter(string name, string tableAlias, SqlType sqlType)
		{
			if( tableAlias!=null && tableAlias.Length>0 )
			{
				_name = tableAlias + StringHelper.Dot + name;
			}
			else
			{
				_name = name;
			}
			_sqlType = sqlType;
		}
예제 #21
0
        /// <summary>
        ///  Initializes the parameter.
        /// </summary>
        /// <param name="dbParam">The db param.</param>
        /// <param name="name">The name.</param>
        /// <param name="sqlType">Type of the SQL.</param>
        protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType)
        {
            base.InitializeParameter(dbParam, name, sqlType);

            if ((sqlType is StringClobSqlType))
            {
                ReflectHelper.TypeFromAssembly(OracleParameterType, DriverAssemblyName, false)
                    .GetProperty("OracleDbType")
                    .SetValue(dbParam,
                        Enum.Parse(ReflectHelper.TypeFromAssembly(OracleDbType, DriverAssemblyName, false), "NClob"), null);
            }
        }
        protected override void InitializeParameter(IDbDataParameter dbParam,string name,SqlType sqlType)
        {
            base.InitializeParameter(dbParam, name, sqlType);

            var stringType = sqlType as StringSqlType;
            if (stringType != null && stringType.LengthDefined && stringType.Length > 4000)
            {
                var parameter = (SqlCeParameter)dbParam;
                parameter.SqlDbType = SqlDbType.NText;
            }

        }
예제 #23
0
	    public bool SupportsSqlType(SqlType sqlType)
	    {
            try
            {
                dialect.GetTypeName(sqlType);
                return true;
            }
            catch
            {
                return false;
            }
	    }
		protected AbstractEnumType(SqlType sqlType,System.Type enumType)
			: base(sqlType)
		{
			if (enumType.IsEnum)
			{
				this.enumType = enumType;
			}
			else
			{
				throw new MappingException(enumType.Name + " did not inherit from System.Enum");
			}
			defaultValue = Enum.GetValues(enumType).GetValue(0);
		}
예제 #25
0
        protected override void InitializeParameter(
            IDbDataParameter dbParam,
            string name,
            SqlType sqlType)
        {
            base.InitializeParameter(dbParam, name, sqlType);

            if (sqlType is StringClobSqlType)
            {
                var parameter = (SqlCeParameter)dbParam;
                parameter.SqlDbType = SqlDbType.NText;
            }
        }
예제 #26
0
		private static void SetVariableLengthParameterSize(IDbDataParameter dbParam, SqlType sqlType)
		{
			// Override the defaults using data from SqlType.
			if (sqlType.LengthDefined)
			{
				dbParam.Size = sqlType.Length;
			}

			if (sqlType.PrecisionDefined)
			{
				dbParam.Precision = sqlType.Precision;
				dbParam.Scale = sqlType.Scale;
			}
		}
예제 #27
0
		public override SqlType[] SqlTypes(IMapping mapping)
		{
			//Not called at runtime so doesn't matter if its slow :)
			SqlType[] sqlTypes = new SqlType[GetColumnSpan(mapping)];
			int n = 0;
			for (int i = 0; i < propertySpan; i++)
			{
				SqlType[] subtypes = propertyTypes[i].SqlTypes(mapping);
				for (int j = 0; j < subtypes.Length; j++)
				{
					sqlTypes[n++] = subtypes[j];
				}
			}
			return sqlTypes;
		}
예제 #28
0
		/// <summary>
		/// Get the name of the database type associated with the given 
		/// <see cref="SqlTypes.SqlType"/>,
		/// </summary>
		/// <param name="sqlType">The SqlType</param>
		/// <returns>The database type name used by ddl.</returns>
		public virtual string GetTypeName( SqlType sqlType )
		{
			if( sqlType.LengthDefined )
			{
				string resultWithLength = typeNames.Get( sqlType.DbType, sqlType.Length );
				if( resultWithLength != null ) return resultWithLength;
			}

			string result = typeNames.Get( sqlType.DbType );
			if( result == null )
			{
				throw new HibernateException( "No default type mapping for SqlType " + sqlType.ToString() );
			}

			return result;
		}
예제 #29
0
		/// <remarks>
		/// This adds logic to ensure that a DbType.Boolean parameter is not created since
		/// ODP.NET doesn't support it.
		/// </remarks>
		protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType)
		{
			// if the parameter coming in contains a boolean then we need to convert it 
			// to another type since ODP.NET doesn't support DbType.Boolean
			switch (sqlType.DbType)
			{
				case DbType.Boolean:
					base.InitializeParameter(dbParam, name, SqlTypeFactory.Int16);
					break;
				case DbType.Guid:
					base.InitializeParameter(dbParam, name, GuidSqlType);
					break;
				default:
					base.InitializeParameter(dbParam, name, sqlType);
					break;
			}
		}
예제 #30
0
        protected override void InitializeParameter(System.Data.IDbDataParameter dbParam, string name, SqlType sqlType)
        {
            base.InitializeParameter(dbParam, name, sqlType);

            //http://thebasilet.blogspot.be/2009/07/nhibernate-oracle-clobs.html
            //System.Data.OracleClient.dll driver generates an exception
            //we set the IDbDataParameter.Value = (string whose length: 4000 > length > 2000 )
            //when we set the IDbDataParameter.DbType = DbType.String
            //when DB Column is of type NCLOB/CLOB
            //The Above is the default behavior for NHibernate.OracleClientDriver
            //So we use the built-in StringClobSqlType to tell the driver to use the NClob Oracle type
            //This will work for both NCLOB/CLOBs without issues.
            //Mapping file will need to be update to use StringClob as the property type
            if ((sqlType is StringClobSqlType))
            {
                ((OracleParameter)dbParam).OracleType = OracleType.NClob;
            }
        }