def sqlwhere(criteria=None):
if not criteria:<EOL><INDENT>return ('<STR_LIT>', [])<EOL><DEDENT>fields = sorted(criteria.keys())<EOL>validate_names(fields)<EOL>values = [criteria[field] for field in fields]<EOL>parts = [field + '<STR_LIT>' for field in fields]<EOL>sql = '<STR_LIT>'.join(parts)<EOL>return (sql, values)<EOL>
Generates SQL where clause. Returns (sql, values).
    Criteria is a dictionary of {field: value}.

    >>> sqlwhere()
    ('', [])
    >>> sqlwhere({'id': 5})
    ('id=%s', [5])
    >>> sqlwhere({'id': 3, 'name': 'toto'})
    ('id=%s and name=%s', [3, 'toto'])
    >>> sqlwhere({'id': 3, 'name': 'toto', 'createdon': '2013-12-02'})
    ('createdon=%s and id=%s and name=%s', ['2013-12-02', 3, 'toto'])