perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cameron B. Prince" <cpri...@rideware.com>
Subject DBIx::Recordset Patch - Direct Query Input
Date Thu, 22 May 2003 20:30:27 GMT

Hey guys,

After digging around in the mailing list, I found the problem with
escaping... But was still stumped as to how I was going to convert some
rather complex queries to a new format I wasn't familiar with.

When I was applying the escaping patch, I decided to try a direct query
input. I discovered that I had to add the $append to the end because it
contains the LIMIT and OFFSET clauses which allow the paging effect to work.

Please let me know if I'm overlooking some reason why I shouldn't do it this
way.

Here's a sample call and the patch:

  [-
  use DBIx::Recordset ;

  $fdat{'!DataSource'} = 'dbi:Pg:dbname=devdb' ;
  $fdat{'$max'}     = 50 ;
  $fdat{'!Query'} = <<EOP;
SELECT a.user__id, a.title, a.dateadded, b.title AS hr_title, c.title AS
w2_title
FROM user a
LEFT OUTER JOIN hr b
ON a.hr__id=b.hr__id
LEFT OUTER JOIN w2 c
ON a.w2__id=c.w2__id
WHERE a.dateadded = (
        SELECT MAX(dateadded)
        FROM user
)
EOP

  *set = DBIx::Recordset -> Search(\%fdat) ;
  $names = $set -> Names ;
  -]

  <table>
    <tr>
      <th>[+ $names -> [$col] +]</th>
    </tr>
    <tr>
      [- $rec = $set[$row] -]
      <td>[+ $rec -> {$names->[$col]} +]</td>
    </tr>
  </table>

<br><br>

[+do { local $escmode = 3 ;$set->PrevNextForm
({-prev=>'<<Back', -next=>'Next>>'}, \%fdat) } +]

<br><br>



--- DBIx/Recordset.pm.orig      2003-05-23 03:14:50.000000000 -0500
+++ DBIx/Recordset.pm   2003-05-23 04:20:43.000000000 -0500
@@ -161,6 +161,7 @@
         $self->{'*DBIAttr'}    = $data_source->{'*DBIAttr'} ;
         $self->{'*MainHdl'}    = 0 ;
         $self->{'*TableFilter'}= $data_source->{'*TableFilter'} ;
+        $self->{'*Query'}      = $data_source->{'*Query'} ;
         }
     elsif (ref ($data_source) eq 'DBIx::Database')
         { # copy from database object
@@ -447,6 +448,7 @@
     $self -> SetupMemberVar ('Order', $parm) ;
     $self -> SetupMemberVar ('TableFilter', $parm) ;
     $self -> SetupMemberVar ('DoOnConnect', $parm) ;
+    $self -> SetupMemberVar ('Query', $parm) ;


     if ($self -> {'*Serial'})
@@ -1325,7 +1327,13 @@
     $fields ||= '*';
     $table    = $self->{'*TabJoin'} || $self->{'*Table'} ;

-    my $statement = "SELECT $fields FROM $table $where $expr $groupby
$group $orderby $order $append" ;
+    my $statement;
+
+    if ($self->{'*Query'}) {
+       $statement = $self->{'*Query'} . " " . $append;
+    } else {
+       $statement = "SELECT $fields FROM $table $where $expr $groupby
$group $orderby $order $append" ;
+    }

     if ($self->{'*Debug'} > 1)
         {
@@ -3063,9 +3071,11 @@
     my $start = $self -> {'*StartRecordNo'} ;
     my $max   = $self -> {'*FetchMax'} - $self -> {'*FetchStart'} + 1 ;

-
+
     my $esc = '' ;
-    $esc = '\\' if (defined ($HTML::Embperl::escmode) &&
($HTML::Embperl::escmode & 1)) ;
+    $esc = '\\' if ((defined ($HTML::Embperl::escmode) &&
+    ($HTML::Embperl::escmode & 1)) || (defined ($Embperl::escmode) &&
+    ($Embperl::escmode & 1))) ;
     my $buttons = "$esc<form method=$esc\"POST$esc\"$esc>$esc<input
type=$esc\"hidden$esc\" name=$esc\"\$start$esc\"
value=$esc\"$start$esc\"$esc>\n$esc<input type=$esc\"hidden$esc\"
name=$esc\"\$max$esc\" value=$esc\"$max$esc\"$esc>\n" ;
     my $k ;
     my $v ;


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Mime
View raw message