| 1 | Better reporting of installation issues related to PySqlite. |
|---|
| 2 | |
|---|
| 3 | Use the same mechanism as for errors on VCS connectors (r7435). |
|---|
| 4 | |
|---|
| 5 | Related to #8265. |
|---|
| 6 | |
|---|
| 7 | diff --git a/trac/db/api.py b/trac/db/api.py |
|---|
| 8 | --- a/trac/db/api.py |
|---|
| 9 | +++ b/trac/db/api.py |
|---|
| 10 | @@ -37,6 +37,10 @@ |
|---|
| 11 | def get_supported_schemes(): |
|---|
| 12 | """Return the connection URL schemes supported by the connector, and |
|---|
| 13 | their relative priorities as an iterable of `(scheme, priority)` tuples. |
|---|
| 14 | + |
|---|
| 15 | + If `priority` is a negative number, this is indicative of an |
|---|
| 16 | + error condition with the connector. An error message should be |
|---|
| 17 | + attached to the `error` attribute of the connector. |
|---|
| 18 | """ |
|---|
| 19 | |
|---|
| 20 | def get_connection(path, log=None, **kwargs): |
|---|
| 21 | @@ -116,18 +120,17 @@ |
|---|
| 22 | |
|---|
| 23 | def _get_connector(self): ### FIXME: Make it public? |
|---|
| 24 | scheme, args = _parse_db_str(self.connection_uri) |
|---|
| 25 | - candidates = {} |
|---|
| 26 | + candidates = [] |
|---|
| 27 | for connector in self.connectors: |
|---|
| 28 | for scheme_, priority in connector.get_supported_schemes(): |
|---|
| 29 | if scheme_ != scheme: |
|---|
| 30 | continue |
|---|
| 31 | - highest = candidates.get(scheme_, (None, 0))[1] |
|---|
| 32 | - if priority > highest: |
|---|
| 33 | - candidates[scheme] = (connector, priority) |
|---|
| 34 | - |
|---|
| 35 | - connector = candidates.get(scheme, [None])[0] |
|---|
| 36 | - if not connector: |
|---|
| 37 | + candidates.append((priority, connector)) |
|---|
| 38 | + if not candidates: |
|---|
| 39 | raise TracError('Unsupported database type "%s"' % scheme) |
|---|
| 40 | + priority, connector = max(candidates) |
|---|
| 41 | + if priority < 0: |
|---|
| 42 | + raise TracError(connector.error) |
|---|
| 43 | |
|---|
| 44 | if scheme == 'sqlite': |
|---|
| 45 | # Special case for SQLite to support a path relative to the |
|---|
| 46 | diff --git a/trac/db/sqlite_backend.py b/trac/db/sqlite_backend.py |
|---|
| 47 | --- a/trac/db/sqlite_backend.py |
|---|
| 48 | +++ b/trac/db/sqlite_backend.py |
|---|
| 49 | @@ -22,6 +22,7 @@ |
|---|
| 50 | from trac.db.api import IDatabaseConnector |
|---|
| 51 | from trac.db.util import ConnectionWrapper |
|---|
| 52 | from trac.util import get_pkginfo, getuser |
|---|
| 53 | +from trac.util.translation import _ |
|---|
| 54 | |
|---|
| 55 | _like_escape_re = re.compile(r'([/_%])') |
|---|
| 56 | |
|---|
| 57 | @@ -112,9 +113,18 @@ |
|---|
| 58 | |
|---|
| 59 | def __init__(self): |
|---|
| 60 | self._version = None |
|---|
| 61 | + self.error = None |
|---|
| 62 | |
|---|
| 63 | def get_supported_schemes(self): |
|---|
| 64 | - return [('sqlite', 1)] |
|---|
| 65 | + if not have_pysqlite: |
|---|
| 66 | + self.error = _("Coudn't load Python bindings for SQLite") |
|---|
| 67 | + elif sqlite.sqlite_version_info >= (3, 3, 3): |
|---|
| 68 | + if sqlite.version_info < (1, 0, 7): |
|---|
| 69 | + self.error = _("Need at least PySQlite 1.0.7 or higher") |
|---|
| 70 | + elif sqlite.version_info[0] == 2 and \ |
|---|
| 71 | + sqlite.version_info < (2, 0, 7): |
|---|
| 72 | + self.error = _("Need at least PySqlite 2.0.7 or higher") |
|---|
| 73 | + yield ('sqlite', self.error and -1 or 1) |
|---|
| 74 | |
|---|
| 75 | def get_connection(self, path, log=None, params={}): |
|---|
| 76 | if not self._version: |
|---|