Ejemplo n.º 1
0
        protected IEnumerable <RootObjectState <TType, TState> > GetBasedOnKnownIdentifiers(SchemaConnection connection, ObjectTypeHelper helper,
                                                                                            Func <string, RootObjectState <TType, TState> > getEmptyState)
        {
            if (!helper.IsStateStorageInitialized)
            {
                return(Enumerable.Empty <RootObjectState <TType, TState> >());
            }

            return(connection.ExecuteSql("select name from nrdo_object where type = " + connection.SchemaDriver.QuoteParam("type"),
                                         result => getEmptyState(result.GetString("name")),
                                         cmd => cmd.SetString("type", "nvarchar", Name)));
        }
Ejemplo n.º 2
0
        private void executeChange(string sql, Func <DatabaseState, DatabaseState> updateState, Action <StateStorage> updateStorage, ErrorResponse errorResponse, bool useTransaction)
        {
            doStepAction();

            bool storageRefreshNeeded = false;

            try
            {
                while (true)
                {
                    using (var transaction = useTransaction ? connection.StartTransaction() : null)
                    {
                        try
                        {
                            if (sql != null)
                            {
                                StatementCount++;
                                Output.Verbose(sql);
                                try
                                {
                                    connection.ExecuteSql(sql);
                                }
                                catch (DbException ex)
                                {
                                    if (useTransaction)
                                    {
                                        transaction.RollBack();
                                    }

                                    output.ReportVerbose("SQL statement failed:\r\n" + sql + "\r\n" + ex);

                                    if (!HasFailed &&
                                        errorResponse.HasFlag(ErrorResponse.FlagBit_PromptToRetry) &&
                                        output.CanPrompt)
                                    {
                                        if (output.Prompt(OutputMode.Warning,
                                                          "SQL Statement failed:\r\n" + sql.Substring(0, Math.Min(sql.Length, 200)) + "...\r\n" + ex.Message,
                                                          "Try again?"))
                                        {
                                            continue;
                                        }
                                    }

                                    if (errorResponse.HasFlag(ErrorResponse.FlagBit_Warn))
                                    {
                                        output.Report(errorResponse.HasFlag(ErrorResponse.FlagBit_SetFailureState) ? OutputMode.Error : OutputMode.Warning,
                                                      "SQL Statement failed:\r\n" + sql.Substring(0, Math.Min(sql.Length, 200)) + "...\r\n" + ex.Message);
                                    }

                                    if (errorResponse.HasFlag(ErrorResponse.FlagBit_SetFailureState))
                                    {
                                        Fail(null);
                                    }

                                    if (errorResponse.HasFlag(ErrorResponse.FlagBit_Throw))
                                    {
                                        throw;
                                    }
                                    else
                                    {
                                        return;
                                    }
                                }
                            }

                            var newCurrent = updateState(current);
                            if (Storage != null)
                            {
                                storageRefreshNeeded = true;
                                updateStorage(Storage);
                            }
                            if (useTransaction)
                            {
                                transaction.Commit();
                            }

                            storageRefreshNeeded = false;
                            current = newCurrent;
                            return;
                        }
                        catch
                        {
                            if (useTransaction)
                            {
                                transaction.RollBack();
                            }
                            throw;
                        }
                    }
                }
            }
            finally
            {
                if (storageRefreshNeeded && Storage != null)
                {
                    Storage.Refresh();
                }
            }
        }