Beispiel #1
0
    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)
Beispiel #2
0
 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()
Beispiel #3
0
    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
Beispiel #4
0
    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)
Beispiel #5
0
    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
Beispiel #6
0
 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
Beispiel #7
0
    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()
Beispiel #8
0
    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()
Beispiel #9
0
 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()
Beispiel #10
0
 def unlock(self, _rowid):
     record = DBSRow(self, self.dd, _rowid, internal=self.internal)
     return record.unlock()
Beispiel #11
0
 def lock(self, _rowid, timeout=5):
     record = DBSRow(self, self.dd, _rowid, internal=self.internal)
     return record.lock(timeout)
Beispiel #12
0
 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)
Beispiel #13
0
 def unlock(self, _rowid):
     record = DBSRow(self, self.dd, _rowid, internal=self.internal)
     return record.unlock()
Beispiel #14
0
 def lock(self, _rowid, timeout=5):
     record = DBSRow(self, self.dd, _rowid, internal=self.internal)
     return record.lock(timeout)
Beispiel #15
0
 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)