当前位置: 首页>>代码示例>>Python>>正文


Python Flavor.set方法代码示例

本文整理汇总了Python中sql.Flavor.set方法的典型用法代码示例。如果您正苦于以下问题:Python Flavor.set方法的具体用法?Python Flavor.set怎么用?Python Flavor.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sql.Flavor的用法示例。


在下文中一共展示了Flavor.set方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_select_union_flavor

# 需要导入模块: from sql import Flavor [as 别名]
# 或者: from sql.Flavor import set [as 别名]
 def test_select_union_flavor(self):
     flavor = Flavor.get()
     prev = flavor.quote_character
     flavor.quote_character = '`'
     self._test_select_union_quote('`')
     flavor.quote_character = prev
     Flavor.set(flavor)
开发者ID:jiaxiaolei,项目名称:python-sql,代码行数:9,代码来源:test_select.py

示例2: start

# 需要导入模块: from sql import Flavor [as 别名]
# 或者: from sql.Flavor import set [as 别名]
 def start(self, database_name, user, readonly=False, context=None,
         close=False, autocommit=False):
     '''
     Start transaction
     '''
     Database = backend.get('Database')
     assert self.user is None
     assert self.database is None
     assert self.close is None
     assert self.context is None
     if not database_name:
         database = Database().connect()
     else:
         database = Database(database_name).connect()
     Flavor.set(Database.flavor)
     self.user = user
     self.database = database
     self.readonly = readonly
     self.connection = database.get_connection(readonly=readonly,
         autocommit=autocommit)
     self.close = close
     self.context = context or {}
     self.create_records = {}
     self.delete_records = {}
     self.delete = {}
     self.timestamp = {}
     self.counter = 0
     self._datamanagers = []
     return self
开发者ID:coopengo,项目名称:trytond,代码行数:31,代码来源:transaction.py

示例3: test_select_limit_offset

# 需要导入模块: from sql import Flavor [as 别名]
# 或者: from sql.Flavor import set [as 别名]
    def test_select_limit_offset(self):
        query = self.table.select(limit=50, offset=10)
        self.assertEqual(str(query),
            'SELECT * FROM "t" AS "a" LIMIT 50 OFFSET 10')
        self.assertEqual(query.params, ())

        query.limit = None
        self.assertEqual(str(query),
            'SELECT * FROM "t" AS "a" OFFSET 10')
        self.assertEqual(query.params, ())

        query.offset = 0
        self.assertEqual(str(query),
            'SELECT * FROM "t" AS "a"')
        self.assertEqual(query.params, ())

        flavor = Flavor(max_limit=-1)
        Flavor.set(flavor)
        try:
            query.offset = None
            self.assertEqual(str(query),
                'SELECT * FROM "t" AS "a"')
            self.assertEqual(query.params, ())

            query.offset = 0
            self.assertEqual(str(query),
                'SELECT * FROM "t" AS "a"')
            self.assertEqual(query.params, ())

            query.offset = 10
            self.assertEqual(str(query),
                'SELECT * FROM "t" AS "a" LIMIT -1 OFFSET 10')
            self.assertEqual(query.params, ())
        finally:
            Flavor.set(Flavor())
开发者ID:jiaxiaolei,项目名称:python-sql,代码行数:37,代码来源:test_select.py

示例4: test_no_as

# 需要导入模块: from sql import Flavor [as 别名]
# 或者: from sql.Flavor import set [as 别名]
 def test_no_as(self):
     query = self.table.select(self.column.as_('foo'))
     try:
         Flavor.set(Flavor(no_as=True))
         self.assertEqual(str(query), 'SELECT "a"."c" "foo" FROM "t" "a"')
         self.assertEqual(query.params, ())
     finally:
         Flavor.set(Flavor())
开发者ID:jefurry,项目名称:python-sql,代码行数:10,代码来源:test_as.py

示例5: test_at_time_zone_mapping

# 需要导入模块: from sql import Flavor [as 别名]
# 或者: from sql.Flavor import set [as 别名]
    def test_at_time_zone_mapping(self):
        class MyAtTimeZone(Function):
            _function = 'MY_TIMEZONE'

        time_zone = AtTimeZone(self.table.c1, 'UTC')
        flavor = Flavor(function_mapping={
                AtTimeZone: MyAtTimeZone,
                })
        Flavor.set(flavor)
        try:
            self.assertEqual(str(time_zone), 'MY_TIMEZONE("c1", %s)')
            self.assertEqual(time_zone.params, ('UTC',))
        finally:
            Flavor.set(Flavor())
