#include #include #include #include #include #include "Field.h" Field::Field(QWidget *parent, int db_id, int PropId, int BacType, QString label) { this->parent = parent; this->PropId = PropId; this->BacType = BacType; this->db_id = db_id; this->label = (label == QString()) ? NULL : new QLabel(label); } QWidget *Field::Input() { return input; } QWidget *Field::Label() { return label; } QVariant Field::Value() { return value; } void Field::SaveToDB(QSqlDatabase *dbh) { QSqlQuery insert(*dbh); QSqlQuery update(*dbh); int length = calculateLength(); update.prepare("UPDATE property SET prop_val = :value, prop_size = :length WHERE prop_id = :id AND object = :obj_id"); update.bindValue(":value", value); update.bindValue(":length", length); update.bindValue(":id", PropId); update.bindValue(":obj_id", db_id); update.exec(); if(update.numRowsAffected() == 0) { insert.prepare("INSERT INTO property (object, prop_id, prop_val, prop_size, prop_type, readable, writable) " "VALUES(:obj_id, :id, :value, :length, :type, 1, 1)"); insert.bindValue(":id", PropId); insert.bindValue(":obj_id", db_id); insert.bindValue(":value", value); insert.bindValue(":length", length); insert.bindValue(":type", BacType); insert.exec(); } }