Exemple #1
0
 /// <summary>
 /// Creates and runs an ALTER TABLE SQL statement to drop the given column from the table
 /// </summary>
 /// <param name="column">The column to drop</param>
 public void DropColumn(DiscoveredColumn column)
 {
     using (IManagedConnection connection = Database.Server.GetManagedConnection())
     {
         Helper.DropColumn(connection.Connection, column);
     }
 }
        /// <summary>
        /// API constructor, instead use <see cref="DiscoveredTable.DiscoverColumns"/> instead.
        /// </summary>
        /// <param name="r">All the values in r will be copied into the Dictionary property of this class called ProprietaryDatatype</param>
        /// <param name="sqlType">Your infered SQL data type for it e.g. varchar(50)</param>
        /// <param name="column">The column it belongs to, can be null e.g. if your datatype belongs to a DiscoveredParameter instead</param>
        public DiscoveredDataType(DbDataReader r, string sqlType, DiscoveredColumn column)
        {
            SQLType = sqlType;
            Column  = column;

            for (int i = 0; i < r.FieldCount; i++)
            {
                ProprietaryDatatype.Add(r.GetName(i), r.GetValue(i));
            }
        }
Exemple #3
0
        public DbParameter GetParameter(DbParameter p, DiscoveredColumn discoveredColumn, object value, CultureInfo culture)
        {
            try
            {
                if (culture == null)
                {
                    culture = CultureInfo.CurrentCulture;
                }

                if (!factories.ContainsKey(culture))
                {
                    factories.Add(culture, new TypeDeciderFactory(culture));
                }

                var tt = TypeTranslater;
                p.DbType = tt.GetDbTypeForSQLDBType(discoveredColumn.DataType.SQLType);
                var cSharpType = tt.GetCSharpTypeForSQLDBType(discoveredColumn.DataType.SQLType);

                if (IsBasicallyNull(value))
                {
                    p.Value = DBNull.Value;
                }
                else
                if (value is string strVal && factories[culture].IsSupported(cSharpType))     //if the input is a string and it's for a hard type e.g. TimeSpan
                {
                    var decider = factories[culture].Create(cSharpType);
                    var o       = decider.Parse(strVal);

                    //Not all DBMS support DBParameter.Value = new TimeSpan(...);
                    if (o is TimeSpan)
                    {
                        o = FormatTimespanForDbParameter((TimeSpan)o);
                    }

                    p.Value = o;
                }
                else
                {
                    p.Value = value;
                }
            }
Exemple #4
0
 public DiscoveredRelationship AddForeignKey(DiscoveredColumn foreignKey, DiscoveredColumn primaryKey, bool cascadeDeletes, string constraintName = null, DatabaseOperationArgs args = null)
 {
     return(AddForeignKey(new Dictionary <DiscoveredColumn, DiscoveredColumn> {
         { foreignKey, primaryKey }
     }, cascadeDeletes, constraintName, args));
 }
 public abstract void DropColumn(DbConnection connection, DiscoveredColumn columnToDrop);
 /// <summary>
 /// Based on column name and Table
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 protected bool Equals(DiscoveredColumn other)
 {
     return(string.Equals(_name, other._name) && Equals(Table, other.Table));
 }