def update(self, _rowid, **kwargs): """ Update a record. The kwargs are named parameters. """ fieldnames=kwargs.keys() fieldnames.sort() values = dict([(self.dd.attrs[n.lower()], v) for (n, v) in kwargs.items()]) record = DBSRow(self, self.dd, _rowid, internal=self.internal, fieldids=values.keys()) record.update(values)
def delete(self, _rowid=None, filters=None, explain=False): if _rowid: record = DBSRow(self, self.dd, _rowid, internal=self.internal) yield record.delete() else: gl_cache = {} plan = make_plan(self, filters=filters, gl_cache=gl_cache, explain=explain) if explain: for message in plan: yield message else: for rowid, gl_root, rowid_path in plan: if len(rowid_path) == 1: record = DBSRow(self, self.dd, rowid, internal=self.internal) yield record.delete() else: record = DBSRow(self, self.dd, rowid_path, internal=self.internal) yield record.delete()
def insert(self, **kwargs): """ Insert a record. The kwargs are named parameters. """ fieldnames=kwargs.keys() fieldnames.sort() # TODO: pass in primary key - if the client passes it, I am ignoring it. values = dict([(self.dd.attrs[n.lower()], v) for (n, v) in kwargs.items() if n != '_rowid']) record = DBSRow(self, self.dd, None, internal=self.internal, fieldids=values.keys()) try: return record.insert(values) except: #import pdb; pdb.post_mortem() raise
def update(self, _rowid, **kwargs): """ Update a record. The kwargs are named parameters. """ fieldnames = kwargs.keys() fieldnames.sort() values = dict([(self.dd.attrs[n.lower()], v) for (n, v) in kwargs.items()]) record = DBSRow(self, self.dd, _rowid, internal=self.internal, fieldids=values.keys()) record.update(values)
def insert(self, **kwargs): """ Insert a record. The kwargs are named parameters. """ fieldnames = kwargs.keys() fieldnames.sort() # TODO: pass in primary key - if the client passes it, I am ignoring it. values = dict([(self.dd.attrs[n.lower()], v) for (n, v) in kwargs.items() if n != '_rowid']) record = DBSRow(self, self.dd, None, internal=self.internal, fieldids=values.keys()) try: return record.insert(values) except: #import pdb; pdb.post_mortem() raise
def description(self): """ Describe the resultset. This is made by the DBSRow object. """ if self._description is None: record = DBSRow(self, self.dd, None, fieldids=self.fieldids, internal=self.internal) self._description = record.description return self._description
def get(self, rowid, asdict=False): """ The logic to retrieve and update the row is in the DBSRow class. This call constructs a DBSRow class, and verifies that the row exists in the database. It returns sequence, as per the dbapi spec. Multiples are a problem. The multiple is returned as a nested sequence of sequences. """ record = DBSRow(self, self.dd, rowid, fieldids=self.fieldids, internal=self.internal) if self.internal: record.raw_retrieve(self._gl_cache) else: record.retrieve() if asdict: return dict(zip(self.fieldnames(), record.as_list())) else: return record.as_list()
def unlock(self, _rowid): record = DBSRow(self, self.dd, _rowid, internal=self.internal) return record.unlock()
def lock(self, _rowid, timeout=5): record = DBSRow(self, self.dd, _rowid, internal=self.internal) return record.lock(timeout)
def traverse_pointer(self, fieldname, value, fieldnames=None): """ Given a pointer, follow it to the next file. """ handler = DBSRow(self, self.dd, None, internal=self.internal) return handler.traverse(fieldname, value, fieldnames=fieldnames)