示例#1
0
        /// <summary>
        /// Создаёт текст создания столбца
        /// </summary>
        /// <param name="column">Столбец</param>
        /// <returns>Текст создания столбца</returns>
        public static string BuildColumnCreateCommand(Column column)
        {
            StringBuilder sb = null;
            if (column.ColumnType.DbType.HasValue)
            {
                sb = GetDbTypeString(column);
            }
            else
            {
                sb = GetSqlDbTypeString(column);
            }

            if (column.ColumnType.Length != 0 && column.ColumnType.Scale == 0)
            {
                sb.AppendFormat("({0}) ", column.ColumnType.Length);
            }
            else if (column.ColumnType.Length != 0 && column.ColumnType.Scale != 0)
            {
                sb.AppendFormat("({0}, {1}) ", column.ColumnType.Length, column.ColumnType.Scale);
            }

            if (column.Constraint is Default)
            {
                sb.Append("default " + GetDefaultValue(column.Constraint as Default) + " ");
            }

            sb.Append(column.Nullable ? "null" : "not null");
            return sb.ToString();
        }
示例#2
0
        /// <summary>
        /// Создаёт текст создания столбца
        /// </summary>
        /// <param name="column">Столбец</param>
        /// <returns>Текст создания столбца</returns>
        public static string BuildColumnCreateCommand(Column column)
        {
            StringBuilder sb = null;
            if (column.ColumnType.DbType.HasValue)
            {
                sb = GetDbTypeString(column);
            }
            else
            {
                sb = GetSqlDbTypeString(column);
            }

            if (column.ColumnType.Length != 0 && column.ColumnType.Scale == 0)
            {
                sb.AppendFormat("({0}) ", column.ColumnType.Length);
            }
            else if (column.ColumnType.Length != 0 && column.ColumnType.Scale != 0)
            {
                sb.AppendFormat("({0}, {1}) ", column.ColumnType.Length, column.ColumnType.Scale);
            }

            sb.Append(column.Nullable ? "null" : "not null");
            if (column.Identity)
            {
                sb.Append(" identity(1, 1)");
            }

            return sb.ToString();
        }
示例#3
0
 /// <summary>
 /// Добавляет колонку
 /// </summary>
 /// <param name="table">Таблица</param>
 /// <param name="column">Колонка</param>
 public void AddColumn(Table table, Column column)
 {
     try
     {
         strategy.AddColumn(table, column);
     }
     catch
     {
     }
 }
示例#4
0
        /// <summary>
        /// ��������� �������
        /// </summary>
        /// <param name="table">�������</param>
        /// <param name="column">�������</param>
        public void AddColumn(Table table, Column column)
        {
            if (!column.Nullable && (column.Constraint == null || !(column.Constraint is Default)))
            {
                throw new ArgumentException();
            }

            try
            {
                ExecuteNonQuery(razor.Parse(TemplateManager.GetAddColumnTemplate(), new object[] { table, column }, "add column"));
            }
            catch (TemplateCompilationException ex)
            {
                ex.Errors.ToList().ForEach(p => Console.WriteLine(p.ErrorText));
            }

            log.Info("�������� ������� {0} � ������� {1}", column.Name, table.Name);
        }
示例#5
0
        /// <summary>
        /// Получает строку из перечисления DbType
        /// </summary>
        /// <param name="column">Колонка</param>
        /// <returns>Строка</returns>
        private static StringBuilder GetSqlDbTypeString(Column column)
        {
            var sb = new StringBuilder(string.Format("[{0}]", column.Name));
            switch (column.ColumnType.SqlDbType)
            {
                case SqlDbType.VarBinary:
                    sb.Append(" varbinary(MAX) ");
                    break;
                default:
                    throw new UnsuportedDbTypeException(column.ColumnType.DbType.GetValueOrDefault());
            }

            return sb;
        }
示例#6
0
        /// <summary>
        /// Получает строку из перечисления DbType
        /// </summary>
        /// <param name="column">Колонка</param>
        /// <returns>Строка</returns>
        private static StringBuilder GetDbTypeString(Column column)
        {
            if (column.ColumnType.DbType == DbType.String && column.ColumnType.Length == 0)
            {
                throw new ArgumentException("String must have length");
            }

            if (column.ColumnType.DbType == DbType.Binary && column.ColumnType.Length == 0)
            {
                throw new ArgumentException("Binary must have length");
            }

            var sb = new StringBuilder(string.Format("[{0}]", column.Name));
            switch (column.ColumnType.DbType)
            {
                case DbType.Decimal:
                    sb.Append(" decimal");
                    break;
                case DbType.String:
                    sb.Append(" nvarchar");
                    break;
                case DbType.Int32:
                    sb.Append(" int ");
                    break;
                case DbType.Boolean:
                    sb.Append(" bit ");
                    break;
                case DbType.Date:
                    sb.Append(" date ");
                    break;
                case DbType.DateTime:
                    sb.Append(" datetime ");
                    break;
                case DbType.Guid:
                    sb.Append(" uniqueidentifier ");
                    break;
                case DbType.Xml:
                    sb.Append(" xml ");
                    break;
                case DbType.Binary:
                    sb.Append(" binary");
                    break;
                default:
                    throw new UnsuportedDbTypeException(column.ColumnType.DbType.GetValueOrDefault());
            }

            return sb;
        }
示例#7
0
        /// <summary>
        /// Получает строку из перечисления DbType
        /// </summary>
        /// <param name="column">Колонка</param>
        /// <returns>Строка</returns>
        private static StringBuilder GetDbTypeString(Column column)
        {
            if (column.ColumnType.DbType == DbType.String && column.ColumnType.Length == 0)
            {
                throw new ArgumentException("String must have length");
            }

            if (column.ColumnType.DbType == DbType.Binary && column.ColumnType.Length == 0)
            {
                throw new ArgumentException("Binary must have length");
            }

            var sb = new StringBuilder(string.Format("\"{0}\"", column.Name.ToUpper()));
            switch (column.ColumnType.DbType)
            {
                case DbType.Decimal:
                    sb.Append(" number");
                    break;
                case DbType.String:
                    sb.Append(" varchar2");
                    break;
                case DbType.Int32:
                    sb.Append(" int ");
                    break;
                case DbType.Boolean:
                    sb.Append(" char(1) ");
                    break;
                case DbType.Date:
                    sb.Append(" date ");
                    break;
                case DbType.DateTime:
                    sb.Append(" date ");
                    break;
                case DbType.Guid:
                    sb.Append(" raw(16) ");
                    break;
                case DbType.Xml:
                    sb.Append(" blob ");
                    break;
                case DbType.Binary:
                    sb.Append(" raw");
                    break;
                default:
                    throw new UnsuportedDbTypeException(column.ColumnType.DbType.GetValueOrDefault());
            }

            return sb;
        }
示例#8
0
文件: Table.cs 项目: deltasem/dbullet
 /// <summary>
 /// Добавляет колонку к таблице
 /// </summary>
 /// <param name="column">Колонка</param>
 /// <returns>Табилца, с добавленой колонкой</returns>
 public Table AddColumn(Column column)
 {
     columns.Add(column);
     return this;
 }