예제 #1
0
    def test_insert_with_values_func(self):
        table1 = self.tables.mytable

        self.assert_compile(
            insert(table1, values=dict(myid=func.lala())),
            "INSERT INTO mytable (myid) VALUES (lala())",
        )
예제 #2
0
    def test_insert_with_values_func(self):
        table1 = self.tables.mytable

        self.assert_compile(
            insert(table1, values=dict(myid=func.lala())),
            "INSERT INTO mytable (myid) VALUES (lala())",
        )
예제 #3
0
    def test_assorted(self):
        table1 = table('mytable',
                       column('myid', Integer),
                       )

        table2 = table(
            'myothertable',
            column('otherid', Integer),
        )

        # test an expression with a function
        self.assert_compile(func.lala(3, 4, literal("five"),
                                      table1.c.myid) * table2.c.otherid,
                            "lala(:lala_1, :lala_2, :param_1, mytable.myid) * "
                            "myothertable.otherid")

        # test it in a SELECT
        self.assert_compile(select(
            [func.count(table1.c.myid)]),
            "SELECT count(mytable.myid) AS count_1 FROM mytable")

        # test a "dotted" function name
        self.assert_compile(select([func.foo.bar.lala(
            table1.c.myid)]),
            "SELECT foo.bar.lala(mytable.myid) AS lala_1 FROM mytable")

        # test the bind parameter name with a "dotted" function name is
        # only the name (limits the length of the bind param name)
        self.assert_compile(select([func.foo.bar.lala(12)]),
                            "SELECT foo.bar.lala(:lala_2) AS lala_1")

        # test a dotted func off the engine itself
        self.assert_compile(func.lala.hoho(7), "lala.hoho(:hoho_1)")

        # test None becomes NULL
        self.assert_compile(
            func.my_func(
                1,
                2,
                None,
                3),
            "my_func(:my_func_1, :my_func_2, NULL, :my_func_3)")

        # test pickling
        self.assert_compile(
            util.pickle.loads(util.pickle.dumps(
                func.my_func(1, 2, None, 3))),
            "my_func(:my_func_1, :my_func_2, NULL, :my_func_3)")

        # assert func raises AttributeError for __bases__ attribute, since
        # its not a class fixes pydoc
        try:
            func.__bases__
            assert False
        except AttributeError:
            assert True