issue dbo::ptr in member of a class
Added by Lamiel Toch almost 6 years ago
Hello,
I have 2 wapplications, a writer that write in a database and a reader which read the data modified.
The problem is that the reader does not see the modification.
May you help me, to solve this issue ?
Thanks in advance.
Best regards
Lamiel
_
#ifndef DEBUG_H
#define DEBUG_H
#include <Wt/WPushButton>
#include <Wt/WLineEdit>
#include <QDebug>
#include <Wt/WText>>
#include <Wt/WApplication>
#include "auth_model/Session.h"
//debug
void debugSaisies(QString tag, Session& session);
Wt::WApplication* createReaderApplication(const WEnvironment& env);
Wt::WApplication* createWriterApplication(const WEnvironment& env);
class ReaderApplication : public WApplication {
public:
ReaderApplication(const WEnvironment& environment) : WApplication(environment) {
Wt::WPushButton* bouton = new WPushButton("CLICK");
root()->addWidget(bouton);
bouton->clicked().connect(this, &ReaderApplication::onClick);
}
protected:
void onClick() {
dbo::Transaction transaction(session);
saisie = session.find<Saisies>().where("id = ?").bind(13184);
qDebug() << "readerApp" << QString::fromStdString(saisie->valeur);
transaction.commit();
root()->addWidget(new Wt::WText(WString::fromUTF8(" " + saisie->valeur)));
}
Session session;
dbo::ptr<Saisies> saisie;
};
class WriterApplication : public WApplication {
public:
WriterApplication(const WEnvironment& environment) : WApplication(environment) {
lineEdit = new WLineEdit();
root()->addWidget(lineEdit);
lineEdit->changed().connect(this, &WriterApplication::onClick);
}
protected:
Wt::WLineEdit* lineEdit;
void onClick() {
dbo::Transaction transaction(session);
saisie = session.find<Saisies>().where("id = ?").bind(13184);
saisie.modify()->valeur = lineEdit->text().toUTF8();
transaction.commit();
}
Session session;
dbo::ptr<Saisies> saisie;
};
#endif // DEBUG_H
Replies (1)
RE: issue dbo::ptr in member of a class - Added by Mark Petryk almost 6 years ago
Hi Lamiel,
It's a little hard for me to see your program flow, but it appears as if you have two separate applications running?
The 'saisie' object you have there is cache in RAM memory for each application. Once loaded, they are not checked on the disk again for updates. So, if you update one ptr instance on one WApplication instance, the second application instance is unaware of the change unless it re-reads what's on disk. You can 'purge' the ptr object from RAM cache by calling:
There are other methods as well.