Esempio n. 1
0
def test_multi_dict_params():
    res = substitute_params(
        'SELECT * FROM empl '
        'WHERE (name = %(name)s AND city = %(city)s) '
        'OR supervisor = %(name)s',
        {'name': b'John Doe', 'city': b'Nowhere'})
    eq_(res, b"SELECT * FROM empl "
             b"WHERE (name = 'John Doe' AND city = 'Nowhere') "
             b"OR supervisor = 'John Doe'")

    res = substitute_params(
        'SELECT * FROM empl '
        'WHERE (name = %(name)s AND city = %(city)s) '
        'OR supervisor = %(name)s',
        {'name': u'John Doe', 'city': u'Nowhere'})
    eq_(res, b"SELECT * FROM empl "
             b"WHERE (name = 'John Doe' AND city = 'Nowhere') "
             b"OR supervisor = 'John Doe'")

    res = substitute_params(
        'SELECT * FROM empl '
        'WHERE (name = %(name)s AND city = %(city)s) '
        'OR supervisor = %(name)s',
        {'name': u'John Doé', 'city': u'Nowhere'})
    eq_(res, b"SELECT * FROM empl "
             b"WHERE (name = N'John Do\xc3\xa9' AND city = 'Nowhere') "
             b"OR supervisor = N'John Do\xc3\xa9'")
Esempio n. 2
0
def test_tuple_with_in():
    res = substitute_params(
        'SELECT * FROM empl WHERE id IN %s',
        ((5, 6),))
    eq_(res, b"SELECT * FROM empl WHERE id IN (5,6)")

    res = substitute_params(
        'SELECT * FROM empl WHERE id IN %s',
        ((b'foo', b'bar'),))
    eq_(res, b"SELECT * FROM empl WHERE id IN ('foo','bar')")

    res = substitute_params(
        'SELECT * FROM empl WHERE id IN %s',
        ((u'foo', u'bar'),))
    eq_(res, b"SELECT * FROM empl WHERE id IN (N'foo',N'bar')")

    # single item
    res = substitute_params(
        'SELECT * FROM empl WHERE id IN %s',
        ((b'foo',),))
    eq_(res, b"SELECT * FROM empl WHERE id IN ('foo')")

    res = substitute_params(
        'SELECT * FROM empl WHERE id IN %s',
        ((u'foo',),))
    eq_(res, b"SELECT * FROM empl WHERE id IN (N'foo')")
Esempio n. 3
0
def test_tuple_with_in():
    res = substitute_params(
        'SELECT * FROM empl WHERE id IN %s',
        ((5, 6),))
    eq_(res, b"SELECT * FROM empl WHERE id IN (5,6)")

    res = substitute_params(
        'SELECT * FROM empl WHERE id IN %s',
        ((b'foo', b'bar'),))
    eq_(res, b"SELECT * FROM empl WHERE id IN ('foo','bar')")

    res = substitute_params(
        'SELECT * FROM empl WHERE id IN %s',
        ((u'foo', u'bar'),))
    eq_(res, b"SELECT * FROM empl WHERE id IN (N'foo',N'bar')")

    # single item
    res = substitute_params(
        'SELECT * FROM empl WHERE id IN %s',
        ((b'foo',),))
    eq_(res, b"SELECT * FROM empl WHERE id IN ('foo')")

    res = substitute_params(
        'SELECT * FROM empl WHERE id IN %s',
        ((u'foo',),))
    eq_(res, b"SELECT * FROM empl WHERE id IN (N'foo')")
Esempio n. 4
0
def test_single_dict_params():
    res = substitute_params('SELECT * FROM cust WHERE salesrep = %(name)s',
                            {'name': b'John Doe'})
    eq_(res, b"SELECT * FROM cust WHERE salesrep = 'John Doe'")

    res = substitute_params('SELECT * FROM cust WHERE salesrep = %(name)s',
                            {'name': u'John Doe'})
    eq_(res, b"SELECT * FROM cust WHERE salesrep = N'John Doe'")
Esempio n. 5
0
def test_param_quote():
    res = substitute_params('SELECT * FROM empl WHERE name = %s',
                            b"John's Doe")
    eq_(res, b"SELECT * FROM empl WHERE name = 'John''s Doe'")

    res = substitute_params('SELECT * FROM empl WHERE name = %s',
                            u"John's Doe")
    eq_(res, b"SELECT * FROM empl WHERE name = N'John''s Doe'")
Esempio n. 6
0
def test_too_many_params():
    try:
        substitute_params(
            'SELECT * FROM cust WHERE salesrep = %s and foo = %s', ('bar', ))
        assert False, 'expected exception b/c too many params in sql'
    except ValueError as exc:
        if 'more placeholders in sql than params available' not in str(exc):
            raise
Esempio n. 7
0
    def test_single_param(self):
        res = _mssql.substitute_params('SELECT * FROM employees WHERE id=%s', 13)
        eq_(res, b'SELECT * FROM employees WHERE id=13')

        res = _mssql.substitute_params('SELECT * FROM empl WHERE name=%s', b'John Doe')
        eq_(res, b"SELECT * FROM empl WHERE name='John Doe'")

        res = _mssql.substitute_params('SELECT * FROM empl WHERE name=%s', u'John Doe')
        eq_(res, b"SELECT * FROM empl WHERE name=N'John Doe'")
Esempio n. 8
0
def test_too_many_params():
    try:
        substitute_params(
            'SELECT * FROM cust WHERE salesrep = %s and foo = %s',
            ('bar',))
        assert False, 'expected exception b/c too many params in sql'
    except ValueError as exc:
        if 'more placeholders in sql than params available' not in str(exc):
            raise
Esempio n. 9
0
def test_single_param():
    res = substitute_params('SELECT * FROM employees WHERE id = %s', 13)
    eq_(res, b'SELECT * FROM employees WHERE id = 13')

    res = substitute_params('SELECT * FROM empl WHERE name = %s', b'John Doe')
    eq_(res, b"SELECT * FROM empl WHERE name = 'John Doe'")

    res = substitute_params('SELECT * FROM empl WHERE name = %s', u'John Doe')
    eq_(res, b"SELECT * FROM empl WHERE name = N'John Doe'")
Esempio n. 10
0
def test_unicode_params():
    res = substitute_params(
        u'SELECT * FROM \u0394 WHERE name = %s',
        u'\u03A8'
    )
    eq_(res, b"SELECT * FROM \xce\x94 WHERE name = N'\xce\xa8'")

    res = substitute_params(u"testing ascii (\u0105\u010D\u0119) 1=%d 'one'=%s", (1, u'str'))
    eq_(res, b"testing ascii (\xc4\x85\xc4\x8d\xc4\x99) 1=1 'one'=N'str'")
Esempio n. 11
0
    def test_tuple_with_in(self):
        res = _mssql.substitute_params('SELECT * FROM empl WHERE id IN %s', ((5, 6),))
        eq_(res, "SELECT * FROM empl WHERE id IN (5,6)")

        res = _mssql.substitute_params('SELECT * FROM empl WHERE id IN %s', (('foo', 'bar'),))
        eq_(res, "SELECT * FROM empl WHERE id IN ('foo','bar')")

        # single item
        res = _mssql.substitute_params('SELECT * FROM empl WHERE id IN %s', (('foo',),))
        eq_(res, "SELECT * FROM empl WHERE id IN ('foo')")
Esempio n. 12
0
def test_weird_key_names_dict_params():
    res = substitute_params(
        'SELECT * FROM cust WHERE salesrep = %(n %s ##ame)s',
        {'n %s ##ame': b'John Doe'})
    eq_(res, b"SELECT * FROM cust WHERE salesrep = 'John Doe'")

    res = substitute_params(
        'SELECT * FROM cust WHERE salesrep = %(n %s ##ame)s',
        {'n %s ##ame': u'John Doe'})
    eq_(res, b"SELECT * FROM cust WHERE salesrep = N'John Doe'")
Esempio n. 13
0
def test_param_quote():
    res = substitute_params(
        'SELECT * FROM empl WHERE name = %s',
        b"John's Doe")
    eq_(res, b"SELECT * FROM empl WHERE name = 'John''s Doe'")

    res = substitute_params(
        'SELECT * FROM empl WHERE name = %s',
        u"John's Doe")
    eq_(res, b"SELECT * FROM empl WHERE name = N'John''s Doe'")
Esempio n. 14
0
def test_percent_in_param():
    res = substitute_params(
        'SELECT * FROM empl WHERE name LIKE %s',
        b'J%')
    eq_(res, b"SELECT * FROM empl WHERE name LIKE 'J%'")

    res = substitute_params(
        'SELECT * FROM empl WHERE name LIKE %s',
        u'J%')
    eq_(res, b"SELECT * FROM empl WHERE name LIKE N'J%'")
Esempio n. 15
0
def test_weird_key_names_dict_params():
    res = substitute_params(
        'SELECT * FROM cust WHERE salesrep = %(n %s ##ame)s',
        {'n %s ##ame': b'John Doe'})
    eq_(res, b"SELECT * FROM cust WHERE salesrep = 'John Doe'")

    res = substitute_params(
        'SELECT * FROM cust WHERE salesrep = %(n %s ##ame)s',
        {'n %s ##ame': u'John Doe'})
    eq_(res, b"SELECT * FROM cust WHERE salesrep = N'John Doe'")
Esempio n. 16
0
    def test_tuple_with_in(self):
        res = _mssql.substitute_params("SELECT * FROM empl WHERE id IN %s", ((5, 6),))
        eq_(res, "SELECT * FROM empl WHERE id IN (5,6)")

        res = _mssql.substitute_params("SELECT * FROM empl WHERE id IN %s", (("foo", "bar"),))
        eq_(res, "SELECT * FROM empl WHERE id IN ('foo','bar')")

        # single item
        res = _mssql.substitute_params("SELECT * FROM empl WHERE id IN %s", (("foo",),))
        eq_(res, "SELECT * FROM empl WHERE id IN ('foo')")
Esempio n. 17
0
def test_single_dict_params():
    res = substitute_params(
        'SELECT * FROM cust WHERE salesrep = %(name)s',
        {'name': b'John Doe'})
    eq_(res, b"SELECT * FROM cust WHERE salesrep = 'John Doe'")

    res = substitute_params(
        'SELECT * FROM cust WHERE salesrep = %(name)s',
        {'name': u'John Doe'})
    eq_(res, b"SELECT * FROM cust WHERE salesrep = N'John Doe'")
Esempio n. 18
0
def test_percent_in_param():
    res = substitute_params(
        'SELECT * FROM empl WHERE name LIKE %s',
        b'J%')
    eq_(res, b"SELECT * FROM empl WHERE name LIKE 'J%'")

    res = substitute_params(
        'SELECT * FROM empl WHERE name LIKE %s',
        u'J%')
    eq_(res, b"SELECT * FROM empl WHERE name LIKE N'J%'")
Esempio n. 19
0
def test_missing_dict_param():
    expected_err = 'params dictionary did not contain value for placeholder'

    try:
        substitute_params('SELECT * FROM cust WHERE salesrep = %(name)s',
                          {'foobar': 'John Doe'})
        assert False, \
            'expected exception b/c dict did not contain replacement value'
    except ValueError as exc:
        if expected_err not in str(exc):
            raise
Esempio n. 20
0
    def test_multi_dict_params(self):
        res = _mssql.substitute_params(
                'SELECT * FROM empl WHERE (name=%(name)s AND city=%(city)s) or supervisor=%(name)s',
                { 'name': b'John Doe', 'city': b'Nowhere' }
            )
        eq_(res, b"SELECT * FROM empl WHERE (name='John Doe' AND city='Nowhere') or supervisor='John Doe'")

        res = _mssql.substitute_params(
                'SELECT * FROM empl WHERE (name=%(name)s AND city=%(city)s) or supervisor=%(name)s',
                { 'name': u'John Doe', 'city': u'Nowhere' }
            )
        eq_(res, b"SELECT * FROM empl WHERE (name=N'John Doe' AND city=N'Nowhere') or supervisor=N'John Doe'")
