KumbiaPHP  beta2
Framework PHP
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Páginas
informix.php
Ir a la documentación de este archivo.
1 <?php
24 require_once CORE_PATH . 'libs/db/adapters/pdo.php';
25 
33 class DbPdoInformix extends DbPDO
34 {
35 
39  protected $db_rbdm = "informix";
40 
45  const TYPE_INTEGER = "INTEGER";
46 
51  const TYPE_DATE = "DATE";
52 
57  const TYPE_VARCHAR = "VARCHAR";
58 
63  const TYPE_DECIMAL = "DECIMAL";
64 
69  const TYPE_DATETIME = "DATETIME";
70 
75  const TYPE_CHAR = "CHAR";
76 
81  public function initialize()
82  {
83 
84  }
85 
92  public function table_exists($table, $schema='')
93  {
97  $table = addslashes("$table");
98  $num = $this->fetch_one("SELECT COUNT(*) FROM systables WHERE tabname = '$table'");
99  return (int) $num[0];
100  }
101 
108  public function limit($sql, $number)
109  {
113  $number = (int) $number;
114  return "$sql -- LIMIT $number\n";
115  }
116 
123  public function drop_table($table, $if_exists=true)
124  {
125  if ($if_exists) {
126  if ($this->table_exists($table)) {
127  return $this->query("DROP TABLE $table");
128  } else {
129  return true;
130  }
131  } else {
132  //$this->set_return_rows(false);
133  return $this->query("DROP TABLE $table");
134  }
135  }
136 
150  public function create_table($table, $definition, $index=array())
151  {
152  $create_sql = "CREATE TABLE $table (";
153  if (!is_array($definition)) {
154  new KumbiaException("Definici&oacute;n invalida para crear la tabla '$table'");
155  return false;
156  }
157  $create_lines = array();
158  $index = array();
159  $unique_index = array();
160  $primary = array();
161  //$not_null = "";
162  //$size = "";
163  foreach ($definition as $field => $field_def) {
164  if (isset($field_def['not_null'])) {
165  $not_null = $field_def['not_null'] ? 'NOT NULL' : '';
166  } else {
167  $not_null = "";
168  }
169  if (isset($field_def['size'])) {
170  $size = $field_def['size'] ? '(' . $field_def['size'] . ')' : '';
171  } else {
172  $size = "";
173  }
174  if (isset($field_def['index'])) {
175  if ($field_def['index']) {
176  $index[] = "INDEX($field)";
177  }
178  }
179  if (isset($field_def['unique_index'])) {
180  if ($field_def['unique_index']) {
181  $index[] = "UNIQUE($field)";
182  }
183  }
184  if (isset($field_def['primary'])) {
185  if ($field_def['primary']) {
186  $primary[] = "$field";
187  }
188  }
189  if (isset($field_def['auto'])) {
190  if ($field_def['auto']) {
191  $field_def['type'] = "SERIAL";
192  }
193  }
194  if (isset($field_def['extra'])) {
195  $extra = $field_def['extra'];
196  } else {
197  $extra = "";
198  }
199  $create_lines[] = "$field " . $field_def['type'] . $size . ' ' . $not_null . ' ' . $extra;
200  }
201  $create_sql.= join(',', $create_lines);
202  $last_lines = array();
203  if (count($primary)) {
204  $last_lines[] = 'PRIMARY KEY(' . join(",", $primary) . ')';
205  }
206  if (count($index)) {
207  $last_lines[] = join(',', $index);
208  }
209  if (count($unique_index)) {
210  $last_lines[] = join(',', $unique_index);
211  }
212  if (count($last_lines)) {
213  $create_sql.= ',' . join(',', $last_lines) . ')';
214  }
215  return $this->query($create_sql);
216  }
217 
223  public function list_tables()
224  {
225  return $this->fetch_all("SELECT tabname FROM systables WHERE tabtype = 'T' AND version <> 65537");
226  }
227 
234  public function describe_table($table, $schema='')
235  {
242  $describe = $this->fetch_all("SELECT c.colname AS Field, c.coltype AS Type,
243  'YES' AS NULL, c.collength as Length
244  FROM systables t, syscolumns c WHERE
245  c.tabid = t.tabid AND t.tabname = '$table' ORDER BY c.colno");
246  $final_describe = array();
247  foreach ($describe as $field) {
248  //Serial
249  if ($field['field'] == 'id') {
250  $field["key"] = 'PRI';
251  $field["null"] = 'NO';
252  } else {
253  $field["key"] = '';
254  }
255  if (substr($field['field'], -3) == '_id') {
256  $field["null"] = 'NO';
257  }
258  if ($field['type'] == 262) {
259  $field['type'] = "integer";
260  }
261  if ($field['type'] == 13) {
262  $field['type'] = "varchar(" . $field['length'] . ")";
263  }
264  if ($field['type'] == 2) {
265  $field['type'] = "int(" . $field['length'] . ")";
266  }
267  if ($field['type'] == 7) {
268  $field['type'] = "date";
269  }
270  $final_describe[] = array(
271  "Field" => $field["field"],
272  "Type" => $field["type"],
273  "Null" => $field["null"],
274  "Key" => $field["key"]
275  );
276  }
277  return $final_describe;
278  }
279 
280 }