Project

General

Profile

« Previous | Next » 

Revision 2210

sql.py: Added Query, Table, Col

View differences:

lib/sql.py
117 117
    if schema != None: return esc_name_(schema)+'.'+table
118 118
    else: return table
119 119

  
120
##### Queries
121

  
122
class Query:
123
    def __init__(self, str='', values=None):
124
        if str == None: str = []
125
        
126
        self.str = str
127
        self.values = values
128

  
120 129
##### Database connections
121 130

  
122 131
db_config_names = ['engine', 'host', 'user', 'password', 'database', 'schemas']
......
381 390
                into_ref[0] = next_version(into_ref[0])
382 391
                # try again with next version of name
383 392

  
393
class Table:
394
    def __init__(self, name, schema=None):
395
        '''
396
        @param schema str|None (for no schema)
397
        '''
398
        self.name = name
399
        self.schema = schema
400
    
401
    def to_str(self, db): return qual_name(db, self.schema, self.name)
402

  
403
class Col:
404
    def __init__(self, name, table=None):
405
        '''
406
        @param table Table|None (for no table)
407
        '''
408
        assert table == None or isinstance(table, Table)
409
        
410
        self.name = name
411
        self.table = table
412
    
413
    def to_str(self, db):
414
        str_ = ''
415
        if self.table != None: str_ += self.table.to_str(db)+'.'
416
        str_ += esc_name(db, self.name)
417
        return str_
418

  
384 419
order_by_pkey = object() # tells mk_select() to order by the pkey
385 420

  
386 421
join_using = object() # tells mk_select() to join the column with USING

Also available in: Unified diff