开发者ID:XasaKura,项目名称:Xsql,代码行数:16,代码来源:test_functions.py

示例6: test_no_boolean

# 需要导入模块: from sql import Flavor [as 别名]
# 或者: from sql.Flavor import set [as 别名]
 def test_no_boolean(self):
     true = Literal(True)
     false = Literal(False)
     self.assertEqual(str(true), '%s')
     self.assertEqual(true.params, (True,))
     self.assertEqual(str(false), '%s')
     self.assertEqual(false.params, (False,))
     try:
         Flavor.set(Flavor(no_boolean=True))
         self.assertEqual(str(true), '(1 = 1)')
         self.assertEqual(str(false), '(1 != 1)')
         self.assertEqual(true.params, ())
         self.assertEqual(false.params, ())
     finally:
         Flavor.set(Flavor())
开发者ID:jefurry,项目名称:python-sql,代码行数:17,代码来源:test_literal.py

示例7: test_mapping

# 需要导入模块: from sql import Flavor [as 别名]
# 或者: from sql.Flavor import set [as 别名]
    def test_mapping(self):
        class MyAbs(Function):
            _function = 'MY_ABS'
            params = ('test',)

        abs_ = Abs(self.table.c1)
        flavor = Flavor(function_mapping={
                Abs: MyAbs,
                })
        Flavor.set(flavor)
        try:
            self.assertEqual(str(abs_), 'MY_ABS("c1")')
            self.assertEqual(abs_.params, ('test',))
        finally:
            Flavor.set(Flavor())
开发者ID:zilberstein,项目名称:visit_counter,代码行数:17,代码来源:test_functions.py

示例8: test_select_offset_fetch

# 需要导入模块: from sql import Flavor [as 别名]
# 或者: from sql.Flavor import set [as 别名]
    def test_select_offset_fetch(self):
        try:
            Flavor.set(Flavor(limitstyle='fetch'))
            query = self.table.select(limit=50, offset=10)
            self.assertEqual(str(query),
                'SELECT * FROM "t" AS "a" '
                'OFFSET (10) ROWS FETCH FIRST (50) ROWS ONLY')
            self.assertEqual(query.params, ())

            query.limit = None
            self.assertEqual(str(query),
                'SELECT * FROM "t" AS "a" OFFSET (10) ROWS')
            self.assertEqual(query.params, ())

            query.offset = 0
            self.assertEqual(str(query),
                'SELECT * FROM "t" AS "a"')
            self.assertEqual(query.params, ())
        finally:
            Flavor.set(Flavor())
开发者ID:XasaKura,项目名称:Xsql,代码行数:22,代码来源:test_select.py

示例9: test_no_null_ordering

# 需要导入模块: from sql import Flavor [as 别名]
# 或者: from sql.Flavor import set [as 别名]
    def test_no_null_ordering(self):
        try:
            Flavor.set(Flavor(null_ordering=False))

            exp = NullsFirst(self.column)
            self.assertEqual(str(exp),
                'CASE WHEN ("c" IS NULL) THEN %s ELSE %s END ASC, "c"')
            self.assertEqual(exp.params, (0, 1))

            exp = NullsFirst(Desc(self.column))
            self.assertEqual(str(exp),
                'CASE WHEN ("c" IS NULL) THEN %s ELSE %s END ASC, "c" DESC')
            self.assertEqual(exp.params, (0, 1))

            exp = NullsLast(Literal(2))
            self.assertEqual(str(exp),
                'CASE WHEN (%s IS NULL) THEN %s ELSE %s END ASC, %s')
            self.assertEqual(exp.params, (2, 1, 0, 2))
        finally:
            Flavor.set(Flavor())
开发者ID:jefurry,项目名称:python-sql,代码行数:22,代码来源:test_order.py

示例10: test_mapping

