Subject: | PATCH: configurable NULL and BOOLEAN representation |
The attached patch adds two options to DBI::Shell to let the user control the representation of NULL ( '(NULL)', undef, '(unknown)', etc.) and BOOLEAN (1 and 0, 't' and 'f', 'TRUE' and 'FALSE', etc.) values.
This patch is a small step toward a cleaner (IMHO) DBI::Format::* design, with values' representation (what do NULLs look like? what about INTERVALs?) distinct from encoding (do we HTML- or XML-encode? URI-escape? scrub ASCII non-printables?). Additionally, some code duplicated across most formatter subclasses was moved into DBI::Format::Base, with SUPER::foo calls added as needed.
It wasn't clear to me how to unit test this change, though current tests pass. I'm happy to polish this as needed.
@dbi:Pg:mjp> /option
...
bool_format: Y,N
null_format: (NULL)
@dbi:Pg:mjp> SELECT true, false, null;
bool,bool,?column?
'Y','N','(NULL)'
[1 rows of 3 fields returned]
@dbi:Pg:mjp> /option bool_format=TRUE,FALSE
/option bool_format=TRUE,FALSE (was Y,N)
@dbi:Pg:mjp> /option null_format=UNKNOWN
/option null_format=UNKNOWN (was (NULL))
@dbi:Pg:mjp> SELECT true, false, null;
bool,bool,?column?
'TRUE','FALSE','UNKNOWN'
[1 rows of 3 fields returned]
This patch is a small step toward a cleaner (IMHO) DBI::Format::* design, with values' representation (what do NULLs look like? what about INTERVALs?) distinct from encoding (do we HTML- or XML-encode? URI-escape? scrub ASCII non-printables?). Additionally, some code duplicated across most formatter subclasses was moved into DBI::Format::Base, with SUPER::foo calls added as needed.
It wasn't clear to me how to unit test this change, though current tests pass. I'm happy to polish this as needed.
@dbi:Pg:mjp> /option
...
bool_format: Y,N
null_format: (NULL)
@dbi:Pg:mjp> SELECT true, false, null;
bool,bool,?column?
'Y','N','(NULL)'
[1 rows of 3 fields returned]
@dbi:Pg:mjp> /option bool_format=TRUE,FALSE
/option bool_format=TRUE,FALSE (was Y,N)
@dbi:Pg:mjp> /option null_format=UNKNOWN
/option null_format=UNKNOWN (was (NULL))
@dbi:Pg:mjp> SELECT true, false, null;
bool,bool,?column?
'TRUE','FALSE','UNKNOWN'
[1 rows of 3 fields returned]
Subject: | DBI-Shell-11.95-nullbool-format.patch |
Message body is not shown because it is too large.