Here is how my code looks:
bool
ProtocolRepository::update(const Protocol& protocol)
{
auto record = model->record(protocol.id);
if (record.isEmpty()) {
return false;
}
record.setValue("name", protocol.name);
record.setGenerated("name", false);
record.setGenerated("id", false);
if (!model->setRecord(protocol.id, record)) {
return false;
}
return model->submitAll();
}
Instead of changing protocols name setRecord
inserts same row with new id and default sql name.
Here is sql script of table creation:
CREATE TABLE IF NOT EXISTS protocols
(
id INTEGER PRIMARY KEY,
name TEXT NOT NULL DEFAULT UNKNOWN,
protocol_path TEXT NOT NULL DEFAULT UNKNOWN,
created_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
is_pinned NUMBER(1) NOT NULL DEFAULT FALSE,
execution_seconds INTEGER DEFAULT NULL
);
Using qt5, clang and sqlite db
I tried to do same thing but without setGenerated
method and then setRecord
just return false.
p.s. Record with such id exists and is not empty
protocol.id
was also 0 in this case. But anyway that was typo, thanks