# 需要导入模块: from sql import Flavor [as 别名]
# 或者: from sql.Flavor import set [as 别名]
    def test_mapping(self):
        class MyAbs(Function):
            _function = 'MY_ABS'
            params = ('test',)

        class MyOverlay(FunctionKeyword):
            _function = 'MY_OVERLAY'
            _keywords = ('', 'PLACING', 'FROM', 'FOR')

        class MyCurrentTime(FunctionNotCallable):
            _function = 'MY_CURRENT_TIME'

        class MyTrim(Trim):
            _function = 'MY_TRIM'

        abs_ = Abs(self.table.c1)
        overlay = Overlay(self.table.c1, 'test', 2)
        current_time = CurrentTime()
        trim = Trim(' test ')
        flavor = Flavor(function_mapping={
                Abs: MyAbs,
                Overlay: MyOverlay,
                CurrentTime: MyCurrentTime,
                Trim: MyTrim,
                })
        Flavor.set(flavor)
        try:
            self.assertEqual(str(abs_), 'MY_ABS("c1")')
            self.assertEqual(abs_.params, ('test',))

            self.assertEqual(str(overlay),
                'MY_OVERLAY("c1" PLACING %s FROM %s)')
            self.assertEqual(overlay.params, ('test', 2))

            self.assertEqual(str(current_time), 'MY_CURRENT_TIME')
            self.assertEqual(current_time.params, ())

            self.assertEqual(str(trim), 'MY_TRIM(BOTH %s FROM %s)')
            self.assertEqual(trim.params, (' ', ' test ',))
        finally:
            Flavor.set(Flavor())
开发者ID:XasaKura,项目名称:Xsql,代码行数:43,代码来源:test_functions.py

示例11: test_mod_paramstyle

# 需要导入模块: from sql import Flavor [as 别名]
# 或者: from sql.Flavor import set [as 别名]
    def test_mod_paramstyle(self):
        flavor = Flavor(paramstyle='format')
        Flavor.set(flavor)
        try:
            mod = Mod(self.table.c1, self.table.c2)
            self.assertEqual(str(mod), '("c1" %% "c2")')
            self.assertEqual(mod.params, ())
        finally:
            Flavor.set(Flavor())

        flavor = Flavor(paramstyle='qmark')
        Flavor.set(flavor)
        try:
            mod = Mod(self.table.c1, self.table.c2)
            self.assertEqual(str(mod), '("c1" % "c2")')
            self.assertEqual(mod.params, ())
        finally:
            Flavor.set(Flavor())
开发者ID:jefurry,项目名称:python-sql,代码行数:20,代码来源:test_operators.py

示例12: test_not_ilike

# 需要导入模块: from sql import Flavor [as 别名]
# 或者: from sql.Flavor import set [as 别名]
    def test_not_ilike(self):
        flavor = Flavor(ilike=True)
        Flavor.set(flavor)
        try:
            for like in [NotILike(self.table.c1, 'foo'),
                    ~self.table.c1.ilike('foo')]:
                self.assertEqual(str(like), '("c1" NOT ILIKE %s)')
                self.assertEqual(like.params, ('foo',))
        finally:
            Flavor.set(Flavor())

        flavor = Flavor(ilike=False)
        Flavor.set(flavor)
        try:
            like = NotILike(self.table.c1, 'foo')
            self.assertEqual(str(like), '(UPPER("c1") NOT LIKE UPPER(%s))')
            self.assertEqual(like.params, ('foo',))
        finally:
            Flavor.set(Flavor())
开发者ID:jefurry,项目名称:python-sql,代码行数:21,代码来源:test_operators.py

示例13: test_ilike

# 需要导入模块: from sql import Flavor [as 别名]
# 或者: from sql.Flavor import set [as 别名]
    def test_ilike(self):
        flavor = Flavor(ilike=True)
        Flavor.set(flavor)
        try:
            for like in [ILike(self.table.c1, 'foo'),
                    self.table.c1.ilike('foo'),
                    ~NotILike(self.table.c1, 'foo')]:
                self.assertEqual(str(like), '("c1" ILIKE %s)')
                self.assertEqual(like.params, ('foo',))
        finally:
            Flavor.set(Flavor())

        flavor = Flavor(ilike=False)
        Flavor.set(flavor)
        try:
            like = ILike(self.table.c1, 'foo')
            self.assertEqual(str(like), '("c1" LIKE %s)')
            self.assertEqual(like.params, ('foo',))
        finally:
            Flavor.set(Flavor())
