Example #1
0
		private static string GetVariableType(DbType dbType)
		{
			switch (dbType) {
				case DbType.AnsiString:
				case DbType.AnsiStringFixedLength:
				case DbType.String:
				case DbType.StringFixedLength: return "string";

				case DbType.Binary:		return "byte[]";
				case DbType.Boolean:	return "bool";
				case DbType.Byte:		return "byte";

				case DbType.Currency:
				case DbType.Decimal:
				case DbType.VarNumeric:	return "decimal";

				case DbType.Date:
				case DbType.DateTime:	return "DateTime";

				case DbType.Double:		return "double";
				case DbType.Guid:		return "Guid";
				case DbType.Int16:		return "short";
				case DbType.Int32:		return "int";
				case DbType.Int64:		return "long";
				case DbType.Object:		return "object";
				case DbType.SByte:		return "sbyte";
				case DbType.Single:		return "float";
				case DbType.Time:		return "TimeSpan";
				case DbType.UInt16:		return "ushort";
				case DbType.UInt32:		return "uint";
				case DbType.UInt64:		return "ulong";

				default:				return "string";
			}
		}
 public static bool ContainsRule(Csla.Core.BusinessBase obj, DbType type, string propertyName)
 {
     switch (type)
     {
         case DbType.Int16:
         case DbType.Int32:
         case DbType.Int64:
             return obj.BrokenRulesCollection.Any(
                  brokenRule => brokenRule.RuleName == string.Format("rule://epiworx.core.validation.integerrequired/{0}", propertyName))
                     || obj.BrokenRulesCollection.Any(
                         brokenRule => brokenRule.RuleName == string.Format("rule://csla.rules.commonrules.dataannotation/{0}?a=Epiworx.Core.Validation.IntegerRequiredAttribute", propertyName));
         case DbType.Decimal:
             return obj.BrokenRulesCollection.Any(
                 brokenRule => brokenRule.RuleName == string.Format("rule://epiworx.core.validation.decimalrequired/{0}", propertyName));
         case DbType.Date:
             return obj.BrokenRulesCollection.Any(
               brokenRule => brokenRule.RuleName == string.Format("rule://epiworx.core.validation.daterequired/{0}", propertyName));
         case DbType.DateTime:
             return obj.BrokenRulesCollection.Any(
               brokenRule => brokenRule.RuleName == string.Format("rule://epiworx.core.validation.datetimerequired/{0}", propertyName));
         case DbType.String:
         case DbType.StringFixedLength:
             return obj.BrokenRulesCollection.Any(
              brokenRule => brokenRule.RuleName == string.Format("rule://epiworx.core.validation.stringrequired/{0}", propertyName));
         default:
             throw new NotSupportedException();
     }
 }
Example #3
0
 protected CouchBase(string username, string password, AuthenticationType aT, DbType dbType)
 {
     this.username = username;
     this.password = password;
     this.authType = aT;
     this.dbType = dbType;
 }
Example #4
0
 /// <summary>
 /// Constructs a VarArgsSQLFunction instance with a 'static' return type.  An example of a 'static'
 /// return type would be something like an <code>UPPER</code> function which is always returning
 /// a SQL VARCHAR and thus a string type.
 /// </summary>
 /// <param name="registeredType">the return type</param>
 /// <param name="begin">the beginning of the function templating</param>
 /// <param name="sep">the separator for each individual function argument</param>
 /// <param name="end">the end of the function templating</param>
 public VarArgsSQLFunction(DbType registeredType, String begin, String sep, String end)
 {
     this.registeredType = registeredType;
     this.begin = begin;
     this.sep = sep;
     this.end = end;
 }
Example #5
0
        protected override string TypeName(DbType type) {
            switch (type) {
                case DbType.Binary:
                    return "bit";

                case DbType.Boolean:
                    return "smallint unsigned";

                case DbType.Byte:
                    return "smallint unsigned";

                case DbType.DateTime:
                case DbType.DateTime2:
                    return "timestamp";

                case DbType.DateTimeOffset:
                    return "timestamptz";

                case DbType.Double:
                    return "double precision";

                default:
                    return base.TypeName(type);
            }
        }
