Results 1 to 4 of 4

Thread: Lock strategy

  1. #1
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    10

    Default Lock strategy

    Hello,

    I am using a QSqlTableModel and would like to have the following behaviour. If a user tries modify a record, we lock the record and if it was already locked (i. e. the lock fails) we issue an error message and prevent the user to edit the occurence.

    I could to it the hard way by trying to detect when the user starts editing a field and do a SELECT fOR UPDATE NOWAIT at that moment but it seems messy and I assume there must be a natural way to do so in Qt.

    So what would be the right way to do that in Qt?

    Thanks!

  2. #2
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    10

    Default Re: Lock strategy

    If there is no standard way...

    Here is what I know.

    The normal way in Qt is that if an occurence is modified in a transaction and that another transaction accesses it, it just freezes when the model tries to carry out the update.

    There are several problems with that.

    1. The user does not know, before the update, if his changes will be accepted. It would be better to react at the beginning of the edition.

    2. I would have preferred it if the program did not access all the time the database.

    3. I have a strange bug when I am not using the "on manual submit" strategy. When I edit a cell, another in the table is randomly modified. I have posted a message here but found no solution

    4. It freezes. It would be better to have an error message like when you have done a SELECT FOR UPDATE NOWAIT

    I am ready to accept 1 and 2. I am desperate about 3 but issue 4 is definitely a problem. It should not freeze.

    The only solution I see would be to use the "on manual submit" strategy to avoid the strange bug (cf 3) and do a SELECT FROM UPDATE NOWAIT at the beginning of every modification or when I change of occurence. But the textChanged signal is emitted each time a character is typed and I would need to place something in the createEditor function in the item delegate. This way, I will be able to set the locks and to prevent the edition in case the query fails (ie if the record is already locked). It would be more natural to detect changes at the level of the model but Isee no signals I could use or events I could override.

    It seems complicated...

    At least, I would be glad if I could somehow that freeze. How could I do?

    And, what would be the natural way to implement the locks in Qt? I assume there something for that. I do not ask for a ready made solution. But if someone could point me to a piece of documentation, give me a class name...

    Thanks!

    There i

  3. #3
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    10

    Default Re: Lock strategy

    In case of a problem, there are usually knowledgeable people who reply helpfully and very quickly.

    I guess that your silence means there is nothing in Qt that does that. There is no natural way that has been programmed to manage locks. So there is no way to build a normal, reliable database application.

    This is incredible. In my professionnal life, I have basically two backgrounds: scienfific/mathematical programming in C++ and database applications in other languages. For this large project, I had the opportunity to choose the tools I wanted so I choose my favourite language C++ and Qt that I dod not know and looked promising. Since the beginning I have struggled against its shortcomings in terms of database management. The examples are numerous; QSqlRelationModel that does not handle left outer joins, QSqlTableModel that does not allow multiple sort fields and many others plus some strange things that occurs for which no one seems to have an aswer. There are other difficulties: the lack of classical events that prevent the programmer to do the things he can do in other frameworks. But this is not really a problem. It become a nightmare if you try to do things you are used to in other frameworks but, if you follow its logic,it can deliver a solution that is more elegant.

    But the conclusion of the difficulties I have had and of the absence of clean mechanism to handle the locks are at least to detect the beginning of the edition of an occurence at the model level men that it is more or less impossible to do a clean, usual and reliable database application with Qt.

    I have really tried to learn, to follow its logic and not to rant because it was lacking features present in other frameworks. But I am dicovering that some things are plainly impossible.

    In total, I have wasted months because of this. I had for solutions (sometimes dodgy) for most of the problems but that lock issue is the end of it. I am writing an application handling medical data used by a large number of people and whet Qt offers is simply insufficient.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,365
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Lock strategy

    Quote Originally Posted by pippo42 View Post
    1. The user does not know, before the update, if his changes will be accepted. It would be better to react at the beginning of the edition.
    That would be premature and inefficient. If someone starts editing an item and then leaves the computer before leaving edit mode, the record would be locked and nothing else could access it.

    2. I would have preferred it if the program did not access all the time the database.
    It's just a matter of submission strategy you set. You can tell the model to submit the data just once.

    3. I have a strange bug when I am not using the "on manual submit" strategy. When I edit a cell, another in the table is randomly modified. I have posted a message here but found no solution
    Provide more info, please.

    4. It freezes. It would be better to have an error message like when you have done a SELECT FOR UPDATE NOWAIT
    What freezes? In what conditions?

    And, what would be the natural way to implement the locks in Qt? I assume there something for that. I do not ask for a ready made solution. But if someone could point me to a piece of documentation, give me a class name...
    What is the exact problem you are having? You can issue SELECT FOR UPDATE, as you already said.

    Quote Originally Posted by pippo42 View Post
    In case of a problem, there are usually knowledgeable people who reply helpfully and very quickly.
    Yes but they like the question to be asked clearly. The more paragraphs (above 2-3) you write in your posts, the less answers you will get Answering your own posts leads to that too - i.e. I read mostly these threads that haven't been replied.

    So there is no way to build a normal, reliable database application.
    This is just trolling. It's easy to throw accusations, it's harder to find humility to look for problems in your own code.

    The examples are numerous; QSqlRelationModel that does not handle left outer joins, QSqlTableModel that does not allow multiple sort fields and many others plus some strange things that occurs for which no one seems to have an aswer.
    These are models that are meant to work for 90% of the people in 90% of the cases. Qt is not dedicated to database programming, remember that. If you're so good in C++ then subclassing proper classes and adding support for what you want shouldn't pose a problem.

    There are other difficulties: the lack of classical events that prevent the programmer to do the things he can do in other frameworks.
    What do you mean by "lack of classical events"? You can use both native platform events and Qt wrapped (or Qt generated) events without any problems. I don't know if any of these fall into the category of "classical events" but for me it would seem so.

    But this is not really a problem. It become a nightmare if you try to do things you are used to in other frameworks but, if you follow its logic,it can deliver a solution that is more elegant.
    It would be stupid to project habits from one framework onto another with completely different rules and architecture. Imagine going to a golf course with a tennis racket and blaming golf balls for lying on the ground all the time.

    I have really tried to learn, to follow its logic and not to rant because it was lacking features present in other frameworks. But I am dicovering that some things are plainly impossible.
    There is a very simple answer for that, actually... RTFM! I assure you you can write reliable database applications in Qt if anything because Qt doesn't prevent you from sending any query to the database or using any library available for C++.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Lock a row in QTreeWidget
    By maka3k in forum Qt Programming
    Replies: 1
    Last Post: 9th March 2010, 13:45
  2. QMutex seems not to lock()
    By sylvaticus in forum Qt Programming
    Replies: 18
    Last Post: 4th December 2009, 10:39
  3. Password storing strategy
    By Lykurg in forum General Discussion
    Replies: 8
    Last Post: 1st July 2009, 18:53
  4. Wrapping Qt classes strategy
    By thru in forum Qt Programming
    Replies: 1
    Last Post: 6th May 2009, 15:12
  5. Nightly Builds/Snapshot strategy/tools
    By BastiBense in forum Qt Programming
    Replies: 1
    Last Post: 12th March 2009, 13:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.