[int(11)]idteeth,
[int(11)]patients_idpatient,
[int(11)]location,
[float]screw_start_x,
[float]screw_start_y,
[float]screw_start_z,
[float]screw_end_x,
[float]screw_end_y,
[float]screw_end_z,
[float]center_x,
[float]center_y,
[float]center_z,
[int(11)]screws_idscrews,
[mediumblob]screwPolyTransform,
[int(1)]isEditedByDentist,
[int(1)]isCustomImplant
[int(11)]idteeth,
[int(11)]patients_idpatient,
[int(11)]location,
[float]screw_start_x,
[float]screw_start_y,
[float]screw_start_z,
[float]screw_end_x,
[float]screw_end_y,
[float]screw_end_z,
[float]center_x,
[float]center_y,
[float]center_z,
[int(11)]screws_idscrews,
[mediumblob]screwPolyTransform,
[int(1)]isEditedByDentist,
[int(1)]isCustomImplant
To copy to clipboard, switch view to plain text mode
//database driver set to MySQL
//SQL Server details.
db.setHostName(_TARGET_SERVER_SQL_HOST_);
db.
setPort(QString(_TARGET_SERVER_SQL_PORT_
).
toInt());
db.setDatabaseName(_TARGET_SERVER_SQL_DB_);
db.setUserName(_TARGET_SERVER_SQL_USER_);
db.setPassword(_TARGET_SERVER_SQL_PASS_);
if(db.open())
{
//db opened successfully
teeth_count = currentPatientRecord->getImplantsCount();
//repeat the UPDATE query for all the patient's implants and while there is no error
while(i < teeth_count && isQuerySuccess)
{
current_tooth = currentPatientRecord->getTeethList()->at(i);
//update only the records of implants with complete specifications
if(current_tooth->isScrewTypeSet())
{
//if the implant has no record in the database then create one by issuing an INSERT query
//otherwise simply update the existing record
if(!current_tooth->getHasDatabaseRecord())
{
query.prepare("INSERT INTO teeth "
"(patients_idpatient, location, screw_start_x, screw_start_y, screw_start_z, "
"screw_end_x, screw_end_y, screw_end_z, center_x, center_y, center_z, "
"screws_idscrews, screwPolyTransform, isEditedByDentist, isCustomImplant) "
"VALUES (:id_patient, :dentist_location_id, :screwSx, :screwSy, :screwSz, "
":screwEx, :screwEy, :screwEz, :screwCx, :screwCy, :screwCz, :screw_type_id, "
":screwPolyTransformStream, :is_edited_by_dentist, :is_custom)");
//bind values which are exclusive to the INSERT query
query.bindValue(":dentist_location_id",(int)current_tooth->getLocationID());
}
else
{
query.prepare("UPDATE teeth SET screw_start_x=:screwSx, screw_start_y=:screwSy, screw_start_z=:screwSz, "
"screw_end_x=:screwEx, screw_end_y=:screwEy, screw_end_z=:screwEz, center_x=:screwCx, "
"center_y=:screwCy, center_z=:screwCz, screws_idscrews=:screw_type_id, "
"screwPolyTransform=:screwPolyTransformStream, isEditedByDentist=:is_edited_by_dentist "
"WHERE idteeth=:tooth_uid_db AND patients_idpatient=:id_patient");
//bind values which are exclusive to the UPDATE query
query.bindValue(":tooth_uid_db",current_tooth->getTeethID());
}
//bind values which are shared between the INSERT and UPDATE query
query.bindValue(":screwSx",(float)current_tooth->getScrewStart_x_mm());
query.bindValue(":screwSy",(float)current_tooth->getScrewStart_y_mm());
query.bindValue(":screwSz",(float)current_tooth->getScrewStart_z_mm());
query.bindValue(":screwEx",(float)current_tooth->getScrewEnd_x_mm());
query.bindValue(":screwEy",(float)current_tooth->getScrewEnd_y_mm());
query.bindValue(":screwEz",(float)current_tooth->getScrewEnd_z_mm());
query.bindValue(":screwCx",(float)current_tooth->getScrewCenter_x_mm());
query.bindValue(":screwCy",(float)current_tooth->getScrewCenter_y_mm());
query.bindValue(":screwCz",(float)current_tooth->getScrewCenter_z_mm());
query.bindValue(":screw_type_id",(int)current_tooth->getScrewTypeID()>0? current_tooth->getScrewTypeID():0);
query.bindValue(":is_edited_by_dentist",(int)current_tooth->isScrewTypeSet());
query.bindValue(":is_custom",(int)current_tooth->getIsCustomImplant());
query.bindValue(":id_patient",(int)currentPatientRecord->getPatientsID());
query.bindValue(":screwPolyTransformStream",qmatrixBA); //qmatrixBA is a QByteArray
if(!query.exec())
{
//query unsuccessful
isQuerySuccess = false;
error_message = "Database Text: " + db.lastError().databaseText()
+ ",Driver Text: " + db.lastError().driverText();
emit error(error_message);
emit finished(isQuerySuccess);
}
//----------------------------------------------------------------------------//
//The following code prints the executed query with the variables replaced by actual values
QMapIterator<QString, QVariant> it(query.boundValues());
while (it.hasNext())
{
it.next();
str.replace(it.key(), it.value().toString());
}
qDebug()<<str;
//----------------------------------------------------------------------------//
}
i++;
}
//if we reached this point then all the queries have been executed without error
emit finished(isQuerySuccess);
db.close();
}
else
{
//db failed to open
isQuerySuccess = false;
error_message = "Database Text: " + db.lastError().databaseText()
+ "Driver Text: " + db.lastError().driverText();
emit error(error_message);
emit finished(isQuerySuccess);
}
//database driver set to MySQL
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
QSqlQuery query;
//SQL Server details.
db.setHostName(_TARGET_SERVER_SQL_HOST_);
db.setPort(QString(_TARGET_SERVER_SQL_PORT_).toInt());
db.setDatabaseName(_TARGET_SERVER_SQL_DB_);
db.setUserName(_TARGET_SERVER_SQL_USER_);
db.setPassword(_TARGET_SERVER_SQL_PASS_);
if(db.open())
{
//db opened successfully
teeth_count = currentPatientRecord->getImplantsCount();
//repeat the UPDATE query for all the patient's implants and while there is no error
while(i < teeth_count && isQuerySuccess)
{
current_tooth = currentPatientRecord->getTeethList()->at(i);
//update only the records of implants with complete specifications
if(current_tooth->isScrewTypeSet())
{
//if the implant has no record in the database then create one by issuing an INSERT query
//otherwise simply update the existing record
if(!current_tooth->getHasDatabaseRecord())
{
query.prepare("INSERT INTO teeth "
"(patients_idpatient, location, screw_start_x, screw_start_y, screw_start_z, "
"screw_end_x, screw_end_y, screw_end_z, center_x, center_y, center_z, "
"screws_idscrews, screwPolyTransform, isEditedByDentist, isCustomImplant) "
"VALUES (:id_patient, :dentist_location_id, :screwSx, :screwSy, :screwSz, "
":screwEx, :screwEy, :screwEz, :screwCx, :screwCy, :screwCz, :screw_type_id, "
":screwPolyTransformStream, :is_edited_by_dentist, :is_custom)");
//bind values which are exclusive to the INSERT query
query.bindValue(":dentist_location_id",(int)current_tooth->getLocationID());
}
else
{
query.prepare("UPDATE teeth SET screw_start_x=:screwSx, screw_start_y=:screwSy, screw_start_z=:screwSz, "
"screw_end_x=:screwEx, screw_end_y=:screwEy, screw_end_z=:screwEz, center_x=:screwCx, "
"center_y=:screwCy, center_z=:screwCz, screws_idscrews=:screw_type_id, "
"screwPolyTransform=:screwPolyTransformStream, isEditedByDentist=:is_edited_by_dentist "
"WHERE idteeth=:tooth_uid_db AND patients_idpatient=:id_patient");
//bind values which are exclusive to the UPDATE query
query.bindValue(":tooth_uid_db",current_tooth->getTeethID());
}
//bind values which are shared between the INSERT and UPDATE query
query.bindValue(":screwSx",(float)current_tooth->getScrewStart_x_mm());
query.bindValue(":screwSy",(float)current_tooth->getScrewStart_y_mm());
query.bindValue(":screwSz",(float)current_tooth->getScrewStart_z_mm());
query.bindValue(":screwEx",(float)current_tooth->getScrewEnd_x_mm());
query.bindValue(":screwEy",(float)current_tooth->getScrewEnd_y_mm());
query.bindValue(":screwEz",(float)current_tooth->getScrewEnd_z_mm());
query.bindValue(":screwCx",(float)current_tooth->getScrewCenter_x_mm());
query.bindValue(":screwCy",(float)current_tooth->getScrewCenter_y_mm());
query.bindValue(":screwCz",(float)current_tooth->getScrewCenter_z_mm());
query.bindValue(":screw_type_id",(int)current_tooth->getScrewTypeID()>0? current_tooth->getScrewTypeID():0);
query.bindValue(":is_edited_by_dentist",(int)current_tooth->isScrewTypeSet());
query.bindValue(":is_custom",(int)current_tooth->getIsCustomImplant());
query.bindValue(":id_patient",(int)currentPatientRecord->getPatientsID());
query.bindValue(":screwPolyTransformStream",qmatrixBA); //qmatrixBA is a QByteArray
if(!query.exec())
{
//query unsuccessful
isQuerySuccess = false;
error_message = "Database Text: " + db.lastError().databaseText()
+ ",Driver Text: " + db.lastError().driverText();
emit error(error_message);
emit finished(isQuerySuccess);
}
//----------------------------------------------------------------------------//
//The following code prints the executed query with the variables replaced by actual values
QString str = query.lastQuery();
QMapIterator<QString, QVariant> it(query.boundValues());
while (it.hasNext())
{
it.next();
str.replace(it.key(), it.value().toString());
}
qDebug()<<str;
//----------------------------------------------------------------------------//
}
i++;
}
//if we reached this point then all the queries have been executed without error
emit finished(isQuerySuccess);
db.close();
}
else
{
//db failed to open
isQuerySuccess = false;
error_message = "Database Text: " + db.lastError().databaseText()
+ "Driver Text: " + db.lastError().driverText();
emit error(error_message);
emit finished(isQuerySuccess);
}
To copy to clipboard, switch view to plain text mode
Bookmarks