Esempio n. 21
0
    def test_single_and_tuple(self):
        res = _mssql.substitute_params(
                'SELECT * FROM cust WHERE salesrep=%s AND id IN %s',
                (b'John Doe', (1, 2, 3))
            )
        eq_(res, b"SELECT * FROM cust WHERE salesrep='John Doe' AND id IN (1,2,3)")

        res = _mssql.substitute_params(
                'SELECT * FROM cust WHERE salesrep=%s AND id IN %s',
                (u'John Doe', (1, 2, 3))
            )
        eq_(res, b"SELECT * FROM cust WHERE salesrep=N'John Doe' AND id IN (1,2,3)")
Esempio n. 22
0
def test_missing_dict_param():
    expected_err = 'params dictionary did not contain value for placeholder'

    try:
        substitute_params(
            'SELECT * FROM cust WHERE salesrep = %(name)s',
            {'foobar': 'John Doe'})
        assert False, \
            'expected exception b/c dict did not contain replacement value'
    except ValueError as exc:
        if expected_err not in str(exc):
            raise
Esempio n. 23
0
def test_single_and_tuple():
    res = substitute_params(
        'SELECT * FROM cust '
        'WHERE salesrep = %s AND id IN %s',
        (b'John Doe', (1, 2, 3)))
    eq_(res, b"SELECT * FROM cust "
             b"WHERE salesrep = 'John Doe' AND id IN (1,2,3)")

    res = substitute_params(
        'SELECT * FROM cust '
        'WHERE salesrep = %s AND id IN %s',
        (u'John Doe', (1, 2, 3)))
    eq_(res, b"SELECT * FROM cust "
             b"WHERE salesrep = N'John Doe' AND id IN (1,2,3)")
Esempio n. 24
0
 def test_missing_dict_param(self):
     try:
         res = _mssql.substitute_params("SELECT * FROM cust WHERE salesrep=%(name)s", {"foobar": "John Doe"})
         assert False, "expected exception b/c dict did not contain replacement value"
     except ValueError, e:
         if "params dictionary did not contain value for placeholder" not in str(e):
             raise
Esempio n. 25
0
 def test_too_many_params(self):
     try:
         res = _mssql.substitute_params("SELECT * FROM cust WHERE salesrep=%s and foo=%s", ("bar",))
         assert False, "expected exception b/c too many params in sql"
     except ValueError, e:
         if "more placeholders in sql than params available" not in str(e):
             raise
Esempio n. 26
0
def test_multi_dict_params():
    res = substitute_params(
        'SELECT * FROM empl '
        'WHERE (name = %(name)s AND city = %(city)s) '
        'OR supervisor = %(name)s',
        {'name': b'John Doe', 'city': b'Nowhere'})
    eq_(res, b"SELECT * FROM empl "
             b"WHERE (name = 'John Doe' AND city = 'Nowhere') "
             b"OR supervisor = 'John Doe'")

    res = substitute_params(
        'SELECT * FROM empl '
        'WHERE (name = %(name)s AND city = %(city)s) '
        'OR supervisor = %(name)s',
        {'name': u'John Doe', 'city': u'Nowhere'})
    eq_(res, b"SELECT * FROM empl "
             b"WHERE (name = N'John Doe' AND city = N'Nowhere') "
             b"OR supervisor = N'John Doe'")
Esempio n. 27
0
 def test_missing_dict_param(self):
     try:
         res = _mssql.substitute_params(
             'SELECT * FROM cust WHERE salesrep=%(name)s',
             { 'foobar': 'John Doe'}
         )
         assert False, 'expected exception b/c dict did not contain replacement value'
     except ValueError, e:
         if 'params dictionary did not contain value for placeholder' not in str(e):
             raise
