示例#1
0
        /// <summary>
        /// Creates a list of statements to apply to the database based on the script editable by the user.
        /// </summary>
        private void CreateActualStatementsList()
        {
            ActualStatementRowsList = null;
            if (string.IsNullOrEmpty(SqlScript))
            {
                return;
            }

            if (_userChangedOriginalQuery && string.Compare(SqlScript, OriginalSqlScript, StringComparison.InvariantCultureIgnoreCase) != 0)
            {
                // The user modified the original query and it is no longer the same as the original one, so the actual statements list is built from the modified SQL script text.
                ActualStatementRowsList = new List <IMySqlDataRow>(_originalStatementRowsList.Count);
                var statementsList = SqlScript.SplitInSqlStatements();
                if (statementsList == null)
                {
                    return;
                }

                foreach (var statementText in statementsList.Where(statementText => !string.IsNullOrEmpty(statementText)))
                {
                    IMySqlDataRow rowToAdd;
                    if (MySqlStatement.GetSqlStatementType(statementText) == MySqlStatement.SqlStatementType.Set)
                    {
                        // If we find a SET statement then assign it to a new MySqlDummyRow since the Statement.SetVariablesSqlQuery will be set to null for non-SET statements.
                        // The reason for this is that we do not know what SET statements were changed by the user, there is no point into trying to find out which ones were
                        //  changed, it is faster to always assign them to MySqlDummyRow and not process them in the actual IMySqlDataRow.Statement.
                        rowToAdd = new MySqlDummyRow(statementText);
                    }
                    else
                    {
                        // Try to find the IMySqlDataRow whose Statement.SqlQuery matches the current one, if found it means the user did not change it so use that one.
                        // If not found it means the user changed it so we assign it to a new MySqlDummyRow.
                        var originalRow = _originalStatementRowsList.FirstOrDefault(iMySqlRow => iMySqlRow.Statement.SqlQuery.Equals(statementText, StringComparison.InvariantCultureIgnoreCase));
                        if (originalRow != null)
                        {
                            originalRow.Statement.SetVariablesSqlQuery = null;
                            rowToAdd = originalRow;
                        }
                        else
                        {
                            rowToAdd = new MySqlDummyRow(statementText);
                        }
                    }

                    if (!ActualStatementRowsList.Contains(rowToAdd))
                    {
                        ActualStatementRowsList.Add(rowToAdd);
                    }
                }
            }
            else
            {
                // The original query did not change so it is safe to assume the actual statements list is the same as the original one.
                ActualStatementRowsList = _originalStatementRowsList;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MySqlDummyRow"/> class.
 /// </summary>
 /// <param name="dummyStatementText">The text that corresponds to a dummy statement.</param>
 /// <param name="errorMessage">The error message related to the dummy statement.</param>
 public MySqlDummyErroredRow(string dummyStatementText, string errorMessage)
     : base(dummyStatementText)
 {
     RowError  = errorMessage;
     Statement = new MySqlStatement(this, errorMessage);
 }