Example #1
0
        public void UpdateTableSetWhereTwoConditionsTest()
        {
            var factory     = new MySQLCommandFactory();
            var table       = Utils.RandomName();
            var column_1    = Utils.RandomName();
            var column_2    = Utils.RandomName();
            var condition_1 = factory.GetConditionFactory().EqualTo(factory.GetDbObjectFactory().CreateColumn(column_1), factory.GetDbObjectFactory().CreateParameter(column_1));
            var condition_2 = factory.GetConditionFactory().EqualTo(factory.GetDbObjectFactory().CreateColumn(column_2), factory.GetDbObjectFactory().CreateParameter(column_2));
            var builder     = factory.CreateDeleteBuilder()
                              .From(factory.GetDbObjectFactory().CreateTable(table))
                              .Where(condition_1.And(condition_2));

            Assert.Equal($"DELETE `{ table }` WHERE (`{ column_1 }` = @{ column_1 }) AND (`{ column_2 }` = @{ column_2 })", builder.Build());
        }
Example #2
0
        public void SelectStarFromWhereAndTest()
        {
            var factory     = new MySQLCommandFactory();
            var table       = Utils.RandomName();
            var column_1    = Utils.RandomName();
            var column_2    = Utils.RandomName();
            var condition_1 = factory.GetConditionFactory().EqualTo(factory.GetDbObjectFactory().CreateColumn(column_1), factory.GetDbObjectFactory().CreateParameter(column_1));
            var condition_2 = factory.GetConditionFactory().EqualTo(factory.GetDbObjectFactory().CreateColumn(column_2), factory.GetDbObjectFactory().CreateParameter(column_2));
            var builder     = factory.CreateSelectBuilder()
                              .From(factory.GetDbObjectFactory().CreateTable(table))
                              .Where(condition_1)
                              .And(condition_2);

            Assert.Equal($"SELECT * FROM `{ table }` WHERE `{ column_1 }` = @{ column_1 } AND `{ column_2 }` = @{ column_2 }", builder.Build());
        }
Example #3
0
        public void UpdateTableSetWhereTwoConditionsTest()
        {
            var factory     = new MySQLCommandFactory();
            var table       = Utils.RandomName();
            var column_1    = Utils.RandomName();
            var column_2    = Utils.RandomName();
            var column_3    = Utils.RandomName();
            var column_4    = Utils.RandomName();
            var condition_3 = factory.GetConditionFactory().EqualTo(factory.GetDbObjectFactory().CreateColumn(column_3), factory.GetDbObjectFactory().CreateParameter(column_3));
            var condition_4 = factory.GetConditionFactory().EqualTo(factory.GetDbObjectFactory().CreateColumn(column_4), factory.GetDbObjectFactory().CreateParameter(column_4));
            var builder     = factory.CreateUpdateBuilder()
                              .Table(factory.GetDbObjectFactory().CreateTable(table))
                              .Set(factory.GetDbObjectFactory().CreateColumn(column_1), factory.GetDbObjectFactory().CreateParameter(column_1))
                              .Set(factory.GetDbObjectFactory().CreateColumn(column_2), factory.GetDbObjectFactory().CreateParameter(column_2))
                              .Where(condition_3.Or(condition_4));

            Assert.Equal($"UPDATE `{ table }` SET `{ column_1 }` = @{ column_1 }, `{ column_2 }` = @{ column_2 } WHERE (`{ column_3 }` = @{ column_3 }) OR (`{ column_4 }` = @{ column_4 })", builder.Build());
        }
Example #4
0
        public void SelectColumnFromLimitTest()
        {
            var factory     = new MySQLCommandFactory();
            var table       = Utils.RandomName();
            var column_1    = Utils.RandomName();
            var column_2    = Utils.RandomName();
            var column_3    = Utils.RandomName();
            var offset      = new Random().Next(1000, 2000);
            var rows        = new Random().Next(10, 20);
            var condition_1 = factory.GetConditionFactory().EqualTo(factory.GetDbObjectFactory().CreateColumn(column_1), factory.GetDbObjectFactory().CreateParameter(column_1));
            var condition_2 = factory.GetConditionFactory().EqualTo(factory.GetDbObjectFactory().CreateColumn(column_2), factory.GetDbObjectFactory().CreateParameter(column_2));
            var condition_3 = factory.GetConditionFactory().EqualTo(factory.GetDbObjectFactory().CreateColumn(column_3), factory.GetDbObjectFactory().CreateParameter(column_3));
            var builder     = factory.CreateSelectBuilder()
                              .From(factory.GetDbObjectFactory().CreateTable(table))
                              .Where(condition_1)
                              .And(condition_2.And(condition_3))
                              .Limit(offset, rows);

            Assert.Equal($"SELECT * FROM `{ table }` WHERE `{ column_1 }` = @{ column_1 } AND (`{ column_2 }` = @{ column_2 }) AND (`{ column_3 }` = @{ column_3 }) LIMIT { offset }, { rows }", builder.Build());
        }
Example #5
0
        public void SelectStarFromWhereNotNullTest()
        {
            var factory = new MySQLCommandFactory();
            var table   = Utils.RandomName();
            var column  = Utils.RandomName();
            var builder = factory.CreateSelectBuilder()
                          .From(factory.GetDbObjectFactory().CreateTable(table))
                          .Where(factory.GetConditionFactory().NotIsNull(
                                     factory.GetDbObjectFactory().CreateColumn(column)));

            Assert.Equal($"SELECT * FROM `{ table }` WHERE `{ column }` IS NOT NULL", builder.Build());
        }
Example #6
0
        public void SelectStarFromWhereGTETest()
        {
            var factory = new MySQLCommandFactory();
            var table   = Utils.RandomName();
            var column  = Utils.RandomName();
            var builder = factory.CreateSelectBuilder()
                          .From(factory.GetDbObjectFactory().CreateTable(table))
                          .Where(factory.GetConditionFactory().GreaterThanOrEqualTo(
                                     factory.GetDbObjectFactory().CreateColumn(column),
                                     factory.GetDbObjectFactory().CreateParameter(column)));

            Assert.Equal($"SELECT * FROM `{ table }` WHERE `{ column }` >= @{ column }", builder.Build());
        }