Changeset 706 for trunk/module/pg.py


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
  • trunk/module/pg.py

    r705 r706  
    341341                print(s)
    342342
     343    @staticmethod
     344    def _make_bool(d):
     345        """Get boolean value corresponding to d."""
     346        return bool(d) if get_bool() else ('t' if d else 'f')
     347
    343348    def _quote_text(self, d):
    344349        """Quote text value."""
     
    355360                return 'NULL'
    356361            d = d.lower() in self._bool_true
    357         else:
    358             d = bool(d)
    359         return ("'f'", "'t'")[d]
     362        return "'t'" if d else "'f'"
    360363
    361364    _date_literals = frozenset('current_date current_time'
     
    723726        except KeyError:
    724727            q = "SELECT has_table_privilege('%s', '%s')" % (qcl, privilege)
    725             ret = self.db.query(q).getresult()[0][0] == 't'
     728            ret = self.db.query(q).getresult()[0][0] == self._make_bool(True)
    726729            self._privileges[(qcl, privilege)] = ret
    727730            return ret
     
    914917        """Clear all the attributes to values determined by the types.
    915918
    916         Numeric types are set to 0, Booleans are set to 'f', and everything
     919        Numeric types are set to 0, Booleans are set to false, and everything
    917920        else is set to the empty string.  If the array argument is present,
    918921        it is used as the array and any entries matching attribute names are
     
    933936                a[n] = 0
    934937            elif t in ('bool', 'boolean'):
    935                 a[n] = 'f'
     938                a[n] = self._make_bool(False)
    936939            else:
    937940                a[n] = ''
Note: See TracChangeset for help on using the changeset viewer.