Example #6
0
 public Parameters(string Name, object Value,DbType dbType)
 {
     ParamName = Name;
     ParamValue = Value;
     ParamDbType = dbType;
     ParamDirection = ParameterDirection.Input;
 }
Example #7
0
 public DBMapping(string first, string second, DbType type, int size)
 {
     this._first = first;
     this._second = second;
     this._type = type;
     this._size = size;
 }
Example #8
0
 public static void CreateParameter(this IDbCommand command, string name, DbType dbType)
 {
   IDbDataParameter parameter = command.CreateParameter();
   parameter.ParameterName = name;
   parameter.DbType = dbType;
   command.Parameters.Add(parameter);
 }
        public RelationalTypeMapping([NotNull] string defaultTypeName, DbType? storeType = null)
        {
            Check.NotEmpty(defaultTypeName, nameof(defaultTypeName));

            DefaultTypeName = defaultTypeName;
            StoreType = storeType;
        }
Example #10
0
 /// <summary>
 /// Extension for adding single parameter
 /// </summary>
 public static void AddParam(this DbCommand cmd, object item, DbType? type = null)
 {
     var p = cmd.CreateParameter();
     p.ParameterName = string.Format("@{0}", cmd.Parameters.Count);
     if (item == null)
     {
         p.Value = DBNull.Value;
     }
     else
     {
         if (item.GetType() == typeof(Guid))
         {
             p.Value = item.ToString();
             p.DbType = DbType.String;
             p.Size = 4000;
         }
         else if (item.GetType() == typeof(ExpandoObject))
         {
             var d = (IDictionary<string, object>)item;
             p.Value = d.Values.FirstOrDefault();
         }
         else
         {
             p.Value = item;
             if (type.HasValue)
                 p.DbType = type.Value;
         }
         if (item.GetType() == typeof(string))
             p.Size = ((string)item).Length > 4000 ? -1 : 4000;
     }
     cmd.Parameters.Add(p);
 }
Example #11
0
 public Column(string name, DbType type)
 {
     ColumnName = name;
     IsAutoIncrement = false;
     Type = type;
     IsNullable = true;
 }
        protected override IDataParameter GetParameter(string name, object paramValue, DbType datatype)
        {
            object value = paramValue;
            DbType localDatatype = datatype;
            if (datatype == DbType.Guid)
                localDatatype = DbType.String;
            else
                localDatatype = datatype;

            NpgsqlParameter param;
            if (datatype == DbType.Guid && value != DBNull.Value)
            {
                value = new Guid(paramValue.ToString());
                param = new NpgsqlParameter(name, localDatatype);
                param.Value = value;
            }
            else
            {
                param = new NpgsqlParameter(name, value);
                param.DbType = localDatatype;

            }

            return param;
        }
Example #13
0
 public ExtendedProperty(string name, object value, DbType dataType, PropertyStateEnum state)
 {
     this.name = name;
     this.value = value;
     this.dataType = dataType;
     this.propertyState = state;
 }
Example #14
0
 public ExtendedProperty(string name, object value, DbType dataType)
 {
     this.name = name;
     this.value = value;
     this.dataType = dataType;
     this.propertyState = PropertyStateEnum.Unmodified;
 }
Example #15
0
 public static void AreEqual(string parameterName, object value, DbType dbType, SqlParameter actual)
 {
     Assert.IsNotNull(actual, "Parameter should not be null.");
     Assert.AreEqual(parameterName, actual.ParameterName, "ParameterName");
     Assert.AreEqual(value, actual.Value, "Value");
     Assert.AreEqual(dbType, actual.DbType, "DbType");
 }
