PageRenderTime 54ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/symfony/vendor/propel-generator/classes/propel/engine/database/model/Column.php

http://pumukit.googlecode.com/
PHP | 921 lines | 603 code | 76 blank | 242 comment | 31 complexity | a5aaa3c5b6788ecea5c8e03c4e8787b9 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /*
  3. * $Id: Column.php 536 2007-01-10 14:30:38Z heltem $
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://propel.phpdb.org>.
  20. */
  21. require_once 'propel/engine/database/model/XMLElement.php';
  22. include_once 'propel/engine/EngineException.php';
  23. include_once 'propel/engine/database/model/PropelTypes.php';
  24. include_once 'propel/engine/database/model/Inheritance.php';
  25. include_once 'propel/engine/database/model/Domain.php';
  26. /**
  27. * A Class for holding data about a column used in an Application.
  28. *
  29. * @author Hans Lellelid <hans@xmpl.org> (Propel)
  30. * @author Leon Messerschmidt <leon@opticode.co.za> (Torque)
  31. * @author Jason van Zyl <jvanzyl@apache.org> (Torque)
  32. * @author Jon S. Stevens <jon@latchkey.com> (Torque)
  33. * @author Daniel Rall <dlr@finemaltcoding.com> (Torque)
  34. * @author Byron Foster <byron_foster@yahoo.com> (Torque)
  35. * @version $Revision: 536 $
  36. * @package propel.engine.database.model
  37. */
  38. class Column extends XMLElement {
  39. const DEFAULT_TYPE = "VARCHAR";
  40. private $name;
  41. private $description;
  42. private $phpName = null;
  43. private $phpNamingMethod;
  44. private $isNotNull = false;
  45. private $size;
  46. /**
  47. * The name to use for the Peer constant that identifies this column.
  48. * (Will be converted to all-uppercase in the templates.)
  49. * @var string
  50. */
  51. private $peerName;
  52. /**
  53. * Type as defined in schema.xml
  54. * @var string
  55. */
  56. private $propelType;
  57. /**
  58. * Type corresponding to Creole type
  59. * @var int
  60. */
  61. private $creoleType;
  62. /**
  63. * Native PHP type
  64. * @var string "string", "boolean", "int", "double"
  65. */
  66. private $phpType;
  67. private $parentTable;
  68. private $position;
  69. private $isPrimaryKey = false;
  70. private $isNodeKey = false;
  71. private $nodeKeySep;
  72. private $isUnique = false;
  73. private $isAutoIncrement = false;
  74. private $isLazyLoad = false;
  75. private $defaultValue;
  76. private $referrers;
  77. // only one type is supported currently, which assumes the
  78. // column either contains the classnames or a key to
  79. // classnames specified in the schema. Others may be
  80. // supported later.
  81. private $inheritanceType;
  82. private $isInheritance;
  83. private $isEnumeratedClasses;
  84. private $inheritanceList;
  85. private $needsTransactionInPostgres; //maybe this can be retrieved from vendorSpecificInfo
  86. /** class name to do input validation on this column */
  87. private $inputValidator = null;
  88. private $domain;
  89. /**
  90. * Creates a new column and set the name
  91. *
  92. * @param name column name
  93. */
  94. public function __construct($name = null)
  95. {
  96. $this->name = $name;
  97. }
  98. /**
  99. * Return a comma delimited string listing the specified columns.
  100. *
  101. * @param columns Either a list of <code>Column</code> objects, or
  102. * a list of <code>String</code> objects with column names.
  103. * @deprecated Use the DDLBuilder->getColumnList() method instead; this will be removed in 1.3
  104. */
  105. public static function makeList($columns, Platform $platform)
  106. {
  107. $list = array();
  108. foreach($columns as $col) {
  109. if ($col instanceof Column) {
  110. $col = $col->getName();
  111. }
  112. $list[] = $platform->quoteIdentifier($col);
  113. }
  114. return implode(", ", $list);
  115. }
  116. /**
  117. * Sets up the Column object based on the attributes that were passed to loadFromXML().
  118. * @see parent::loadFromXML()
  119. */
  120. protected function setupObject()
  121. {
  122. try {
  123. $dom = $this->getAttribute("domain");
  124. if ($dom) {
  125. $this->domain = new Domain();
  126. $this->domain->copy($this->getTable()->getDatabase()->getDomain($dom));
  127. } else {
  128. $this->domain = new Domain();
  129. $this->domain->copy($this->getPlatform()->getDomainForType(self::DEFAULT_TYPE));
  130. $this->setType(strtoupper($this->getAttribute("type")));
  131. }
  132. //Name
  133. $this->name = $this->getAttribute("name");
  134. $this->phpName = $this->getAttribute("phpName");
  135. $this->phpType = $this->getAttribute("phpType");
  136. $this->peerName = $this->getAttribute("peerName");
  137. if (empty($this->phpType)) {
  138. $this->phpType = null;
  139. }
  140. // retrieves the method for converting from specified name to
  141. // a PHP name.
  142. $this->phpNamingMethod = $this->getAttribute("phpNamingMethod", $this->parentTable->getDatabase()->getDefaultPhpNamingMethod());
  143. $this->isPrimaryKey = $this->booleanValue($this->getAttribute("primaryKey"));
  144. $this->isNodeKey = $this->booleanValue($this->getAttribute("nodeKey"));
  145. $this->nodeKeySep = $this->getAttribute("nodeKeySep", ".");
  146. $this->isNotNull = $this->booleanValue($this->getAttribute("required"), false);
  147. // Regardless of above, if this column is a primary key then it can't be null.
  148. if ($this->isPrimaryKey) {
  149. $this->isNotNull = true;
  150. }
  151. //AutoIncrement/Sequences
  152. $this->isAutoIncrement = $this->booleanValue($this->getAttribute("autoIncrement"));
  153. $this->isLazyLoad = $this->booleanValue($this->getAttribute("lazyLoad"));
  154. //Default column value.
  155. $this->domain->replaceDefaultValue($this->getAttribute("default"));
  156. $this->domain->replaceSize($this->getAttribute("size"));
  157. $this->domain->replaceScale($this->getAttribute("scale"));
  158. $this->inheritanceType = $this->getAttribute("inheritance");
  159. $this->isInheritance = ($this->inheritanceType !== null
  160. && $this->inheritanceType !== "false"); // here we are only checking for 'false', so don't
  161. // use boleanValue()
  162. $this->inputValidator = $this->getAttribute("inputValidator");
  163. $this->description = $this->getAttribute("description");
  164. } catch (Exception $e) {
  165. throw new EngineException("Error setting up column " . var_export($this->getAttribute("name"), true) . ": " . $e->getMessage());
  166. }
  167. }
  168. /**
  169. * Gets domain for this column.
  170. * @return Domain
  171. */
  172. public function getDomain()
  173. {
  174. return $this->domain;
  175. }
  176. /**
  177. * Returns table.column
  178. */
  179. public function getFullyQualifiedName()
  180. {
  181. return ($this->parentTable->getName() . '.' . name);
  182. }
  183. /**
  184. * Get the name of the column
  185. */
  186. public function getName()
  187. {
  188. return $this->name;
  189. }
  190. /**
  191. * Set the name of the column
  192. */
  193. public function setName($newName)
  194. {
  195. $this->name = $newName;
  196. }
  197. /**
  198. * Get the description for the Table
  199. */
  200. public function getDescription()
  201. {
  202. return $this->description;
  203. }
  204. /**
  205. * Set the description for the Table
  206. *
  207. * @param newDescription description for the Table
  208. */
  209. public function setDescription($newDescription)
  210. {
  211. $this->description = $newDescription;
  212. }
  213. /**
  214. * Get name to use in PHP sources
  215. * @return string
  216. */
  217. public function getPhpName()
  218. {
  219. if ($this->phpName === null) {
  220. $inputs = array();
  221. $inputs[] = $this->name;
  222. $inputs[] = $this->phpNamingMethod;
  223. try {
  224. $this->phpName = NameFactory::generateName(NameFactory::PHP_GENERATOR, $inputs);
  225. } catch (EngineException $e) {
  226. print $e->getMessage() . "\n";
  227. print $e->getTraceAsString();
  228. }
  229. }
  230. return $this->phpName;
  231. }
  232. /**
  233. * Set name to use in PHP sources
  234. */
  235. public function setPhpName($phpName)
  236. {
  237. $this->phpName = $phpName;
  238. }
  239. /**
  240. * Get the Peer constant name that will identify this column.
  241. * @return string
  242. */
  243. public function getPeerName() {
  244. return $this->peerName;
  245. }
  246. /**
  247. * Set the Peer constant name that will identify this column.
  248. * @param $name string
  249. */
  250. public function setPeerName($name) {
  251. $this->peerName = $name;
  252. }
  253. /**
  254. * Get type to use in PHP sources.
  255. * If no type has been specified, then uses results
  256. * of getPhpNative().
  257. *
  258. * The distinction between getPhpType() and getPhpNative()
  259. * is not as salient in PHP as it is in Java, but we'd like to leave open the
  260. * option of specifying complex types (objects) in the schema. While we can
  261. * always cast to PHP native types, we can't cast objects (in PHP) -- hence the
  262. * importance of maintaining this distinction.
  263. *
  264. * @return string The type name.
  265. * @see getPhpNative()
  266. */
  267. public function getPhpType()
  268. {
  269. if ($this->phpType !== null) {
  270. return $this->phpType;
  271. }
  272. return $this->getPhpNative();
  273. }
  274. /**
  275. * Get the location of this column within the table (one-based).
  276. * @return int value of position.
  277. */
  278. public function getPosition()
  279. {
  280. return $this->position;
  281. }
  282. /**
  283. * Get the location of this column within the table (one-based).
  284. * @param int $v Value to assign to position.
  285. */
  286. public function setPosition($v)
  287. {
  288. $this->position = $v;
  289. }
  290. /**
  291. * Set the parent Table of the column
  292. */
  293. public function setTable(Table $parent)
  294. {
  295. $this->parentTable = $parent;
  296. }
  297. /**
  298. * Get the parent Table of the column
  299. */
  300. public function getTable()
  301. {
  302. return $this->parentTable;
  303. }
  304. /**
  305. * Returns the Name of the table the column is in
  306. */
  307. public function getTableName()
  308. {
  309. return $this->parentTable->getName();
  310. }
  311. /**
  312. * Adds a new inheritance definition to the inheritance list and set the
  313. * parent column of the inheritance to the current column
  314. * @param mixed $inhdata Inheritance or XML data.
  315. */
  316. public function addInheritance($inhdata)
  317. {
  318. if ($inhdata instanceof Inheritance) {
  319. $inh = $inhdata;
  320. $inh->setColumn($this);
  321. if ($this->inheritanceList === null) {
  322. $this->inheritanceList = array();
  323. $this->isEnumeratedClasses = true;
  324. }
  325. $this->inheritanceList[] = $inh;
  326. return $inh;
  327. } else {
  328. $inh = new Inheritance();
  329. $inh->loadFromXML($inhdata);
  330. return $this->addInheritance($inh);
  331. }
  332. }
  333. /**
  334. * Get the inheritance definitions.
  335. */
  336. public function getChildren()
  337. {
  338. return $this->inheritanceList;
  339. }
  340. /**
  341. * Determine if this column is a normal property or specifies a
  342. * the classes that are represented in the table containing this column.
  343. */
  344. public function isInheritance()
  345. {
  346. return $this->isInheritance;
  347. }
  348. /**
  349. * Determine if possible classes have been enumerated in the xml file.
  350. */
  351. public function isEnumeratedClasses()
  352. {
  353. return $this->isEnumeratedClasses;
  354. }
  355. /**
  356. * Return the isNotNull property of the column
  357. */
  358. public function isNotNull()
  359. {
  360. return $this->isNotNull;
  361. }
  362. /**
  363. * Set the isNotNull property of the column
  364. */
  365. public function setNotNull($status)
  366. {
  367. $this->isNotNull = (boolean) $status;
  368. }
  369. /**
  370. * Return NOT NULL String for this column
  371. *
  372. * @return "NOT NULL" if null values are not allowed or an empty string.
  373. */
  374. public function getNotNullString()
  375. {
  376. return $this->getTable()->getDatabase()->getPlatform()->getNullString($this->isNotNull());
  377. }
  378. /**
  379. * Set if the column is a primary key or not
  380. */
  381. public function setPrimaryKey($pk)
  382. {
  383. $this->isPrimaryKey = (boolean) $pk;
  384. }
  385. /**
  386. * Return true if the column is a primary key
  387. */
  388. public function isPrimaryKey()
  389. {
  390. return $this->isPrimaryKey;
  391. }
  392. /**
  393. * Set if the column is the node key of a tree
  394. */
  395. public function setNodeKey($nk)
  396. {
  397. $this->isNodeKey = (boolean) $nk;
  398. }
  399. /**
  400. * Return true if the column is a node key of a tree
  401. */
  402. public function isNodeKey()
  403. {
  404. return $this->isNodeKey;
  405. }
  406. /**
  407. * Set if the column is the node key of a tree
  408. */
  409. public function setNodeKeySep($sep)
  410. {
  411. $this->nodeKeySep = (string) $sep;
  412. }
  413. /**
  414. * Return true if the column is a node key of a tree
  415. */
  416. public function getNodeKeySep()
  417. {
  418. return $this->nodeKeySep;
  419. }
  420. /**
  421. * Set true if the column is UNIQUE
  422. */
  423. public function setUnique($u)
  424. {
  425. $this->isUnique = $u;
  426. }
  427. /**
  428. * Get the UNIQUE property
  429. */
  430. public function isUnique()
  431. {
  432. return $this->isUnique;
  433. }
  434. /**
  435. * Return true if the column requires a transaction in Postgres
  436. */
  437. public function requiresTransactionInPostgres()
  438. {
  439. return $this->needsTransactionInPostgres;
  440. }
  441. /**
  442. * Utility method to determine if this column is a foreign key.
  443. */
  444. public function isForeignKey()
  445. {
  446. return ($this->getForeignKey() !== null);
  447. }
  448. /**
  449. * Determine if this column is a foreign key that refers to the
  450. * same table as another foreign key column in this table.
  451. */
  452. public function isMultipleFK()
  453. {
  454. $fk = $this->getForeignKey();
  455. if ($fk !== null) {
  456. $fks = $this->parentTable->getForeignKeys();
  457. for ($i=0, $len=count($fks); $i < $len; $i++) {
  458. if ($fks[$i]->getForeignTableName() === $fk->getForeignTableName()
  459. && !in_array($this->name, $fks[$i]->getLocalColumns()) ) {
  460. return true;
  461. }
  462. }
  463. }
  464. // No multiple foreign keys.
  465. return false;
  466. }
  467. /**
  468. * get the foreign key object for this column
  469. * if it is a foreign key or part of a foreign key
  470. */
  471. public function getForeignKey()
  472. {
  473. return $this->parentTable->getForeignKey($this->name);
  474. }
  475. /**
  476. * Utility method to get the related table of this column if it is a foreign
  477. * key or part of a foreign key
  478. */
  479. public function getRelatedTableName()
  480. {
  481. $fk = $this->getForeignKey();
  482. return ($fk === null ? null : $fk->getForeignTableName());
  483. }
  484. /**
  485. * Utility method to get the related column of this local column if this
  486. * column is a foreign key or part of a foreign key.
  487. */
  488. public function getRelatedColumnName()
  489. {
  490. $fk = $this->getForeignKey();
  491. if ($fk === null) {
  492. return null;
  493. } else {
  494. $m = $fk->getLocalForeignMapping();
  495. $c = @$m[$this->name];
  496. if ($c === null) {
  497. return null;
  498. } else {
  499. return $c;
  500. }
  501. }
  502. }
  503. /**
  504. * Adds the foreign key from another table that refers to this column.
  505. */
  506. public function addReferrer(ForeignKey $fk)
  507. {
  508. if ($this->referrers === null) {
  509. $this->referrers = array();
  510. }
  511. $this->referrers[] = $fk;
  512. }
  513. /**
  514. * Get list of references to this column.
  515. */
  516. public function getReferrers()
  517. {
  518. if ($this->referrers === null) {
  519. $this->referrers = array();
  520. }
  521. return $this->referrers;
  522. }
  523. /**
  524. * Returns the colunm type
  525. */
  526. public function setType($propelType)
  527. {
  528. $this->domain = new Domain();
  529. $this->domain->copy($this->getPlatform()->getDomainForType($propelType));
  530. $this->propelType = $propelType;
  531. if ($propelType == PropelTypes::VARBINARY|| $propelType == PropelTypes::LONGVARBINARY || $propelType == PropelTypes::BLOB) {
  532. $this->needsTransactionInPostgres = true;
  533. }
  534. }
  535. /**
  536. * Returns the column Creole type as a string.
  537. * @return string The constant representing Creole type: e.g. "VARCHAR".
  538. */
  539. public function getType()
  540. {
  541. return PropelTypes::getCreoleType($this->propelType);
  542. }
  543. /**
  544. * Returns the column type as given in the schema as an object
  545. */
  546. public function getPropelType()
  547. {
  548. return $this->propelType;
  549. }
  550. /**
  551. * Utility method to know whether column needs Blob/Lob handling.
  552. * @return boolean
  553. */
  554. public function isLob()
  555. {
  556. return PropelTypes::isLobType($this->propelType);
  557. }
  558. /**
  559. * Utility method to see if the column is a string
  560. */
  561. public function isString()
  562. {
  563. return PropelTypes::isTextxType($this->propelType);
  564. }
  565. /**
  566. * String representation of the column. This is an xml representation.
  567. */
  568. public function toString()
  569. {
  570. $result = " <column name=\"" . $this->name . '"';
  571. if ($this->phpName !== null) {
  572. $result .= " phpName=\"" . $this->phpName . '"';
  573. }
  574. if ($this->isPrimaryKey) {
  575. $result .= " primaryKey=\"" . ($this->isPrimaryKey ? "true" : "false"). '"';
  576. }
  577. if ($this->isNotNull) {
  578. $result .= " required=\"true\"";
  579. } else {
  580. $result .= " required=\"false\"";
  581. }
  582. $result .= " type=\"" . $this->propelType . '"';
  583. if ($this->domain->getSize() !== null) {
  584. $result .= " size=\"" . $this->domain->getSize() . '"';
  585. }
  586. if ($this->domain->getScale() !== null) {
  587. $result .= " scale=\"" . $this->domain->getScale() . '"';
  588. }
  589. if ($this->domain->getDefaultValue() !== null) {
  590. $result .= " default=\"" . $this->domain->getDefaultValue() . '"';
  591. }
  592. if ($this->isInheritance()) {
  593. $result .= " inheritance=\"" . $this->inheritanceType
  594. . '"';
  595. }
  596. if ($this->isNodeKey()) {
  597. $result .= " nodeKey=\"true\"";
  598. if ($this->getNodeKeySep() !== null) {
  599. $result .= " nodeKeySep=\"" . $this->nodeKeySep . '"';
  600. }
  601. }
  602. // Close the column.
  603. $result .= " />\n";
  604. return $result;
  605. }
  606. /**
  607. * Returns the size of the column
  608. * @return string
  609. */
  610. public function getSize()
  611. {
  612. return $this->domain->getSize();
  613. }
  614. /**
  615. * Set the size of the column
  616. * @param string $newSize
  617. */
  618. public function setSize($newSize)
  619. {
  620. $this->domain->setSize($newSize);
  621. }
  622. /**
  623. * Returns the scale of the column
  624. * @return string
  625. */
  626. public function getScale()
  627. {
  628. return $this->domain->getScale();
  629. }
  630. /**
  631. * Set the scale of the column
  632. * @param string $newScale
  633. */
  634. public function setScale($newScale)
  635. {
  636. $this->domain->setScale($newScale);
  637. }
  638. /**
  639. * Return the size in brackets for use in an sql
  640. * schema if the type is String. Otherwise return an empty string
  641. */
  642. public function printSize()
  643. {
  644. return $this->domain->printSize();
  645. }
  646. /**
  647. * Return a string that will give this column a default value.
  648. * @return string
  649. */
  650. public function getDefaultSetting()
  651. {
  652. $dflt = "";
  653. if ($this->getDefaultValue() !== null) {
  654. $dflt .= "default ";
  655. if (PropelTypes::isTextType($this->getType())) {
  656. $dflt .= '\'' . $this->getPlatform()->escapeText($this->getDefaultValue()) . '\'';
  657. } elseif ($this->getType() == PropelTypes::BOOLEAN) {
  658. $dflt .= $this->getPlatform()->getBooleanString($this->getDefaultValue());
  659. } else {
  660. $dflt .= $this->getDefaultValue();
  661. }
  662. }
  663. return $dflt;
  664. }
  665. /**
  666. * Set a string that will give this column a default value.
  667. */
  668. public function setDefaultValue($def)
  669. {
  670. $this->domain->setDefaultValue($def);
  671. }
  672. /**
  673. * Get the raw string that will give this column a default value.
  674. * @return string
  675. * @see Domain::getDefaultValue()
  676. */
  677. public function getDefaultValue()
  678. {
  679. return $this->domain->getDefaultValue();
  680. }
  681. /**
  682. * Get the default value suitable for use in PHP.
  683. * @return mixed
  684. * @see Domain::getPhpDefaultValue()
  685. */
  686. public function getPhpDefaultValue()
  687. {
  688. return $this->domain->getPhpDefaultValue();
  689. }
  690. /**
  691. * Returns the class name to do input validation
  692. */
  693. public function getInputValidator()
  694. {
  695. return $this->inputValidator;
  696. }
  697. /**
  698. * Return auto increment/sequence string for the target database. We need to
  699. * pass in the props for the target database!
  700. */
  701. public function isAutoIncrement()
  702. {
  703. return $this->isAutoIncrement;
  704. }
  705. /**
  706. * Return auto increment/sequence string for the target database. We need to
  707. * pass in the props for the target database!
  708. */
  709. public function isLazyLoad()
  710. {
  711. return $this->isLazyLoad;
  712. }
  713. /**
  714. * Gets the auto-increment string.
  715. * @return string
  716. */
  717. public function getAutoIncrementString()
  718. {
  719. if ($this->isAutoIncrement()&& IDMethod::NATIVE === $this->getTable()->getIdMethod()) {
  720. return $this->getPlatform()->getAutoIncrement();
  721. } elseif ($this->isAutoIncrement()) {
  722. throw new EngineException("You have specified autoIncrement for column '" . $this->name . "' but you have not specified idMethod=\"native\" for table '" . $this->getTable()->getName() . "'.");
  723. }
  724. return "";
  725. }
  726. /**
  727. * Set the auto increment value.
  728. * Use isAutoIncrement() to find out if it is set or not.
  729. */
  730. public function setAutoIncrement($value)
  731. {
  732. $this->isAutoIncrement = (boolean) $value;
  733. }
  734. /**
  735. * Set the column type from a string property
  736. * (normally a string from an sql input file)
  737. */
  738. public function setTypeFromString($typeName, $size)
  739. {
  740. $tn = strtoupper($typeName);
  741. $this->setType($tn);
  742. if ($size !== null) {
  743. $this->size = $size;
  744. }
  745. if (strpos($tn, "CHAR") !== false) {
  746. $this->domain->setType(PropelTypes::VARCHAR);
  747. } elseif (strpos($tn, "INT") !== false) {
  748. $this->domain->setType(PropelTypes::INTEGER);
  749. } elseif (strpos($tn, "FLOAT") !== false) {
  750. $this->domain->setType(PropelTypes::FLOAT);
  751. } elseif (strpos($tn, "DATE") !== false) {
  752. $this->domain->setType(PropelTypes::DATE);
  753. } elseif (strpos($tn, "TIME") !== false) {
  754. $this->domain->setType(PropelTypes::TIMESTAMP);
  755. } else if (strpos($tn, "BINARY") !== false) {
  756. $this->domain->setType(PropelTypes::LONGVARBINARY);
  757. } else {
  758. $this->domain->setType(PropelTypes::VARCHAR);
  759. }
  760. }
  761. /**
  762. * Return a string representation of the native PHP type which corresponds
  763. * to the Creole type of this column. Use in the generation of Base objects.
  764. *
  765. * @return string PHP datatype used by propel.
  766. */
  767. public function getPhpNative()
  768. {
  769. return PropelTypes::getPHPNative($this->propelType);
  770. }
  771. /**
  772. * Returns true if the column's PHP native type is an
  773. * boolean, int, long, float, double, string
  774. */
  775. public function isPrimitive()
  776. {
  777. $t = $this->getPhpNative();
  778. return in_array($t, array("boolean", "int", "double", "string"));
  779. }
  780. /**
  781. * Return true if column's PHP native type is an
  782. * boolean, int, long, float, double
  783. */
  784. public function isPrimitiveNumeric()
  785. {
  786. $t = $this->getPhpNative();
  787. return in_array($t, array("boolean", "int", "double"));
  788. }
  789. /**
  790. * Get the platform/adapter impl.
  791. *
  792. * @return Platform
  793. */
  794. public function getPlatform()
  795. {
  796. return $this->getTable()->getDatabase()->getPlatform();
  797. }
  798. /**
  799. *
  800. * @return string
  801. * @deprecated Use DDLBuilder->getColumnDDL() instead; this will be removed in 1.3
  802. */
  803. public function getSqlString()
  804. {
  805. $sb = "";
  806. $sb .= $this->getPlatform()->quoteIdentifier($this->getName()) . " ";
  807. $sb .= $this->getDomain()->getSqlType();
  808. if ($this->getPlatform()->hasSize($this->getDomain()->getSqlType())) {
  809. $sb .= $this->getDomain()->printSize();
  810. }
  811. $sb .= " ";
  812. $sb .= $this->getDefaultSetting() . " ";
  813. $sb .= $this->getNotNullString() . " ";
  814. $sb .= $this->getAutoIncrementString();
  815. return trim($sb);
  816. }
  817. }