Ejemplo n.º 1
0
        public virtual string TableField(TableField field, bool includeKey = true)
        {
            StringBuilder str = new StringBuilder();
            str.AppendFormat("`{0}`", field.Name);
            str.Append(' ');
            str.Append(FieldType(field.Type));

            str.Append(FieldLength(field));

            if (field.Unsigned)
                str.Append(" UNSIGNED");
            if (field.Zerofill)
                str.Append(" ZEROFILL");
            if (field.NotNull)
                str.Append(" NOT NULL");
            else
                str.Append(" NULL");
            if (field.AutoIncrement)
                str.Append(" AUTO_INCREMENT");
            if (field.DefaultValue != null)
                str.AppendFormat(" DEFAULT {0}", field.DefaultValue);
            if (includeKey && field.Key.HasFlag(KeyType.Primary))
                str.Append(" PRIMARY KEY");
            return str.ToString();
        }
Ejemplo n.º 2
0
        protected string FieldLength(TableField field)
        {
            StringBuilder str = new StringBuilder();
            if (field.Length != null && field.Length > 0)
            {
                str.Append("(")
                   .Append(field.Length);

                if (field.Precision != null && field.Precision > 0)
                {
                    str.Append(",")
                       .Append(field.Precision);
                }

                str.Append(")");
            }
            return str.ToString();
        }
Ejemplo n.º 3
0
        public virtual TableField TableField(ResultRow field)
        {
            TableField tableField = new TableField()
            {
                Name          = field.GetString("Field"),
                Type          = ParseType(field.GetString("Type")),
                NotNull       = !field.GetString("Null").Equals("YES"),
                Key           = ParseKey(field.GetString("Key")),
                DefaultValue  = field["Default"],
                Unsigned      = field.GetString("Type").Split(' ').Contains("unsigned"),
                Zerofill      = field.GetString("Type").Split(' ').Contains("zerofill"),
                AutoIncrement = field.GetString("Extra").Split(' ').Contains("auto_increment"),
            };

            if (field.GetString("Type").Split('(').Length > 1)
            {
                int closingPar = field.GetString("Type").Split('(')[1].IndexOf(')');
                tableField.Length = int.Parse(field.GetString("Type").Split('(')[1].Substring(0, closingPar));
            }

            return(tableField);
        }