Beispiel #1
0
 def test_orderby_many_asc_desc(self):
     self.assertParse(
         "SELECT * ORDER BY a ASC, b DESC, c;",
         Select(qp.Wildcard(),
                order_by=[
                    qp.OrderBy(qp.Column('a'), qp.Ordering.ASC),
                    qp.OrderBy(qp.Column('b'), qp.Ordering.DESC),
                    qp.OrderBy(qp.Column('c'), qp.Ordering.ASC)
                ]))
Beispiel #2
0
 def test_orderby_many(self):
     self.assertParse(
         qSelect(qp.Wildcard(),
                 order_by=qp.OrderBy(
                     [qp.Column('a'),
                      qp.Column('b'),
                      qp.Column('c')], None)), "SELECT * ORDER BY a, b, c;")
Beispiel #3
0
class TestTranslationBalance(CompileSelectBase):

    group_by = qp.GroupBy([
        qp.Column('account'),
        qp.Function('account_sortkey', [qp.Column(name='account')])
    ], None)

    order_by = qp.OrderBy(
        [qp.Function('account_sortkey', [qp.Column('account')])], None)

    def test_balance(self):
        balance = self.parse("BALANCES;")
        select = qc.transform_balances(balance)
        self.assertEqual(
            qp.Select([
                qp.Target(qp.Column('account'), None),
                qp.Target(qp.Function('sum', [qp.Column('position')]), None),
            ], None, None, self.group_by, self.order_by, None, None, None,
                      None), select)

    def test_balance_with_units(self):
        balance = self.parse("BALANCES AT cost;")
        select = qc.transform_balances(balance)
        self.assertEqual(
            qp.Select([
                qp.Target(qp.Column('account'), None),
                qp.Target(
                    qp.Function(
                        'sum', [qp.Function('cost', [qp.Column('position')])]),
                    None)
            ], None, None, self.group_by, self.order_by, None, None, None,
                      None), select)

    def test_balance_with_units_and_from(self):
        balance = self.parse("BALANCES AT cost FROM year = 2014;")
        select = qc.transform_balances(balance)
        self.assertEqual(
            qp.Select([
                qp.Target(qp.Column('account'), None),
                qp.Target(
                    qp.Function(
                        'sum', [qp.Function('cost', [qp.Column('position')])]),
                    None),
            ],
                      qp.From(qp.Equal(qp.Column('year'), qp.Constant(2014)),
                              None, None, None), None, self.group_by,
                      self.order_by, None, None, None, None), select)
Beispiel #4
0
 def test_orderby_desc(self):
     self.assertParse(
         "SELECT * ORDER BY a DESC;",
         Select(qp.Wildcard(),
                order_by=[qp.OrderBy(qp.Column('a'), qp.Ordering.DESC)]))
Beispiel #5
0
 def test_orderby_desc(self):
     self.assertParse(
         qSelect(qp.Wildcard(),
                 order_by=qp.OrderBy([qp.Column('a')], 'DESC')),
         "SELECT * ORDER BY a DESC;")
Beispiel #6
0
class TestTranslationBalance(CompileSelectBase):

    group_by = qp.GroupBy([
        qp.Column('account'),
        qp.Function('account_sortkey', [qp.Column(name='account')])
    ], None)

    order_by = [
        qp.OrderBy(qp.Function('account_sortkey', [qp.Column('account')]),
                   qp.Ordering.ASC)
    ]

    def test_balance(self):
        balance = self.parse("BALANCES;")
        select = qc.transform_balances(balance)
        self.assertEqual(
            select,
            qp.Select([
                qp.Target(qp.Column('account'), None),
                qp.Target(qp.Function('sum', [qp.Column('position')]), None),
            ], None, None, self.group_by, self.order_by, None, None, None))

    def test_balance_with_units(self):
        balance = self.parse("BALANCES AT cost;")
        select = qc.transform_balances(balance)
        self.assertEqual(
            select,
            qp.Select([
                qp.Target(qp.Column('account'), None),
                qp.Target(
                    qp.Function(
                        'sum', [qp.Function('cost', [qp.Column('position')])]),
                    None)
            ], None, None, self.group_by, self.order_by, None, None, None))

    def test_balance_with_units_and_from(self):
        balance = self.parse("BALANCES AT cost FROM year = 2014;")
        select = qc.transform_balances(balance)
        self.assertEqual(
            select,
            qp.Select([
                qp.Target(qp.Column('account'), None),
                qp.Target(
                    qp.Function(
                        'sum', [qp.Function('cost', [qp.Column('position')])]),
                    None),
            ],
                      qp.From(qp.Equal(qp.Column('year'), qp.Constant(2014)),
                              None, None, None), None, self.group_by,
                      self.order_by, None, None, None))

    def test_print(self):
        self.assertCompile(qc.EvalPrint(None), "PRINT;")

    def test_print_from(self):
        self.assertCompile(
            qc.EvalPrint(
                qc.EvalFrom(
                    qc.Operator(qp.Equal, [
                        qe.YearEntryColumn(),
                        qc.EvalConstant(2014),
                    ]), None, None, None)), """PRINT FROM year = 2014;""")