在尝试插入之前在数据库中查找现有条目
Look for existing entry in database before trying to insert
我目前正在使用 Access 2013。我已经建立了一个围绕提交工作的申请人的数据库。数据库的设置使一个人可以申请许多不同的工作,当同一个人通过我们的网站(使用 JotForms)申请工作时,它会自动更新数据库。
我有一个 Python 脚本从更新数据库的电子邮件中提取申请人的提交信息。我 运行 遇到的问题是在数据库中我将申请人的主要电子邮件设置为 "no duplicates",因此不允许同一个人申请许多不同的工作作为 Python 脚本正在尝试在导致错误的数据库中创建新记录。
在我的 Access 表单 (VBA) 或 Python 中,我需要写什么来告诉我的数据库,如果主要电子邮件相同,只能在申请的职位内创建一条新记录table 与此人的主要电子邮件相关?
表格:
tblPerson_Information tblPosition_Applied_for
Personal_ID (PK) Position_ID
First_Name Position_Personal_ID (FK)
Last_Name Date_of_Submission
Clearance_Type
Primary_Phone
Primary_email
Education_Level
只需在 [tblPerson_Information] table:
中查找电子邮件地址
primary_email = 'gord@example.com' # test data
crsr = conn.cursor()
sql = """\
SELECT Personal_ID FROM tblPerson_Information WHERE Primary_email=?
"""
crsr.execute(sql, (primary_email))
row = crsr.fetchone()
if row is not None:
personal_id = row[0]
print('Email found: tblPerson_Information.Personal_ID = {0}'.format(personal_id))
else:
print('Email not found in tblPerson_Information')
我目前正在使用 Access 2013。我已经建立了一个围绕提交工作的申请人的数据库。数据库的设置使一个人可以申请许多不同的工作,当同一个人通过我们的网站(使用 JotForms)申请工作时,它会自动更新数据库。
我有一个 Python 脚本从更新数据库的电子邮件中提取申请人的提交信息。我 运行 遇到的问题是在数据库中我将申请人的主要电子邮件设置为 "no duplicates",因此不允许同一个人申请许多不同的工作作为 Python 脚本正在尝试在导致错误的数据库中创建新记录。
在我的 Access 表单 (VBA) 或 Python 中,我需要写什么来告诉我的数据库,如果主要电子邮件相同,只能在申请的职位内创建一条新记录table 与此人的主要电子邮件相关?
表格:
tblPerson_Information tblPosition_Applied_for
Personal_ID (PK) Position_ID
First_Name Position_Personal_ID (FK)
Last_Name Date_of_Submission
Clearance_Type
Primary_Phone
Primary_email
Education_Level
只需在 [tblPerson_Information] table:
中查找电子邮件地址primary_email = 'gord@example.com' # test data
crsr = conn.cursor()
sql = """\
SELECT Personal_ID FROM tblPerson_Information WHERE Primary_email=?
"""
crsr.execute(sql, (primary_email))
row = crsr.fetchone()
if row is not None:
personal_id = row[0]
print('Email found: tblPerson_Information.Personal_ID = {0}'.format(personal_id))
else:
print('Email not found in tblPerson_Information')