Beispiel #1
0
 def test_where_functions(self):
     s = SQLGenerator()
     params = {
         'nom': 'dupont',
         'prenom': 'jean',
         'age': SQLExpression('YEARS(%(date)s)', date='2013/01/01')
     }
     self.assertEqual(
         s.where(params),
         'age = YEARS(%(date)s) AND nom = %(nom)s AND prenom = %(prenom)s')
     self.assertEqual(params, {
         'nom': 'dupont',
         'prenom': 'jean',
         'date': '2013/01/01'
     })
     params = {
         'nom': 'dupont',
         'prenom': 'jean',
         'age': SQLExpression('YEARS(%(date)s)', date='2013/01/01')
     }
     self.assertEqual(
         s.where(params, 'x.id = y.id'),
         'x.id = y.id AND age = YEARS(%(date)s) AND nom = %(nom)s AND prenom = %(prenom)s'
     )
     self.assertEqual(params, {
         'nom': 'dupont',
         'prenom': 'jean',
         'date': '2013/01/01'
     })
Beispiel #2
0
 def test_where_values(self):
     s = SQLGenerator()
     self.assertEqual(s.where(['nom']), 'nom = %(nom)s')
     self.assertEqual(s.where(['nom', 'prenom']),
                      'nom = %(nom)s AND prenom = %(prenom)s')
     self.assertEqual(
         s.where(['nom', 'prenom'], 'x.id = y.id'),
         'x.id = y.id AND nom = %(nom)s AND prenom = %(prenom)s')
     params = {'nom': 'dupont', 'prenom': 'jean'}
     self.assertEqual(s.where(params),
                      'nom = %(nom)s AND prenom = %(prenom)s')
     self.assertEqual(
         s.where(params, 'x.id = y.id'),
         'x.id = y.id AND nom = %(nom)s AND prenom = %(prenom)s')