Пример #1
0
 def GetRow(self, _tableName, _columnNames, _rowFactory = None,
         **_conditions):
     rows = self.GetRows(_tableName, _columnNames, _rowFactory,
             **_conditions)
     if len(rows) == 0:
         raise cx_Exceptions.NoDataFound()
     elif len(rows) > 1:
         raise cx_Exceptions.TooManyRows(numRows = len(rows))
     return rows[0]
Пример #2
0
 def FetchRow(self, cursor, **args):
     """Fetch the row from the database and return it as an instance of
        the requested row. An exception will be raised if no rows are
        returned or more than one row is returned."""
     rows = self.FetchRows(cursor, **args)
     if len(rows) > 1:
         raise cx_Exceptions.TooManyRows(numRows = len(rows))
     if not rows:
         raise cx_Exceptions.NoDataFound()
     return rows[0]
Пример #3
0
 def GetCachedValue(self, args):
     if len(args) == 1:
         key, = args
     else:
         key = args
     try:
         return self.rows[key]
     except KeyError:
         if self.ignoreRowNotCached:
             return self.OnRowNotCached(args)
         raise cx_Exceptions.NoDataFound()
Пример #4
0
 def executeandfetchone(self, _sql, _args=None, **_kwargs):
     """Execute the statement and return one and only one row. If no rows
        are found, the NoDataFound exception is raised. If too many rows
        are found, the TooManyRows exception is raised."""
     self.execute(_sql, _args or _kwargs)
     rows = self.fetchall()
     if len(rows) == 0:
         raise cx_Exceptions.NoDataFound()
     elif len(rows) > 1:
         raise cx_Exceptions.TooManyRows(numRows=len(rows))
     return rows[0]
Пример #5
0
 def _FindRow(self, externalRow, errorIfMissing=False):
     row = None
     for path in self.singleRowPaths:
         if path.ignoreRowNotCached:
             continue
         key = path.GetKeyValue(externalRow)
         row = path.rows.get(key)
         if row is not None:
             break
     if errorIfMissing and row is None:
         raise cx_Exceptions.NoDataFound()
     return row
Пример #6
0
 def Retrieve(self, parent):
     if self.parentItem is None:
         handle, row = self.dataSet.InsertRow()
         self.OnNewRow(parent, row)
     elif not self.IsUpdatedIndependently(parent):
         values = [getattr(self.parentItem, n) \
                 for n in self.dataSet.attrNames]
         row = self.dataSet.rowClass(*values)
         self.dataSet.SetRows([row])
     else:
         args = [getattr(self.parentItem, n) \
                 for n in self.parentItem.pkAttrNames]
         self.dataSet.Retrieve(*args)
         if len(self.dataSet.rows) != 1:
             raise cx_Exceptions.NoDataFound()
Пример #7
0
 def _OnLoad(self, rows, *args):
     if len(rows) == 0:
         raise cx_Exceptions.NoDataFound()
     elif len(rows) > 1:
         raise cx_Exceptions.TooManyRows(numRows=len(rows))
     return self._CacheValue(args, rows[0])