[PyQt] Going multiuser with QSqlRelationalTableModel
J Barchan
jnbarchan at gmail.com
Sat Mar 31 20:37:22 BST 2018
On 31 March 2018 at 14:02, Ricardo Araoz <ricaraoz at gmail.com> wrote:
> On 31/03/18 12:37, J Barchan wrote:
>
>
>
> On 30 March 2018 at 16:48, Ricardo Araoz <ricaraoz at gmail.com> wrote:
>
>> Are there any methods for multiuser database programming while working
>> with models and mappers? I mean, something to lock/unlock records and/or
>> tables (not talking about transactions) and something that will tell me
>> when saving if the database records to be updated have been changed since
>> the model read them.
>>
>> TIA
>>
>
> Hi Ricardo,
>
> I am not a PyQt expert person --- just someone using it.
>
> I would say basically "no".
>
> QSqlRelationalTableModel is just a thin layer over QSqlTableModel, and
> that's just QSqlTableQuery/QSqlQuery with some support for putting it in
> a table and allowing you to specify INSERT/DELETE/UPDATE commands. Other
> than that you're really on your own to add your own stuff.
>
> The usual way to handle "multiuser" is to make your DELETE/UPDATE statements
> do *optimistic *updates, i.e. you add a WHERE clause to verify all the
> values in the database are the same as when you read the row in, else
> someone else has changed it and then you error. That's instead of
> *pessimistic* locking, where you lock the row when you read it, which
> doesn't scale. You could implement these yourself.
>
> Otherwise, this isn't a PyQt/Python question, so if you want to discuss in
> detail or see if Qt experts have more to offer than I have you might like
> to join up to https://forum.qt.io/ and come pose your question there.
>
> --
> Kindest,
> Jonathan
>
>
> Hi Jonathan, thanks for your answer. I know I could do it by myself, But
> I'd be missing the automatic behaviour implemented by the
> model/view/delegate schema. I'm now thinking about subclassing the model
> and implementing something in the submit and submitAll methods.
> Cheers
> Ricardo
>
>
But I'd be missing the automatic behaviour implemented by the
> model/view/delegate schema
>
Why would you be missing any of this?
I'm now thinking about subclassing the model and implementing something in
> the submit and submitAll methods
Yes, in case I wasn't clear, of course you should not throw away anything
like the QSqlRelationalTableModel level. You would use that and write
your own sub-classes/super-classes/wrappers to add the functionality you
want on top of what is already there, not replacing it. The approaches I
was suggesting would be in that vein. But my point is you do need to
write the new stuff yourself, unless you can find anything which does this
for you, which I am not aware of.
I have been thinking for a while I'd quite like to add something of a "
QSqlDataSet" class/level to Qt to encapsulate the relationships between
multiple QSqlRelationalTableModels, and so much more. Do you think that
would be a good idea?
--
Kindest,
Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180331/0b1ba461/attachment-0001.html>
More information about the PyQt
mailing list