public void DeleteVersion(long version)
 {
     var expression = new DeleteDataExpression {TableName = VersionTableMetaData.TableName, SchemaName = VersionTableMetaData.SchemaName};
     expression.Rows.Add(new DeletionDataDefinition
     {
         new KeyValuePair<string, object>(VersionTableMetaData.ColumnName, version)
     });
     expression.ExecuteWith(Processor);
 }
        public IMigrationExpression Reverse()
        {
            var expression = new DeleteDataExpression
                                {
                                    SchemaName = SchemaName,
                                    TableName = TableName,
                                };

            expression.Rows.AddRange(Rows);

            return expression;
        }
        public IMigrationExpression Reverse()
        {
            var expression = new DeleteDataExpression
            {
                SchemaName = SchemaName,
                TableName  = TableName,
            };

            expression.Rows.AddRange(Rows);

            return(expression);
        }
        public IMigrationExpression Reverse()
        {
            var expression = new DeleteDataExpression
            {
                SchemaName = SchemaName,
                TableName  = TableName
            };

            foreach (var row in Rows)
            {
                var dataDefinition = new DeletionDataDefinition();
                dataDefinition.AddRange(row);

                expression.Rows.Add(dataDefinition);
            }

            return(expression);
        }
        public IMigrationExpression Reverse()
        {
            var expression = new DeleteDataExpression
                                {
                                    SchemaName = SchemaName,
                                    TableName = TableName
                                };

            foreach (var row in Rows)
            {
                var dataDefinition = new DeletionDataDefinition();
                dataDefinition.AddRange(row);

                expression.Rows.Add(dataDefinition);
            }

            return expression;
        }
        public void CanDeleteAllDataWithNullCondition()
        {
            var expression = new DeleteDataExpression
            {
                IsAllRows = false,
                SchemaName = "public",
                TableName = "Table1"
            };
            expression.Rows.Add(
                new DeletionDataDefinition
                    {
                        new KeyValuePair<string, object>("description", null)
                    });

            var sql = generator.Generate(expression);
            sql.ShouldBe("DELETE FROM \"public\".\"Table1\" WHERE \"description\" IS NULL;");
        }
 public void Truncate(DeleteDataExpression expression)
 {
     expression.TableName = Truncate(expression.TableName);
     List<DeletionDataDefinition> deletions = new List<DeletionDataDefinition>();
     foreach (DeletionDataDefinition deletion in expression.Rows)
     {
         DeletionDataDefinition newDeletion = new DeletionDataDefinition();
         foreach (var data in deletion)
         {
             newDeletion.Add(new KeyValuePair<string, object>(Truncate(data.Key), data.Value));
         }
         deletions.Add(newDeletion);
     }
     expression.Rows.Clear();
     expression.Rows.AddRange(deletions);
 }
 public override string Generate(DeleteDataExpression expression)
 {
     throw new NotImplementedException();
 }
        public void CanDeleteAllData()
        {
            var expression = new DeleteDataExpression
                                 {
                                     IsAllRows=true, TableName = "Table1"
                                 };

            var sql = generator.Generate(expression);
            sql.ShouldBe("DELETE FROM \"public\".\"Table1\";");
        }
        public static DeleteDataExpression GetDeleteDataMultipleRowsExpression()
        {
            var expression = new DeleteDataExpression();
            expression.TableName = TestTableName1;
            expression.Rows.Add(new DeletionDataDefinition
                                    {
                                        new KeyValuePair<string, object>("Name", "Just'in"),
                                        new KeyValuePair<string, object>("Website", null)
                                    });
            expression.Rows.Add(new DeletionDataDefinition
                                    {
                                        new KeyValuePair<string, object>("Website", "github.com")
                                    });

            return expression;
        }
 public override string Generate(DeleteDataExpression expression)
 {
     return string.Format("{0};", base.Generate(expression));
 }
        public void CanDeleteData()
        {
            var expression = new DeleteDataExpression();
            expression.TableName = "TestTable";
            expression.Rows.Add(new DeletionDataDefinition
                                    {
                                        new KeyValuePair<string, object>("Name", "Just'in"),
                                        new KeyValuePair<string, object>("Website", null)
                                    });

            var sql = generator.Generate(expression);

            sql.ShouldBe("DELETE FROM [TestTable] WHERE [Name] = 'Just''in' AND [Website] IS NULL;");
        }
        public override string Generate(DeleteDataExpression expression)
        {
            var result = new StringBuilder();

            if (expression.IsAllRows)
            {
                result.Append(String.Format("DELETE FROM {0}.{1};", Quoter.QuoteSchemaName(expression.SchemaName), Quoter.QuoteTableName(expression.TableName)));
            }
            else
            {
                foreach (var row in expression.Rows)
                {
                    var where = String.Empty;
                    var i = 0;

                    foreach (var item in row)
                    {
                        if (i != 0)
                        {
                            where += " AND ";
                        }

                        where += String.Format("{0} {1} {2}", Quoter.QuoteColumnName(item.Key), item.Value == null ? "IS" : "=", Quoter.QuoteValue(item.Value));
                        i++;
                    }

                    result.Append(String.Format("DELETE FROM {0}.{1} WHERE {2};", Quoter.QuoteSchemaName(expression.SchemaName), Quoter.QuoteTableName(expression.TableName), where));
                }
            }

            return result.ToString();
        }
 public void Truncate(DeleteDataExpression expression)
 {
     expression.TableName = Truncate(expression.TableName);
 }
        public static DeleteDataExpression GetDeleteDataMultipleRowsExpression()
        {
            var expression = new DeleteDataExpression();
            expression.TableName = TestTableName1;
            expression.Rows.Add(new ExplicitDataDefinition(new DataValue("Name", "Just'in"), new DataValue("Website", null)));
            expression.Rows.Add(new ExplicitDataDefinition(new DataValue("Website", "github.com")));

            return expression;
        }
        public override string Generate(DeleteDataExpression expression)
        {
            var result = new StringBuilder();

            if (expression.IsAllRows)
            {
                result.Append(String.Format("DELETE FROM {0}[{1}];", FormatSchema(expression.SchemaName), expression.TableName));
            }
            else
            {
                foreach (var row in expression.Rows)
                {
                    var where = String.Empty;
                    var i = 0;

                    foreach (var item in row)
                    {
                        if (i != 0)
                        {
                            where += " AND ";
                        }

                        where += String.Format("[{0}] = {1}", item.Key, Constant.Format(item.Value));
                        i++;
                    }

                    result.Append(String.Format("DELETE FROM {0}[{1}] WHERE {2};", FormatSchema(expression.SchemaName), expression.TableName, where));
                }
            }

            return result.ToString();
        }
        public void CanDeleteTestFromTable()
        {
            CanInsertAndReadDataFromTestTable();

             var delete = new DeleteDataExpression {TableName = "Foo"};
             delete.Rows.Add(new DeletionDataDefinition {
            new KeyValuePair<string, object>("Id", 1)
            });

             _processor.Process(delete);

             var table = _processor.ReadTableData(string.Empty, "Foo");

             0.ShouldBe(table.Tables[0].Rows.Count);
        }
 public void DeleteVersion(long version)
 {
     var expression = new DeleteDataExpression { TableName = VersionTableMetaData.TableName, SchemaName = VersionTableMetaData.SchemaName };
     expression.Rows.Add(new ExplicitDataDefinition(new DataValue(VersionTableMetaData.ColumnName, version)));
     expression.ExecuteWith(Processor);
 }
 public DeleteDataExpressionBuilder(DeleteDataExpression expression)
 {
     _expression = expression;
 }
 public IDeleteDataOrInSchemaSyntax FromTable(string tableName)
 {
     var expression = new DeleteDataExpression { TableName = tableName };
     _context.Expressions.Add(expression);
     return new DeleteDataExpressionBuilder(expression);
 }
 public static DeleteDataExpression GetDeleteDataAllRowsExpression()
 {
     var expression = new DeleteDataExpression();
     expression.TableName = TestTableName1;
     expression.IsAllRows = true;
     return expression;
 }
        public override string Generate(DeleteDataExpression expression)
        {
            var deleteItems = new List<string>();

            if (expression.IsAllRows)
            {
                deleteItems.Add(string.Format(DeleteData, Quoter.QuoteTableName(expression.TableName), "1 = 1"));
            }
            else
            {
                foreach (var row in expression.Rows)
                {
                    var whereClauses = new List<string>();
                    foreach (KeyValuePair<string, object> item in row)
                    {
                        whereClauses.Add(string.Format("{0} {1} {2}", Quoter.QuoteColumnName(item.Key), item.Value == null ? "IS" : "=", Quoter.QuoteValue(item.Value)));
                    }

                    deleteItems.Add(string.Format(DeleteData, Quoter.QuoteTableName(expression.TableName), String.Join(" AND ", whereClauses.ToArray())));
                }
            }

            return String.Join("; ", deleteItems.ToArray());
        }
 public void Process(DeleteDataExpression expression)
 {
     Process(Generator.Generate(expression));
 }
        public override string Generate(DeleteDataExpression expression)
        {
            var deleteItems = new List<string>();

            if (expression.IsAllRows)
            {
                deleteItems.Add(string.Format(DeleteData, Quoter.QuoteTableName(expression.TableName), "1 = 1", CommandDelimiter));
            }
            else
            {
                foreach (var row in expression.Rows)
                {
                    IEnumerable<IDataValue> columnData = evaluator.Evaluate(row);

                    var whereClauses = new List<string>();

                    foreach (IDataValue item in columnData)
                    {
                        whereClauses.Add(string.Format("{0} {1} {2}", Quoter.QuoteColumnName(item.ColumnName), item.Value == null ? "IS" : "=", Quoter.QuoteDataValue(item)));
                    }

                    deleteItems.Add(string.Format(DeleteData, Quoter.QuoteTableName(expression.TableName), String.Join(" AND ", whereClauses.ToArray()), CommandDelimiter));
                }
            }

            return String.Join(MultilineDelimiter, deleteItems.ToArray());
        }
        public override string Generate(DeleteDataExpression expression)
        {
            var result = new StringBuilder();
            foreach (var row in expression.Rows)
            {
                var where = String.Empty;
                var i = 0;

                foreach (var item in row)
                {
                    if (i != 0)
                    {
                        where += " AND ";
                    }

                    where += String.Format("[{0}] {1} {2}", item.Key, item.Value == null ? "IS" : "=", Constant.Format(item.Value));
                    i++;
                }

                result.Append(String.Format("DELETE FROM {0} WHERE {1};", expression.TableName, where));
            }
            return result.ToString();
        }
        public void CanDeleteAllDataWithCondition()
        {
            var expression = new DeleteDataExpression
            {
                IsAllRows = false,
                SchemaName = "public",
                TableName = "Table1"
            };

            expression.Rows.Add(new ExplicitDataDefinition(new DataValue("description", "wibble")));

            var sql = generator.Generate(expression);
            sql.ShouldBe("DELETE FROM \"public\".\"Table1\" WHERE \"description\" = 'wibble';");
        }
        public void CanDeleteAllDataWithMultipleConditions()
        {
            var expression = new DeleteDataExpression
            {
                IsAllRows = false,
                SchemaName = "public",
                TableName = "Table1"
            };
            expression.Rows.Add(new ExplicitDataDefinition
                                    (
                                        new DataValue("description", null),
                                        new DataValue("id", 10)
                                    ));

            var sql = generator.Generate(expression);
            sql.ShouldBe("DELETE FROM \"public\".\"Table1\" WHERE \"description\" IS NULL AND \"id\" = 10;");
        }
 public abstract string Generate(DeleteDataExpression expression);
 public override string Generate(DeleteDataExpression expression)
 {
     truncator.Truncate(expression);
     return base.Generate(expression);
 }
 public override string Generate(DeleteDataExpression expression)
 {
     return string.Format("DELETE FROM {0}.{1}", Quoter.QuoteSchemaName(expression.SchemaName), base.Generate(expression));
 }