# Source for file Informix.php

Documentation is available at Informix.php

1. <?php
2. /*
3. * $Id: Informix.php 1273 2007-04-18 11:11:07Z zYne $
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, see
19. * <http://www.phpdoctrine.com>.
20. */
21. Doctrine::autoload('Doctrine_DataDict');
22. /**
23. * @package Doctrine
24. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
25. * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
26. * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
27. * @version $Revision: 1273 $
28. * @category Object Relational Mapping
29. * @link www.phpdoctrine.com
30. * @since 1.0
31. */
32. class Doctrine_DataDict_Informix extends Doctrine_DataDict
33. {
34. /**
35. * Obtain DBMS specific SQL code portion needed to declare an text type
36. * field to be used in statements like CREATE TABLE.
37. *
38. * @param array $field associative array with the name of the properties
39. * of the field being declared as array indexes. Currently, the types
40. * of supported field properties are as follows:
41. *
42. * length
43. * Integer value that determines the maximum length of the text
44. * field. If this argument is missing the field should be
45. * declared to have the longest length allowed by the DBMS.
46. *
47. * default
48. * Text value to be used as default for this field.
49. *
50. * notnull
51. * Boolean flag that indicates whether this field is constrained
52. * to not be set to null.
53. *
54. * @return string DBMS specific SQL code portion that should be used to
55. * declare the specified field.
56. */
57. public function getNativeDeclaration($field)
58. {
59. if ( ! isset($field['type'])) {
60. throw new Doctrine_DataDict_Exception('Missing column type.');
61. }
62. switch ($field['type']) {
63. case 'char':
64. case 'varchar':
65. case 'array':
66. case 'object':
67. case 'string':
68. if (empty($field['length']) && array_key_exists('default', $field)) {
69. $field['length'] = $this->conn->varchar_max_length;
70. }
72. $length = (! empty($field['length'])) ? $field['length'] : false;
73. $fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
75. return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR(255)')
76. : ($length ? 'VARCHAR('.$length.')' : 'NVARCHAR');
77. case 'clob':
78. return 'TEXT';
79. case 'blob':
80. return 'BLOB';
81. case 'integer':
82. if (!empty($field['length'])) {
83. $length = $field['length'];
84. if ($length <= 1) {
85. return 'SMALLINT';
86. } elseif ($length == 2) {
87. return 'SMALLINT';
88. } elseif ($length == 3 || $length == 4) {
89. return 'INTEGER';
90. } elseif ($length > 4) {
91. return 'DECIMAL(20)';
92. }
93. }
94. return 'INT';
95. case 'boolean':
96. return 'SMALLINT';
97. case 'date':
98. return 'DATE';
99. case 'time':
100. return 'DATETIME YEAR TO SECOND';
101. case 'timestamp':
102. return 'DATETIME';
103. case 'float':
104. return 'FLOAT';
105. case 'decimal':
106. return 'DECIMAL';
107. }
108. throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.');
109. }
110. }