summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlmr <lmr@592f7852-d20e-0410-864c-8624ca9c26a4>2011-06-22 21:37:21 +0000
committerlmr <lmr@592f7852-d20e-0410-864c-8624ca9c26a4>2011-06-22 21:37:21 +0000
commit7136ad2e3934d645fd2f19153c19de82eb6d4bd1 (patch)
tree183920e466ce547e05da6667c07d982f520c91cb
parent78249b98d69784e69c60bbffdee00f67cfa83ebf (diff)
Add Afe special SQLite based DB backend
For the database unittests, the same change made to support the method get_from_clause on the MySQL backend (see 5408) has to be made for the SQLite backend, as the unittests run under this very database engine. So we had to end up adding a new engine that supports this additional method on compiler, so we can fix the unittest autotest_lib.frontend.afe.rpc_interface_unittest Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com> git-svn-id: svn://test.kernel.org/autotest/trunk@5437 592f7852-d20e-0410-864c-8624ca9c26a4
-rw-r--r--frontend/db/backends/afe_sqlite/__init__.py0
-rw-r--r--frontend/db/backends/afe_sqlite/base.py15
-rw-r--r--frontend/db/backends/afe_sqlite/compiler.py33
-rw-r--r--frontend/db/backends/afe_sqlite/creation.py1
-rw-r--r--frontend/db/backends/afe_sqlite/introspection.py1
-rw-r--r--frontend/db/backends/afe_sqlite/validation.py1
-rw-r--r--frontend/setup_test_environment.py2
7 files changed, 52 insertions, 1 deletions
diff --git a/frontend/db/backends/afe_sqlite/__init__.py b/frontend/db/backends/afe_sqlite/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/frontend/db/backends/afe_sqlite/__init__.py
diff --git a/frontend/db/backends/afe_sqlite/base.py b/frontend/db/backends/afe_sqlite/base.py
new file mode 100644
index 00000000..49cfb04d
--- /dev/null
+++ b/frontend/db/backends/afe_sqlite/base.py
@@ -0,0 +1,15 @@
+"""
+Autotest frontend SQLite based compiler.
+"""
+from django.db.backends.sqlite3.base import DatabaseOperations as SQLiteDatabaseOperations
+from django.db.backends.sqlite3.base import DatabaseWrapper as SQLiteDatabaseWrapper
+
+
+class DatabaseOperations(SQLiteDatabaseOperations):
+ compiler_module = "autotest_lib.frontend.db.backends.afe_sqlite.compiler"
+
+
+class DatabaseWrapper(SQLiteDatabaseWrapper):
+ def __init__(self, *args, **kwargs):
+ super(DatabaseWrapper, self).__init__(*args, **kwargs)
+ self.ops = DatabaseOperations()
diff --git a/frontend/db/backends/afe_sqlite/compiler.py b/frontend/db/backends/afe_sqlite/compiler.py
new file mode 100644
index 00000000..a7e1dde6
--- /dev/null
+++ b/frontend/db/backends/afe_sqlite/compiler.py
@@ -0,0 +1,33 @@
+from django.db.models.sql import compiler
+from autotest_lib.frontend.afe.model_logic import _quote_name
+
+class SQLCompiler(compiler.SQLCompiler):
+ def get_from_clause(self):
+ from_, params = super(SQLCompiler, self).get_from_clause()
+
+ if hasattr(self.query, "_custom_joins"):
+ for join_dict in self.query._custom_joins:
+ from_.append('%s %s AS %s ON (%s)'
+ % (join_dict['join_type'],
+ _quote_name(join_dict['table']),
+ _quote_name(join_dict['alias']),
+ join_dict['condition']))
+ params.extend(join_dict['condition_values'])
+
+ return from_, params
+
+class SQLInsertCompiler(compiler.SQLInsertCompiler, SQLCompiler):
+ pass
+
+class SQLDeleteCompiler(compiler.SQLDeleteCompiler, SQLCompiler):
+ pass
+
+class SQLUpdateCompiler(compiler.SQLUpdateCompiler, SQLCompiler):
+ pass
+
+class SQLAggregateCompiler(compiler.SQLAggregateCompiler, SQLCompiler):
+ pass
+
+class SQLDateCompiler(compiler.SQLDateCompiler, SQLCompiler):
+ pass
+
diff --git a/frontend/db/backends/afe_sqlite/creation.py b/frontend/db/backends/afe_sqlite/creation.py
new file mode 100644
index 00000000..7b77e658
--- /dev/null
+++ b/frontend/db/backends/afe_sqlite/creation.py
@@ -0,0 +1 @@
+from django.db.backends.sqlite3.creation import *
diff --git a/frontend/db/backends/afe_sqlite/introspection.py b/frontend/db/backends/afe_sqlite/introspection.py
new file mode 100644
index 00000000..fc1e37cc
--- /dev/null
+++ b/frontend/db/backends/afe_sqlite/introspection.py
@@ -0,0 +1 @@
+from django.db.backends.sqlite3.introspection import *
diff --git a/frontend/db/backends/afe_sqlite/validation.py b/frontend/db/backends/afe_sqlite/validation.py
new file mode 100644
index 00000000..616d7d87
--- /dev/null
+++ b/frontend/db/backends/afe_sqlite/validation.py
@@ -0,0 +1 @@
+from django.db.backends.sqlite3.validation import *
diff --git a/frontend/setup_test_environment.py b/frontend/setup_test_environment.py
index 87e52483..658541c0 100644
--- a/frontend/setup_test_environment.py
+++ b/frontend/setup_test_environment.py
@@ -8,7 +8,7 @@ import common
# django.conf.settings.LazySettings is buggy and requires us to get something
# from it before we set stuff on it.
getattr(settings, 'DATABASE_ENGINE')
-settings.DATABASE_ENGINE = 'sqlite3'
+settings.DATABASE_ENGINE = 'autotest_lib.frontend.db.backends.afe_sqlite'
settings.DATABASE_NAME = ':memory:'
from django.db import connection