Skip Menu |

This queue is for tickets about the SQL-Abstract CPAN distribution.

Report information
The Basics
Id: 55086
Status: rejected
Priority: 0/
Queue: SQL-Abstract

People
Owner: Nobody in particular
Requestors: MRDVT [...] cpan.org
Cc:
AdminCc:

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



Subject: Add Select Alias support
I needed column alias support in the select function so I hacked this. I do not know how portable across DBs the column alias capability is. 100% backwards compatible and all tests pass. sabs->select("table", ["col1", [col2=>"alias2"], {col3=>alias3}]); $ diff -r SQL-Abstract-1.22 SQL-Abstract diff -r SQL-Abstract-1.22/lib/SQL/Abstract.pm SQL- Abstract/lib/SQL/Abstract.pm 147c147 < our $VERSION = '1.22'; --- Show quoted text
> our $VERSION = '1.22.01';
537c537,554 < my $f = (ref $fields eq 'ARRAY') ? join ', ', map { $self->_quote ($_) } @$fields : $fields; --- Show quoted text
> my $f=$fields; > if (ref($fields) eq 'ARRAY') { > $f=join ', ', > map { > if (ref($_) eq "ARRAY") { > die("Error: Array reference must have two values") > unless scalar(@$_) == 2; > sprintf(qq{%s AS "%s"}, $self->_quote($_->[0]), $_- >[1]); > } elsif (ref($_) eq "HASH") { > die("Error: Hash reference must have one key") > unless scalar(keys %$_) == 1; > sprintf(qq{%s AS "%s"}, $self->_quote(keys(%$_)),
values(%$_)); Show quoted text
> } else { > $self->_quote($_); > } > } @$fields; > } >
diff -r SQL-Abstract-1.22/t/01generate.t SQL-Abstract/t/01generate.t 9c9 < BEGIN { plan tests => 60 } --- Show quoted text
> BEGIN { plan tests => 62 }
16a17,25 Show quoted text
> args => ['test', ["scalar", > [array=>"Aalias"], > {hash=>"Halias"}]], > stmt => 'SELECT scalar, array AS "Aalias", hash
AS "Halias" FROM test', Show quoted text
> stmt_q => 'SELECT `scalar`, `array` AS "Aalias", `hash`
AS "Halias" FROM `test`', Show quoted text
> bind => [] > }, > { > func => 'select',
I, Michael R. Davis (mrdvt92), hereby release this code to the public domain.
On Mon Mar 01 02:35:59 2010, MRDVT wrote: Show quoted text
> I needed column alias support in the select function so I hacked this. > I do not know how portable across DBs the column alias capability is. > > 100% backwards compatible and all tests pass. > > sabs->select("table", ["col1", [col2=>"alias2"], {col3=>alias3}]); >
Please use diff -u in the future. MY EYES! :) I hope you are open to some discussion about this, as I am about to rain hard on the parade. The first syntax ({ col => as }) would conflict badly with what has been in use at DBIx::Class for years (if A and B are functions { A => { B => c } } means A(B(c)). Given how the same team maintains both packages we want to avoid this kind of clash. Besides having two syntaxes to do the same thing is a waste of semantics. So let's focus on [] and AS in general. While technically we could include something like this, semantically it would be awkward. Why would you want to produce such SQL *programmatically*? The only viable use case I see is to do this for functions (and DBIx::Class allows this too). But I don't see a reason to rename columns in an arbitrary query - it would only encourage sloppy programming. You are in full control of what SQL goes in and what you do with the data coming out, the intermediate AS step is for all purposes redundant. So please provide some real-world use cases when AS on a column would be desired. And also please take a look at the DBIx::Class select sub-syntax, and if it will be sufficient for your needs (porting it is a simple exercise in copy/paste): http://dev.catalyst.perl.org/repos/bast/DBIx-Class/0.08/trunk/t/sqlahacks/sql_maker/sql_maker_quote.t Cheers
On Mon Mar 01 02:35:59 2010, MRDVT wrote: Show quoted text
> I needed column alias support in the select function so I hacked this. > I do not know how portable across DBs the column alias capability is. > > 100% backwards compatible and all tests pass. > > sabs->select("table", ["col1", [col2=>"alias2"], {col3=>alias3}]);
No reply from original reporter. Stalling for the time being.
Rejecting patch - author disappeared without any further discussion of the proposed changes.