Changeset 706 for branches/4.x


Ignore:
Timestamp:
Jan 9, 2016, 5:53:44 PM (4 years ago)
Author:
cito
Message:

Make sure DB methods respect the new bool option

Two DB methods assumed that booleans are always returned as strings,
which is no longer true when the set_bool() option is activated.
Added a test run with different global options to make sure that
no DB methods make such tacit assumptions about these options.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.x/module/pg.py

    r690 r706  
    339339                print(s)
    340340
     341    def _make_bool(d):
     342        """Get boolean value corresponding to d."""
     343        if get_bool():
     344            return bool(d)
     345        return d and 't' or 'f'
     346    _make_bool = staticmethod(_make_bool)
     347
    341348    def _quote_text(self, d):
    342349        """Quote text value."""
     
    353360                return 'NULL'
    354361            d = d.lower() in self._bool_true
    355         else:
    356             d = bool(d)
    357         return ("'f'", "'t'")[d]
     362        return d and "'t'" or "'f'"
    358363
    359364    _date_literals = frozenset('current_date current_time'
     
    717722        except KeyError:
    718723            q = "SELECT has_table_privilege('%s', '%s')" % (qcl, privilege)
    719             ret = self.db.query(q).getresult()[0][0] == 't'
     724            ret = self.db.query(q).getresult()[0][0] == self._make_bool(True)
    720725            self._privileges[(qcl, privilege)] = ret
    721726            return ret
     
    896901        """Clear all the attributes to values determined by the types.
    897902
    898         Numeric types are set to 0, Booleans are set to 'f', and everything
     903        Numeric types are set to 0, Booleans are set to false, and everything
    899904        else is set to the empty string.  If the array argument is present,
    900905        it is used as the array and any entries matching attribute names are
     
    915920                a[n] = 0
    916921            elif t in ('bool', 'boolean'):
    917                 a[n] = 'f'
     922                a[n] = self._make_bool(False)
    918923            else:
    919924                a[n] = ''
Note: See TracChangeset for help on using the changeset viewer.