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 /* $Id: InsertQuery.class.php 4687 2007-12-09 18:57:18Z voxus $ */ 00012 00016 final class InsertQuery extends InsertOrUpdateQuery 00017 { 00021 public function into($table) 00022 { 00023 $this->table = $table; 00024 00025 return $this; 00026 } 00027 00033 public function setTable($table) 00034 { 00035 return $this->into($table); 00036 } 00037 00038 public function toDialectString(Dialect $dialect) 00039 { 00040 $query = "INSERT INTO ".$dialect->quoteTable($this->table)." "; 00041 00042 $fields = array(); 00043 $values = array(); 00044 00045 foreach ($this->fields as $var => $val) { 00046 $fields[] = $dialect->quoteField($var); 00047 00048 if ($val === null) 00049 $values[] = 'NULL'; 00050 elseif (true === $val) 00051 $values[] = 'TRUE'; 00052 elseif (false === $val) 00053 $values[] = 'FALSE'; 00054 else 00055 $values[] = $dialect->quoteValue($val); 00056 } 00057 00058 if (!$fields || !$values) 00059 throw new WrongStateException('what should i insert?'); 00060 00061 $fields = implode(', ', $fields); 00062 $values = implode(', ', $values); 00063 00064 $query .= "({$fields}) VALUES ({$values})"; 00065 00066 return $query; 00067 } 00068 00069 public function where(LogicalObject $exp, $logic = null) 00070 { 00071 throw new UnsupportedMethodException(); 00072 } 00073 00074 public function andWhere(LogicalObject $exp) 00075 { 00076 throw new UnsupportedMethodException(); 00077 } 00078 00079 public function orWhere(LogicalObject $exp) 00080 { 00081 throw new UnsupportedMethodException(); 00082 } 00083 } 00084 ?>