本文整理汇总了Python中mysqlstmt.Select类的典型用法代码示例。如果您正苦于以下问题:Python Select类的具体用法?Python Select怎么用?Python Select使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Select类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_where_value_object
def test_where_value_object(self):
class TestClass(object):
def __str__(self):
return "object as a string"
q = Select()
sql_t = q.from_table('t1').where_value('t1c1', TestClass()).sql()
assert_equals(sql_t, ('SELECT * FROM t1 WHERE `t1c1` = ?', ['object as a string']))
示例2: test_having_value_or
def test_having_value_or(self):
q = Select()
sql_t = q.from_table('t1').having_or().having_value('t1c1', 3).having_value('t1c1', 5).sql()
assert_equals(sql_t, ('SELECT * FROM t1 HAVING (`t1c1` = 3 OR `t1c1` = 5)', None))
示例3: test_join_field
def test_join_field(self):
# join(table, 'Field1')
# JOIN table USING (Field1)
q = Select()
sql_t = q.columns(['t1c1', 't2c1']).from_table('t1').left_join('t2', 't1c1').sql()
assert_equals(sql_t, ('SELECT `t1c1`, `t2c1` FROM t1 LEFT JOIN t2 USING (`t1c1`)', None))
示例4: test_select_quote_col_func
def test_select_quote_col_func(self):
q = Select()
sql_t = q.from_table('t1').columns('DATE(`t1c1`)').sql()
assert_equals(sql_t, ('SELECT DATE(`t1c1`) FROM t1', None))
示例5: test_select_distinct
def test_select_distinct(self):
q = Select('t1')
sql_t = q.set_option('DISTINCT').columns('t1c1').sql()
assert_equals(sql_t, ('SELECT DISTINCT `t1c1` FROM t1', None))
示例6: test_select_no_table
def test_select_no_table(self):
q = Select()
sql_t = q.column_expr('1+1').sql()
assert_equals(sql_t, ('SELECT 1+1', None))
示例7: test_join_no_root
def test_join_no_root(self):
q = Select()
q.columns(['t1c1', 't2c1']).left_join('t2', 't1c1').sql()
示例8: test_qualify_columns
def test_qualify_columns(self):
q = Select()
sql_t = q.from_table('t1').columns(('t1c1', 't1c2')).qualify_columns('t1', ('t1c1',)).sql()
assert_equals(sql_t, ('SELECT t1.`t1c1`, `t1c2` FROM t1', None))
示例9: test_having_expr_with_expr_param
def test_having_expr_with_expr_param(self):
q = Select()
sql_t = q.from_table('t1').having_expr('`t1c1` = PASSWORD(?)', ('mypw',)).sql()
assert_equals(sql_t, ('SELECT * FROM t1 HAVING `t1c1` = PASSWORD(?)', ['mypw']))
示例10: test_having_expr
def test_having_expr(self):
q = Select()
sql_t = q.from_table('t1').having_expr('`t1c1` = NOW()').sql()
assert_equals(sql_t, ('SELECT * FROM t1 HAVING `t1c1` = NOW()', None))
示例11: test_having_raw_value_with_param
def test_having_raw_value_with_param(self):
q = Select()
sql_t = q.from_table('t1').having_raw_value('t1c1', 'PASSWORD(?)', value_params=('mypw',)).sql()
assert_equals(sql_t, ('SELECT * FROM t1 HAVING `t1c1` = PASSWORD(?)', ['mypw']))
示例12: test_having_values_dict
def test_having_values_dict(self):
q = Select()
sql_t = q.from_table('t1').having_value(OrderedDict([('t1c1', 3), ('t1c2', 'string')])).sql()
assert_equals(sql_t, ('SELECT * FROM t1 HAVING (`t1c1` = 3 AND `t1c2` = ?)', ['string']))
示例13: test_select_col_callable
def test_select_col_callable(self):
q = Select()
sql_t = q.from_table('t1').columns('t1c1')()
assert_equals(sql_t, ('SELECT `t1c1` FROM t1', None))
示例14: test_having_value_or_and
def test_having_value_or_and(self):
q = Select(having_predicate='AND')
sql_t = q.from_table('t1').having_or().having_value('t1c1', 1).having_value('t1c1', 5).having_or().having_value('t1c1', 6).having_value('t1c1', 10).sql()
assert_equals(sql_t, ('SELECT * FROM t1 HAVING ((`t1c1` = 1 OR `t1c1` = 5) AND (`t1c1` = 6 OR `t1c1` = 10))', None))
示例15: test_having_value_and_or
def test_having_value_and_or(self):
q = Select()
sql_t = q.from_table('t1').having_and().having_value('t1c1', 1).having_value('t1c2', 5).having_and().having_value('t1c1', 6).having_value('t1c2', 10).sql()
assert_equals(sql_t, ('SELECT * FROM t1 HAVING ((`t1c1` = 1 AND `t1c2` = 5) OR (`t1c1` = 6 AND `t1c2` = 10))', None))