class MainWindow(QMainWindow, Auth):
def init(self):
super(MainWindow, self).init()
self.ui_auth = Auth()
self.ui_auth.setupUi(self)
self.ui_auth.pushButton.clicked.connect(self.__connection_bd)

def __connection_bd(self):
try:
self.bd = pymysql.connect(host=“mysql81.hostland.ru”, port=3306, user=self.ui_auth.lineEdit.text(), passwd=self.ui_auth.lineEdit_2.text(), database=“host1859239_naus”)
# self.bd = 2
Dialog_msg(self).set_text(text=‘Подключение к БД - Успешно’, flag=True)
except Exception as error:
Dialog_msg(self).set_text(text=f’{error}‘, flag=False)

def cursor_execute(self, text):
self.bd.cursor.execute(text)

def write_in_bd_temp(self, sql):
try:
self.bd.cursor().execute(sql)
except Exception as e:
print(e)
self.bd.rollback()
raise e

def get_in_bd(self, sql):
self.bd.cursor().execute(sql)
return self.bd.fetchall()

class Dialog_select_option(QDialog, select_option):
def init(self, parent=None):
QDialog.init(self, parent)
self.ui_select_option = select_option()
self.ui_select_option.setupUi(self)
self.setModal(True)
self.setVisible(True)
self.main_window = window
self.ui_select_option.pushButton.clicked.connect(self.register_student)
self.ui_select_option.pushButton_2.clicked.connect(self.ball_in_protocol)

def register_student(self):
self.main_window.get_cursor()
self.main_window.cursor_execute(‘BEGIN’)
for row_number in range(len(data_student)):
sql = f"""INSERT INTO mdl_user (username, mdl_user.password, lastname, firstname, email, confirmed, mnethostid, lang, timezone, timecreated, timemodified)
VALUES (’{data_student[‘username’][row_number]}‘, MD5({data_student[‘password’][row_number]}), ‘{data_student[‘lastname’][row_number]}’, ‘{data_student[‘firstname’][row_number]}’,
‘{data_student[‘email’][row_number]}’, 1, 1, ‘ru’, ‘99’, ‘UNIX_TIMESTAMP(now()’, ‘UNIX_TIMESTAMP(now()’)“”“
self.main_window.write_in_bd_temp(sql=sql)
sql = f”""INSERT INTO mdl_user_enrolments (enrolid, userid, timestart, modifierid)
VALUES ((SELECT id FROM mdl_enrol WHERE enrol = ‘manual’ and courseid = (SELECT id FROM mdl_course WHERE shortname = ‘{data_student[‘course1’][row_number]}’)),
(SELECT id from mdl_user where username=’{data_student[‘username’][row_number]}‘), UNIX_TIMESTAMP(), 11)“”“
self.main_window.write_in_bd_temp(sql=sql)
sql = f”""INSERT INTO mdl_role_assignments (roleid, contextid, userid, timemodified)
VALUES (
(SELECT id FROM mdl_role WHERE shortname = ‘student’),
(SELECT id FROM mdl_context WHERE contextlevel = 50 AND instanceid = (SELECT id FROM mdl_course WHERE shortname = ‘{data_student[‘course1’][row_number]}’)),
(SELECT id FROM mdl_user WHERE username=’{data_student[‘username’][row_number]}),
UNIX_TIMESTAMP())“”“
self.main_window.write_in_bd_temp(sql=sql)
sql = f”““INSERT INTO mdl_groups (courseid, name, description, descriptionformat, enrolmentkey, timecreated, timemodified)
VALUES ((SELECT id FROM mdl_course WHERE shortname = ‘{data_student[‘course1’][row_number]}’), ‘{data_student[‘group1’][row_number]}’, ‘’, 1, ‘’, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())””“
self.main_window.write_in_bd_temp(sql=sql)
sql = f”““INSERT INTO mdl_groups_members (groupid, userid, timeadded, component)
VALUES ((select id from mdl_groups where name=‘{data_student[‘group1’][row_number]}’), (SELECT id from mdl_user where username=‘{data_student[‘username’][row_number]}’), UNIX_TIMESTAMP(), ‘’)””“
self.main_window.write_in_bd_temp(sql=sql)
for row_number in range(len(data_student)):
sql=f’select * from mdl_user where username=”{data_student[‘username’][row_number]}"'
print(self.main_window.get_in_bd(sql))
self.main_window.write_in_bd_temp(sql=sql)
self.main_window.cursor_execute(‘COMMIT’)

if name == “main”:
app = QApplication(sys.argv)

window = MainWindow()
window.show()

sys.exit(app.exec())

У меня к тебе вопрос. Я тебе представил код на python. Блок if name не трогать. Он неизменяемый. Как отработает запросы к бд в цикле for row_number in range(len(data_student))? Прервется ли код, если возникнет ошибка при выполнении sql кода? На отступы не смотри