I tested perl-DBI-1.48 and perl-DBI-1.50.

In the simple testcase

       while($hash_ref = $dep_sth->fetchrow_hashref) {
               foreach my $key (keys(%$hash_ref)) {
                       print "(".utf8::is_utf8($key).") ".$key."\n";
               }
               print "\n";
               foreach my $value (values(%$hash_ref)) {
                       print "(".utf8::is_utf8($value).") ".$value."\n";
               }
       }

I found that keys from fetchrow_hashref are always with turned off SvUTF8.
The reason was using

SV**    hv_store(HV* tb, const char* key, I32 klen, SV* val, U32 hash)


to put values into a hash in fetchrow_hashref function in DBI.xs. Key is
char* type. It is correct to use hv_store_ent.

I propose the following patch

diff -uNr DBI-1.48-orig/DBI.xs DBI-1.48/DBI.xs
--- DBI-1.48-orig/DBI.xs        2005-01-20 19:06:28.000000000 +0800
+++ DBI-1.48/DBI.xs     2006-02-27 17:25:53.000000000 +0800
@@ -3928,10 +3928,8 @@
        ka_av = (AV*)SvRV(ka_rv);
        hv    = newHV();
        for (i=0; i < num_fields; ++i) {        /* honor the original order
as sent by the database */
-           STRLEN len;
            SV  **field_name_svp = av_fetch(ka_av, i, 1);
-           char *field_name     = SvPV(*field_name_svp, len);
-           hv_store(hv, field_name, len, newSVsv((SV*)(AvARRAY(rowav)[i])),
0);
+           hv_store_ent(hv, newSVsv(*field_name_svp),
newSVsv((SV*)(AvARRAY(rowav)[i])), 0);
        }
        RETVAL = newRV((SV*)hv);
        SvREFCNT_dec(hv);       /* since newRV incremented it   */

Reply via email to