-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDuplicateChecker.py
31 lines (24 loc) · 1.14 KB
/
DuplicateChecker.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
import mysql.connector as mysql
from FakeDataGenerator import generate_regular_fake_data
import mysql.connector as mysql
import random
# Function to check and remove Duplicate entries
def checker(connection, config, table_name, table_data, column_name, fake_data, column_info):
cursor = connection.cursor()
query = f"SELECT {column_name} FROM {table_name} WHERE {column_name} = %s"
cursor.execute(query, (fake_data,))
result = cursor.fetchall()
values = [row[0] for row in result]
while fake_data in values:
fake_data = generate_regular_fake_data(column_name, column_info)
return fake_data
# Function to check and remove Duplicate entries in foreign key
def checkerForForeignKey(connection, config, table_name, table_data, column_name, fake_data, column_info, referenced_table, referenced_column, values):
cursor = connection.cursor()
query = f"SELECT {column_name} FROM {table_name} WHERE {column_name} = %s"
cursor.execute(query, (fake_data,))
result = cursor.fetchall()
values1 = [row[0] for row in result]
while fake_data in values1:
fake_data = random.choice(values)[0]
return fake_data