简体   繁体   English

如何在 Qt 中一次插入多个查询到 sql?

[英]How in Qt i can insert several queries into sql in one time?

In SQL, I have foreign keys in tables so my insert one by one doesn't work.在 SQL 中,我在表中有外键,所以我一个一个地插入不起作用。 How can I insert several queries in one time?如何一次插入多个查询?

query.prepare("ISERT INTO job_format (job_format_id, location, work_schedule)"
              "VALUES (:job_format_idValue, :locationValue, :work_scheduleValue)");
query.bindValue(":job_format_idValue", lastJobFormat + 1);
query.bindValue(":locationValue", ui->tableWidgetData->item(i,4)->text());
query.bindValue(":work_scheduleValue", ui->tableWidgetData->item(i,3)->text());
query.exec();

query.prepare("INSERT INTO vacancy (vacancy_id, salary, company_id, profession, job_format, contacts, experience) "
              "VALUES (:vacancy_idValue, :salaryValue, :company_idValue, :professionValue, :job_formatValue, :contactsValue, :experienceValue)");
query.bindValue(":vacancy_idValue", lastVacancy + 1);
query.bindValue(":salaryValue", ui->tableWidgetData->item(i,5)->text());
query.bindValue(":company_idValue", currentID);
query.bindValue(":professionValue", ui->tableWidgetData->item(i,0)->text());
query.bindValue(":job_formatValue", lastJobFormat + 1);
query.bindValue(":contactsValue", ui->tableWidgetData->item(i,6)->text());
query.bindValue(":experienceValue", ui->tableWidgetData->item(i,1)->text());
query.exec();

query.prepare("INSERT INTO skills_for_vacancy (line_skills_for_vacancy_id, vacancy_id, skill) "
              "VALUES (:line_skills_for_vacancy_idValue, :vacancy_idValue, :skill)");
query.bindValue(":line_skills_for_vacancy_idValue", lastLineSkill + 1);
query.bindValue(":vacancy_idValue", lastVacancy + 1);
query.bindValue(":skill", tableSkillsMas[i]);
query.exec();

This is my foreign keys这是我的外键在此处输入图像描述

First line ISERT INTO not INSERT...第一行 ISERT INTO 不是 INSERT...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM