1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
38 """Returns a list of ResultRow objects based upon a connected cursor
39 and a query sql string to execute"""
40
41
42 cursor.execute(sql)
43
44
45 return getdict(cursor.fetchall(), cursor.description)
46
47
49 """Returns a list of DBRow objects based upon already retrieved results
50 and the query description returned from cursor.description"""
51
52
53 fields = {}
54 for i in range(len(description)):
55 fields[description[i][0]] = i
56
57
58 rows = []
59 for result in results:
60 rows.append(DBRow(result, fields))
61
62
63 return rows
64
65
67 """A single row in a result set with a dictionary-style and list-style interface"""
68
70 """Called by ResultSet function. Don't call directly"""
71 self.row = row
72 self.fields = fields
73
75 return "<DBrow with %s fields>" % len(self)
76
78 """Returns a string representation"""
79 return str(self.row)
80
82 return self.row[self.fields[attr]]
83
85 """Returns the value of the named column"""
86 if type(key) == type(1):
87 return self.row[key]
88 else:
89 return self.row[self.fields[key]]
90
92 """Not used in this implementation"""
93 raise TypeError, "can't set an item of a result set"
94
96 """Returns the value of the numbered column"""
97 return self.row[i: j]
98
100 """Not used in this implementation"""
101 raise TypeError, "can't set an item of a result set"
102
104 """Returns the field names"""
105 return self.fields.keys()
106
108 """Returns a dictionary of the keys and their indices in the row"""
109 return self.fields
110
112 """Returns whether the given key is valid"""
113 return self.fields.has_key(key)
114
116 """Returns how many columns are in this row"""
117 return len(self.row)
118
120 return len(self.row) != 0
121
123
124 if other == None:
125 return False
126 return self.fields == other.fields
127