本文整理汇总了Python中sqlobject.converters.sqlrepr函数的典型用法代码示例。如果您正苦于以下问题:Python sqlrepr函数的具体用法?Python sqlrepr怎么用?Python sqlrepr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sqlrepr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_datetime
def test_datetime():
from datetime import datetime, date, time
assert sqlrepr(datetime(2005, 7, 14, 13, 31, 2)) == "'2005-07-14 13:31:02.0'"
assert sqlrepr(date(2005, 7, 14)) == "'2005-07-14'"
assert sqlrepr(time(13, 31, 2)) == "'13:31:02.0'"
# now dates before 1900
assert sqlrepr(datetime(1428, 7, 14, 13, 31, 2)) == "'1428-07-14 13:31:02.0'"
assert sqlrepr(date(1428, 7, 14)) == "'1428-07-14'"
示例2: test_insert
def test_insert():
# Single column, no keyword arguments.
instance = Insert('test', [('test',)])
assert sqlrepr(instance, 'mysql') == "INSERT INTO test VALUES ('test')"
# Multiple columns, no keyword arguments.
instance2 = Insert('test', [('1st', '2nd', '3th', '4th')])
assert sqlrepr(instance2, 'postgres') == "INSERT INTO test VALUES ('1st', '2nd', '3th', '4th')"
# Multiple rows, multiple columns, "valueList" keyword argument.
instance3 = Insert('test', valueList=[('a1', 'b1'), ('a2', 'b2'), ('a3', 'b3')])
assert sqlrepr(instance3, 'sqlite') == "INSERT INTO test VALUES ('a1', 'b1'), ('a2', 'b2'), ('a3', 'b3')"
# Multiple columns, "values" keyword argument.
instance4 = Insert('test', values=('v1', 'v2', 'v3'))
assert sqlrepr(instance4, 'mysql') == "INSERT INTO test VALUES ('v1', 'v2', 'v3')"
# Single column, "valueList" keyword argument.
instance5 = Insert('test', valueList=[('v1',)])
assert sqlrepr(instance5, 'mysql') == "INSERT INTO test VALUES ('v1')"
# Multiple rows, Multiple columns, template.
instance6 = Insert('test', valueList=[('a1', 'b1'), ('a2', 'b2')], template=['col1', 'col2'])
assert sqlrepr(instance6, 'mysql') == "INSERT INTO test (col1, col2) VALUES ('a1', 'b1'), ('a2', 'b2')"
# Multiple columns, implicit template (dictionary value).
instance7 = Insert('test', valueList=[{'col1': 'a1', 'col2': 'b1'}])
assert sqlrepr(instance7, 'mysql') == "INSERT INTO test (col2, col1) VALUES ('b1', 'a1')"
# Multiple rows, Multiple columns, implicit template.
instance8 = Insert('test', valueList=[{'col1': 'a1', 'col2': 'b1'},
{'col1': 'a2', 'col2': 'b2'}])
assert sqlrepr(instance8, 'mysql') == "INSERT INTO test (col2, col1) VALUES ('b1', 'a1'), ('b2', 'a2')"
示例3: test_sets
def test_sets():
try:
set
except NameError:
pass
else:
assert sqlrepr(set([1])) == "(1)"
if sys.version_info[:3] < (2, 6, 0): # Module sets was deprecated in Python 2.6
try:
from sets import Set
except ImportError:
pass
else:
assert sqlrepr(Set([1])) == "(1)"
示例4: test_sets
def test_sets():
try:
set
except NameError:
pass
else:
assert sqlrepr(set([1])) == "(1)"
示例5: test_datetime
def test_datetime():
from datetime import datetime, date, time
if SODateTimeCol.datetimeFormat.find('.%f') > 0:
assert sqlrepr(datetime(2005, 7, 14, 13, 31, 2)) == \
"'2005-07-14 13:31:02.000000'"
else:
assert sqlrepr(datetime(2005, 7, 14, 13, 31, 2)) == \
"'2005-07-14 13:31:02'"
assert sqlrepr(date(2005, 7, 14)) == "'2005-07-14'"
if SOTimeCol.timeFormat.find('.%f') > 0:
assert sqlrepr(time(13, 31, 2)) == "'13:31:02.000000'"
else:
assert sqlrepr(time(13, 31, 2)) == "'13:31:02'"
# now dates before 1900
if SODateTimeCol.datetimeFormat.find('.%f') > 0:
assert sqlrepr(datetime(1428, 7, 14, 13, 31, 2)) == \
"'1428-07-14 13:31:02.000000'"
else:
assert sqlrepr(datetime(1428, 7, 14, 13, 31, 2)) == \
"'1428-07-14 13:31:02'"
assert sqlrepr(date(1428, 7, 14)) == "'1428-07-14'"
示例6: test_string_newline
def test_string_newline():
assert sqlrepr('A String\nAnother', 'postgres') == "E'A String\\nAnother'"
assert sqlrepr('A String\nAnother', 'sqlite') == "'A String\nAnother'"
示例7: test_simple_string
def test_simple_string():
assert sqlrepr('A String', 'firebird') == "'A String'"
示例8: test_select
def test_select():
instance = Select('test')
assert sqlrepr(instance, 'mysql') == "SELECT test"
示例9: test_tuple
def test_tuple():
assert sqlrepr(('one', 'two', 'three'), 'postgres') == \
"('one', 'two', 'three')"
示例10: test_none
def test_none():
assert sqlrepr(None) == "NULL"
示例11: test_integer
def test_integer():
assert sqlrepr(10) == "10"
示例12: test_string_
def test_string_():
assert sqlrepr('A String\tAnother', 'postgres') == "E'A String\\tAnother'"
assert sqlrepr('A String\'Another', 'firebird') == "'A String''Another'"
示例13: test_constant
def test_constant():
instance = SQLConstant('test')
assert sqlrepr(instance) == repr(instance)
示例14: test_call
def test_call():
instance = SQLCall('test', ('test',))
assert sqlrepr(instance, 'mysql') == "'test'('test')"
示例15: test_op
def test_op():
instance = SQLOp('and', 'this', 'that')
assert sqlrepr(instance, 'mysql') == "(('this') AND ('that'))"