correctly decode hstore with @ in data
[APKPM.git] / lib / APKPM / Store.pm
index eafd73d..19aaa6c 100644 (file)
@@ -66,9 +66,27 @@ sub sql : Job : Encode(e_json) : MinProcesses(0) {
 
        warn "# $rows rows get_username_table $workload\n";
 
+       $rows = $sth->fetchall_arrayref;
+       my @columns = @{ $sth->{NAME} };
+
+       # decode hash column
+       my $hash_col;
+       foreach ( 0 .. $#columns ) {
+               $hash_col = $_ if $columns[$_] eq 'h';
+       }
+       if ( defined $hash_col ) {
+               map {
+                       my $hash = $_->[$hash_col];
+                       $hash =~ s/\@/\\\@/g;
+                       $_->[$hash_col] = eval "{ $hash }";
+                       $_->[$hash_col] = "ERROR: $@ for $hash" if $@;
+               } @$rows
+       }
+
        return {
-               columns => $sth->{NAME},
-               rows => $sth->fetchall_arrayref,
+               columns => \@columns,
+               rows => $rows,
+               hash_col => $hash_col,
        };
 }