Support for ParamValues in dbd::mysql and a note on DBD::ODBC

Support for ParamValues in dbd::mysql and a note on DBD::ODBC

am 31.03.2006 14:38:08 von Martin.Evans

It would appear dbd::mysql 3.0002_4 does not support ParamValues.
As far as I can see it is also not in _5. I am far from an XS expert but the
following addition to dbd_st_FETCH_attrib in dbdimp.c seems to work. If anyone
cares to comment on whether there is a better or proper way to do this I'd be
happy to learn from them. Unfortunately it is not easy for me to supply a patch
as my dbd::mysql is 3.0002_4 and is massively patched and hacked already (my
addition between + and - MJE.

case 'P':
if (strEQ(key, "PRECISION"))
retsv= ST_FETCH_AV(AV_ATTRIB_PRECISION);
/* +MJE */
if (strEQ(key, "ParamValues")) {
HV *pvhv = newHV();
if (DBIc_NUM_PARAMS(imp_sth)) {
unsigned int n;
SV *sv;
char key[100];
I32 keylen;
for (n = 0; n < DBIc_NUM_PARAMS(imp_sth); n++) {
# Not sure this is the correct way to create the param keys
keylen = sprintf(key, "%d", n);
hv_store(pvhv, key, keylen, newSVsv(imp_sth->params[n].value),
0);
}
}
retsv = newRV_noinc((SV*)pvhv);
}
/* -MJE */
break;

Incidentally, DBD::ODBC does support ParamValues BUT they cannot be retrieved
after execute fails. I believe this is because dbd_st_FETCH_attrib attempts to
do a dbd_describe (for most attribs) before returning ParamValues and that fails
if execute has failed. I am not sure if it needs to call dbd_describe for
ParamValues and I've asked Jeff to comment.

Martin
--
Martin J. Evans
Easysoft Ltd, UK
http://www.easysoft.com