| Home | Trees | Indices | Help |
|
|---|
|
|
Helper class to generate SQL strings to use with python's DB-API.
| Instance Methods | |||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
| Method Details |
:param model: list of columns to select
:param tables: list of tables used in from
:param params: dictionary that will be used as in cursor.execute(sql, params)
:param joins: optional list of restriction statements to insert in the
where clause. Usually used to perform joins.
>>> s = SQLGenerator()
>>> s.adv_select(['column'],[('test', 't')], {})
'SELECT column FROM test AS t'
>>> s.adv_select(['column'],[('test', 't')], {'nom':'dupont'})
'SELECT column FROM test AS t WHERE nom = %(nom)s'
|
:param table: name of the table
:param params: dictionary that will be used as in cursor.execute(sql,params)
>>> s = SQLGenerator()
>>> s.delete('test',{'nom':'dupont'})
'DELETE FROM test WHERE nom = %(nom)s'
>>> s.delete('test',{'nom':'dupont','prenom':'jean'})
'DELETE FROM test WHERE nom = %(nom)s AND prenom = %(prenom)s'
|
:param table: name of the table
:param params: dictionary that will be used as in cursor.execute(sql,params)
>>> s = SQLGenerator()
>>> s.insert('test',{'nom':'dupont'})
'INSERT INTO test ( nom ) VALUES ( %(nom)s )'
>>> s.insert('test',{'nom':'dupont','prenom':'jean'})
'INSERT INTO test ( nom, prenom ) VALUES ( %(nom)s, %(prenom)s )'
|
:param table: name of the table
:param params: dictionary that will be used as in cursor.execute(sql,params)
>>> s = SQLGenerator()
>>> s.select('test',{})
'SELECT * FROM test'
>>> s.select('test',{'nom':'dupont'})
'SELECT * FROM test WHERE nom = %(nom)s'
>>> s.select('test',{'nom':'dupont','prenom':'jean'})
'SELECT * FROM test WHERE nom = %(nom)s AND prenom = %(prenom)s'
|
:param keys: list of keys >>> s = SQLGenerator() >>> s.set(['nom']) 'nom = %(nom)s' >>> s.set(['nom','prenom']) 'nom = %(nom)s, prenom = %(prenom)s' |
:param table: name of the table
:param params: dictionary that will be used as in cursor.execute(sql,params)
>>> s = SQLGenerator()
>>> s.update('test', {'id':'001','nom':'dupont'}, ['id'])
'UPDATE test SET nom = %(nom)s WHERE id = %(id)s'
>>> s.update('test',{'id':'001','nom':'dupont','prenom':'jean'},['id'])
'UPDATE test SET nom = %(nom)s, prenom = %(prenom)s WHERE id = %(id)s'
|
:param keys: list of keys >>> s = SQLGenerator() >>> s.where(['nom']) 'nom = %(nom)s' >>> s.where(['nom','prenom']) 'nom = %(nom)s AND prenom = %(prenom)s' >>> s.where(['nom','prenom'], 'x.id = y.id') 'x.id = y.id AND nom = %(nom)s AND prenom = %(prenom)s' |
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Sun Dec 27 17:18:42 2009 | http://epydoc.sourceforge.net |