コード例 #1
0
        public virtual DbParameter AddParameter(DbCommand dm, string name, DbType dbType, int size,
                                                ParameterDirection direction, bool nullable, byte precision, byte scale, string sourceColumn,
                                                DataRowVersion sourceVersion, object value)
        {
            ////if (dbType == DbType.String)
            ////    throw new Exception("请不要使用DbType.String进行数据库查询!");

            if (CheckInjectAttackForSp(dm, value))
            {
                throw new Exception("输入的部分内容可能对系统稳定性造成影响,操作已停止![" + value + "]");
            }

            var param = ProviderFactory.CreateParameter();

            if (param != null)
            {
                param.ParameterName = name;
                param.DbType        = dbType;
                param.Size          = size;
                param.Value         = value ?? DBNull.Value;
                param.Direction     = direction;
                param.IsNullable    = nullable;
                param.SourceColumn  = sourceColumn;
                param.SourceVersion = sourceVersion;
                dm.Parameters.Add(param);
            }
            return(param);
        }
コード例 #2
0
        //************************************************************************
        /// <summary>
        /// DBプロバイダファクトリに関連付けられたCommandパラメータを作成する。
        /// </summary>
        /// <param name="argParameterName">パラメータ名</param>
        /// <param name="argValue">値</param>
        /// <returns>DBプロバイダファクトリに関連付けられたCommandパラメータ</returns>
        //************************************************************************
        protected IDbDataParameter CreateCmdParam(string argParameterName, object ParameterName)
        {
            IDbDataParameter param = ProviderFactory.CreateParameter();

            param.ParameterName = argParameterName;
            param.Value         = ParameterName;
            return(param);
        }
コード例 #3
0
        /// <summary>
        /// 创建参数
        /// </summary>
        /// <returns></returns>
        protected virtual DbParameter CreateDbParameter(string name, object value, DbType type = DbType.String)
        {
            DbParameter parameter = ProviderFactory.CreateParameter();

            parameter.ParameterName = name;
            parameter.Value         = value;
            parameter.DbType        = type;
            return(parameter);
        }
コード例 #4
0
        /// <summary>
        ///创建CreateDbParameter对象
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="dbType"></param>
        /// <param name="parameterDirection"></param>
        /// <returns></returns>
        public DbParameter CreateDbParameter(string name, object value, DbType dbType, ParameterDirection parameterDirection = ParameterDirection.Input)
        {
            DbParameter parameter = ProviderFactory.CreateParameter();

            parameter.ParameterName = name;
            parameter.Value         = (value ?? "");
            parameter.DbType        = dbType;
            parameter.Direction     = parameterDirection;
            return(parameter);
        }
コード例 #5
0
        public IDbDataParameter CreateParameter(string name, object value)
        {
            var parameter = ProviderFactory.CreateParameter();

            if (parameter == null)
            {
                return(null);
            }

            parameter.ParameterName = ParameterKey + name;
            parameter.Value         = value;
            return(parameter);
        }
コード例 #6
0
        /// <summary>
        /// Creates a Dbparameter obtaining the information from a DataColumn object.
        /// </summary>
        /// <param name="paramName">The name for the parameter.</param>
        /// <param name="dColumn">The DataColumn object to extract the information from.</param>
        /// <returns>A new DBParameter object containing the desired configuration.</returns>
        protected DbParameter CreateParameterFromColumn(string paramName, DataColumn dColumn)
        {
            DbParameter parameter = ProviderFactory.CreateParameter();

            if (parameter != null)
            {
                parameter.ParameterName = paramName;
                parameter.DbType        = GetDBType(dColumn.DataType);
                parameter.SourceColumn  = dColumn.ColumnName;
                parameter.SourceVersion = DataRowVersion.Current;
                return(parameter);
            }
            return(null);
        }
コード例 #7
0
ファイル: RecordMember.cs プロジェクト: fmazzant/Record
        /// <summary>
        /// Create a new parameter instance
        /// </summary>
        /// <param name="pParameterName">Parameter's name</param>
        /// <param name="pCompareKind">Compare operation</param>
        /// <param name="pValue">Parameter's value</param>
        /// <returns>Parameter</returns>
        protected RecordParameter CreateParameter(String pParameterName, CompareKind pCompareKind, object pValue)
        {
            if (ProviderFactory == null)
            {
                throw new RecordProviderFactoryNullException("Provider Factory is null");
            }

            DbParameter parameter = (DbParameter)ProviderFactory.CreateParameter();

            parameter.ParameterName = pParameterName;
            parameter.Value         = pValue != null ? pValue : String.Empty;
            RecordParameter rparameter = new RecordParameter(parameter, pCompareKind);

            return(rparameter);
        }
コード例 #8
0
ファイル: DagentKernel.cs プロジェクト: akawa777/Dagent
        public virtual DbParameter CreateDbParameter(DbParameter parameter)
        {
            DbParameter dbParameter = ProviderFactory.CreateParameter();

            dbParameter.ParameterName = ParameterPrefix + parameter.ParameterName;
            dbParameter.Value         = parameter.Value;

            DbType?dbType = GetDbType(parameter.Value);

            if (dbType.HasValue)
            {
                dbParameter.DbType = dbType.Value;
            }

            return(dbParameter);
        }
コード例 #9
0
        public DbParameter CreateParameter(string Name, object value)
        {
            var p = ProviderFactory.CreateParameter();

            p.ParameterName = Name;
            if (value != null)
            {
                p.Value = value;
            }
            else
            {
                p.SourceColumnNullMapping = true;
                p.Value = DBNull.Value;
            }
            return(p);
        }
コード例 #10
0
        protected virtual DbCommand GetDbCommand()
        {
            var command = ProviderFactory.CreateCommand();

            command.Connection  = Connection;
            command.CommandText = SqlQuery.Sql;
            if (SqlQuery.CommandTimeout > 0)
            {
                command.CommandTimeout = SqlQuery.CommandTimeout;
            }
            if (SqlQuery.StoredProcedure)
            {
                command.CommandType = CommandType.StoredProcedure;
            }
            if (SqlQuery.Parameters != null)
            {
                foreach (var key in SqlQuery.Parameters.Keys)
                {
                    var obj = SqlQuery.Parameters[key];
                    var pso = obj as PSObject;
                    if (pso != null)
                    {
                        obj = pso.ImmediateBaseObject;
                    }
                    var param = ProviderFactory.CreateParameter();
                    param.ParameterName = key.ToString();
                    param.Value         = obj;
                    command.Parameters.Add(param);
                    WriteVerbose("Adding parameter " + param.ParameterName + "=" + param.Value.ToString());
                }
            }
            if (Transaction == null && SqlQuery.CUD && TransactionContext == null && !NoTrans)
            {
                WriteVerbose("Starting transaction.");
                Transaction = Connection.BeginTransaction();
            }
            if (Transaction != null)
            {
                command.Transaction = Transaction;
            }
            return(command);
        }