2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
10 from autofill_merge_common import SerializeProfiles, ColumnNameToFieldType
14 """Serializes the autofill_profiles table from the specified database."""
16 if len(sys.argv) != 2:
17 print "Usage: python serialize_profiles.py <path/to/database>"
20 database = sys.argv[1]
21 if not os.path.isfile(database):
22 print "Cannot read database at \"%s\"" % database
25 # Read the autofill_profile_names table.
27 connection = sqlite3.connect(database, 0)
28 cursor = connection.cursor()
29 cursor.execute("SELECT * from autofill_profile_names;")
30 except sqlite3.OperationalError:
31 print ("Failed to read the autofill_profile_names table from \"%s\"" %
35 # For backward-compatibility, the result of |cursor.description| is a list of
36 # 7-tuples, in which the first item is the column name, and the remaining
38 types = [ColumnNameToFieldType(item[0]) for item in cursor.description]
40 for profile in cursor:
42 profiles[guid] = zip(types, profile)
44 # Read the autofill_profile_emails table.
46 cursor.execute("SELECT * from autofill_profile_emails;")
47 except sqlite3.OperationalError:
48 print ("Failed to read the autofill_profile_emails table from \"%s\"" %
52 types = [ColumnNameToFieldType(item[0]) for item in cursor.description]
53 for profile in cursor:
55 profiles[guid].extend(zip(types, profile))
57 # Read the autofill_profiles table.
59 cursor.execute("SELECT * from autofill_profiles;")
60 except sqlite3.OperationalError:
61 print "Failed to read the autofill_profiles table from \"%s\"" % database
64 types = [ColumnNameToFieldType(item[0]) for item in cursor.description]
65 for profile in cursor:
67 profiles[guid].extend(zip(types, profile))
69 # Read the autofill_profile_phones table.
71 cursor.execute("SELECT * from autofill_profile_phones;")
72 except sqlite3.OperationalError:
73 print ("Failed to read the autofill_profile_phones table from \"%s\"" %
77 for profile in cursor:
79 profiles[guid].append(("PHONE_HOME_WHOLE_NUMBER", profile[2]))
81 print SerializeProfiles(profiles.values())
85 if __name__ == '__main__':