Example #16
0
 internal static void TryDetermineSubQueryDataType(SelectStatement query, out Type dataType, out DbType dbType)
 {
     // Automatically determine data type if possible.
     if (query.SelectList.Count == 1)
     {
         SelectItem firstItem = query.SelectList[0];
         if (firstItem.ItemType == SqlItemType.Column)
         {
             IDbColumn field = (IDbColumn)firstItem.Item;
             dataType = field.DataType;
             dbType = field.DbType;
         }
         else if (firstItem.ItemType == SqlItemType.Function)
         {
             Function function = (Function)firstItem.Item;
             dataType = function.DataType;
             dbType = function.DbType;
         }
         else
         {
             dataType = typeof(object);
             dbType = DbType.Object;
         }
     }
     else
     {
         dataType = typeof(object);
         dbType = DbType.Object;
     }
 }
Example #17
0
 public Parameters(string Name, object Value, ParameterDirection Direction)
 {
     ParamName = Name;
     ParamValue = Value;
     ParamDbType = DbType.Object;
     ParamDirection = Direction;
 }
Example #18
0
		public DbParameter CreateParameter(Type connectionType, string sourceColumn, ParameterDirection parameterDirection, DbType parameterDbType, int parameterSize, byte parameterPrecision, byte parameterScale, bool parameterNullable, string parameterName, object parameterValue)
		{
			DbParameter dbParameter;

			if ((object)connectionType == null)
				throw new ArgumentNullException(nameof(connectionType));

			using (DbConnection dbConnection = (DbConnection)Activator.CreateInstance(connectionType))
			{
				using (DbCommand dbCommand = dbConnection.CreateCommand())
					dbParameter = dbCommand.CreateParameter();

				dbParameter.ParameterName = parameterName;
				dbParameter.Size = parameterSize;
				dbParameter.Value = parameterValue;
				dbParameter.Direction = parameterDirection;
				dbParameter.DbType = parameterDbType;
				this.ReflectionFascade.SetLogicalPropertyValue(dbParameter, "IsNullable", parameterNullable, true, false);
				dbParameter.Precision = parameterPrecision;
				dbParameter.Scale = parameterScale;
				dbParameter.SourceColumn = sourceColumn;

				return dbParameter;
			}
		}
Example #19
0
 public void CreateAndCacheDbCommandParameters(string sqlCommandText,
                                               DbCommand command,
                                               string[] paramNames,
                                               DbType[] paramDbTypes,
                                               object[] paramValues) 
 {
     lock (lockObject)
     {
         if (this.ParameterCache.IsCache(sqlCommandText))
         {
             this.ParameterCache.AddParametersFromCache(sqlCommandText, command, paramDbTypes, paramValues);
         }
         else
         {
             if (this.ParameterCache.IsCache(sqlCommandText))
             {
                 this.ParameterCache.AddParametersFromCache(sqlCommandText, command, paramDbTypes, paramValues);
             }
             else
             {
                 this.ParameterCache.CreateAndCacheParameters(sqlCommandText, command, paramNames, paramDbTypes, paramValues);
             }
         }
     }
 }
Example #20
0
 public void Add(string name, DbType type)
 {
     DbParameter parameter = Command.CreateParameter();
     parameter.ParameterName = string.Format("{0}{1}", ParameterPrefix, name);
     parameter.DbType = type;
     Command.Parameters.Add(parameter);
 }
 public EntityParameter(string parameterName, DbType dbType, int size, string sourceColumn)
 {
     SetParameterNameWithValidation(parameterName, "parameterName");
     DbType = dbType;
     Size = size;
     SourceColumn = sourceColumn;
 }
 public DbParameterHelper(DbType type, string name, object value, ParameterDirection direction)
 {
     DbType = type;
     Name = name;
     Value = value;
     Direction = direction;
 }
