Beispiel #1
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(' ').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();
            }
        }
Beispiel #2
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);
        }
Beispiel #3
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();
            }
        }
Beispiel #4
0
        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);
        }
Beispiel #5
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);
        }
Beispiel #6
0
 public override string AddColumnSql(string table, ColumnDesc col, string colAfter) {
     return "ALTER TABLE `" + table + "` ADD COLUMN " + col.Column + " " + col.FormatType();
 }