How hard would it be for DBI to export a hash of data def's?

2004-08-23 Thread Steven Lembark
For example "neat" (see below for perldoc) 'knows' if a string
is numeric or char in the database. If I could get a hash keyed
by $sth->{NAME} that had, say, DBD-specific metadata it'd help
quite a bit on handling some error situaions. One use is returning
a copy of the query with placeholders filled in for cut+paste
troubleshooting; another is pretty-printing results where numeric
sequences stored as strings need to be quoted for further use
(i.e., /^\d+$/ is not a good enough test for quotishness when
Perl gets all the data back as strings).
If whatever neat uses were exported -- perhaps in DBD-specific
fashion to accomodate varying levels of metadata available in
the different databases -- it'd sure help...
  "neat"
$str = DBI::neat($value);
$str = DBI::neat($value, $maxlen);
  Return a string containing a neat (and tidy) represen-
  tation of the supplied value.
  Strings will be quoted, although internal quotes will
  not be escaped.  Values known to be numeric will be
  unquoted. Undefined (NULL) values will be shown as
  "undef" (without quotes).
  If the string is flagged internally as utf8 then dou-
  ble quotes will be used, otherwise single quotes are
  used and unprintable characters will be replaced by
  dot (.).
  For result strings longer than $maxlen the result
  string will be truncated to "$maxlen-4" and ""...'""
  will be appended.  If $maxlen is 0 or "undef", it
  defaults to $DBI::neat_maxlen which, in turn, defaults
  to 400.
  This function is designed to format values for human
  consumption.  It is used internally by the DBI for
  "trace" output. It should typically not be used for
  formatting values for database use.  (See also
  "quote".)

--
Steven Lembark   85-09 90th Street
Workhorse ComputingWoodhaven, NY 11421
[EMAIL PROTECTED] 1 888 359 3508


Re: How hard would it be for DBI to export a hash of data def's?

2004-08-24 Thread Tim Bunce
On Mon, Aug 23, 2004 at 03:53:51PM -0400, Steven Lembark wrote:
> For example "neat" (see below for perldoc) 'knows' if a string
> is numeric or char in the database.

Not quite. It knows if the perl scalar value has numeric and/or
string representations cached (the SvPOK and SvINOK flags).

> If I could get a hash keyed
> by $sth->{NAME} that had, say, DBD-specific metadata it'd help
> quite a bit on handling some error situaions. One use is returning
> a copy of the query with placeholders filled in for cut+paste
> troubleshooting;

I don't see how anything keyed by NAME could help with anything
related to placeholders.

For placeholders the ParamValues attribute exists already and
I've also previously talked about adding a ParamAttribs attribute.

> another is pretty-printing results where numeric
> sequences stored as strings need to be quoted for further use
> (i.e., /^\d+$/ is not a good enough test for quotishness when
> Perl gets all the data back as strings).

DBI::looks_like_number() would be better, for some definition of better.

> If whatever neat uses were exported -- perhaps in DBD-specific
> fashion to accomodate varying levels of metadata available in
> the different databases -- it'd sure help...

Some concrete examples would sure help me :)

Tim.