cvs: pearweb /include pear-database-category.php

From: Date: Sun, 10 Feb 2008 18:23:36 +0000
Subject: cvs: pearweb /include pear-database-category.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-cvs+get-50957@lists.php.net to get a copy of this message
dufuz Sun Feb 10 18:23:36 2008 UTC Modified files: /pearweb/include pear-database-category.php Log: Cosmetics http://cvs.php.net/viewvc.cgi/pearweb/include/pear-database-category.php?r1=1.5&r2=1.6&diff_format=u Index: pearweb/include/pear-database-category.php diff -u pearweb/include/pear-database-category.php:1.5 pearweb/include/pear-database-category.php:1.6 --- pearweb/include/pear-database-category.php:1.5 Wed Feb 6 01:02:09 2008 +++ pearweb/include/pear-database-category.php Sun Feb 10 18:23:36 2008 @@ -18,7 +18,7 @@ | Martin Jansen <mj@php.net> | | Richard Heyes <richard@php.net> | +----------------------------------------------------------------------+ - $Id: pear-database-category.php,v 1.5 2008/02/06 01:02:09 dufuz Exp $ + $Id: pear-database-category.php,v 1.6 2008/02/10 18:23:36 dufuz Exp $ */ // These classes correspond to tables and methods define operations on @@ -58,8 +58,7 @@ $desc = (empty($data['desc'])) ? 'none' : $data['desc']; $parent = (empty($data['parent'])) ? null : $data['parent']; - $sql = 'INSERT INTO categories (id, name, description, parent)'. - 'VALUES (?, ?, ?, ?)'; + $sql = 'INSERT INTO categories (id, name, description, parent) VALUES (?, ?, ?, ?)'; $id = $dbh->nextId('categories'); $err = $dbh->query($sql, array($id, $name, $desc, $parent)); if (DB::isError($err)) { @@ -85,9 +84,12 @@ */ static function update($id, $name, $desc = '') { - $data = $GLOBALS['dbh']->getOne('SELECT name FROM categories WHERE id = ?', array($id)); + $sql = 'SELECT name FROM categories WHERE id = ?'; + $data = $GLOBALS['dbh']->getOne($sql, array($id)); $GLOBALS['pear_rest']->deleteCategoryREST($data); - $ret = $GLOBALS['dbh']->query('UPDATE categories SET name = ?, description = ? WHERE id = ?', array($name, $desc, $id)); + + $sql = 'UPDATE categories SET name = ?, description = ? WHERE id = ?'; + $ret = $GLOBALS['dbh']->query($sql, array($name, $desc, $id)); $GLOBALS['pear_rest']->saveCategoryREST($name); $GLOBALS['pear_rest']->saveAllCategoriesREST(); $GLOBALS['pear_rest']->savePackagesCategoryREST($name); @@ -144,8 +146,8 @@ static function listAll() { global $dbh; - return $dbh->getAll("SELECT * FROM categories ORDER BY name", - null, DB_FETCHMODE_ASSOC); + $sql = 'SELECT * FROM categories ORDER BY name'; + return $dbh->getAll($sql, null, DB_FETCHMODE_ASSOC); } /** @@ -245,31 +247,31 @@ { global $dbh; if ($parent === null) { - $left = $dbh->getOne("select max(cat_right) + 1 from categories - where parent is null"); + $left = $dbh->getOne("SELECT max(cat_right) + 1 FROM categories + WHERE parent IS NULL"); $left = ($left !== null) ? $left : 1; // first node } else { - $left = $dbh->getOne("select cat_right from categories where id = $parent"); + $left = $dbh->getOne("SELECT cat_right FROM categories WHERE id = $parent"); } $right = $left + 1; // update my self - $err = $dbh->query("update categories - set cat_left = $left, cat_right = $right - where id = $id"); + $err = $dbh->query("UPDATE categories + SET cat_left = $left, cat_right = $right + WHERE id = $id"); if (PEAR::isError($err)) { return $err; } if ($parent === null) { return true; } - $err = $dbh->query("update categories set cat_left = cat_left+2 - where cat_left > $left"); + $err = $dbh->query("UPDATE categories SET cat_left = cat_left+2 + WHERE cat_left > $left"); if (PEAR::isError($err)) { return $err; } // (cat_right >= $left) == update the parent but not the node itself - $err = $dbh->query("update categories set cat_right = cat_right+2 - where cat_right >= $left and id <> $id"); + $err = $dbh->query("UPDATE categories SET cat_right = cat_right+2 + WHERE cat_right >= $left and id <> $id"); if (PEAR::isError($err)) { return $err; }

« previous php.pear.cvs (#50957) next »