• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from django.db.backends.mysql.base import DatabaseCreation as MySQLCreation
2from django.db.backends.mysql.base import DatabaseOperations as MySQLOperations
3from django.db.backends.mysql.base import DatabaseWrapper as MySQLDatabaseWrapper
4from django.db.backends.mysql.base import DatabaseIntrospection as MySQLIntrospection
5
6try:
7    import MySQLdb as Database
8except ImportError, e:
9    from django.core.exceptions import ImproperlyConfigured
10    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
11
12
13class DatabaseOperations(MySQLOperations):
14    compiler_module = "autotest_lib.frontend.db.backends.afe.compiler"
15
16
17class DatabaseWrapper(MySQLDatabaseWrapper):
18    def __init__(self, *args, **kwargs):
19        self.connection = None
20        super(DatabaseWrapper, self).__init__(*args, **kwargs)
21        self.creation = MySQLCreation(self)
22        try:
23            self.ops = DatabaseOperations()
24        except TypeError:
25            self.ops = DatabaseOperations(connection=kwargs.get('connection'))
26        self.introspection = MySQLIntrospection(self)
27
28    def _valid_connection(self):
29        if self.connection is not None:
30            if self.connection.open:
31                try:
32                    self.connection.ping()
33                    return True
34                except Database.DatabaseError:
35                    self.connection.close()
36                    self.connection = None
37        return False
38