Represent a simple SQL Builder
Beispiel #1
0
        public override string ToString()
        {
            var sql = new SqlBuilder(MySqlAdapter.Default);

            WriteTo(sql);

            return sql.ToString();
        }
Beispiel #2
0
        public void WriteTo(SqlBuilder sb)
        {
            sb.WriteIdentifier(Name);

            sb.Append(" ");

            sb.Write(Type);

            if (!IsOptional)
            {
                sb.Append(" NOT NULL");
            }

            if (AutoIncriment)
            {
                sb.Append(" AUTO_INCREMENT");
            }

            if (IsKey)
            {
                sb.Append(" ");

                sb.Append(IsUnique ? "UNIQUE" : "PRIMARY");

                sb.Append(" KEY");
            }

            if (Default != null)
            {
                sb.Append(" DEFAULT ");

                sb.Append(Default);
            }

            if (OnUpdate != null)
            {
                sb.Append(" ON UPDATE ");

                sb.Append(OnUpdate);
            }

            if (Format != null)
            {
                sb.Append(" " + Format.Value.ToString().ToUpper());
            }
        }
        protected PageParser(int size, Type type)
        {
            if (size <= 0)
                throw new ArgumentOutOfRangeException("size");

            Builders = new SqlBuilder[size];
            for (int i = 0; i < size; ++i)
            {
                Builders[i] = new SqlBuilder();
            }

            if (type != null)
            {
                if (!type.IsEnum)
                    throw new InvalidOperationException("Type passed into PageParser is not enum type!");
            }

            FlagsType = type;
        }
Beispiel #4
0
        public void WriteTo(SqlBuilder sql)
        {
            sql.CreateTable(new SchemaObject(Name));

            sql.AppendLine(" (");

            var i = 0;

            foreach (var column in Columns)
            {
                if (++i != 1)
                {
                    sql.AppendLine(",");
                }

                sql.Indent(1);

                column.WriteTo(sql);
            }

            if (!PrimaryKey[0].IsIdentity)
            {
                sql.AppendLine(",");

                sql.Indent(1);

                sql.Append("PRIMARY KEY ");

                sql.WriteTuple(PrimaryKey.Names);
            }

            foreach (var index in Indexes)
            {
                sql.AppendLine(",");

                if (index.Type == IndexFlags.Unique)
                {
                    // UNIQUE KEY `ix_phone` (`country`, `area`, `number`, `extension`),

                    sql.Indent(1);

                    sql.Append("UNIQUE KEY ");
                    sql.WriteIdentifier(index.Name);
                    sql.Append(" ");
                    sql.WriteTuple(ValueList.With(index.Members));
                }
                else
                {
                    sql.Indent(1);
                    sql.Append("INDEX ");

                    sql.WriteIdentifier(index.Name);

                    sql.Append(" ");
                
                    sql.WriteTuple(ValueList.With(index.Members));
                }
            }

            sql.AppendLine("");

            sql.Append(")");
        }
Beispiel #5
0
        public static string ToSql(this DbTypeInfo type)
        {
            var sql = new SqlBuilder(MySqlAdapter.Default);

            sql.Write(type);

            return sql.ToString();
        }