Esempio n. 1
0
        public int ExecuteDownCommand(dynamic down)
        {
            var sql = _sql_formatter.GenerateSQLDown(down);

            using (var connection = GetOpenConnection()) {
                var transaction = connection.BeginTransaction(System.Data.IsolationLevel.Serializable);
                var cmd         = connection.CreateCommand();
                cmd.Transaction = transaction;
                try {
                    foreach (var s in sql)
                    {
                        if (_configuration.Verbose)
                        {
                            Console.WriteLine("Executing SQL: " + s);
                        }
                        cmd.CommandText = s;
                        cmd.ExecuteNonQuery();
                    }
                    transaction.Commit();
                } catch {
                    transaction.Rollback();
                    throw;
                } finally {
                    connection.Close();
                }
            }
            return(sql.Length);
        }
Esempio n. 2
0
        public virtual int ExecuteDownCommand(dynamic down)
        {
            if (down.down == null)
            {
                return(0);
            }
            var  sql         = _sql_formatter.GenerateSQLDown(down);
            bool has_filesmo = false;

            try {
                bool fsmo = down.down.filesmo != null;
                has_filesmo = fsmo;
            } catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException) {
                // intentionally let thru, no smo object
            }
            if (has_filesmo)
            {
                ExecuteSmo(_settings.ConnectionString(), sql[0]);
                return(1);
            }
            using (var connection = GetOpenConnection()) {
                var transaction = connection.BeginTransaction(System.Data.IsolationLevel.Serializable);
                var cmd         = connection.CreateCommand();
                cmd.Transaction = transaction;
                try {
                    foreach (var s in sql)
                    {
                        if (s.Contains("DROP TABLE"))
                        {
                            if (_configuration.Verbose)
                            {
                                Console.WriteLine("DROPPING CONSTRAINTS BEFORE Executing SQL: " + s);
                            }

                            string table_name = s.Replace("DROP TABLE ", "").Trim();
                            foreach (var drop_string in DropTableConstraints(table_name, cmd))
                            {
                                cmd.CommandText = drop_string;
                                cmd.ExecuteNonQuery();
                            }
                        }
                        if (_configuration.Verbose)
                        {
                            Console.WriteLine("Executing SQL: " + s);
                        }
                        cmd.CommandText = s;
                        cmd.ExecuteNonQuery();
                    }
                    transaction.Commit();
                } catch {
                    transaction.Rollback();
                    throw;
                } finally {
                    connection.Close();
                }
            }
            return(sql.Length);
        }