/** * 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()); }
protected function initialize() { $this->schemaDomainMap = array(); foreach (PropelTypes::getPropelTypes() as $type) { $this->schemaDomainMap[$type] = new Domain($type); } $this->schemaDomainMap[PropelTypes::BU_DATE] = new Domain("DATE"); $this->schemaDomainMap[PropelTypes::BU_TIMESTAMP] = new Domain("TIMESTAMP"); $this->schemaDomainMap[PropelTypes::BOOLEAN] = new Domain("INTEGER"); }
/** * Returns true if the column's PHP native type is a class name. * @return boolean * @see PropelTypes::isPhpObjectType() */ public function isPhpObjectType() { return PropelTypes::isPhpObjectType($this->getPhpType()); }
/** * Initializes the SQL to PHP map so that it * can be used by client code. */ public static function initialize() { if (self::$isInitialized === false) { self::$TEXT_TYPES = array ( self::CHAR, self::VARCHAR, self::LONGVARCHAR, self::CLOB, self::DATE, self::TIME, self::TIMESTAMP, self::BU_DATE, self::BU_TIMESTAMP ); self::$LOB_TYPES = array ( self::VARBINARY, self::LONGVARBINARY, self::CLOB, self::BLOB ); /* * Create Creole -> native PHP type mappings. */ self::$propelToPHPNativeMap = array(); self::$propelToPHPNativeMap[self::CHAR] = self::CHAR_NATIVE_TYPE; self::$propelToPHPNativeMap[self::VARCHAR] = self::VARCHAR_NATIVE_TYPE; self::$propelToPHPNativeMap[self::LONGVARCHAR] = self::LONGVARCHAR_NATIVE_TYPE; self::$propelToPHPNativeMap[self::CLOB] = self::CLOB_NATIVE_TYPE; self::$propelToPHPNativeMap[self::NUMERIC] = self::NUMERIC_NATIVE_TYPE; self::$propelToPHPNativeMap[self::DECIMAL] = self::DECIMAL_NATIVE_TYPE; self::$propelToPHPNativeMap[self::TINYINT] = self::TINYINT_NATIVE_TYPE; self::$propelToPHPNativeMap[self::SMALLINT] = self::SMALLINT_NATIVE_TYPE; self::$propelToPHPNativeMap[self::INTEGER] = self::INTEGER_NATIVE_TYPE; self::$propelToPHPNativeMap[self::BIGINT] = self::BIGINT_NATIVE_TYPE; self::$propelToPHPNativeMap[self::REAL] = self::REAL_NATIVE_TYPE; self::$propelToPHPNativeMap[self::FLOAT] = self::FLOAT_NATIVE_TYPE; self::$propelToPHPNativeMap[self::DOUBLE] = self::DOUBLE_NATIVE_TYPE; self::$propelToPHPNativeMap[self::BINARY] = self::BINARY_NATIVE_TYPE; self::$propelToPHPNativeMap[self::VARBINARY] = self::VARBINARY_NATIVE_TYPE; self::$propelToPHPNativeMap[self::LONGVARBINARY] = self::LONGVARBINARY_NATIVE_TYPE; self::$propelToPHPNativeMap[self::BLOB] = self::BLOB_NATIVE_TYPE; self::$propelToPHPNativeMap[self::DATE] = self::DATE_NATIVE_TYPE; self::$propelToPHPNativeMap[self::BU_DATE] = self::BU_DATE_NATIVE_TYPE; self::$propelToPHPNativeMap[self::TIME] = self::TIME_NATIVE_TYPE; self::$propelToPHPNativeMap[self::TIMESTAMP] = self::TIMESTAMP_NATIVE_TYPE; self::$propelToPHPNativeMap[self::BU_TIMESTAMP] = self::BU_TIMESTAMP_NATIVE_TYPE; self::$propelToPHPNativeMap[self::BOOLEAN] = self::BOOLEAN_NATIVE_TYPE; /* * Create Propel -> Creole _name_ mappings (not CreoleType:: mappings). * (this is now pretty useless since we've designed them to be the same!) */ self::$propelTypeToCreoleTypeMap = array(); self::$propelTypeToCreoleTypeMap[self::CHAR] = self::CHAR; self::$propelTypeToCreoleTypeMap[self::VARCHAR] = self::VARCHAR; self::$propelTypeToCreoleTypeMap[self::LONGVARCHAR] = self::LONGVARCHAR; self::$propelTypeToCreoleTypeMap[self::CLOB] = self::CLOB; self::$propelTypeToCreoleTypeMap[self::NUMERIC] = self::NUMERIC; self::$propelTypeToCreoleTypeMap[self::DECIMAL] = self::DECIMAL; self::$propelTypeToCreoleTypeMap[self::TINYINT] = self::TINYINT; self::$propelTypeToCreoleTypeMap[self::SMALLINT] = self::SMALLINT; self::$propelTypeToCreoleTypeMap[self::INTEGER] = self::INTEGER; self::$propelTypeToCreoleTypeMap[self::BIGINT] = self::BIGINT; self::$propelTypeToCreoleTypeMap[self::REAL] = self::REAL; self::$propelTypeToCreoleTypeMap[self::FLOAT] = self::FLOAT; self::$propelTypeToCreoleTypeMap[self::DOUBLE] = self::DOUBLE; self::$propelTypeToCreoleTypeMap[self::BINARY] = self::BINARY; self::$propelTypeToCreoleTypeMap[self::VARBINARY] = self::VARBINARY; self::$propelTypeToCreoleTypeMap[self::LONGVARBINARY] = self::LONGVARBINARY; self::$propelTypeToCreoleTypeMap[self::BLOB] = self::BLOB; self::$propelTypeToCreoleTypeMap[self::DATE] = self::DATE; self::$propelTypeToCreoleTypeMap[self::TIME] = self::TIME; self::$propelTypeToCreoleTypeMap[self::TIMESTAMP] = self::TIMESTAMP; self::$propelTypeToCreoleTypeMap[self::BOOLEAN] = self::BOOLEAN; // These are pre-epoch dates, which we need to map to String type // since they cannot be properly handled using strtotime() -- or even numeric // timestamps on Windows. self::$propelTypeToCreoleTypeMap[self::BU_DATE] = self::VARCHAR; self::$propelTypeToCreoleTypeMap[self::BU_TIMESTAMP] = self::VARCHAR; /* * Create Creole type code to Propel type map. */ self::$creoleToPropelTypeMap = array(); self::$creoleToPropelTypeMap[CreoleTypes::CHAR] = self::CHAR; self::$creoleToPropelTypeMap[CreoleTypes::VARCHAR] = self::VARCHAR; self::$creoleToPropelTypeMap[CreoleTypes::LONGVARCHAR] = self::LONGVARCHAR; self::$creoleToPropelTypeMap[CreoleTypes::CLOB] = self::CLOB; self::$creoleToPropelTypeMap[CreoleTypes::NUMERIC] = self::NUMERIC; self::$creoleToPropelTypeMap[CreoleTypes::DECIMAL] = self::DECIMAL; self::$creoleToPropelTypeMap[CreoleTypes::TINYINT] = self::TINYINT; self::$creoleToPropelTypeMap[CreoleTypes::SMALLINT] = self::SMALLINT; self::$creoleToPropelTypeMap[CreoleTypes::INTEGER] = self::INTEGER; self::$creoleToPropelTypeMap[CreoleTypes::BIGINT] = self::BIGINT; self::$creoleToPropelTypeMap[CreoleTypes::REAL] = self::REAL; self::$creoleToPropelTypeMap[CreoleTypes::FLOAT] = self::FLOAT; self::$creoleToPropelTypeMap[CreoleTypes::DOUBLE] = self::DOUBLE; self::$creoleToPropelTypeMap[CreoleTypes::BINARY] = self::BINARY; self::$creoleToPropelTypeMap[CreoleTypes::VARBINARY] = self::VARBINARY; self::$creoleToPropelTypeMap[CreoleTypes::LONGVARBINARY] = self::LONGVARBINARY; self::$creoleToPropelTypeMap[CreoleTypes::BLOB] = self::BLOB; self::$creoleToPropelTypeMap[CreoleTypes::DATE] = self::DATE; self::$creoleToPropelTypeMap[CreoleTypes::TIME] = self::TIME; self::$creoleToPropelTypeMap[CreoleTypes::TIMESTAMP] = self::TIMESTAMP; self::$creoleToPropelTypeMap[CreoleTypes::BOOLEAN] = self::BOOLEAN; self::$creoleToPropelTypeMap[CreoleTypes::YEAR] = self::INTEGER; self::$isInitialized = true; } }
/** * Get the PHP snippet for binding a value to a column. * Warning: duplicates logic from DBOracle::bindValue(). * Any code modification here must be ported there. */ public function getColumnBindingPHP($column, $identifier, $columnValueAccessor, $tab = "\t\t\t") { if ($column->getPDOType() == PropelTypes::CLOB_EMU) { return sprintf("%s\$stmt->bindParam(%s, %s, %s, strlen(%s));\r\n", $tab, $identifier, $columnValueAccessor, PropelTypes::getPdoTypeString($column->getType()), $columnValueAccessor); } return parent::getColumnBindingPHP($column, $identifier, $columnValueAccessor, $tab); }
/** * Initialize the type -> Domain mapping. */ protected function initialize() { $this->schemaDomainMap = array(); foreach (PropelTypes::getPropelTypes() as $type) { $this->schemaDomainMap[$type] = new Domain($type); } // BU_* no longer needed, so map these to the DATE/TIMESTAMP domains $this->schemaDomainMap[PropelTypes::BU_DATE] = new Domain(PropelTypes::DATE); $this->schemaDomainMap[PropelTypes::BU_TIMESTAMP] = new Domain(PropelTypes::TIMESTAMP); // Boolean is a bit special, since typically it must be mapped to INT type. $this->schemaDomainMap[PropelTypes::BOOLEAN] = new Domain(PropelTypes::BOOLEAN, "INTEGER"); }
/** * Creates an column node * * @param object $column The Creole column * @return object The column node instance */ protected function createColumnNode($column) { $node = $this->doc->createElement("column"); $table = $column->getTable(); $colName = $column->getName(); $colType = $column->getType(); $colSize = $column->getSize(); $colScale = $column->getScale(); if ($colType === CreoleTypes::OTHER) { $this->log("Column [" . $table->getName() . "." . $colName . "] has a column type (" . $column->getNativeType() . ") that Propel does not support.", PROJECT_MSG_WARN); } $node->setAttribute("name", $colName); if ($this->isSamePhpName()) { $node->setAttribute("phpName", $colName); } $node->setAttribute("type", PropelTypes::getPropelType($colType)); if ($colSize > 0 && ($colType == CreoleTypes::CHAR || $colType == CreoleTypes::VARCHAR || $colType == CreoleTypes::LONGVARCHAR || $colType == CreoleTypes::DECIMAL || $colType == CreoleTypes::FLOAT || $colType == CreoleTypes::NUMERIC)) { $node->setAttribute("size", (string) $colSize); } if ($colScale > 0 && ($colType == CreoleTypes::DECIMAL || $colType == CreoleTypes::FLOAT || $colType == CreoleTypes::NUMERIC)) { $node->setAttribute("scale", (string) $colScale); } if (!$column->isNullable()) { $node->setAttribute("required", "true"); } if ($column->isAutoIncrement()) { $node->setAttribute("autoIncrement", "true"); } if (in_array($colName, $this->getTablePkCols($table))) { $node->setAttribute("primaryKey", "true"); } if (($defValue = $column->getDefaultValue()) !== null) { $node->setAttribute("default", iconv($this->dbEncoding, 'utf-8', $defValue)); } if ($vendorNode = $this->createVendorInfoNode($column->getVendorSpecificInfo())) { $node->appendChild($vendorNode); } return $node; }
/** * Creates an column node * * @param object $column The Creole column * @return object The column node instance */ protected function createColumnNode($column) { $node = $this->doc->createElement("column"); $table = $column->getTable(); $colName = $column->getName(); $colType = $column->getType(); $colSize = $column->getSize(); $colScale = $column->getScale(); if ($colType === CreoleTypes::OTHER) { $this->log("Column [" . $table->getName() . "." . $colName . "] has a column type (".$column->getNativeType().") that Propel does not support.", PROJECT_MSG_WARN); } $node->setAttribute("name", $colName); if ($this->isSamePhpName()) { $node->setAttribute("phpName", $colName); } $node->setAttribute("type", PropelTypes::getPropelType($colType)); if ($colSize > 0 && ( $colType == CreoleTypes::CHAR || $colType == CreoleTypes::VARCHAR || $colType == CreoleTypes::LONGVARCHAR || $colType == CreoleTypes::DECIMAL || $colType == CreoleTypes::FLOAT || $colType == CreoleTypes::NUMERIC)) { $node->setAttribute("size", (string) $colSize); } if ($colScale > 0 && ( $colType == CreoleTypes::DECIMAL || $colType == CreoleTypes::FLOAT || $colType == CreoleTypes::NUMERIC)) { $node->setAttribute("scale", (string) $colScale); } if (!$column->isNullable()) { $node->setAttribute("required", "true"); } if ($column->isAutoIncrement()) { $node->setAttribute("autoIncrement", "true"); } if (in_array($colName, $this->getTablePkCols($table))) { $node->setAttribute("primaryKey", "true"); } //following changed to insert '' instead of blank if default is empty but not null. And to not insert CURRENT_TIMESTAMP since creole can't handle it. $defValue = $column->getDefaultValue(); if (null !== $defValue && 'CURRENT_TIMESTAMP' != $defValue) { if ('' === $defValue) { $node->setAttribute("default", "''"); } else { $node->setAttribute("default", iconv($this->dbEncoding, 'utf-8', $defValue)); } } if ($vendorNode = $this->createVendorInfoNode($column->getVendorSpecificInfo())) { $node->appendChild($vendorNode); } return $node; }
/** * Get the PHP snippet for binding a value to a column. * Warning: duplicates logic from DBAdapter::bindValue(). * Any code modification here must be ported there. */ public function getColumnBindingPHP($column, $identifier, $columnValueAccessor, $tab = "\t\t\t") { $script = ''; $hasValuePreparation = false; if ($column->isTemporalType()) { // nothing special, the internal value was already properly formatted by the setter } elseif ($column->isLobType()) { // we always need to make sure that the stream is rewound, otherwise nothing will // get written to database. $script .= "\nif (is_resource({$columnValueAccessor})) {\n rewind({$columnValueAccessor});\n}"; } $script .= sprintf("\n\$stmt->bindValue(%s, %s, %s);", $identifier, $columnValueAccessor, PropelTypes::getPdoTypeString($column->getType())); return preg_replace('/^(.+)/m', $tab . '$1', $script); }
/** * Return a string representation of the native PHP type which corresponds * to the Creole type of this column. Use in the generation of Base objects. * * @return string PHP datatype used by propel. */ public function getPhpNative() { return PropelTypes::getPHPNative($this->propelType); }