コード例 #1
0
def test_update():
    x = {'a': 1, 'b': '2', 'c': 1223.4}
    sql, params = query_builder.update('foo', **x)
    assert sql == 'UPDATE `foo` SET `a`=%(_QB_a)s, `b`=%(_QB_b)s, `c`=%(_QB_c)s'
    assert params == {'_QB_a': 1, '_QB_b': '2', '_QB_c': 1223.4}
    assert database.escape_query(
        sql, params) == r"UPDATE `foo` SET `a`=1, `b`='2', `c`=1223.4"
コード例 #2
0
def test_replace():
    rows = [{'a': 1, 'b': '2', 'c': 1223.4}, {'a': 2, 'b': '5', 'c': 1}]
    sql, params = query_builder.multi_replace('foo', *rows)
    assert sql == 'REPLACE INTO `foo` (`a`, `b`, `c`) VALUES (%(_QB_ROW_0)s), (%(_QB_ROW_1)s)'
    assert params == {'_QB_ROW_0': [1, '2', 1223.4], '_QB_ROW_1': [2, '5', 1]}
    assert database.escape_query(
        sql, params
    ) == r"REPLACE INTO `foo` (`a`, `b`, `c`) VALUES (1,'2',1223.4), (2,'5',1)"
コード例 #3
0
ファイル: queue.py プロジェクト: aashanand/memsql-python
    def _build_extra_predicate(self, extra_predicate):
        """ This method is a good one to extend if you want to create a queue which always applies an extra predicate. """
        if extra_predicate is None:
            return ''

        # if they don't have a supported format seq, wrap it for them
        if not isinstance(extra_predicate[1], (list, dict, tuple)):
            extra_predicate = [extra_predicate[0], (extra_predicate[1], )]

        extra_predicate = database.escape_query(*extra_predicate)

        return 'AND (' + extra_predicate + ')'
コード例 #4
0
ファイル: queue.py プロジェクト: yuhonghong7035/memsql-python
    def _build_extra_predicate(self, extra_predicate):
        """ This method is a good one to extend if you want to create a queue which always applies an extra predicate. """
        if extra_predicate is None:
            return ''

        # if they don't have a supported format seq, wrap it for them
        if not isinstance(extra_predicate[1], (list, dict, tuple)):
            extra_predicate = [extra_predicate[0], (extra_predicate[1], )]

        extra_predicate = database.escape_query(*extra_predicate)

        return 'AND (' + extra_predicate + ')'
コード例 #5
0
def test_simple_expression():
    x = {'a': 1, 'b': '2', 'c': 1223.4}
    sql, params = query_builder.simple_expression(', ', **x)
    assert sql == '`a`=%(_QB_a)s, `b`=%(_QB_b)s, `c`=%(_QB_c)s'
    assert params == {'_QB_a': 1, '_QB_b': '2', '_QB_c': 1223.4}
    assert database.escape_query(sql, params) == r"`a`=1, `b`='2', `c`=1223.4"
コード例 #6
0
def build_example_query(job, file_id):
    load_data = LoadDataStmt(job, file_id, '<source file>')
    return database.escape_query(*load_data.build())
コード例 #7
0
ファイル: load_data.py プロジェクト: cuigrey/memsql-loader
def build_example_query(job, file_id):
    load_data = LoadDataStmt(job, file_id, '<source file>')
    return database.escape_query(*load_data.build())
コード例 #8
0
def test_update():
    x = { 'a': 1, 'b': '2', 'c': 1223.4 }
    sql, params = query_builder.update('foo', **x)
    assert sql == 'UPDATE `foo` SET `a`=%(_QB_a)s, `b`=%(_QB_b)s, `c`=%(_QB_c)s'
    assert params == { '_QB_a': 1, '_QB_b': '2', '_QB_c': 1223.4 }
    assert database.escape_query(sql, params) == r"UPDATE `foo` SET `a`=1, `b`='2', `c`=1223.4"
コード例 #9
0
def test_replace():
    rows = [{ 'a': 1, 'b': '2', 'c': 1223.4 }, { 'a': 2, 'b': '5', 'c': 1 }]
    sql, params = query_builder.multi_replace('foo', *rows)
    assert sql == 'REPLACE INTO `foo` (`a`, `b`, `c`) VALUES (%(_QB_ROW_0)s), (%(_QB_ROW_1)s)'
    assert params == { '_QB_ROW_0': [1, '2', 1223.4], '_QB_ROW_1': [2, '5', 1] }
    assert database.escape_query(sql, params) == r"REPLACE INTO `foo` (`a`, `b`, `c`) VALUES (1,'2',1223.4), (2,'5',1)"
コード例 #10
0
def test_simple_expression():
    x = { 'a': 1, 'b': '2', 'c': 1223.4 }
    sql, params = query_builder.simple_expression(', ', **x)
    assert sql == '`a`=%(_QB_a)s, `b`=%(_QB_b)s, `c`=%(_QB_c)s'
    assert params == { '_QB_a': 1, '_QB_b': '2', '_QB_c': 1223.4 }
    assert database.escape_query(sql, params) == r"`a`=1, `b`='2', `c`=1223.4"