DeleteQuery.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2004-2007 by Konstantin V. Arkhipov                     *
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 
00015     final class DeleteQuery extends QuerySkeleton implements SQLTableName
00016     {
00017         protected $table    = null;
00018         
00019         public function getId()
00020         {
00021             throw new UnsupportedMethodException();
00022         }
00023         
00027         public function from($table)
00028         {
00029             $this->table = $table;
00030             
00031             return $this;
00032         }
00033         
00034         public function getTable()
00035         {
00036             return $this->table;
00037         }
00038         
00039         public function toDialectString(Dialect $dialect)
00040         {
00041             if ($this->where) {
00042                 $deleteStr =
00043                     'DELETE FROM '.$dialect->quoteTable($this->table)
00044                     .parent::toDialectString($dialect);
00045                 
00046                 $this->checkReturning($dialect);
00047                 
00048                 if (empty($this->returning)) {
00049                     return $deleteStr;
00050                 } else {
00051                     $query =
00052                         $deleteStr
00053                         .' RETURNING '
00054                         .$this->toDialectStringReturning($dialect);
00055                     
00056                     return $query;
00057                 }
00058             } else
00059                 throw new WrongArgumentException(
00060                     "leave '{$this->table}' table alone in peace, bastard"
00061                 );
00062         }
00063     }
00064 ?>