コード例 #1
0
ファイル: db_object.py プロジェクト: haoqoo/vitess
 def get_count(class_, cursor, column_value_pairs=None, **columns):
   if not column_value_pairs:
     column_value_pairs = columns.items()
     column_value_pairs.sort()
   query, bind_vars = sql_builder.build_count_query(class_.table_name,
                                                    column_value_pairs)
   cursor.execute(query, bind_vars)
   return cursor.fetch_aggregate_function(sum)
コード例 #2
0
 def test_build_count_query(self):
     query, bind_vars = sql_builder.build_count_query(table_name='my_table',
                                                      column_value_pairs=[
                                                          ('col_a', 2)
                                                      ])
     self.assertEqual(
         query, 'SELECT COUNT(1) FROM my_table WHERE col_a = %(col_a_1)s')
     self.assertEqual(bind_vars, dict(col_a_1=2))
コード例 #3
0
 def get_count(class_, cursor, column_value_pairs=None, **columns):
     if not column_value_pairs:
         column_value_pairs = columns.items()
         column_value_pairs.sort()
     query, bind_vars = sql_builder.build_count_query(
         class_.table_name, column_value_pairs)
     cursor.execute(query, bind_vars)
     return cursor.fetch_aggregate_function(sum)
コード例 #4
0
ファイル: sql_builder_test.py プロジェクト: haoqoo/vitess
 def test_build_count_query(self):
   query, bind_vars = sql_builder.build_count_query(
       table_name='my_table', column_value_pairs=[('col_a', 2)])
   self.assertEqual(
       query, 'SELECT COUNT(1) FROM my_table WHERE col_a = %(col_a_1)s')
   self.assertEqual(bind_vars, dict(col_a_1=2))