def __str__(self): if self.sort == ASC: return str(SqlReference(self.column_name)) return '{} {}'.format( SqlReference(self.column_name), self.sort, )
def __str__(self): if self.alias: return '{} AS {}'.format( SqlReference(self.column_name), SqlReference(self.alias), ) return str(SqlReference(self.column_name))
def __unicode__(self): if self.alias: return six.u('%s AS %s') % ( SqlReference(self.column_name), SqlReference(self.alias), ) else: return six.text_type(SqlReference(self.column_name))
def __unicode__(self): if self.sort == ASC: return six.text_type(SqlReference(self.column_name)) else: return six.u('%s %s') % ( SqlReference(self.column_name), self.sort, )
def set(self, *args, **kwds): if args and isinstance(args[0], str): self._on_conflict = SqlReference(args[0]) args = args[1:] else: raise InvalidQueryException( 'ON CONFLICT (column_name) DO UPDATE needs reference to column as first argument' ) super().set(*args, **kwds)
def __unicode__(self): if self.alias: table = six.u('%s AS %s') % ( SqlReference(self.table_name), SqlReference(self.alias), ) else: table = force_text(SqlReference(self.table_name)) if self._joins: self._minimize_joins() table += six.u(' ') + six.u(' ').join( six.u('%s %s%s') % ( JOIN_TYPES[join['type']], join['table'], six.u(' ON %s') % join['ons'] if join['ons'].is_set else '', ) for join in self._joins) return table
def __str__(self): if self.alias: table = '{} AS {}'.format( SqlReference(self.table_name), SqlReference(self.alias), ) else: table = force_text(SqlReference(self.table_name)) if self._joins: self._minimize_joins() table += ' ' + ' '.join( '{} {}{}'.format( JOIN_TYPES[join['type']], join['table'], ' ON {}'.format(join['ons']) if join['ons'].is_set else '', ) for join in self._joins ) return table
def __unicode__(self): foo = six.u('%(col)s %(rel)s %(val)s') value = self.value if isinstance(value, (list, tuple, xrange)) and None in value: value = [v for v in value if v is not None] # If list of values is empty, there must be only condition for NULL. if value: foo = six.u('(') + foo + six.u(' OR %(col)s IS NULL)') else: foo = '%(col)s IS NULL' return foo % { 'col': SqlReference(self.column_name), 'rel': self.relation, 'val': self._get_value_for_str(value), }
def _get_expr_as_string(self): if isinstance(self.expr, (list, tuple)): return six.u(', ').join(force_text(SqlReference(e)) for e in self.expr) return SqlReference(self.expr)
def test_security_subselect(): select = sqlpuzzle.select_from('table') assert str(SqlReference(select)) == '(SELECT * FROM "table")'
def test_sqlreference_compare_to_str(): assert SqlReference('foo') == '"foo"' assert SqlReference('foo') != 'foo'
def __str__(self): value_transformer = SqlReference if isinstance(self.value, str) else SqlValue return self._value._format_condition(SqlReference(self.column_name), value_transformer=value_transformer)
def test_subselect(self): select = sqlpuzzle.select_from('table') self.assertEqual(str(SqlReference(select)), '(SELECT * FROM "table")')
def test_unicode(self): self.assertEqual(str(SqlReference(six.u('test'))), '"test"')
def test_string(self): self.assertEqual(str(SqlReference('test')), '"test"')
def test_database_table_column(self): self.assertEqual(str(SqlReference('db.table.column')), '"db"."table"."column"')
def test_table_column(self): self.assertEqual(str(SqlReference('table.column')), '"table"."column"')
def test_security_table_column(): assert str(SqlReference('table.column')) == '"table"."column"'
def __str__(self): return self._value._format_condition(SqlReference(self.column_name), value_transformer=SqlValue)
def __unicode__(self): return six.u('%s = %s') % ( SqlReference(self.column_name), SqlValue(self.value), )
def columns(self): return ', '.join(str(SqlReference(value.column_name)) for value in self._parts)
def test_security_database_table_column(): assert str(SqlReference('db.table.column')) == '"db"."table"."column"'
def __str__(self): return '{} = {}'.format( SqlReference(self.column_name), SqlValue(self.value), )
def _get_value_for_str(value): if isinstance(value, six.string_types): return SqlReference(value) return SqlValue(value)
def columns(self): return ', '.join(str(SqlReference(column)) for column in self.all_columns)
def test_security_string(): assert str(SqlReference('test')) == '"test"'