Retrieve all crash dumps in the database, optionally filtering them by signature and timestamp, and/or sorting them by timestamp. Results can be paged to avoid consuming too much memory if the database is large. @see: L{find_by_example} @type sign
(self, signature=None, order=0, since=None, until=None, offset=None, limit=None)
| 811 | |
| 812 | @Transactional |
| 813 | def find(self, signature=None, order=0, since=None, until=None, offset=None, limit=None): |
| 814 | """ |
| 815 | Retrieve all crash dumps in the database, optionally filtering them by |
| 816 | signature and timestamp, and/or sorting them by timestamp. |
| 817 | |
| 818 | Results can be paged to avoid consuming too much memory if the database |
| 819 | is large. |
| 820 | |
| 821 | @see: L{find_by_example} |
| 822 | |
| 823 | @type signature: object |
| 824 | @param signature: (Optional) Return only through crashes matching |
| 825 | this signature. See L{Crash.signature} for more details. |
| 826 | |
| 827 | @type order: int |
| 828 | @param order: (Optional) Sort by timestamp. |
| 829 | If C{== 0}, results are not sorted. |
| 830 | If C{> 0}, results are sorted from older to newer. |
| 831 | If C{< 0}, results are sorted from newer to older. |
| 832 | |
| 833 | @type since: datetime |
| 834 | @param since: (Optional) Return only the crashes after and |
| 835 | including this date and time. |
| 836 | |
| 837 | @type until: datetime |
| 838 | @param until: (Optional) Return only the crashes before this date |
| 839 | and time, not including it. |
| 840 | |
| 841 | @type offset: int |
| 842 | @param offset: (Optional) Skip the first I{offset} results. |
| 843 | |
| 844 | @type limit: int |
| 845 | @param limit: (Optional) Return at most I{limit} results. |
| 846 | |
| 847 | @rtype: list(L{Crash}) |
| 848 | @return: List of Crash objects. |
| 849 | """ |
| 850 | |
| 851 | # Validate the parameters. |
| 852 | if since and until and since > until: |
| 853 | warnings.warn("CrashDAO.find() got the 'since' and 'until' arguments reversed, corrected automatically.") |
| 854 | since, until = until, since |
| 855 | if limit is not None and not limit: |
| 856 | warnings.warn("CrashDAO.find() was set a limit of 0 results, returning without executing a query.") |
| 857 | return [] |
| 858 | |
| 859 | # Build the SQL query. |
| 860 | query = self._session.query(CrashDTO) |
| 861 | if signature is not None: |
| 862 | sig_pickled = pickle.dumps(signature, protocol=0) |
| 863 | query = query.filter(CrashDTO.signature == sig_pickled) |
| 864 | if since: |
| 865 | query = query.filter(CrashDTO.timestamp >= since) |
| 866 | if until: |
| 867 | query = query.filter(CrashDTO.timestamp < until) |
| 868 | if order: |
| 869 | if order > 0: |
| 870 | query = query.order_by(asc(CrashDTO.timestamp)) |