Author: spadkins
Date: Sun Oct 31 07:27:31 2010
New Revision: 14511
Modified:
p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm
p5ee/trunk/App-Repository/t/DBI-select-join.t
Log:
enhanced so that queries which include undefined columns in the order by clause
exclude those columns and work correctly otherwise
Modified: p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm (original)
+++ p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm Sun Oct 31 07:27:31 2010
@@ -1313,23 +1313,20 @@
$dir = " desc";
}
$column_def = $table_def->{column}{$column};
- if (!defined $column_def) {
- $order_by_dbexpr = $column;
- }
- else {
- $order_by_dbexpr = $dbexpr{$column};
+ next if (!defined $column_def);
- if (!$order_by_dbexpr) {
- $order_by_dbexpr = $column_def->{dbexpr};
- $dbexpr{$column} = $order_by_dbexpr;
- $self->_require_tables($order_by_dbexpr, \%reqd_tables,
$tablealiashref, 1);
- }
-
- $columnalias = $column_def->{alias};
- if (defined $columnidx{$column} && $columnalias) {
- $order_by_dbexpr = $columnalias;
- }
- }
+ $order_by_dbexpr = $dbexpr{$column};
+
+ if (!$order_by_dbexpr) {
+ $order_by_dbexpr = $column_def->{dbexpr};
+ $dbexpr{$column} = $order_by_dbexpr;
+ $self->_require_tables($order_by_dbexpr, \%reqd_tables,
$tablealiashref, 1);
+ }
+
+ $columnalias = $column_def->{alias};
+ if (defined $columnidx{$column} && $columnalias) {
+ $order_by_dbexpr = $columnalias;
+ }
if ($order_by_dbexpr =~ /{/) { #}
$order_by_dbexpr = $self->substitute($order_by_dbexpr,
$params);
Modified: p5ee/trunk/App-Repository/t/DBI-select-join.t
==============================================================================
--- p5ee/trunk/App-Repository/t/DBI-select-join.t (original)
+++ p5ee/trunk/App-Repository/t/DBI-select-join.t Sun Oct 31 07:27:31 2010
@@ -744,6 +744,26 @@
p.first_name
EOF
$sql =
$rep->_mk_select_joined_sql("test_person",{},["first_name","last_name","city","state","age"],
+
{ordercols=>["last_name.asc","foo","city","address","gender.desc","first_name"]});
+is($sql, $expect_sql, "_mk_select_joined_sql(): order_by, embedded directions,
erroneous order-by column");
+&check_select($sql,7);
+
+$expect_sql = <<EOF;
+select
+ p.first_name,
+ p.last_name,
+ p.city,
+ p.state,
+ p.age
+from test_person p
+order by
+ p.last_name asc,
+ p.city,
+ p.address,
+ p.gender desc,
+ p.first_name
+EOF
+$sql =
$rep->_mk_select_joined_sql("test_person",{},["first_name","last_name","city","state","age"],
{ordercols=>["last_name","city","address","gender","first_name"],
directions=>{last_name=>"ASC",city=>"",address=>undef,gender=>"Desc"}});
is($sql, $expect_sql, "_mk_select_joined_sql(): ordercols, directions");