[Xerte-dev] Problem with Number of uses count in both trunk and v2.0

Smith, John J.J.Smith at gcu.ac.uk
Sat Jun 29 22:09:06 BST 2013


Hi,

I've noticed (and fixed) a bug which has been introduced into v2.0 (and probably before) where 'number_of_uses' in templatedetails is setup with default of NULL and was not being set to 0 when a new template was created. In this situation the play code query which runs number_of_uses=number_of_uses+1 doesn't work and the value stays as NULL...

So I've fixed it so that when new ones are created that 0 is inserted in this field but existing ones are stuck in limbo... I thought about fixing it in upgrade.php but have come up with what seems to me to be an elegant solution in play.php. I've changed the UPDATE query to:

    SET number_of_uses=COALESCE(number_of_uses+1,1)

which seems to work. Basically COALESCE returns the first value that isn't NULL... so if number_of_uses is NULL then so it the +1 so in that case it returns the second value of 1.

Never having used this SQL function before though i'm wondering what you all think about this... it seems to work with the problematic entries as well as the ok ones but is there anything I'm missing with the use of this function? I've committed it to trunk but will wait before pushing it into v2.0 branch to see what you all think...

Regards,

John Smith | Learning Technologist
Room A251, Govan Mbeki Building | School of Health & Life Sciences | Glasgow Caledonian University
Cowcaddens Road | Glasgow | G4 0BA

Glasgow Caledonian University is a registered Scottish charity, number SC021474

Winner: Times Higher Education’s Widening Participation Initiative of the Year 2009 and Herald Society’s Education Initiative of the Year 2009.
http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,6219,en.html

Winner: Times Higher Education’s Outstanding Support for Early Career Researchers of the Year 2010, GCU as a lead with Universities Scotland partners.
http://www.gcu.ac.uk/newsevents/news/bycategory/theuniversity/1/name,15691,en.html


More information about the Xerte-dev mailing list