Good way to multiple access SQL
Sorry if my question is too simple but I ask me what is the good way to multiple access SQL.
My Qt software:
1- Load data in class and display in widget
2- User can changes data and Update SQL through the class.
But in multiple access case:
1- USER 1 Load data in class and display in widget
2- USER 2 Load data in class and display in widget
3- USER 1 makes some data changes and Update SQL through the class.
4- USER 2 makes some data changes and Update SQL through the class.
-> Error: the changements of USER 1 are erased by USER 2 without message or other.
How to do this ? Thanks
In the case of SQLITE or MYSQL ?
If all users access the database only through your application you can have them notify one another of changes via QTcpSocket otherwise before submitting any change you need to perform a select and check that the value was not altered in the meantime
Check out QSqlDriver's notification capability. From personal experience it works well with Postgresql. I would assume that it works with MySQL, perhaps even SQLite. It is dependent on the driver implementation though.
check hasFeature() but I doubt SQLite has QSqlDriver::EventNotifications
qDebug() << "driver EventNotifications: " << sdlDrv->hasFeature(QSqlDriver::EventNotifications);
-> driver EventNotifications: false
Arf, so I must make it manually ? by QTcpSocket or internally by an flag ?
I'm afraid so
Use the original data as a where clause for the
updatestatement. This way if the data has changed in the meantime you can know, and show a message to the user, even suggest him a reload.
@kshegunov This, complicates the SQL requests...
That may be, but guarantees consistency! In any case there isn't another reliable way to do it, beside writing your own application server.
Ok, many thanks at All!