~psycopg/psycopg/2.0.x

« back to all changes in this revision

Viewing changes to lib/extras.py

  • Committer: Federico Di Gregorio
  • Date: 2005-02-28 15:50:55 UTC
  • Revision ID: fog-a5b4fd4af28bdc8788020a6cf3d3e6179d0a1e75
Adaptation fixes (a lot.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
 
72
72
 
73
73
 
74
 
class AsIs(object):
75
 
    """An adapter that just return the object 'as is'.
76
 
 
77
 
    psycopg 1.99.9 has some optimizations that make impossible to call adapt()
78
 
    without adding some basic adapters externally. This limitation will be
79
 
    lifted in a future release. In the meantime you can use the AsIs adapter.
80
 
    """
81
 
    def __init__(self, obj):
82
 
        self.__obj = obj
83
 
    def getquoted(self):
84
 
        return str(self.__obj)
85
 
    def prepare(self, conn):
86
 
        pass
87
 
    __str__ = getquoted
88
 
 
89
74
class SQL_IN(object):
90
75
    """Adapt any iterable to an SQL quotable object."""
91
76
    
92
77
    def __init__(self, seq):
93
78
        self._seq = seq
94
79
        
95
 
    def prepare(self, conn):
96
 
        pass
97
 
    
98
80
    def getquoted(self):
99
81
        # this is the important line: note how every object in the
100
82
        # list is adapted and then how getquoted() is called on it
101
83
        qobjs = [str(_A(o).getquoted()) for o in self._seq]
102
84
 
103
85
        return '(' + ', '.join(qobjs) + ')'
104
 
        
 
86
 
105
87
    __str__ = getquoted
106
 
 
107
 
 
 
88
    
108
89
_RA(tuple, SQL_IN)
109
 
_RA(int, AsIs)
110
 
_RA(float, AsIs)