public static DataInfo GetDataKeyValue(string dataKeyName)
        {
            string _connStr = SetConn();

            DataInfo d = new DataInfo();

            SQLUpdateNugget n = SQLUpdateNugget.GetNuggets("SchemaVersionCheck").FirstOrDefault();
            if (n != null) {
                List<SqlParameter> parms = new List<SqlParameter>();

                SqlParameter parmKey = new SqlParameter();
                parmKey.ParameterName = "@DataKey";
                parmKey.SqlDbType = SqlDbType.VarChar;
                parmKey.Size = 100;
                parmKey.Direction = ParameterDirection.Input;
                parmKey.Value = dataKeyName;

                parms.Add(parmKey);

                DataTable dt = ExecuteDataTableCommands(_connStr, n.SQLQuery, parms);

                if (dt.Rows.Count > 0) {
                    DataRow dr = dt.Rows[0];

                    d.DataKey = dr["DataKey"].ToString();
                    d.DataValue = dr["DataValue"].ToString();
                }
            }

            if (d != null && String.IsNullOrEmpty(d.DataValue)) {
                d.DataValue = String.Empty;
            }

            return d;
        }
예제 #2
0
        public DatabaseUpdateStatus PerformUpdates()
        {
            DatabaseUpdateStatus status = new DatabaseUpdateStatus();

            bool bUpdate = true;
            List <DatabaseUpdateMessage> lst = new List <DatabaseUpdateMessage>();

            if (!DoCMSTablesExist())
            {
                HandleResponse(lst, "Create Database", CreateCMSDatabase());
            }
            else
            {
                HandleResponse(lst, "Database already exists");
            }

            bUpdate = DatabaseNeedsUpdate();

            DataInfo ver = GetDbSchemaVersion();

            int iUpdate = 1;

            if (bUpdate || (ver.DataValue != DatabaseUpdate.CurrentDbVersion))
            {
                if (ver.DataValue != DatabaseUpdate.CurrentDbVersion)
                {
                    if (!IsPostStep04)
                    {
                        HandleResponse(lst, BuildUpdateString(iUpdate++), AlterStep00());
                        HandleResponse(lst, BuildUpdateString(iUpdate++), AlterStep01());
                        HandleResponse(lst, BuildUpdateString(iUpdate++), AlterStep02());
                        HandleResponse(lst, BuildUpdateString(iUpdate++), AlterStep03());
                        HandleResponse(lst, BuildUpdateString(iUpdate++), AlterStep04());
                    }

                    if (!IsPostStep09)
                    {
                        HandleResponse(lst, BuildUpdateString(iUpdate++), AlterStep05());
                        HandleResponse(lst, BuildUpdateString(iUpdate++), AlterStep06());
                        HandleResponse(lst, BuildUpdateString(iUpdate++), AlterStep07());
                        HandleResponse(lst, BuildUpdateString(iUpdate++), AlterStep08());
                        HandleResponse(lst, BuildUpdateString(iUpdate++), AlterStep09());
                    }

                    ver = GetDbSchemaVersion();

                    if (ver.DataValue != DatabaseUpdate.CurrentDbVersion)
                    {
                        if (ver.DataValue.Length < 2 || ver.DataValue.StartsWith("201305") || ver.DataValue.StartsWith("201306"))
                        {
                            HandleResponse(lst, BuildUpdateString(iUpdate++), AlterStep10());
                        }
                        ver = GetDbSchemaVersion();
                        if (ver.DataValue == DatabaseUpdate.DbVersion10 || ver.DataValue.StartsWith("201306") || ver.DataValue.StartsWith("201309"))
                        {
                            HandleResponse(lst, BuildUpdateString(iUpdate++), AlterStep11());
                        }
                        ver = GetDbSchemaVersion();
                        if (ver.DataValue == DatabaseUpdate.DbVersion11 || ver.DataValue.StartsWith("201309") || ver.DataValue.StartsWith("201409") || ver.DataValue.StartsWith("201410"))
                        {
                            HandleResponse(lst, BuildUpdateString(iUpdate++), AlterStep12());
                        }
                    }
                }
                else
                {
                    HandleResponse(lst, "Database up-to-date [" + ver.DataValue + "] ");
                }
            }
            else
            {
                HandleResponse(lst, "Database up-to-date [" + ver.DataValue + "] ");
            }

            ResetFailedSQL();

            ResetSQLState();

            bUpdate = DatabaseNeedsUpdate();

            status.NeedsUpdate = bUpdate;
            status.Messages    = lst;

            return(status);
        }