本文整理汇总了Python中sql.Flavor类的典型用法代码示例。如果您正苦于以下问题:Python Flavor类的具体用法?Python Flavor怎么用?Python Flavor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Flavor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_select_limit_offset
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())
示例2: test_select_union_flavor
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)
示例3: start
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
示例4: test_no_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())
示例5: __str__
def __str__(self):
Mapping = Flavor.get().function_mapping.get(self.__class__)
if Mapping:
return str(Mapping(*self.args))
param = Flavor.get().param
def format(arg):
if isinstance(arg, basestring):
return param
else:
return str(arg)
return self._function + '(' + ', '.join(map(format, self.args)) + ')'
示例6: __str__
def __str__(self):
Mapping = Flavor.get().function_mapping.get(self.__class__)
if Mapping:
return str(Mapping(self.string, self.position, self.characters))
param = Flavor.get().param
def format(arg):
if isinstance(arg, basestring):
return param
else:
return str(arg)
return self._function + "(%s %s FROM %s)" % (self.position, format(self.characters), format(self.string))
示例7: test_at_time_zone_mapping
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())
示例8: test_mapping
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())
示例9: test_no_boolean
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())
示例10: _format
def _format(self, operand, param=None):
if param is None:
param = Flavor.get().param
if isinstance(operand, Expression):
return str(operand)
elif isinstance(operand, (Select, CombiningQuery)):
return '(' + operand + ')'
# return '(%s)' % operand
elif isinstance(operand, (list, tuple)):
subStrings = []
for o in operand:
subStrings.append(self._format(o, param))
joinedString = ""
for joiningIndex in range(len(subStrings)):
joinedString = joinedString + subStrings[joiningIndex]
if joiningIndex != len(subStrings) - 1:
joinedString = joinedString + ", "
return '(' + joinedString + ')'
elif isinstance(operand, array):
subStrings = (param,) * len(operand)
joinedString = ""
for joiningIndex in range(len(subStrings)):
joinedString = joinedString + subStrings[joiningIndex]
if joiningIndex != len(subStrings) - 1:
joinedString = joinedString + ", "
return '(' + joinedString + ')'
else:
return param
示例11: __str__
def __str__(self):
flavor = Flavor.get()
Mapping = flavor.function_mapping.get(self.__class__)
if Mapping:
return str(Mapping(self.field, self.zone))
param = flavor.param
return str(self.field) + " AT TIME ZONE " + param
示例12: __str__
def __str__(self):
Mapping = Flavor.get().function_mapping.get(self.__class__)
if Mapping:
return str(Mapping(*self.args))
return (self._function + '('
+ ' '.join(chain(*zip(
self._keywords,
map(self._format, self.args))))[1:]
+ ')')
示例13: __str__
def __str__(self):
param = Flavor.get().param
def format(value):
if isinstance(value, basestring):
return param
else:
return str(value)
return (self._conditional
+ '(' + ', '.join(map(format, self.values)) + ')')
示例14: _format
def _format(self, operand):
param = Flavor.get().param
if isinstance(operand, Expression):
return str(operand)
elif isinstance(operand, (Select, CombiningQuery)):
return '(%s)' % operand
elif isinstance(operand, (list, tuple)):
return '(' + ', '.join(self._format(o) for o in operand) + ')'
else:
return param
示例15: test_no_null_ordering
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())