Esempio n. 1
0
        public string GetIndexSQL(string strTableName, out string strPKTableName, out string strWithoutPKTableName
                                  , out string strNotReadTableName, string HOSPITAL_NO)
        {
            strNotReadTableName   = "";
            strWithoutPKTableName = "";
            strPKTableName        = "";
            try
            {
                StringBuilder ret = new StringBuilder();


                ProcString ps = new ProcString();
                //lsj--类名
                string strClassName = strTableName;//ps.GetClassName(strTableName);//lsj

                //lsj--小写的类名--在此做类的对象来用。
                string strLowerClassName = ps.ConvertStringToUpperOrLower(strClassName, false);

                TableInfo     tableInfo = new TableInfo("", "", strTableName);
                StringBuilder sbBody    = new StringBuilder();

                //---------------------------------------------
                //if (strTableName.Substring(0, 2) != "JH"
                //    && (tableInfo.CheckColumnName("PATIENT_ID") //表中需要有PATIENT_ID
                //    && tableInfo.CheckColumnName("HOSPITAL_NO"))
                //    && tableInfo.strPKName != "")//有主键
                //{
                //    strReadTableName = strTableName;
                //}

                if (strTableName.Substring(0, 2) != "JH"
                    //&& (tableInfo.CheckColumnName("PATIENT_ID") //表中需要有PATIENT_ID
                    && !tableInfo.CheckColumnName("HOSPITAL_NO"))
                // && tableInfo.strPKName != "")//有主键
                {
                    sbBody.AppendLine(" ------------" + strTableName + "------------------------");
                    sbBody.AppendLine(" EXECUTE IMMEDIATE 'alter table " + strTableName + " add HOSPITAL_NO VARCHAR2(16) default " + HOSPITAL_NO + " not null';");
                    if (!string.IsNullOrEmpty(tableInfo.strPKName))
                    {
                        strPKTableName = strTableName;
                        sbBody.AppendLine(" EXECUTE IMMEDIATE 'alter table " + strTableName + "  drop constraint " + tableInfo.strPKName + " cascade';");
                        sbBody.AppendLine(" select count(*) into index_count from user_indexes where index_name='" + tableInfo.strPKName + "';");
                        sbBody.AppendLine(" if index_count > 0 then");
                        sbBody.AppendLine("     EXECUTE IMMEDIATE 'drop index " + tableInfo.strPKName + "';");
                        sbBody.AppendLine(" end if;");

                        sbBody.AppendLine(" EXECUTE IMMEDIATE 'alter table  " + strTableName + " add constraint " + tableInfo.strPKName
                                          + " primary key (" + ps.GetIndexSQL(tableInfo) + ", HOSPITAL_NO)';");
                    }
                    else//无主键的表不修改主键也不增加主键
                    {
                        strWithoutPKTableName = strTableName;
                    }

                    ret.Append(sbBody.ToString());
                }
                else
                {
                    strNotReadTableName = strTableName;
                    ret.Append(sbBody.ToString());
                }
                return(ret.ToString());
            }
            catch (Exception ex)
            {
                string st = ex.Message;
                return(null);
            }
        }