PDA

View Full Version : Concurrent database access and QDataWidgetMapper?



cyberduck
5th December 2013, 11:58
Hello,

i have two database questions:

1.) Each user should sees a consistent view of the data. What have i to do
if two or more user have simultaneously access to my database?

2.) What are the right classes to set a QDataWidgetMapper for my database?

I have try to use QSqlTableModel, but the problem is, one dataset can include
data fom the table "Experiment", "Temperatur" and "Qualities". How can i get
a Model for the QDataWidgetMapper to handle this?

9838



QSqlTableModel *model = new QSqlTableModel();
model->setTable("Temperatur");
model->setFilter("ExperimentID=" + QString::number(ID));
model->select();

QDataWidgetMapper *mapper = new QDataWidgetMapper(this);
mapper->setModel(model);
mapper->setItemDelegate(new QSqlRelationalDelegate(this));
mapper->addMapping(min, model->fieldIndex("min"));
mapper->addMapping(max, model->fieldIndex("max"));
mapper->toFirst();




CREATE TABLE [Experiment]
(
[ExperimentID] integer NOT NULL PRIMARY KEY AUTOINCREMENT,
[Name] varchar (100) NOT NULL,
[Date] datetime NOT NULL DEFAULT '0000-00-00'
);


CREATE TABLE [Temperatur]
(
[ExperimentID] integer NOT NULL DEFAULT 0,
[min] integer DEFAULT 0,
[max] integer DEFAULT 0,
[average] integer DEFAULT 0,
...
);

CREATE TABLE[Qualities]
(
[ExperimentID] integer NOT NULL DEFAULT 0,
[material] integer DEFAULT 0,
[fuel] integer DEFAULT 0,
[container] integer DEFAULT 0,
...
);

anda_skoa
5th December 2013, 13:56
1.) Each user should sees a consistent view of the data. What have i to do
if two or more user have simultaneously access to my database?

You could poll the database for changes or use an out-of-band communication mechanism to notify other clients when changes have been made



2.) What are the right classes to set a QDataWidgetMapper for my database?

I have try to use QSqlTableModel, but the problem is, one dataset can include
data fom the table "Experiment", "Temperatur" and "Qualities". How can i get
a Model for the QDataWidgetMapper to handle this?


Using QSqlQueryModel with a query that gets the necessary data from all involved tables?


Cheers,
_

cyberduck
10th December 2013, 10:25
Hi,

thank you for the reply.

So far so good, i got a QSqlRecord from the QSqlQueryModel, but i cant write it back!

The QSqlQueryModel is read-only and i want change or insert data into the database. How can i do that?

Can you help me please?