Beispiel #1
0
        /// <summary>
        /// 修改表的列结构
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="columns">列结构</param>
        /// <param name="conn">数据库链接</param>
        /// <returns></returns>
        public static bool AlterTable(string tableName, MDataColumn columns, string conn)
        {
            List <string> sqls = SqlCreateForSchema.AlterTableSql(tableName, columns, conn);

            if (sqls.Count > 0)
            {
                DalType dalType  = DalType.None;
                string  database = string.Empty;

                using (MProc proc = new MProc(null, conn))
                {
                    dalType  = proc.DalType;
                    database = proc.dalHelper.DataBase;
                    proc.SetAopState(Aop.AopOp.CloseAll);
                    if (proc.DalType == DalType.MsSql)
                    {
                        proc.BeginTransation();//仅对mssql有效。
                    }
                    foreach (string sql in sqls)
                    {
                        proc.ResetProc(sql);
                        if (proc.ExeNonQuery() == -2)
                        {
                            proc.RollBack();
                            Log.WriteLogToTxt(proc.DebugInfo);
                            return(false);
                        }
                    }
                    proc.EndTransation();
                }
                RemoveCache(tableName, database, dalType);
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// 获取指定的表架构生成的SQL(Alter Table)的说明语句
        /// </summary>
        public static string GetAlterTableSql(string tableName, MDataColumn columns, string conn)
        {
            List <string> sqlItems = SqlCreateForSchema.AlterTableSql(tableName, columns, conn);

            if (sqlItems.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (string sql in sqlItems)
                {
                    sb.AppendLine(sql);
                }
                sqlItems = null;
                return(sb.ToString());
            }
            return(string.Empty);
        }
Beispiel #3
0
 /// <summary>
 /// 获取指定的表架构生成的SQL(Create Table)的说明语句
 /// </summary>
 public static string GetCreateTableSql(string tableName, MDataColumn columns, DalType dalType, string version)
 {
     return(SqlCreateForSchema.CreateTableSql(tableName, columns, dalType, version));
 }
Beispiel #4
0
 /// <summary>
 /// 获取指定的表架构生成的SQL(Create Table)的说明语句
 /// </summary>
 public static string GetCreateTableDescriptionSql(string tableName, MDataColumn columns, DalType dalType)
 {
     return(SqlCreateForSchema.CreateTableDescriptionSql(tableName, columns, dalType));
 }