本文整理汇总了Python中sql.Flavor类的典型用法代码示例。如果您正苦于以下问题:Python Flavor类的具体用法?Python Flavor怎么用?Python Flavor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Flavor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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())
开发者ID:jiaxiaolei,项目名称:python-sql,代码行数:35,代码来源:test_select.py
示例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)
开发者ID:jiaxiaolei,项目名称:python-sql,代码行数:7,代码来源:test_select.py
示例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
开发者ID:coopengo,项目名称:trytond,代码行数:29,代码来源:transaction.py
示例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())
开发者ID:jefurry,项目名称:python-sql,代码行数:8,代码来源:test_as.py
示例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)) + ')'
开发者ID:zilberstein,项目名称:visit_counter,代码行数:12,代码来源:functions.py
示例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))
开发者ID:ernestoluisrojas,项目名称:ShnergleServer,代码行数:13,代码来源:functions.py
示例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())
开发者ID:XasaKura,项目名称:Xsql,代码行数:14,代码来源:test_functions.py
示例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())
开发者ID:zilberstein,项目名称:visit_counter,代码行数:15,代码来源:test_functions.py
示例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())
开发者ID:jefurry,项目名称:python-sql,代码行数:15,代码来源:test_literal.py
示例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
开发者ID:Shoreray,项目名称:bss_final,代码行数:28,代码来源:operators.py
示例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
开发者ID:Shoreray,项目名称:bss_final,代码行数:7,代码来源:functions.py
示例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:]
+ ')')
开发者ID:michaelfarrell76,项目名称:ExpertmentPlanner2,代码行数:9,代码来源:functions.py
示例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)) + ')')
开发者ID:zilberstein,项目名称:visit_counter,代码行数:10,代码来源:conditionals.py
示例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
开发者ID:ernestoluisrojas,项目名称:ShnergleServer,代码行数:10,代码来源:operators.py
示例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())
开发者ID:jefurry,项目名称:python-sql,代码行数:20,代码来源:test_order.py
示例16: create_sql_sequence
def create_sql_sequence(self, number_next=None):
'Create the SQL sequence'
cursor = Transaction().connection.cursor()
param = Flavor.get().param
if self.type != 'incremental':
return
if number_next is None:
number_next = self.number_next
cursor.execute('CREATE SEQUENCE "' + self._sql_sequence_name
+ '" INCREMENT BY ' + param + ' START WITH ' + param,
(self.number_increment, number_next))
开发者ID:coopengo,项目名称:trytond,代码行数:11,代码来源:sequence.py
示例17: params
def params(self):
Mapping = Flavor.get().function_mapping.get(self.__class__)
if Mapping:
return Mapping(*self.args).params
p = ()
for arg in self.args:
if isinstance(arg, Expression):
p += arg.params
else:
p += (arg,)
return p
开发者ID:ernestoluisrojas,项目名称:ShnergleServer,代码行数:11,代码来源:functions.py
示例18: test_select_offset_fetch
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,代码行数:20,代码来源:test_select.py
示例19: params
def params(self):
Mapping = Flavor.get().function_mapping.get(self.__class__)
if Mapping:
return Mapping(*self.args).params
p = []
for arg in self.args:
if isinstance(arg, Expression):
p.extend(arg.params)
else:
p.append(arg)
return tuple(p)
开发者ID:Shoreray,项目名称:bss_final,代码行数:11,代码来源:functions.py
示例20: test_mapping
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,代码行数:41,代码来源:test_functions.py
注:本文中的sql.Flavor类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论