/** * Gets the propertly escaped (and quoted) value for a column. * @param ColumnValue $colValue * @return mixed The proper value to be added to the string. */ protected function getColumnValueSql(ColumnValue $colValue) { $column = $colValue->getColumn(); $creoleTypeString = PropelTypes::getCreoleType($column->getPropelType()); $creoleTypeCode = CreoleTypes::getCreoleCode($creoleTypeString); $method = 'get' . CreoleTypes::getAffix($creoleTypeCode) . 'Sql'; return $this->{$method}($colValue->getValue()); }
/** * Adds the hydrate() method, which sets attributes of the object based on a ResultSet. */ protected function addHydrate(&$script) { $table = $this->getTable(); $script .= "\n\t/**\n\t * Hydrates (populates) the object variables with values from the database resultset.\n\t *\n\t * An offset (1-based \"start column\") is specified so that objects can be hydrated\n\t * with a subset of the columns in the resultset rows. This is needed, for example,\n\t * for results of JOIN queries where the resultset row includes columns from two or\n\t * more tables.\n\t *\n\t * @param ResultSet \$rs The ResultSet class with cursor advanced to desired record pos.\n\t * @param int \$startcol 1-based offset column which indicates which restultset column to start with.\n\t * @return int next starting column\n\t * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.\n\t */\n\tpublic function hydrate(ResultSet \$rs, \$startcol = 1)\n\t{\n\t\ttry {\n"; $n = 0; foreach ($table->getColumns() as $col) { if (!$col->isLazyLoad()) { $affix = CreoleTypes::getAffix(CreoleTypes::getCreoleCode($col->getType())); $clo = strtolower($col->getName()); switch ($col->getType()) { case PropelTypes::DATE: case PropelTypes::TIME: case PropelTypes::TIMESTAMP: $script .= "\n\t\t\t\$this->{$clo} = \$rs->get{$affix}(\$startcol + {$n}, null);\n"; break; default: $script .= "\n\t\t\t\$this->{$clo} = \$rs->get{$affix}(\$startcol + {$n});\n"; } $n++; } // if col->isLazyLoad() } /* foreach */ if ($this->getBuildProperty("addSaveMethod")) { $script .= "\n\t\t\t\$this->resetModified();\n"; } $script .= "\n\t\t\t\$this->setNew(false);\n\n\t\t\t// FIXME - using NUM_COLUMNS may be clearer.\n\t\t\treturn \$startcol + {$n}; // {$n} = " . $this->getPeerClassname() . "::NUM_COLUMNS - " . $this->getPeerClassname() . "::NUM_LAZY_LOAD_COLUMNS).\n\n\t\t} catch (Exception \$e) {\n\t\t\tthrow new PropelException(\"Error populating " . $table->getPhpName() . " object\", \$e);\n\t\t}\n\t}\n"; }
/** * populates stmt values (?,?,?) on sql querys * @param PreparedStatement, stmt, the prepared statement. * @param array, fields, the affected fields */ private static function populateStmtValues($stmt, $fields) { $i = 1; foreach ($fields as $field) { if ($field->getValue() === NULL) { $stmt->setNull($i++); } else { $setter = 'set' . CreoleTypes::getAffix(CreoleTypes::getCreoleCode(strtoupper($field->type))); $stmt->{$setter}($i++, $field->getValue()); } } }