-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_uid.py
70 lines (53 loc) · 2.3 KB
/
create_uid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
############################################################
# Create unique id to the tables after XML Import
#
# XML_Phone_Book_Database
#
## Author (Pseudonym): Hermann12; Date: 10.01.2021
############################################################
import sqlite3
def create_uniqueid(db_file):
# If the uniqueid is empty, generate one
connection = sqlite3.connect(db_file)
print(f"Database connected")
print(f"Version {sqlite3.version}")
print(f"SQLITE_VERSION (Library) {sqlite3.sqlite_version}")
connection.row_factory = lambda cursor, row: row[0]
cursor = connection.cursor()
sql1 = "SELECT uniqueid FROM contacts;"
unique_id = cursor.execute(sql1).fetchall()
cursor.execute("SELECT count(*) from contacts")
result = cursor.fetchone()
print("DB count function:", result)
check_sum = []
for row in unique_id:
# print(type(row))
check_sum.append(row)
# print("Unique_id:",row)
# print(check_sum)
Sum = sum(check_sum)
print(f'Sum of Check: {Sum}')
if Sum == 0:
print(len(check_sum))
sql2 =('UPDATE contacts SET uniqueid=rowid;')
cursor.execute(sql2)
connection.commit()
else:
print("Uniqueid is not empty")
cursor.execute('UPDATE numbers SET uniqueid =(SELECT uniqueid FROM contacts WHERE contacts.realName = numbers.realName);')
connection.commit()
cursor.execute('UPDATE emails SET uniqueid =(SELECT uniqueid FROM contacts WHERE contacts.realName = emails.realName);')
connection.commit()
cursor.execute('UPDATE address SET uniqueid =(SELECT uniqueid FROM contacts WHERE contacts.realName = address.realName);')
connection.commit()
cursor.execute('UPDATE birthday SET uniqueid =(SELECT uniqueid FROM contacts WHERE contacts.realName = birthday.realName);')
connection.commit()
cursor.execute('UPDATE note SET uniqueid =(SELECT uniqueid FROM contacts WHERE contacts.realName = note.realName);')
connection.commit()
connection.close()
print('Process finished, database closed!')
if __name__ == '__main__':
""" Input XML file definition """
# db_file = "04_Fritz_Phonebook.db"
# create_uniqueid(db_file)
print('Finished')