Home | History | Annotate | Download | only in afe
      1 from django.db.backends.mysql.base import DatabaseCreation as MySQLCreation
      2 from django.db.backends.mysql.base import DatabaseOperations as MySQLOperations
      3 from django.db.backends.mysql.base import DatabaseWrapper as MySQLDatabaseWrapper
      4 from django.db.backends.mysql.base import DatabaseIntrospection as MySQLIntrospection
      5 
      6 try:
      7     import MySQLdb as Database
      8 except ImportError, e:
      9     from django.core.exceptions import ImproperlyConfigured
     10     raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
     11 
     12 
     13 class DatabaseOperations(MySQLOperations):
     14     compiler_module = "autotest_lib.frontend.db.backends.afe.compiler"
     15 
     16 
     17 class 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