Re: Help sought with definition and implementation of ParamTypes attribute

"H.Merijn Brand" <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.sybase.devel
Message-ID <[email protected]>
On Sun, 12 Oct 2008 21:25:12 +0100, Tim Bunce <[email protected]>
wrote:

> On Sun, Oct 12, 2008 at 02:55:51AM -0000, Greg Sabino Mullane wrote:
> > 
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: RIPEMD160
> > 
> > 
> > > values are hashrefs of type information in the same form as that
> > > provided to the various bind_param() methods
> > ...
> > 
> > > I'm not sure why the values of the keys are hash references unless
> > > multiple values are to be stored. If multiple values per key are stored
> > > what are they typically? I can only find one DBD which implements
> > > ParamTypes (DBD::Pg) and unless I am mistaken it sets the values of the
> > > keys to a scalar value - the type of the parameter.
> > 
> > Yes, it's scalar values in DBD::Pg. If I recall correctly, it was done that
> > way simply because it seemed better to return a simple name. To be 100%
> > accurate it should probably return a hashref because that's what bind_param
> > takes. In other words:
> > 
> >   $sth->bind_param('$1', 234, { pg_type => SQL_INTEGER });
> >   warn Dumper $sth->{ParamTypes};
> > 
> > gives:
> > 
> > $VAR1 = {
> >           '1' => 'integer'
> >         };
> > 
> > When it should technically return:
> > 
> > $VAR1 = {
> >           '1' => { pg_type => 'SQL_INTEGER' }
> >         };
> 
> The intention is that this code:
> 
>     $ParamTypes  = $sth1->{ParamTypes};
>     $ParamValues = $sth1->{ParamValues};
> 
>     $sth2->bind_param( $_, $ParamValues->{$_}, $ParamTypes->{$_} )
>         for keys %$ParamTypes;
> 
> should make the values bound to $sth2, and the way they're treated by
> the driver, be the same way as they were for $sth1.
> 
> So { '1' => 'integer' } sure looks like a bug.

But the underlying question was if it should return

  $VAR = { 1 => 1 };

or

  $VAR = { 1 => { pg_type => 1 }};

My DBD::Unify currently does the first. It returns numerical scalars,
not hash-refs

> > However, bind_param currently saves the value to an internal form, without
> > saving how it got there, which makes the key of that inner hash ('pg_type')
> > difficult to show. Because the value, SQL_INTEGER, is really a constant, it's
> > equally difficult to know to output 'SQL_INTEGER' - we'd really have to output
> > the number it maps to.
> 
> Yes. Outputting the _string_ "SQL_INTEGER" would be wrong as it wouldn't
> work for the code above.
> 
> > I can easily adjust ParamTypes in DBD::Pg to give a hashref, if that's
> > what you end up doing for DBD::ODBC

-- 
H.Merijn Brand          Amsterdam Perl Mongers  http://amsterdam.pm.org/
using & porting perl 5.6.2, 5.8.x, 5.10.x, 5.11.x on HP-UX 10.20, 11.00,
11.11, 11.23, and 11.31, SuSE 10.1, 10.2, and 10.3, AIX 5.2, and Cygwin.
http://mirrors.develooper.com/hpux/           http://www.test-smoke.org/
http://qa.perl.org      http://www.goldmark.org/jeff/stupid-disclaimers/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.