• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sqlbuilder.sqlrepr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sqlobject.sqlbuilder.sqlrepr函数的典型用法代码示例。如果您正苦于以下问题:Python sqlrepr函数的具体用法?Python sqlrepr怎么用?Python sqlrepr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sqlrepr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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'"
    assert sqlrepr(date(2005, 7, 14)) == "'2005-07-14'"
    assert sqlrepr(time(13, 31, 2)) == "'13:31:02'"
    # now dates before 1900
    assert sqlrepr(datetime(1428, 7, 14, 13, 31, 2)) == "'1428-07-14 13:31:02'"
    assert sqlrepr(date(1428, 7, 14)) == "'1428-07-14'"
开发者ID:xblaster,项目名称:scrutator,代码行数:8,代码来源:test_converters.py


示例2: test_empty_AND

def test_empty_AND():
    assert AND() is None
    assert AND(True) is True

    # sqlrepr() is needed because AND() returns an SQLExpression that overrides
    # comparison. The following
    #     AND('x', 'y') == "foo bar"
    # is True! (-: Eeek!
    assert sqlrepr(AND(1, 2)) == sqlrepr(SQLOp("AND", 1, 2)) == "((1) AND (2))"
    assert sqlrepr(AND(1, 2, '3'), "sqlite") == \
        sqlrepr(SQLOp("AND", 1, SQLOp("AND", 2, '3')), "sqlite") == \
        "((1) AND ((2) AND ('3')))"
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:12,代码来源:test_sqlbuilder.py


示例3: test_sets

def test_sets():
    try:
        set
    except NameError:
        pass
    else:
        assert sqlrepr(set([1])) == "(1)"
    try:
        from sets import Set
    except ImportError:
        pass
    else:
        assert sqlrepr(Set([1])) == "(1)"
开发者ID:xblaster,项目名称:scrutator,代码行数:13,代码来源:test_converters.py


示例4: 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')"
开发者ID:xblaster,项目名称:scrutator,代码行数:33,代码来源:test_converters.py


示例5: 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)"
开发者ID:OnShift,项目名称:sqlobject,代码行数:14,代码来源:test_converters.py


示例6: test_str_or_sqlrepr

def test_str_or_sqlrepr():
    select = Select(['id', 'name'], staticTables=['employees'],
                    where='value>0', orderBy='id')
    assert sqlrepr(select, 'sqlite') == \
        'SELECT id, name FROM employees WHERE value>0 ORDER BY id'

    select = Select(['id', 'name'], staticTables=['employees'],
                    where='value>0', orderBy='id', lazyColumns=True)
    assert sqlrepr(select, 'sqlite') == \
        'SELECT id FROM employees WHERE value>0 ORDER BY id'

    insert = Insert('employees', values={'id': 1, 'name': 'test'})
    assert sqlrepr(insert, 'sqlite') == \
        "INSERT INTO employees (id, name) VALUES (1, 'test')"

    update = Update('employees', {'name': 'test'}, where='id=1')
    assert sqlrepr(update, 'sqlite') == \
        "UPDATE employees SET name='test' WHERE id=1"

    update = Update('employees', {'name': 'test', 'age': 42}, where='id=1')
    assert sqlrepr(update, 'sqlite') == \
        "UPDATE employees SET age=42, name='test' WHERE id=1"

    delete = Delete('employees', where='id=1')
    assert sqlrepr(delete, 'sqlite') == \
        "DELETE FROM employees WHERE id=1"

    raises(TypeError, Delete, 'employees')

    delete = Delete('employees', where=None)
    assert sqlrepr(delete, 'sqlite') == \
        "DELETE FROM employees"
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:32,代码来源:test_sqlbuilder.py


示例7: test_CONCAT

def test_CONCAT():
    setupClass(SOTestSQLBuilder)
    SOTestSQLBuilder(name='test', value=42)

    assert sqlrepr(CONCAT('a', 'b'), 'mysql') == "CONCAT('a', 'b')"
    assert sqlrepr(CONCAT('a', 'b'), 'sqlite') == "'a' || 'b'"
    assert sqlrepr(CONCAT('prefix', SOTestSQLBuilder.q.name), 'mysql') == \
        "CONCAT('prefix', so_test_sql_builder.name)"
    assert sqlrepr(CONCAT('prefix', SOTestSQLBuilder.q.name), 'sqlite') == \
        "'prefix' || so_test_sql_builder.name"

    select = Select([CONCAT(SOTestSQLBuilder.q.name, '-suffix')],
                    staticTables=['so_test_sql_builder'])
    connection = getConnection()
    rows = connection.queryAll(connection.sqlrepr(select))
    result = rows[0][0]
    if not PY2 and not isinstance(result, str):
        result = result.decode('ascii')
    assert result == "test-suffix"
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:19,代码来源:test_sqlbuilder.py


