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 <[email protected]>
---
 frontend/db/backends/afe_sqlite/base.py          |   15 ++++++++++
 frontend/db/backends/afe_sqlite/compiler.py      |   32 ++++++++++++++++++++++
 frontend/db/backends/afe_sqlite/creation.py      |    1 +
 frontend/db/backends/afe_sqlite/introspection.py |    1 +
 frontend/db/backends/afe_sqlite/validation.py    |    1 +
 frontend/setup_test_environment.py               |    2 +-
 6 files changed, 51 insertions(+), 1 deletions(-)
 create mode 100644 frontend/db/backends/afe_sqlite/__init__.py
 create mode 100644 frontend/db/backends/afe_sqlite/base.py
 create mode 100644 frontend/db/backends/afe_sqlite/compiler.py
 create mode 100644 frontend/db/backends/afe_sqlite/creation.py
 create mode 100644 frontend/db/backends/afe_sqlite/introspection.py
 create mode 100644 frontend/db/backends/afe_sqlite/validation.py

diff --git a/frontend/db/backends/afe_sqlite/__init__.py 
b/frontend/db/backends/afe_sqlite/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/frontend/db/backends/afe_sqlite/base.py 
b/frontend/db/backends/afe_sqlite/base.py
new file mode 100644
index 0000000..49cfb04
--- /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 0000000..781a7c3
--- /dev/null
+++ b/frontend/db/backends/afe_sqlite/compiler.py
@@ -0,0 +1,32 @@
+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
\ No newline at end of file
diff --git a/frontend/db/backends/afe_sqlite/creation.py 
b/frontend/db/backends/afe_sqlite/creation.py
new file mode 100644
index 0000000..7b77e65
--- /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 0000000..fc1e37c
--- /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 0000000..616d7d8
--- /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 87e5248..658541c 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
-- 
1.7.5.4

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to