root/galaxy-central/eggs/SQLAlchemy-0.5.6_dev_r6498-py2.6.egg/sqlalchemy/exc.py

リビジョン 3, 6.2 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1# Copyright (C) 2005, 2006, 2007, 2008, 2009 Michael Bayer mike_mp@zzzcomputing.com
2#
3# This module is part of SQLAlchemy and is released under
4# the MIT License: http://www.opensource.org/licenses/mit-license.php
5
6"""Exceptions used with SQLAlchemy.
7
8The base exception class is SQLAlchemyError.  Exceptions which are raised as a
9result of DBAPI exceptions are all subclasses of
10:class:`~sqlalchemy.exc.DBAPIError`.
11
12"""
13
14
15class SQLAlchemyError(Exception):
16    """Generic error class."""
17
18
19class ArgumentError(SQLAlchemyError):
20    """Raised when an invalid or conflicting function argument is supplied.
21
22    This error generally corresponds to construction time state errors.
23
24    """
25
26
27class CircularDependencyError(SQLAlchemyError):
28    """Raised by topological sorts when a circular dependency is detected"""
29
30
31class CompileError(SQLAlchemyError):
32    """Raised when an error occurs during SQL compilation"""
33
34class IdentifierError(SQLAlchemyError):
35    """Raised when a schema name is beyond the max character limit"""
36
37# Moved to orm.exc; compatability definition installed by orm import until 0.6
38ConcurrentModificationError = None
39
40class DisconnectionError(SQLAlchemyError):
41    """A disconnect is detected on a raw DB-API connection.
42
43    This error is raised and consumed internally by a connection pool.  It can
44    be raised by a ``PoolListener`` so that the host pool forces a disconnect.
45
46    """
47
48
49# Moved to orm.exc; compatability definition installed by orm import until 0.6
50FlushError = None
51
52class TimeoutError(SQLAlchemyError):
53    """Raised when a connection pool times out on getting a connection."""
54
55
56class InvalidRequestError(SQLAlchemyError):
57    """SQLAlchemy was asked to do something it can't do.
58
59    This error generally corresponds to runtime state errors.
60
61    """
62
63class NoSuchColumnError(KeyError, InvalidRequestError):
64    """A nonexistent column is requested from a ``RowProxy``."""
65
66class NoReferenceError(InvalidRequestError):
67    """Raised by ``ForeignKey`` to indicate a reference cannot be resolved."""
68   
69class NoReferencedTableError(NoReferenceError):
70    """Raised by ``ForeignKey`` when the referred ``Table`` cannot be located."""
71
72class NoReferencedColumnError(NoReferenceError):
73    """Raised by ``ForeignKey`` when the referred ``Column`` cannot be located."""
74
75class NoSuchTableError(InvalidRequestError):
76    """Table does not exist or is not visible to a connection."""
77
78
79class UnboundExecutionError(InvalidRequestError):
80    """SQL was attempted without a database connection to execute it on."""
81
82
83# Moved to orm.exc; compatability definition installed by orm import until 0.6
84UnmappedColumnError = None
85
86class DBAPIError(SQLAlchemyError):
87    """Raised when the execution of a database operation fails.
88
89    ``DBAPIError`` wraps exceptions raised by the DB-API underlying the
90    database operation.  Driver-specific implementations of the standard
91    DB-API exception types are wrapped by matching sub-types of SQLAlchemy's
92    ``DBAPIError`` when possible.  DB-API's ``Error`` type maps to
93    ``DBAPIError`` in SQLAlchemy, otherwise the names are identical.  Note
94    that there is no guarantee that different DB-API implementations will
95    raise the same exception type for any given error condition.
96
97    If the error-raising operation occured in the execution of a SQL
98    statement, that statement and its parameters will be available on
99    the exception object in the ``statement`` and ``params`` attributes.
100
101    The wrapped exception object is available in the ``orig`` attribute.
102    Its type and properties are DB-API implementation specific.
103
104    """
105
106    def instance(cls, statement, params, orig, connection_invalidated=False):
107        # Don't ever wrap these, just return them directly as if
108        # DBAPIError didn't exist.
109        if isinstance(orig, (KeyboardInterrupt, SystemExit)):
110            return orig
111
112        if orig is not None:
113            name, glob = orig.__class__.__name__, globals()
114            if name in glob and issubclass(glob[name], DBAPIError):
115                cls = glob[name]
116
117        return cls(statement, params, orig, connection_invalidated)
118    instance = classmethod(instance)
119
120    def __init__(self, statement, params, orig, connection_invalidated=False):
121        try:
122            text = str(orig)
123        except (KeyboardInterrupt, SystemExit):
124            raise
125        except Exception, e:
126            text = 'Error in str() of DB-API-generated exception: ' + str(e)
127        SQLAlchemyError.__init__(
128            self, '(%s) %s' % (orig.__class__.__name__, text))
129        self.statement = statement
130        self.params = params
131        self.orig = orig
132        self.connection_invalidated = connection_invalidated
133
134    def __str__(self):
135        if isinstance(self.params, (list, tuple)) and len(self.params) > 10 and isinstance(self.params[0], (list, dict, tuple)):
136            return ' '.join((SQLAlchemyError.__str__(self),
137                             repr(self.statement),
138                             repr(self.params[:2]),
139                             '... and a total of %i bound parameter sets' % len(self.params)))
140        return ' '.join((SQLAlchemyError.__str__(self),
141                         repr(self.statement), repr(self.params)))
142
143
144# As of 0.4, SQLError is now DBAPIError.
145# SQLError alias will be removed in 0.6.
146SQLError = DBAPIError
147
148class InterfaceError(DBAPIError):
149    """Wraps a DB-API InterfaceError."""
150
151
152class DatabaseError(DBAPIError):
153    """Wraps a DB-API DatabaseError."""
154
155
156class DataError(DatabaseError):
157    """Wraps a DB-API DataError."""
158
159
160class OperationalError(DatabaseError):
161    """Wraps a DB-API OperationalError."""
162
163
164class IntegrityError(DatabaseError):
165    """Wraps a DB-API IntegrityError."""
166
167
168class InternalError(DatabaseError):
169    """Wraps a DB-API InternalError."""
170
171
172class ProgrammingError(DatabaseError):
173    """Wraps a DB-API ProgrammingError."""
174
175
176class NotSupportedError(DatabaseError):
177    """Wraps a DB-API NotSupportedError."""
178
179
180# Warnings
181
182class SADeprecationWarning(DeprecationWarning):
183    """Issued once per usage of a deprecated API."""
184
185
186class SAPendingDeprecationWarning(PendingDeprecationWarning):
187    """Issued once per usage of a deprecated API."""
188
189
190class SAWarning(RuntimeWarning):
191    """Issued at runtime."""
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。