Project

General

Profile

« Previous | Next » 

Revision 2216

sql_gen.py: ValueCond.to_str(): Made value_code a Code object instead of a string, and renamed it to left_value to reflect where it goes. Added as_ValueCond().

View differences:

lib/sql_gen.py
5 5
class Code:
6 6
    def to_str(self, db): raise NotImplemented()
7 7

  
8
class Literal:
8
class Literal(Code):
9 9
    def __init__(self, value): self.value = value
10 10
    
11 11
    def to_str(self, db): return db.esc_value(self.value)
12 12

  
13
def is_null(value): return isinstance(value, Literal) and value.value == None
14

  
13 15
class Table(Code):
14 16
    def __init__(self, name, schema=None):
15 17
        '''
......
42 44
        
43 45
        self.value = value
44 46
    
45
    def to_str(self, db, value_code):
47
    def to_str(self, db, left_value):
46 48
        '''
47
        @param value_code The SQL code that the condition is being applied on
49
        @param left_value The Code object that the condition is being applied on
48 50
        '''
49 51
        raise NotImplemented()
50 52

  
......
53 55
        ValueCond.__init__(self, value)
54 56
        self.operator = operator
55 57
    
56
    def to_str(self, db, value_code):
57
        return value_code+' '+self.operator+' '+self.value.to_str(db)
58
    def to_str(self, db, left_value):
59
        if not isinstance(left_value, Code): left_value = Col(left_value)
60
        
61
        operator = self.operator
62
        if is_null(self.value): operator = 'IS'
63
        return left_value.to_str(db)+' '+operator+' '+self.value.to_str(db)
64

  
65
def as_ValueCond(value):
66
    if not isinstance(value, ValueCond): return CompareCond(value)
67
    else: return value

Also available in: Unified diff