Rename the tables in the databases, by prefixing the app name. This is
in preparation for merging the two databases and the two Django
projects into one.

Note that this renames *all* standard Autotest DB tables in both the
autotest_web and tko databases.  If you have scripts written directly
against these databases, *they will break*.  If your scripts access
the RPC interfaces, they should continue to work.

Another patch will be along within the next few weeks to actually move
the TKO tables into the autotest_web database.

From: James Ren <jamesren@google.com>
Signed-off-by: Steve Howard <showard@google.com>

Rename the tables in the databases, by prefixing the app name. This is
in preparation for merging the two databases and the two Django projects
into one.

Note that this renames *all* standard Autotest DB tables in both the autotest_web and tko databases.  If you have scripts written directly against these databases, *they will break*.  If your scripts access the RPC interfaces, they should continue to work.

From: James Ren <jamesren@google.com>
Signed-off-by: Steve Howard <showard@google.com>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@4040 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/cli/query_results b/cli/query_results
index aa2c3f2..d872778 100755
--- a/cli/query_results
+++ b/cli/query_results
@@ -15,7 +15,7 @@
 parser = optparse.OptionParser()
 parser.add_option('-C', '--columns', action='store', dest='columns',
             default='*', help="""\
-By default or when using the -c flag: 
+By default or when using the -c flag:
 kernel hostname test label machine_group reason tag user status
 
 OR
@@ -50,11 +50,11 @@
 elif options.old_condition:
     where = query_lib.parse_scrub_and_gen_condition(
                 options.old_condition, frontend.test_view_field_dict)
-    view = 'test_view'
+    view = 'tko_test_view'
     tag = 'tag'
 elif options.new_condition:
     where = options.new_condition.replace('%', '%%')
-    view = 'test_view_2'
+    view = 'tko_test_view_2'
     tag = 'job_tag'
 else:
     parser.error('You must specify at least one condition.')
@@ -74,9 +74,9 @@
 if options.host_label:
     database = database_connection.DatabaseConnection("AUTOTEST_WEB")
     database.connect()
-    sql = ("SELECT hostname FROM labels JOIN hosts_labels "
-           "ON labels.id=hosts_labels.label_id JOIN hosts "
-           "ON hosts_labels.host_id=hosts.id WHERE name=%s")
+    sql = ("SELECT hostname FROM afe_labels JOIN afe_hosts_labels "
+           "ON afe_labels.id=afe_hosts_labels.label_id JOIN afe_hosts "
+           "ON afe_hosts_labels.host_id=afe_hosts.id WHERE name=%s")
     results = database.execute(sql, options.host_label)
     hosts = [row[0] for row in results]
     where += " AND hostname IN ('" + "','".join(hosts) + "')"