示例#1
0
文件: MySQL.cs 项目: rdebath/MCGalaxy
        protected override void CreateTableColumns(StringBuilder sql, ColumnDesc[] columns)
        {
            string priKey = null;

            for (int i = 0; i < columns.Length; i++)
            {
                ColumnDesc col = columns[i];
                sql.Append(col.Column).Append(' ').Append(col.FormatType());

                if (col.PrimaryKey)
                {
                    priKey = col.Column;
                }
                if (col.AutoIncrement)
                {
                    sql.Append(" AUTO_INCREMENT");
                }
                if (col.NotNull)
                {
                    sql.Append(" NOT NULL");
                }

                if (i < columns.Length - 1)
                {
                    sql.Append(',');
                }
                else if (priKey != null)
                {
                    sql.Append(", PRIMARY KEY(").Append(priKey).Append(") ");
                }
                sql.AppendLine();
            }
        }
示例#2
0
        /// <summary> Adds a new coloumn to the given table. </summary>
        /// <remarks> Note colAfter is only a hint - some database backends ignore this. </remarks>
        public static void AddColumn(string table, ColumnDesc col, string colAfter)
        {
            ValidateName(table);
            string sql = Backend.AddColumnSql(table, col, colAfter);

            Execute(sql, null);
        }
示例#3
0
        public override void AddColumn(string table, ColumnDesc col, string colAfter)
        {
            ValidateTable(table);
            string syntax = "ALTER TABLE `" + table + "` ADD COLUMN "
                            + col.Column + " " + col.FormatType();

            Database.Execute(syntax);
        }
示例#4
0
文件: MySQL.cs 项目: rdebath/MCGalaxy
        public override string AddColumnSql(string table, ColumnDesc col, string colAfter)
        {
            string sql = "ALTER TABLE `" + table + "` ADD COLUMN " + col.Column + " " + col.FormatType();

            if (colAfter.Length > 0)
            {
                sql += " AFTER " + colAfter;
            }
            return(sql);
        }
示例#5
0
        protected override void CreateTableColumns(StringBuilder sql, ColumnDesc[] columns)
        {
            string priKey = null;

            for (int i = 0; i < columns.Length; i++)
            {
                ColumnDesc col = columns[i];
                sql.Append(col.Column).Append(' ');

                if (col.Type == ColumnType.Bool)
                {
                    sql.Append("TINYINT");
                }
                else
                {
                    sql.Append(col.FormatType());
                }

                // When the primary key isn't autoincrement, we use the same form as mysql
                // Otherwise we have to use sqlite's 'PRIMARY KEY AUTO_INCREMENT' form
                if (col.PrimaryKey)
                {
                    if (!col.AutoIncrement)
                    {
                        priKey = col.Column;
                    }
                    else
                    {
                        sql.Append(" PRIMARY KEY");
                    }
                }
                if (col.AutoIncrement)
                {
                    sql.Append(" AUTOINCREMENT");
                }
                if (col.NotNull)
                {
                    sql.Append(" NOT NULL");
                }
                if (col.DefaultValue != null)
                {
                    sql.Append(" DEFAULT ").Append(col.DefaultValue);
                }

                if (i < columns.Length - 1)
                {
                    sql.Append(',');
                }
                else if (priKey != null)
                {
                    sql.Append(", PRIMARY KEY(").Append(priKey).Append(") ");
                }
                sql.AppendLine();
            }
        }
示例#6
0
        public override void AddColumn(string table, ColumnDesc col, string colAfter)
        {
            ValidateTable(table);
            string sql = "ALTER TABLE `" + table + "` ADD COLUMN " + col.Column + " " + col.FormatType();

            if (colAfter.Length > 0)
            {
                sql += " AFTER " + colAfter;
            }
            Database.Execute(sql, null);
        }
示例#7
0
        // == Higher level column functions ==

        /// <summary> Adds a new coloumn to the given table. </summary>
        /// <remarks> Note colAfter is only a hint - some database backends ignore this. </remarks>
        public abstract void AddColumn(string table, ColumnDesc col, string colAfter);
示例#8
0
 /// <summary> Returns SQL for adding a new coloumn to the given table. </summary>
 /// <remarks> Note colAfter is only a hint - some database backends ignore this. </remarks>
 public abstract string AddColumnSql(string table, ColumnDesc col, string colAfter);
示例#9
0
 public override string AddColumnSql(string table, ColumnDesc col, string colAfter) {
     return "ALTER TABLE `" + table + "` ADD COLUMN " + col.Column + " " + col.FormatType();
 }