Issues

ZF-79: Zend_Db_Pdo_Mssql uninitialized variable (TRAC#89 darby)

Issue Type: Bug Created: 2006-06-20T23:18:53.000+0000 Last Updated: 2007-07-05T14:43:08.000+0000 Status: Resolved Fix version(s): - 0.2.0 (29/Oct/06)

Reporter: Zend Framework (zend_framework) Assignee: Gavin (gavin) Tags: - Zend_Db

Related issues: - ZF-234

Attachments:

Description

http://framework.zend.com/developer/ticket/89

Rob Allen confirms this as a bug:

message from Jan Pieper:

I´ve found a variable where I can´t see where it comes from. It is not initialized and nothing.

Zend/Db/Pdo/Mssql.php:137 $order = implode(',', $parts['order']);

What is $parts? (Revision: 464)

-- Jan Pieper

Comments

Posted by Zend Framework (zend_framework) on 2006-06-20T23:19:20.000+0000

06/05/06 11:20:07: Modified by gavin

The code in Zend/Db/Pdo/Mssql.php is not consistent with information presented here: http://lists.bestpractical.com/pipermail/rt-devel/…

Hopefully, someone familiar with MSSQL will volunteer a patch :)

Posted by Justin Plock (jplock) on 2006-08-02T15:33:07.000+0000

/** * Adds an adapter-specific LIMIT clause to the SELECT statement. * * @link http://lists.bestpractical.com/pipermail/rt-devel/… * @return string */ public function limit($sql, $count, $offset) { if ($count) {

       $orderby = stristr($sql, 'ORDER BY');
       if ($orderby !== false) {
           $sort = (stripos($orderby, 'desc') !== false) ? 'desc' : 'asc';
           $order = str_ireplace('ORDER BY', '', $orderby);
           $order = trim(preg_replace('/ASC|DESC/i', '', $order));
       }

       $sql = preg_replace('/^SELECT /i', 'SELECT TOP '.($count+$offset).' ', $sql);

       $sql = 'SELECT * FROM (SELECT TOP '.$count.' * FROM ('.$sql.') AS inner_tbl';
       if ($orderby !== false) {
           $sql .= ' ORDER BY '.$order.' ';
           $sql .= (stripos($sort, 'asc') !== false) ? 'DESC' : 'ASC';
       }
       $sql .= ') AS outer_tbl';
       if ($orderby !== false) {
           $sql .= ' ORDER BY '.$order.' '.$sort;
       }
  }
  return $sql;

}

I've found this code works pretty well in some other applications I've done

Posted by Justin Plock (jplock) on 2006-08-02T15:38:25.000+0000

<pre class="highlight">
   /**
    * Adds an adapter-specific LIMIT clause to the SELECT statement.
    *
    * @link <a href="http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html">http://lists.bestpractical.com/pipermail/rt-devel/…</a>
    * @return string
    */
   public function limit($sql, $count, $offset)
   {
       if ($count) {

           $orderby = stristr($sql, 'ORDER BY');
           if ($orderby !== false) {
               $sort = (stripos($orderby, 'desc') !== false) ? 'desc' : 'asc';
               $order = str_ireplace('ORDER BY', '', $orderby);
               $order = trim(preg_replace('/ASC|DESC/i', '', $order));
           }

           $sql = preg_replace('/^SELECT /i', 'SELECT TOP '.($count+$offset).' ', $sql);

           $sql = 'SELECT * FROM (SELECT TOP '.$count.' * FROM ('.$sql.') AS inner_tbl';
           if ($orderby !== false) {
               $sql .= ' ORDER BY '.$order.' ';
               $sql .= (stripos($sort, 'asc') !== false) ? 'DESC' : 'ASC';
           }
           $sql .= ') AS outer_tbl';
           if ($orderby !== false) {
               $sql .= ' ORDER BY '.$order.' '.$sort;
           }
      }
      return $sql;
  }

Let's try this again.

Posted by Justin Plock (jplock) on 2006-08-02T15:43:43.000+0000

I don't think I have access to actually make this change in the SVN repository, but I believe this new limit() method will resolve this issue.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts