HTD

Merge lp:~ahayzen/htd/31.fix_1065642 into lp:htd/3.1

Proposed by Andrew Hayzen
Status: Merged
Approved by: Andrew Hayzen
Approved revision: 28
Merged at revision: 28
Proposed branch: lp:~ahayzen/htd/31.fix_1065642
Merge into: lp:htd/3.1
Diff against target: 97 lines (+18/-10)
2 files modified
htd31/_objects/cursor.py (+7/-8)
htd31/_objects/record.py (+11/-2)
To merge this branch: bzr merge lp:~ahayzen/htd/31.fix_1065642
Reviewer Review Type Date Requested Status
Andrew Hayzen Approve
Review via email: mp+129310@code.launchpad.net

Description of the change

Select and Update now yield Record object.

To post a comment you must log in.
Revision history for this message
Andrew Hayzen (ahayzen) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'htd31/_objects/cursor.py'
2--- htd31/_objects/cursor.py 2012-10-01 23:04:00 +0000
3+++ htd31/_objects/cursor.py 2012-10-11 21:17:41 +0000
4@@ -177,8 +177,7 @@
5
6 self._file.unlock() # Unlock
7
8- return Record(key, data, self.connection, self.table,
9- self._file.header["KEY"])
10+ return Record(data, self.connection, self.table)
11
12 @trace
13 def __iter__(self):
14@@ -208,8 +207,7 @@
15
16 self._file.unlock()
17
18- return Record(None, data, self.connection, self.table,
19- self._file.header["KEY"])
20+ return Record(data, self.connection, self.table)
21
22 @trace
23 def __len__(self):
24@@ -513,10 +511,10 @@
25
26 prog.count()
27
28- if numatts == 1:
29+ if numatts == 1: # 1 att doesn't return record
30 yield tmp[attribute[0]]
31 else:
32- yield tmp
33+ yield Record(tmp, self.connection, self.table)
34
35 self._file.lock_reading()
36
37@@ -525,7 +523,7 @@
38 self._file.unlock()
39
40 @trace
41- def update(self, where, args):
42+ def update(self, where=None, args={}):
43 """ Update a generator into the table """
44
45 perm("o", self._access)
46@@ -548,7 +546,8 @@
47 x += 1 # Next record
48 continue
49
50- record = unsanitise(record, self._file.header["ATT"])
51+ record = Record(unsanitise(record, self._file.header["ATT"]),
52+ self.connection, self.table)
53 record = (yield record) # Send/Recieve new record
54
55 integrity_check(record, self._file.header, self.connection)
56
57=== modified file 'htd31/_objects/record.py'
58--- htd31/_objects/record.py 2012-09-28 16:33:28 +0000
59+++ htd31/_objects/record.py 2012-10-11 21:17:41 +0000
60@@ -25,7 +25,7 @@
61
62 class Record(object):
63 """ Class that provides read-only record and foreign key support """
64- def __init__(self, key, data={}, con=None, table=None, identifier=[]):
65+ def __init__(self, data={}, con=None, table=None):
66 # Load variables
67 if con is not None:
68 self._con = ref(con)
69@@ -33,7 +33,6 @@
70 self._con = None
71
72 self.data = data
73- self.key = key
74 self.table = table
75 self._index = 0
76
77@@ -84,11 +83,21 @@
78 if len(r1m_link) > 0: # For 1-m relationships
79 tbl, att = r1m_link[0] # Pick first relation
80
81+ if att not in self.data:
82+ raise ValueError("This record does not have the required " \
83+ "attribute (%s), please add the attribute " \
84+ "to the query." % att)
85+
86 data = cur[self.data[att]]
87
88 if len(rm1_link) > 0: # For m-1 relationships
89 tbl, att = rm1_link[0] # Pick first relation
90
91+ if att not in self.data:
92+ raise ValueError("This record does not have the required " \
93+ "attribute (%s), please add the attribute " \
94+ "to the query." % att)
95+
96 data = list(cur.select(where="%s=={val}" % att,
97 args=dict(val=(att, self.data[att]))))
98

Subscribers

People subscribed via source and target branches

to all changes: