public void InsertAppliedScript(DatabaseVersion version, string schema, IScript script, IScript rollbackScript = null)
        {
            var reader = new ScriptReader();

            try
            {
                _connection.Execute(@"INSERT INTO {0}.appliedscripts (id, version_id, forward_script, backward_script)
                                        VALUES ({0}.appliedscripts_seq.nextval, (SELECT id as version_id FROM {0}.versions WHERE version = :version), :forwardScript, :rollbackScript)".FormatWith(schema),
                                    new
                {
                    version        = version.Version,
                    forwardScript  = string.Join(Environment.NewLine, reader.GetContents(script.Path)),
                    rollbackScript = rollbackScript.IsNull() ? null : string.Join(Environment.NewLine, reader.GetContents(rollbackScript.Path))
                });
            }
            catch (OracleException oracleException)
            {
                if (oracleException.IsFor(OracleErrors.TableOrViewDoesNotExist))
                {
                    Output.Warn("Applied scripts table in schema '{0}' could not be found, applied script could not be recorded.".FormatWith(schema));
                    return;
                }

                throw;
            }
        }
Exemple #2
0
        public SqlPlusScript(IScript script)
        {
            _script = script;

            _wrappedScriptPath = System.IO.Path.GetTempFileName();

            var reader = new ScriptReader();

            using (var fileStream = File.OpenWrite(_wrappedScriptPath))
            {
                using (var tempFile = new StreamWriter(fileStream, UTF8.WithoutByteOrderMark))
                {
                    tempFile.WriteLine("SET ECHO ON");
                    tempFile.WriteLine("WHENEVER SQLERROR EXIT SQL.SQLCODE");

                    foreach (var scriptLine in reader.GetContents(_script.Path))
                    {
                        tempFile.WriteLine(scriptLine);
                    }

                    tempFile.WriteLine("COMMIT;");
                    tempFile.WriteLine("EXIT");
                }
            }
        }
        public void InsertAppliedScript(DatabaseVersion version, string schema, IScript script, IScript rollbackScript = null)
        {
            var reader = new ScriptReader();

            try
            {
                _connection.Execute(@"INSERT INTO {0}.appliedscripts (id, version_id, forward_script, backward_script)
                                        VALUES ({0}.appliedscripts_seq.nextval, (SELECT id as version_id FROM {0}.versions WHERE version = :version), :forwardScript, :rollbackScript)".FormatWith(schema),
                    new
                    {
                        version = version.Version,
                        forwardScript = string.Join(Environment.NewLine, reader.GetContents(script.Path)),
                        rollbackScript = rollbackScript.IsNull() ? null : string.Join(Environment.NewLine, reader.GetContents(rollbackScript.Path))
                    });
            }
            catch (OracleException oracleException)
            {
                if (oracleException.IsFor(OracleErrors.TableOrViewDoesNotExist))
                {
                    Output.Warn("Applied scripts table in schema '{0}' could not be found, applied script could not be recorded.".FormatWith(schema));
                    return;
                }

                throw;
            }
        }