Get the column names from a resultset

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Get the column names from a resultset

RAPPAZ Francois
I understand that I can retrieve a limited list of columns from a table using

$rs = $self->{schema}->resultset('User')->search_rs(undef, {columns => [qw / id_user nom prenom / ], order_by => 'nom',});

Now, is there a way to retrieve the columns names from a result set, when such a object is received as an argument ?

Is there a way to have

@colnames = $resultset->get_column_names;  

??

Thanks

François Rappaz

Centre de documentation de la Faculté des Sciences Université de Fribourg DokPe - Dokumentationszentrum der Naturwissenschaftlichen Fakultät Universität Freiburg Pérolles CH-1700 Fribourg Switzerland http://www.unifr.ch/dokpe/
Tel.: 41 (0)26 300 92 60
Fax.: 41 (0)26 300 97 30



_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: Get the column names from a resultset

David Schmidt
this should work

https://metacpan.org/pod/DBIx::Class::ResultSource#columns


you can get the result source from your resultset via $rs->result_source.


cheers

On 1 July 2014 14:05, RAPPAZ Francois <[hidden email]> wrote:

> I understand that I can retrieve a limited list of columns from a table using
>
> $rs = $self->{schema}->resultset('User')->search_rs(undef, {columns => [qw / id_user nom prenom / ], order_by => 'nom',});
>
> Now, is there a way to retrieve the columns names from a result set, when such a object is received as an argument ?
>
> Is there a way to have
>
> @colnames = $resultset->get_column_names;
>
> ??
>
> Thanks
>
> François Rappaz
>
> Centre de documentation de la Faculté des Sciences Université de Fribourg DokPe - Dokumentationszentrum der Naturwissenschaftlichen Fakultät Universität Freiburg Pérolles CH-1700 Fribourg Switzerland http://www.unifr.ch/dokpe/
> Tel.: 41 (0)26 300 92 60
> Fax.: 41 (0)26 300 97 30
>
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@...

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: Get the column names from a resultset

RAPPAZ Francois
Thanks for the suggestion

But no it doesn't work

I had tried already the code you proposed, but in fact it does give all the column from the underlaying table even if the columns is limited in the resultset.

Best

François

> -----Original Message-----
> From: David Schmidt [mailto:[hidden email]]
> Sent: mardi, 1. juillet 2014 14:15
> To: DBIx::Class user and developer list
> Subject: Re: [Dbix-class] Get the column names from a resultset
>
> this should work
>
> https://metacpan.org/pod/DBIx::Class::ResultSource#columns
>
>
> you can get the result source from your resultset via $rs-
> >result_source.
>
>
> cheers
>
> On 1 July 2014 14:05, RAPPAZ Francois <[hidden email]> wrote:
> > I understand that I can retrieve a limited list of columns from a
> table using
> >
> > $rs = $self->{schema}->resultset('User')->search_rs(undef, {columns
> => [qw / id_user nom prenom / ], order_by => 'nom',});
> >
> > Now, is there a way to retrieve the columns names from a result set,
> when such a object is received as an argument ?
> >
> > Is there a way to have
> >
> > @colnames = $resultset->get_column_names;
> >
> > ??
> >
> > Thanks
> >
> > François Rappaz
> >
> > Centre de documentation de la Faculté des Sciences Université de
> Fribourg DokPe - Dokumentationszentrum der Naturwissenschaftlichen
> Fakultät Universität Freiburg Pérolles CH-1700 Fribourg Switzerland
> http://www.unifr.ch/dokpe/
> > Tel.: 41 (0)26 300 92 60
> > Fax.: 41 (0)26 300 97 30
> >
> >
> >
> > _______________________________________________
> > List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> > IRC: irc.perl.org#dbix-class
> > SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> > Searchable Archive: http://www.grokbase.com/group/dbix-
> [hidden email]
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-
> [hidden email]
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: Get the column names from a resultset

Peter Rabbitson-2
In reply to this post by RAPPAZ Francois
On Tue, Jul 01, 2014 at 12:05:36PM +0000, RAPPAZ Francois wrote:
> I understand that I can retrieve a limited list of columns from a table using
>
> $rs = $self->{schema}->resultset('User')->search_rs(undef, {columns => [qw / id_user nom prenom / ], order_by => 'nom',});
>
> Now, is there a way to retrieve the columns names from a result set, when such a object is received as an argument ?
>
> Is there a way to have
>
> @colnames = $resultset->get_column_names;  

Not currently. Work is being planned on this but it is more involved
than it appears on the surface.

As of now it's recommended to just carry around the set of columns with
you. You can also dig in the return of $rs->_resolved_attrs, HOWEVER
THIS IS UNSUPPORTED AND *WILL* CHANGE without a warning. So make sure to
write sufficient tests if yoiu go this route.

Cheers


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...