示例8: test_Select

def test_Select():
    setupClass(SOTestSQLBuilder)

    select1 = Select([const.id, func.MAX(const.salary)],
                     staticTables=['employees'])
    assert sqlrepr(select1) == 'SELECT id, MAX(salary) FROM employees'

    select2 = Select([SOTestSQLBuilder.q.name, SOTestSQLBuilder.q.value])
    assert sqlrepr(select2) == \
        'SELECT so_test_sql_builder.name, so_test_sql_builder.value ' \
        'FROM so_test_sql_builder'

    union = Union(select1, select2)
    assert sqlrepr(union) == \
        'SELECT id, MAX(salary) FROM employees ' \
        'UNION SELECT so_test_sql_builder.name, so_test_sql_builder.value ' \
        'FROM so_test_sql_builder'

    union = Union(SOTestSQLBuilder.select().queryForSelect())
    assert sqlrepr(union) == \
        'SELECT so_test_sql_builder.id, so_test_sql_builder.name, ' \
        'so_test_sql_builder.value FROM so_test_sql_builder WHERE 1 = 1'
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:22,代码来源:test_sqlbuilder.py


示例9: test_op

def test_op():
    instance = SQLOp('and', 'this', 'that')
    assert sqlrepr(instance, 'mysql') == "(('this') AND ('that'))"
开发者ID:xblaster,项目名称:scrutator,代码行数:3,代码来源:test_converters.py


示例10: test_bool

def test_bool():
    assert sqlrepr(True, 'postgres') == "'t'"
    assert sqlrepr(False, 'postgres') == "'f'"
    assert sqlrepr(True, 'mysql') == "1"
    assert sqlrepr(False, 'mysql') == "0"
开发者ID:xblaster,项目名称:scrutator,代码行数:5,代码来源:test_converters.py


示例11: test_tuple

def test_tuple():
    assert sqlrepr(('one', 'two', 'three'), 'postgres') == "('one', 'two', 'three')"
开发者ID:xblaster,项目名称:scrutator,代码行数:2,代码来源:test_converters.py


示例12: test_list

def test_list():
    assert sqlrepr(['one', 'two', 'three'], 'postgres') == "('one', 'two', 'three')"
开发者ID:xblaster,项目名称:scrutator,代码行数:2,代码来源:test_converters.py


示例13: test_dict

def test_dict():
    assert sqlrepr({"key": "value"}, "sqlite") == "('key')"
开发者ID:xblaster,项目名称:scrutator,代码行数:2,代码来源:test_converters.py


示例14: test_modulo

def test_modulo():
    setupClass(SOTestSQLBuilder)
    assert sqlrepr(SOTestSQLBuilder.q.value % 2 == 0, 'mysql') == \
        "((MOD(so_test_sql_builder.value, 2)) = (0))"
    assert sqlrepr(SOTestSQLBuilder.q.value % 2 == 0, 'sqlite') == \
        "(((so_test_sql_builder.value) % (2)) = (0))"
开发者ID:LutzSteinborn,项目名称:sqlobject,代码行数:6,代码来源:test_sqlbuilder.py


示例15: test_string_

def test_string_():
    assert sqlrepr('A String\tAnother', 'postgres') == "'A String\\tAnother'"
    assert sqlrepr('A String\'Another', 'firebird') == "'A String''Another'"
开发者ID:xblaster,项目名称:scrutator,代码行数:3,代码来源:test_converters.py


示例16: test_string_b

def test_string_b():
    assert sqlrepr('A String\bAnother', 'postgres') == "'A String\\bAnother'"
开发者ID:xblaster,项目名称:scrutator,代码行数:2,代码来源:test_converters.py


示例17: test_string_000

def test_string_000():
    assert sqlrepr('A String\000Another', 'postgres') == "'A String\\0Another'"
开发者ID:xblaster,项目名称:scrutator,代码行数:2,代码来源:test_converters.py


示例18: test_string_newline

def test_string_newline():
    assert sqlrepr('A String\nAnother', 'postgres') == "'A String\\nAnother'"
    assert sqlrepr('A String\nAnother', 'sqlite') == "'A String\nAnother'"
开发者ID:xblaster,项目名称:scrutator,代码行数:3,代码来源:test_converters.py


示例19: test_simple_string

def test_simple_string():
    assert sqlrepr('A String', 'firebird') == "'A String'"
开发者ID:xblaster,项目名称:scrutator,代码行数:2,代码来源:test_converters.py


示例20: test_constant

def test_constant():
    instance = SQLConstant('test')
    assert sqlrepr(instance) == repr(instance)
开发者ID:xblaster,项目名称:scrutator,代码行数:3,代码来源:test_converters.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python dbtest.setupClass函数代码示例发布时间:2022-05-27
下一篇:
Python converters.sqlrepr函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap