UpdateQuery.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2004-2007 by Anton E. Lebedevich                        *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: UpdateQuery.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class UpdateQuery
00017         extends InsertOrUpdateQuery
00018         implements JoinCapableQuery
00019     {
00020         private $joiner = null;
00021         
00022         public function __construct($table = null)
00023         {
00024             $this->table = $table;
00025             $this->joiner = new Joiner();
00026         }
00027         
00028         public function __clone()
00029         {
00030             $this->joiner = clone $this->joiner;
00031         }
00032         
00036         public function from($table, $alias = null)
00037         {
00038             $this->joiner->from(new FromTable($table, $alias));
00039 
00040             return $this;
00041         }
00042         
00043         public function hasJoinedTable($table)
00044         {
00045             return $this->joiner->hasJoinedTable($table);
00046         }
00047         
00051         public function join($table, LogicalObject $logic, $alias = null)
00052         {
00053             $this->joiner->join(new SQLJoin($table, $logic, $alias));
00054             return $this;
00055         }
00056         
00060         public function leftJoin($table, LogicalObject $logic, $alias = null)
00061         {
00062             $this->joiner->leftJoin(new SQLLeftJoin($table, $logic, $alias));
00063             return $this;
00064         }
00065         
00069         public function setTable($table)
00070         {
00071             $this->table = $table;
00072             
00073             return $this;
00074         }
00075 
00076         public function toDialectString(Dialect $dialect)
00077         {
00078             $query = "UPDATE ".$dialect->quoteTable($this->table)." SET ";
00079             
00080             $sets = array();
00081 
00082             foreach ($this->fields as $var => $val) {
00083                 if ($val instanceof DialectString)
00084                     $sets[] =
00085                         $dialect->quoteField($var)
00086                         .' = ('
00087                         .$val->toDialectString($dialect)
00088                         .')';
00089                 elseif ($val === null)
00090                     $sets[] = $dialect->quoteField($var).' = NULL';
00091                 elseif (true === $val)
00092                     $sets[] = $dialect->quoteField($var).' = TRUE';
00093                 elseif (false === $val)
00094                     $sets[] = $dialect->quoteField($var).' = FALSE';
00095                 else
00096                     $sets[] =
00097                         $dialect->quoteField($var)
00098                         .' = '
00099                         .$dialect->quoteValue($val);
00100             }
00101             
00102             return
00103                 $query
00104                 .implode(', ', $sets)
00105                 .$this->joiner->toDialectString($dialect)
00106                 .parent::toDialectString($dialect);
00107         }
00108     }
00109 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4