开发者ID:XasaKura,项目名称:Xsql,代码行数:22,代码来源:test_operators.py

示例14: test_select_rownum

# 需要导入模块: from sql import Flavor [as 别名]
# 或者: from sql.Flavor import set [as 别名]
    def test_select_rownum(self):
        try:
            Flavor.set(Flavor(limitstyle='rownum'))
            query = self.table.select(limit=50, offset=10)
            self.assertEqual(str(query),
                'SELECT "a".* FROM ('
                    'SELECT "b".*, ROWNUM AS "rnum" FROM ('
                        'SELECT * FROM "t" AS "c") AS "b" '
                    'WHERE (ROWNUM <= %s)) AS "a" '
                'WHERE ("rnum" > %s)')
            self.assertEqual(query.params, (60, 10))

            query = self.table.select(
                self.table.c1.as_('col1'), self.table.c2.as_('col2'),
                limit=50, offset=10)
            self.assertEqual(str(query),
                'SELECT "a"."col1", "a"."col2" FROM ('
                    'SELECT "b"."col1", "b"."col2", ROWNUM AS "rnum" FROM ('
                        'SELECT "c"."c1" AS "col1", "c"."c2" AS "col2" '
                        'FROM "t" AS "c") AS "b" '
                    'WHERE (ROWNUM <= %s)) AS "a" '
                'WHERE ("rnum" > %s)')
            self.assertEqual(query.params, (60, 10))

            subquery = query.select(query.col1, query.col2)
            self.assertEqual(str(subquery),
                'SELECT "a"."col1", "a"."col2" FROM ('
                    'SELECT "b"."col1", "b"."col2" FROM ('
                        'SELECT "a"."col1", "a"."col2", ROWNUM AS "rnum" '
                        'FROM ('
                            'SELECT "c"."c1" AS "col1", "c"."c2" AS "col2" '
                            'FROM "t" AS "c") AS "a" '
                        'WHERE (ROWNUM <= %s)) AS "b" '
                    'WHERE ("rnum" > %s)) AS "a"')
            # XXX alias of query is reused but not a problem
            # as it is hidden in subquery
            self.assertEqual(query.params, (60, 10))

            query = self.table.select(limit=50, offset=10,
                order_by=[self.table.c])
            self.assertEqual(str(query),
                'SELECT "a".* FROM ('
                    'SELECT "b".*, ROWNUM AS "rnum" FROM ('
                        'SELECT * FROM "t" AS "c" ORDER BY "c"."c") AS "b" '
                    'WHERE (ROWNUM <= %s)) AS "a" '
                'WHERE ("rnum" > %s)')
            self.assertEqual(query.params, (60, 10))

            query = self.table.select(limit=50)
            self.assertEqual(str(query),
                'SELECT "a".* FROM ('
                    'SELECT * FROM "t" AS "b") AS "a" '
                'WHERE (ROWNUM <= %s)')
            self.assertEqual(query.params, (50,))

            query = self.table.select(offset=10)
            self.assertEqual(str(query),
                'SELECT "a".* FROM ('
                    'SELECT "b".*, ROWNUM AS "rnum" FROM ('
                        'SELECT * FROM "t" AS "c") AS "b") AS "a" '
                'WHERE ("rnum" > %s)')
            self.assertEqual(query.params, (10,))

            query = self.table.select(self.table.c.as_('col'),
                where=self.table.c >= 20,
                limit=50, offset=10)
            self.assertEqual(str(query),
                'SELECT "a"."col" FROM ('
                    'SELECT "b"."col", ROWNUM AS "rnum" FROM ('
                        'SELECT "c"."c" AS "col" FROM "t" AS "c" '
                        'WHERE ("c"."c" >= %s)) AS "b" '
                    'WHERE (ROWNUM <= %s)) AS "a" '
                'WHERE ("rnum" > %s)')
            self.assertEqual(query.params, (20, 60, 10))
        finally:
            Flavor.set(Flavor())
开发者ID:jefurry,项目名称:python-sql,代码行数:78,代码来源:test_select.py


注:本文中的sql.Flavor.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。