findmissing: Find subsequent patches to fixes

It looks a bit silly if we are constantly submitting fixes for fixes if
know the subsequent patches before hand. Solution is to do an interative
lookup.

Note this solution is temporarily and will be replaced by
crrev.com/c/2208004 once the database supports CTEs.

BUG=None
TEST=Pass in known test SHA

Change-Id: Ia334b028378c9a8aa1aaebaf175369bc65dd73d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/2146069
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Commit-Queue: Curtis Malainey <cujomalainey@chromium.org>
Tested-by: Guenter Roeck <groeck@chromium.org>
diff --git a/contrib/findmissing/cloudsql_interface.py b/contrib/findmissing/cloudsql_interface.py
index f304692..7398a97 100755
--- a/contrib/findmissing/cloudsql_interface.py
+++ b/contrib/findmissing/cloudsql_interface.py
@@ -15,6 +15,25 @@
 
 DEFAULT_MERGED_REASON = 'Fix merged into linux chrome'
 
+
+def upstream_fixes_for_shas(db, upstream_shas):
+    """Returns list of fixer sha's for a given upstream sha.
+
+    TODO(*): remove this after build_ordered_fixes_table_map moved to SQL CTE
+    Note: above todo is blocked by migration to MySQL 5.7, once upgraded then we can switch
+    """
+    upstream_shas = ["\'" + sha + "\'" for sha in upstream_shas]
+    c = db.cursor()
+
+    # format string here since we are inserting n elements
+    q = """SELECT fixedby_upstream_sha
+            FROM upstream_fixes
+            WHERE upstream_sha IN ({})""".format(', '.join(upstream_shas))
+    c.execute(q)
+
+    return [a[0] for a in c.fetchall()]
+
+
 def get_fixes_table_primary_key(db, fixes_table, fix_change_id):
     """Retrieves the primary keys from a fixes table using changeid."""
     c = db.cursor(MySQLdb.cursors.DictCursor)