Esempio n. 28
0
 def test_missing_dict_param(self):
     try:
         res = _mssql.substitute_params(
             'SELECT * FROM cust WHERE salesrep=%(name)s',
             { 'foobar': 'John Doe'}
         )
         assert False, 'expected exception b/c dict did not contain replacement value'
     except ValueError as e:
         if 'params dictionary did not contain value for placeholder' not in str(e):
             raise
Esempio n. 29
0
def test_percent_not_touched_with_no_params():
    sql = "SELECT COUNT(*) FROM employees WHERE name LIKE 'J%'"
    res = substitute_params(sql, None)
    eq_(res, sql)
Esempio n. 30
0
def test_keyed_param_with_d():
    res = substitute_params(
        'SELECT * FROM employees WHERE id = %(emp_id)d',
        {'emp_id': 13})
    eq_(res, b'SELECT * FROM employees WHERE id = 13')
Esempio n. 31
0
 def test_single_and_tuple(self):
     res = _mssql.substitute_params("SELECT * FROM cust WHERE salesrep=%s AND id IN %s", ("John Doe", (1, 2, 3)))
     eq_(res, "SELECT * FROM cust WHERE salesrep='John Doe' AND id IN (1,2,3)")
Esempio n. 32
0
def test_bare_percent_dict():
    res = substitute_params('select 5 % %(divisor)s', {'divisor': 3})
    eq_(res, b"select 5 % 3")
Esempio n. 33
0
 def test_single_dict_params(self):
     res = _mssql.substitute_params("SELECT * FROM cust WHERE salesrep=%(name)s", {"name": "John Doe"})
     eq_(res, "SELECT * FROM cust WHERE salesrep='John Doe'")
Esempio n. 34
0
 def test_weird_key_names_dict_params(self):
     res = _mssql.substitute_params("SELECT * FROM cust WHERE salesrep=%(n %s ##ame)s", {"n %s ##ame": "John Doe"})
     eq_(res, "SELECT * FROM cust WHERE salesrep='John Doe'")
Esempio n. 35
0
 def test_bare_percent_dict(self):
     res = _mssql.substitute_params("select 5 % %(divisor)s", {"divisor": 3})
     eq_(res, "select 5 % 3")
Esempio n. 36
0
 def test_bare_percent_position(self):
     res = _mssql.substitute_params("select 5 % %s", 3)
     eq_(res, "select 5 % 3")
Esempio n. 37
0
 def test_single_dict_params(self):
     res = _mssql.substitute_params(
             'SELECT * FROM cust WHERE salesrep=%(name)s',
             { 'name': 'John Doe'}
         )
     eq_(res, "SELECT * FROM cust WHERE salesrep='John Doe'")
Esempio n. 38
0
 def test_single_param_with_d(self):
     res = _mssql.substitute_params('SELECT * FROM employees WHERE id=%d', 13)
     eq_(res, 'SELECT * FROM employees WHERE id=13')
Esempio n. 39
0
 def test_single_param_with_d(self):
     res = _mssql.substitute_params("SELECT * FROM employees WHERE id=%d", 13)
     eq_(res, "SELECT * FROM employees WHERE id=13")
Esempio n. 40
0
 def test_bare_percent_position(self):
     res = _mssql.substitute_params('select 5 % %s', 3)
     eq_(res, "select 5 % 3")
Esempio n. 41
0
 def test_percent_in_param(self):
     res = _mssql.substitute_params('SELECT * FROM empl WHERE name LIKE %s', 'J%')
     eq_(res, "SELECT * FROM empl WHERE name LIKE 'J%'")
Esempio n. 42
0
 def test_percent_in_param(self):
     res = _mssql.substitute_params("SELECT * FROM empl WHERE name LIKE %s", "J%")
     eq_(res, "SELECT * FROM empl WHERE name LIKE 'J%'")
