Esempio n. 1
0
 def test_get_insert_identity_composed(self):
     result = self.connection.execute("INSERT INTO test (title) "
                                      "VALUES ('Title 30')")
     primary_key = (Column("id", SQLToken("test")),
                    Column("title", SQLToken("test")))
     primary_variables = (Variable(), Variable(u"Title 30"))
     expr = result.get_insert_identity(primary_key, primary_variables)
     select = Select(Column("title", SQLToken("test")), expr)
     result = self.connection.execute(select)
     self.assertEquals(result.get_one(), ("Title 30", ))
Esempio n. 2
0
    def test_expressions_in_union_order_by(self):
        # The following statement breaks in postgres:
        #     SELECT 1 AS id UNION SELECT 1 ORDER BY id+1;
        # With the error:
        #     ORDER BY on a UNION/INTERSECT/EXCEPT result must
        #     be on one of the result columns
        column = SQLRaw("1")
        Alias.auto_counter = 0
        alias = Alias(column, "id")
        expr = Union(Select(alias),
                     Select(column),
                     order_by=alias + 1,
                     limit=1,
                     offset=1,
                     all=True)

        state = State()
        statement = compile(expr, state)
        self.assertEquals(
            statement, 'SELECT * FROM '
            '((SELECT 1 AS id) UNION ALL (SELECT 1)) AS "_1" '
            'ORDER BY id+? LIMIT 1 OFFSET 1')
        self.assertVariablesEqual(state.parameters, [Variable(1)])

        result = self.connection.execute(expr)
        self.assertEquals(result.get_one(), (1, ))
Esempio n. 3
0
 def test_set_variable(self):
     variable = Variable()
     self.result.set_variable(variable, marker)
     self.assertEquals(variable.get(), marker)
Esempio n. 4
0
 def test_set_variable(self):
     variable = Variable()
     self.result.set_variable(variable, marker)
     self.assertEquals(variable.get(), marker)
Esempio n. 5
0
 def test_set_variable(self):
     variable = Variable()
     self.result.set_variable(variable, marker)
     assert variable.get() == marker