示例#1
0
        public bool CreateDetachTable(string description)
        {
            #region 创建分表

            try
            {
                string currentdbprefix = BaseConfigs.GetTablePrefix + "posts"; //当前数据表所使用的前辍
                //取出当前表中最大ID的记录表名称
                int tablelistmaxid = Posts.GetMaxPostTableId();
                if (!Posts.UpdateMinMaxField(tablelistmaxid)) //表值总数不能大于213
                {
                    base.RegisterStartupScript("", "<script>alert('表值总数不能大于213,当前最大值为" + tablelistmaxid + "!');window.location.href='global_detachtable.aspx';</script>");
                    return(false);
                }
                //更新当前表中最大ID的记录用的最大和最小tid字段
                //if (tablelistmaxid > 0)
                //{
                //    Posts.UpdateMinMaxField(currentdbprefix + tablelistmaxid, tablelistmaxid);
                //}

                string tablename = currentdbprefix + (tablelistmaxid + 1);

                try
                {
                    //构建相应表及全文索引
                    Databases.CreatePostTableAndIndex(tablename);
                }
                catch (Exception ex)
                {
                    string message = ex.Message.Replace("'", " ");
                    message = message.Replace("\\", "/");
                    message = message.Replace("\r\n", "\\r\\n");
                    message = message.Replace("\r", "\\r");
                    message = message.Replace("\n", "\\n");
                    base.RegisterStartupScript("", "<script>alert('" + message + "');</script>");
                }
                finally
                {
                    if (tablelistmaxid > 0)
                    {
                        Posts.AddPostTableToTableList(description, Posts.GetMaxPostTableTid(currentdbprefix + tablelistmaxid));
                    }
                    else
                    {
                        // DatabaseProvider.GetInstance().AddPostTableToTableList(description, DatabaseProvider.GetInstance().GetMaxPostTableTid(currentdbprefix), 0);
                        Posts.AddPostTableToTableList(description, Posts.GetMaxPostTableTid(currentdbprefix));
                    }
                    Caches.ReSetPostTableInfo();

                    Posts.CreateStoreProc(tablelistmaxid + 1);
                }
                return(true);
            }
            catch
            {
                return(false);
            }

            #endregion
        }