Esempio n. 43
0
 def test_bare_percent_dict(self):
     res = _mssql.substitute_params('select 5 % %(divisor)s', {'divisor': 3})
     eq_(res, "select 5 % 3")
Esempio n. 44
0
 def test_single_and_tuple(self):
     res = _mssql.substitute_params(
             'SELECT * FROM cust WHERE salesrep=%s AND id IN %s',
             ('John Doe', (1, 2, 3))
         )
     eq_(res, "SELECT * FROM cust WHERE salesrep='John Doe' AND id IN (1,2,3)")
Esempio n. 45
0
def test_bare_percent_position():
    res = substitute_params('select 5 % %s', 3)
    eq_(res, b"select 5 % 3")
Esempio n. 46
0
def test_single_param_with_d():
    res = substitute_params(
        'SELECT * FROM employees WHERE id = %d',
        13)
    eq_(res, b'SELECT * FROM employees WHERE id = 13')
Esempio n. 47
0
def test_single_param_with_d():
    res = substitute_params(
        'SELECT * FROM employees WHERE id = %d',
        13)
    eq_(res, b'SELECT * FROM employees WHERE id = 13')
Esempio n. 48
0
 def test_multi_dict_params(self):
     res = _mssql.substitute_params(
         "SELECT * FROM empl WHERE (name=%(name)s AND city=%(city)s) or supervisor=%(name)s",
         {"name": "John Doe", "city": "Nowhere"},
     )
     eq_(res, "SELECT * FROM empl WHERE (name='John Doe' AND city='Nowhere') or supervisor='John Doe'")
Esempio n. 49
0
 def test_param_quote(self):
     res = _mssql.substitute_params('SELECT * FROM empl WHERE name=%s', "John's Doe")
     eq_(res, "SELECT * FROM empl WHERE name='John''s Doe'")
Esempio n. 50
0
    def test_single_param(self):
        res = _mssql.substitute_params('SELECT * FROM employees WHERE id=%s', 13)
        eq_(res, 'SELECT * FROM employees WHERE id=13')

        res = _mssql.substitute_params('SELECT * FROM empl WHERE name=%s', 'John Doe')
        eq_(res, "SELECT * FROM empl WHERE name='John Doe'")
Esempio n. 51
0
def test_percent_not_touched_with_no_params():
    sql = "SELECT COUNT(*) FROM employees WHERE name LIKE 'J%'"
    res = substitute_params(sql, None)
    eq_(res, sql)
Esempio n. 52
0
def test_bare_percent_position():
    res = substitute_params('select 5 % %s', 3)
    eq_(res, b"select 5 % 3")
Esempio n. 53
0
def test_bare_percent_dict():
    res = substitute_params('select 5 % %(divisor)s', {'divisor': 3})
    eq_(res, b"select 5 % 3")
Esempio n. 54
0
 def test_weird_key_names_dict_params(self):
     res = _mssql.substitute_params(
             'SELECT * FROM cust WHERE salesrep=%(n %s ##ame)s',
             { 'n %s ##ame': 'John Doe'}
         )
     eq_(res, "SELECT * FROM cust WHERE salesrep='John Doe'")
Esempio n. 55
0
    def test_single_param(self):
        res = _mssql.substitute_params("SELECT * FROM employees WHERE id=%s", 13)
        eq_(res, "SELECT * FROM employees WHERE id=13")

        res = _mssql.substitute_params("SELECT * FROM empl WHERE name=%s", "John Doe")
        eq_(res, "SELECT * FROM empl WHERE name='John Doe'")
Esempio n. 56
0
 def test_multi_dict_params(self):
     res = _mssql.substitute_params(
             'SELECT * FROM empl WHERE (name=%(name)s AND city=%(city)s) or supervisor=%(name)s',
             { 'name': 'John Doe', 'city': 'Nowhere' }
         )
     eq_(res, "SELECT * FROM empl WHERE (name='John Doe' AND city='Nowhere') or supervisor='John Doe'")