Example #23
0
        /// <summary>
        /// Initialises a new instance of the <see cref="ColumnInfo"/> class.
        /// </summary>
        /// <param name="columnName">The name of the column in the database table.</param>
        /// <param name="dbType">The <see cref="DbType"/> of the column in the database table.</param>
        /// <param name="propertyInfo">The property info for the property the column maps to.</param>
        /// <param name="isIdentifier">A value indicating whether column is the table identifier column (primary key).</param>
        /// <param name="allowInsert">true if the column can be inserted, otherwise false.</param>
        /// <param name="allowUpdate">true if the column can be updated, otherwise false.</param>
        /// <param name="sequenceName">The name of the sequence which generates the identifier value or null if sequences are not used.</param>
        /// <exception cref="ArgumentNullException">Thrown if columnName or propertyInfo are null.</exception>
        public ColumnInfo(
            string columnName,
            DbType dbType,
            PropertyInfo propertyInfo,
            bool isIdentifier,
            bool allowInsert,
            bool allowUpdate,
            string sequenceName)
        {
            if (columnName == null)
            {
                throw new ArgumentNullException("columnName");
            }

            if (propertyInfo == null)
            {
                throw new ArgumentNullException("propertyInfo");
            }

            this.columnName = columnName;
            this.dbType = dbType;
            this.propertyInfo = propertyInfo;
            this.isIdentifier = isIdentifier;
            this.allowInsert = allowInsert;
            this.allowUpdate = allowUpdate;
            this.sequenceName = sequenceName;
        }
 public SqlParameter(SqlStatement sqlStatement, object value, DbType dbType, string name)
 {
     this.Parent = sqlStatement ;
     this.value = value;
     this.dbType = dbType;
     this.name = name;
 }
Example #25
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 + "]");

            DbParameter param = this.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;
        }
 public FakeDataParameter(DbType dbType, 
     string parameterName, object value)
     : this(dbType, 
     ParameterDirection.Input, true, null, null, 
     DataRowVersion.Current, value)
 {
 }
Example #27
0
 public string DbTypeToString(DbType type, int? length)
 {
     string ret;
     if (TypesAsStrings.TryGetValue(type, out ret))
         return ret;
     throw new NotImplementedException(Enum.GetName(typeof(DbType), type));
 }
Example #28
0
 public Parameter(String parameterName, DbType dbtype)
 {
     _parameterName = parameterName;
     _value = DBNull.Value;
     _dbType = dbtype;
     _sourceVersion = DataRowVersion.Default;
 }
Example #29
0
        /// <summary>
        /// 将C#值转成数据库能存储的值
        /// </summary>
        /// <param name="valu"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public object ParamConvertValue(object valu, DbType type)
        {
            if (valu == null) { return null; }

            // 时间类型转换
            if (type == DbType.DateTime)
            {
                DateTime dtValue; DateTime.TryParse(valu.ToString(), out dtValue);
                if (dtValue == DateTime.MinValue) { valu = new DateTime(1900, 1, 1); }
            }
            // 枚举类型转换
            if (valu is Enum) { valu = Convert.ToInt32(valu); }

            // List类型转换成字符串并以,分隔
            if (valu.GetType().IsGenericType)
            {
                var sb = new StringBuilder();
                // list类型
                if (valu.GetType().GetGenericTypeDefinition() != typeof(Nullable<>))
                {
                    var enumerator = ((IEnumerable)valu).GetEnumerator();
                    while (enumerator.MoveNext()) { sb.Append(enumerator.Current + ","); }
                }
                else
                {
                    if (valu.GetType().GetGenericArguments()[0] == typeof(int))
                    {
                        var enumerator = ((IEnumerable<int?>)valu).GetEnumerator();
                        while (enumerator.MoveNext()) { sb.Append(enumerator.Current.GetValueOrDefault() + ","); }
                    }
                }
                valu = sb.Length > 0 ? sb.Remove(sb.Length - 1, 1).ToString() : "";
            }
            return valu;
        }
Example #30
0
		public static string GetVariableType(DbType dbType, bool isNullableColumn)
		{
			string variableType = GetVariableType(dbType);
			if (isNullableColumn && Utility.IsNullableDbType(dbType))
				variableType = variableType + "?";
			return variableType;
		}