@@ -42,6 +42,7 @@ def __init__(self, dsn, tilevel, enc='utf-8'):
4242 self .encoding = enc
4343 self .failures = 0
4444 self .calls = 0
45+ self .make_mappings ()
4546
4647 def getconn (self , create = True ):
4748 conn = pool .getconn (self .dsn )
@@ -89,32 +90,23 @@ def close(self):
8990 def sortKey (self ):
9091 return 1
9192
93+ def make_mappings (self ):
94+ """Generate the mappings used later by self.convert_description()."""
95+ self .type_mappings = {}
96+ for t , s in [(INTEGER ,'i' ), (LONGINTEGER , 'i' ), (NUMBER , 'n' ),
97+ (BOOLEAN ,'n' ), (ROWID , 'i' ),
98+ (DATETIME , 'd' ), (DATE , 'd' ), (TIME , 'd' )]:
99+ for v in t .values :
100+ self .type_mappings [v ] = (t , s )
101+
92102 def convert_description (self , desc , use_psycopg_types = False ):
93103 """Convert DBAPI-2.0 description field to Zope format."""
94104 items = []
95105 for name , typ , width , ds , p , scale , null_ok in desc :
96- if typ == NUMBER :
97- if typ == INTEGER or typ == LONGINTEGER :
98- typs = 'i'
99- else :
100- typs = 'n'
101- typp = NUMBER
102- elif typ == BOOLEAN :
103- typs = 'n'
104- typp = BOOLEAN
105- elif typ == ROWID :
106- typs = 'i'
107- typp = ROWID
108- # FIXME: shouldn't DATETIME include other types?
109- elif typ == DATETIME or typ == DATE or typ == TIME :
110- typs = 'd'
111- typp = DATETIME
112- else :
113- typs = 's'
114- typp = STRING
106+ m = self .type_mappings .get (typ , (STRING , 's' ))
115107 items .append ({
116108 'name' : name ,
117- 'type' : use_psycopg_types and typp or typs ,
109+ 'type' : use_psycopg_types and m [ 0 ] or m [ 1 ] ,
118110 'width' : width ,
119111 'precision' : p ,
120112 'scale' : scale ,
0 commit comments