Esempio n. 1
0
        private static string GetFormatValueByType(IDataParameter parameter)
        {
            var dbTypeName = string.Empty;

            if (parameter.GetType().Name.Equals("NpgsqlParameter", StringComparison.InvariantCultureIgnoreCase))
            {
                var type         = parameter.GetType();
                var postgresType = type.GetProperty("PostgresType")?.GetValue(parameter, null);
                if (postgresType != null)
                {
                    dbTypeName = postgresType.GetType().GetProperty("Name")?.GetValue(postgresType, null) as string;
                    if (dbTypeName.IsNotNullOrEmpty())
                    {
                        dbTypeName = $"::{dbTypeName}";
                    }
                }
            }

            var value = parameter.Value;

            if (value is IEnumerable enumerable && !(enumerable is string))
            {
                var blob = enumerable as byte[];
                if (blob.IsNotNullOrEmpty())
                {
                    return($"\'[Blob with length: {blob.Length}]\'{dbTypeName}");
                }

                var values = (from object a in enumerable select GetFormatValueByType(a)).ToList();
                return($"array[{string.Join(", ", values)}]{dbTypeName}");
            }

            return($"{GetFormatValueByType(value)}{dbTypeName}");
        }
Esempio n. 2
0
        protected override IDataParameter CreateParameter(string name, ParameterDirection direction, object value, DBColumn column = null)
        {
            IDataParameter parameter = Command.CreateParameter();

            if (value is Guid)
            {
                value = GuidToString((Guid)value);
            }

            parameter.ParameterName = name;
            parameter.Direction     = direction;
            parameter.Value         = value == null ? DBNull.Value : value;

            if (value != null && value is string && column != null && (!string.IsNullOrWhiteSpace(column.DataType)))
            {
                if (column.DataType.ToUpper() == "CLOB")
                {
                    PropertyInfo field = parameter.GetType().GetProperty("OracleDbType");
                    if (field != null)
                    {
                        field.SetValue(parameter, 105, null);//105 对应OracleDbType.Clob
                    }
                }
            }
            return(parameter);
        }
Esempio n. 3
0
            protected override void SetParameterValue(IDataParameter param, object value, DbType?type)
            {
                base.SetParameterValue(param, value, null);

                // SQL CE Binary has a size limit of 8000. We have to explicitely set the type of the parameter to SqlDbType.Image
                // to be able to support a larger payload.
                if (param.DbType == DbType.Binary)
                {
                    param.GetType().InvokeMember("SqlDbType",
                                                 BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty,
                                                 Type.DefaultBinder, param, new object[] { SqlDbType.Image });
                }
            }
Esempio n. 4
0
            protected override void SetParameterValue(IDataParameter param, object value, DbType? type)
            {
                base.SetParameterValue(param, value, null);

                // SQL CE Binary has a size limit of 8000. We have to explicitely set the type of the parameter to SqlDbType.Image 
                // to be able to support a larger payload.
                if (param.DbType == DbType.Binary)
                {
                    param.GetType().InvokeMember("SqlDbType",
                                                 BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty,
                                                 Type.DefaultBinder, param, new object[] { SqlDbType.Image });
                }
            }
        static private void RemoveExtraParameters(IDbCommand cmd, int pcount)
        {
            while (pcount < cmd.Parameters.Count)
            {
#if DEBUG
                if (AdapterSwitches.OleDbSql.TraceVerbose)
                {
                    IDataParameter p = (IDataParameter)cmd.Parameters[cmd.Parameters.Count - 1];
                    Debug.WriteLine("removing extra " + p.GetType().Name + " " + p.ParameterName);
                }
#endif
                cmd.Parameters.RemoveAt(cmd.Parameters.Count - 1);
            }
        }
        static private IDataParameter GetNextParameter(IDbCommand cmd, int pcount)
        {
            if (pcount < cmd.Parameters.Count)
            {
                IDataParameter p = (IDataParameter)cmd.Parameters[pcount];
#if DEBUG
                if (AdapterSwitches.OleDbSql.TraceVerbose)
                {
                    Debug.WriteLine("reusing " + p.GetType().Name + " " + p.ParameterName);
                }
#endif
                return(p);
            }
            return(cmd.CreateParameter());
        }
Esempio n. 7
0
        /// <summary>
        /// Sets a parameter value in Parameters C to Value, and if the parameter type is
        /// a string, and the parameter length is greater than the length
        /// of the value, sets the parameter length to the length of the
        /// value.  This is because Text parameter length is always the max
        /// length which causes an excess memory consumption.
        /// </summary>
        /// <param name="C">The parameter collection</param>
        /// <param name="Name">The parameter to set.</param>
        /// <param name="Value">The value to set it to.</param>
        public void SetValue(IDataParameterCollection C, string Name, Object Value)
        {
            if (!C.Contains(Name))
            {
                return;
            }
            IDataParameter P = (IDataParameter)C[Name];

            if (IsTextField(P))
            {
                int          Len = (Value == null)?0:((string)Value).Length;
                PropertyInfo M   = P.GetType().GetProperty("Size");
                if (M != null)
                {
                    M.SetValue(P, Len, null);
                }
            }
            if (Value != null)
            {
                P.Value = Value;
            }
        }
Esempio n. 8
0
 private static void SetSqlDbTypeToNText(IDataParameter parameter)
 {
     Debug.Assert(parameter.GetType().Name == "SqlCeParameter");
     parameter.GetType().GetProperty("SqlDbType").SetValue(parameter, 11, null); // 11: corresponds to SqlDbType.NText
 }
Esempio n. 9
0
 private static void SetSqlDbTypeToNText(IDataParameter parameter)
 {
     Debug.Assert(parameter.GetType().Name == "SqlCeParameter");
     parameter.GetType().GetProperty("SqlDbType").SetValue(parameter, 11, null); // 11: corresponds to SqlDbType.NText
 }