예제 #1
0
        private object GetDefaultValue(DataRow row, SqlServerColumnSchema column, TableSchema table)
        {
            object defaultValue       = null;
            string defaultValueString = null;

            if (row.IsNull(ColumnsSchemaNames.ColumnDefault))
            {
                defaultValue = column.AllowNull ? DBNull.Value : _defaultValueMapping[column.SqlDbType];
            }
            else
            {
                defaultValueString = GetDefaultValueString((string)row[ColumnsSchemaNames.ColumnDefault]);
                defaultValue       = GetDefaultValueFromString(defaultValueString, column.SqlDbType);
            }

            SqlServerParseDefaultValueEventArgs e = new SqlServerParseDefaultValueEventArgs(
                table.Name, column.Name, column.SqlDbType, defaultValueString, defaultValue);

            OnParseDefaultValue(e);
            if (e.Handled)
            {
                defaultValue = e.DefaultValue;
            }

            if ((defaultValue == null) || (defaultValue == DBNull.Value))
            {
                return(column.AllowNull ? DBNull.Value : _defaultValueMapping[column.SqlDbType]);
            }
            return(defaultValue);
        }
예제 #2
0
        private SqlServerColumnSchema CreateColumnSchema(DataRow row, TableSchema table)
        {
            SqlServerColumnSchema column = new SqlServerColumnSchema((string)row[ColumnsSchemaNames.ColumnName])
            {
                AllowNull = ((string)row[ColumnsSchemaNames.IsNullable]).Equals("yes", StringComparison.OrdinalIgnoreCase),
                SqlDbType = GetSqlDbType(row)
            };

            column.DefaultValue = GetDefaultValue(row, column, table);
            if (!row.IsNull(ColumnsSchemaNames.CharacterMaximumLength))
            {
                column.Size = (int)row[ColumnsSchemaNames.CharacterMaximumLength];
            }
            if (!row.IsNull(ColumnsSchemaNames.DatetimePrecision))
            {
                System.Diagnostics.Debug.Assert(column.Size == 0,
                                                "Setting DatetimePrecision but SqlServerColumnSchema.Size is already set.");
                column.Size = Convert.ToInt32(row[ColumnsSchemaNames.DatetimePrecision]);
            }
            if (!row.IsNull(ColumnsSchemaNames.NumericPrecision))
            {
                column.Precision = Convert.ToByte(row[ColumnsSchemaNames.NumericPrecision]);
            }
            if (!row.IsNull(ColumnsSchemaNames.NumericScale))
            {
                column.Scale = Convert.ToByte(row[ColumnsSchemaNames.NumericScale]);
            }

            return(column);
        }
예제 #3
0
        private SqlServerColumnSchema CreateColumnSchema(DataRow row, TableSchema table)
        {
            SqlServerColumnSchema column = new SqlServerColumnSchema((string)row[ColumnsSchemaNames.ColumnName])
            {
                AllowNull = ((string)row[ColumnsSchemaNames.IsNullable]).Equals("yes", StringComparison.OrdinalIgnoreCase),
                SqlDbType = GetSqlDbType(row)
            };

            column.DefaultValue = GetDefaultValue(row, column, table);
            if (!row.IsNull(ColumnsSchemaNames.CharacterMaximumLength))
            {
                column.Size = (int)row[ColumnsSchemaNames.CharacterMaximumLength];
            }

            return(column);
        }