[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 /* 4 * $Id: DataSQLBuilder.php 1310 2006-05-04 07:36:54Z fabien $ 5 * 6 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 7 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 8 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 9 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 10 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 11 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 12 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 13 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 14 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 16 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 17 * 18 * This software consists of voluntary contributions made by many individuals 19 * and is licensed under the LGPL. For more information please see 20 * <http://propel.phpdb.org>. 21 */ 22 23 require_once 'propel/engine/builder/DataModelBuilder.php'; 24 25 /** 26 * Baseclass for SQL data dump SQL building classes. 27 * 28 * @author Hans Lellelid <hans@xmpl.org> 29 * @package propel.engine.builder.sql 30 */ 31 abstract class DataSQLBuilder extends DataModelBuilder { 32 33 /** 34 * The main method in this class, returns the SQL for INSERTing data into a row. 35 * @param DataRow $row The row to process. 36 * @return string 37 */ 38 public function buildRowSql(DataRow $row) 39 { 40 $sql = ""; 41 $platform = $this->getPlatform(); 42 $table = $this->getTable(); 43 44 $sql .= "INSERT INTO ".$this->quoteIdentifier($this->getTable()->getName())." ("; 45 46 // add column names to SQL 47 $colNames = array(); 48 foreach ($row->getColumnValues() as $colValue) { 49 $colNames[] = $this->quoteIdentifier($colValue->getColumn()->getName()); 50 } 51 52 $sql .= implode(',', $colNames); 53 54 $sql .= ") VALUES ("; 55 56 $colVals = array(); 57 foreach ($row->getColumnValues() as $colValue) { 58 $colVals[] = $this->getColumnValueSql($colValue); 59 } 60 61 $sql .= implode(',', $colVals); 62 $sql .= "); 63 "; 64 65 return $sql; 66 } 67 68 /** 69 * Gets the propertly escaped (and quoted) value for a column. 70 * @param ColumnValue $colValue 71 * @return mixed The proper value to be added to the string. 72 */ 73 protected function getColumnValueSql(ColumnValue $colValue) 74 { 75 $column = $colValue->getColumn(); 76 $creoleTypeString = PropelTypes::getCreoleType($column->getPropelType()); 77 $creoleTypeCode = CreoleTypes::getCreoleCode($creoleTypeString); 78 $method = 'get' . CreoleTypes::getAffix($creoleTypeCode) . 'Sql'; 79 return $this->$method($colValue->getValue()); 80 } 81 82 83 84 /** 85 * Gets a representation of a binary value suitable for use in a SQL statement. 86 * Default behavior is true = 1, false = 0. 87 * @param boolean $value 88 * @return int 89 */ 90 protected function getBooleanSql($value) 91 { 92 return (int) $value; 93 } 94 95 96 /** 97 * Gets a representation of a BLOB/LONGVARBINARY value suitable for use in a SQL statement. 98 * @param mixed $blob Blob object or string data. 99 * @return string 100 */ 101 protected function getBlobSql($blob) 102 { 103 // they took magic __toString() out of PHP5.0.0; this sucks 104 if (is_object($blob)) { 105 return "'" . $this->escape($blob->__toString()) . "'"; 106 } else { 107 return "'" . $this->escape($blob) . "'"; 108 } 109 } 110 111 /** 112 * Gets a representation of a CLOB/LONGVARCHAR value suitable for use in a SQL statement. 113 * @param mixed $clob Clob object or string data. 114 * @return string 115 */ 116 protected function getClobSql($clob) 117 { 118 // they took magic __toString() out of PHP5.0.0; this sucks 119 if (is_object($clob)) { 120 return "'" . $this->escape($clob->__toString()) . "'"; 121 } else { 122 return "'" . $this->escape($clob) . "'"; 123 } 124 } 125 126 /** 127 * Gets a representation of a date value suitable for use in a SQL statement. 128 * @param string $value 129 * @return string 130 */ 131 protected function getDateSql($value) 132 { 133 return "'" . date('Y-m-d', strtotime($value)) . "'"; 134 } 135 136 /** 137 * Gets a representation of a decimal value suitable for use in a SQL statement. 138 * @param double $value 139 * @return float 140 */ 141 protected function getDecimalSql($value) 142 { 143 return (float) $value; 144 } 145 146 /** 147 * Gets a representation of a double value suitable for use in a SQL statement. 148 * @param double $value 149 * @return double 150 */ 151 protected function getDoubleSql($value) 152 { 153 return (double) $value; 154 } 155 156 /** 157 * Gets a representation of a float value suitable for use in a SQL statement. 158 * @param float $value 159 * @return float 160 */ 161 protected function getFloatSql($value) 162 { 163 return (float) $value; 164 } 165 166 /** 167 * Gets a representation of an integer value suitable for use in a SQL statement. 168 * @param int $value 169 * @return int 170 */ 171 protected function getIntSql($value) 172 { 173 return (int) $value; 174 } 175 176 /** 177 * Gets a representation of a NULL value suitable for use in a SQL statement. 178 * @return null 179 */ 180 protected function getNullSql() 181 { 182 return 'NULL'; 183 } 184 185 /** 186 * Gets a representation of a string value suitable for use in a SQL statement. 187 * @param string $value 188 * @return string 189 */ 190 protected function getStringSql($value) 191 { 192 return "'" . $this->getPlatform()->escapeText($value) . "'"; 193 } 194 195 /** 196 * Gets a representation of a time value suitable for use in a SQL statement. 197 * @param string $value 198 * @return string 199 */ 200 protected function getTimeSql($paramIndex, $value) 201 { 202 return "'" . date('H:i:s', strtotime($value)) . "'"; 203 } 204 205 /** 206 * Gets a representation of a timestamp value suitable for use in a SQL statement. 207 * @param string $value 208 * @return string 209 */ 210 function getTimestampSql($value) 211 { 212 return "'" . date('Y-m-d H:i:s', strtotime($value)) . "'"; 213 } 214 215 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |