sqltest inconsistency

Bug #143776 reported by José Henrique Reis
2
Affects Status Importance Assigned to Milestone
Products.ZSQLMethods
Invalid
Wishlist
Unassigned

Bug Description

Some time ago Dieter Maurer changed the sqlvar behaviour to map Python None to SQL NULL for all types (issue 556). I think that sqltest should have the same behavior, so parameters explicitly passed as None are mapped to SQL null.

This would bring consistency between sqlvar and sqltest and would allow to greater flexibility in the construction of zsql methods, like in this example:

update table
set <dtml-sqlgroup>
  <dtml-sqltest abc type="nb" optional><dtml-comma>
  <dtml-sqltest dof type="nb" optional>
</dtml-sqlgroup>
where ghi = <dtml-sqlvar ghi type="nb">

if called with 'abc="123", ghi="789 this would result in:

update table
set (abc = '123', dof = null)
where ghi = '789'

Revision history for this message
José Henrique Reis (jhreis) wrote :
Revision history for this message
José Henrique Reis (jhreis) wrote :

Sorry, my example are wrong. The correct is:

if called with 'abc="123", dof=None, ghi="789 this would result in:

update table
set (abc = '123', dof = null)
where ghi = '789'

Revision history for this message
José Henrique Reis (jhreis) wrote :

After reading the Zope Book with more attention, I realized that the sqltest tag is used for comparisons and not attributions. So, in the case of the null values , we have to use different operators for equality ( is ) and difference ( is not ).
Follows a new diff with the suggested modifications:

132a133,138
> if v is None:
> try:
> return "%s %s %s" % (self.column, null_operators[self.op], 'null')
> except KeyError:
> raise ValueError, 'Invalid operator for null value, <em>%s</em>' % name
>
200a207,208
>
> null_operators = { '=': 'is', '<>': 'is not' }

Changed in zope2:
importance: Medium → Wishlist
status: New → Confirmed
affects: zope2 → products.zsqlmethods
Revision history for this message
Colin Watson (cjwatson) wrote :

The products.zsqlmethods project on Launchpad has been archived at the request of the Zope developers (see https://answers.launchpad.net/launchpad/+question/683589 and https://answers.launchpad.net/launchpad/+question/685285). If this bug is still relevant, please refile it at https://github.com/zopefoundation/products.zsqlmethods.

Changed in products.zsqlmethods:
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.