Skip Menu |

This queue is for tickets about the DBIx-Perlish CPAN distribution.

Report information
The Basics
Id: 53969
Status: resolved
Priority: 0/
Queue: DBIx-Perlish

People
Owner: Nobody in particular
Requestors: hinrik.sig [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Runtime column names
It would be very useful to be able to compute column names at runtime. This is possible with table names via C<< my $t : table = $name; >>, but in the case of columns it can only be done inside a string used in a return statement (e.g. C<< return "$t->{$col};" >>). It would be nice if C<< table->{$col} == $value; >> and such were possible. The docs mention that this might be added in a future version. So, consider this an official request. :)
Subject: Re: [rt.cpan.org #53969] Runtime column names
Date: Mon, 25 Jan 2010 13:27:43 +0100
To: Hinrik Orn Sigurdsson via RT <bug-DBIx-Perlish [...] rt.cpan.org>
From: Anton Berezin <tobez [...] tobez.org>
On Sun, Jan 24, 2010 at 10:55:35PM -0500, Hinrik Orn Sigurdsson via RT wrote: Show quoted text
> Sun Jan 24 22:55:34 2010: Request 53969 was acted upon. > Transaction: Ticket created by HINRIK > Queue: DBIx-Perlish > Subject: Runtime column names > Broken in: (no value) > Severity: Wishlist > Owner: Nobody > Requestors: hinrik.sig@gmail.com > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=53969 > > > > It would be very useful to be able to compute column names at runtime. > This is possible with table names via C<< my $t : table = $name; >>, but > in the case of columns it can only be done inside a string used in a > return statement (e.g. C<< return "$t->{$col};" >>). It would be nice if > C<< table->{$col} == $value; >> and such were possible. > > The docs mention that this might be added in a future version. So, > consider this an official request. :)
I don't understand. Consider this script: === #! /usr/bin/perl use 5.006; use strict; use warnings; use DBIx::Perlish; use DBD::SQLite; use Data::Dump; my $dbh = DBI->connect("dbi:SQLite:"); $dbh->do("create table names (id integer, name text)"); db_insert 'names', { id => 1, name => "hello" }; db_insert 'names', { id => 33, name => "smth/xx" }; db_insert 'names', { id => 3, name => "ehlo" }; fetch(id => 3); fetch(name => "hello"); sub fetch { my ($col, $val) = @_; my $r = db_fetch { names->$col == $val; }; dd $r; } === It produces { id => 3, name => "ehlo" } { id => 1, name => "hello" } Is that what you want? -- Matters of elegance ought to be left to the tailor and to the cobbler. -- L. Boltzmann
Oh, sorry! I thought I had tried that approach earlier and it failed, but I was obviously Doing It Wrong. Works now. Thanks.