PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/inc/MDB2/Schema/Parser.php

https://github.com/chregu/fluxcms
PHP | 787 lines | 670 code | 39 blank | 78 comment | 184 complexity | cd10819a684f83f23637829a2399bcfe MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0, LGPL-2.1
  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP versions 4 and 5 |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox, |
  6. // | Stig. S. Bakken, Lukas Smith |
  7. // | All rights reserved. |
  8. // +----------------------------------------------------------------------+
  9. // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
  10. // | API as well as database abstraction for PHP applications. |
  11. // | This LICENSE is in the BSD license style. |
  12. // | |
  13. // | Redistribution and use in source and binary forms, with or without |
  14. // | modification, are permitted provided that the following conditions |
  15. // | are met: |
  16. // | |
  17. // | Redistributions of source code must retain the above copyright |
  18. // | notice, this list of conditions and the following disclaimer. |
  19. // | |
  20. // | Redistributions in binary form must reproduce the above copyright |
  21. // | notice, this list of conditions and the following disclaimer in the |
  22. // | documentation and/or other materials provided with the distribution. |
  23. // | |
  24. // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
  25. // | Lukas Smith nor the names of his contributors may be used to endorse |
  26. // | or promote products derived from this software without specific prior|
  27. // | written permission. |
  28. // | |
  29. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
  30. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
  31. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
  32. // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
  33. // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
  34. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  35. // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
  36. // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
  37. // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
  38. // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
  39. // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
  40. // | POSSIBILITY OF SUCH DAMAGE. |
  41. // +----------------------------------------------------------------------+
  42. // | Author: Christian Dickmann <dickmann@php.net> |
  43. // +----------------------------------------------------------------------+
  44. //
  45. // $Id: Parser.php,v 1.25 2006/01/04 20:10:35 lsmith Exp $
  46. //
  47. require_once 'XML/Parser.php';
  48. /**
  49. * Parses an XML schema file
  50. *
  51. * @package MDB2_Schema
  52. * @category Database
  53. * @access protected
  54. * @author Christian Dickmann <dickmann@php.net>
  55. */
  56. class MDB2_Schema_Parser extends XML_Parser
  57. {
  58. var $database_definition = array();
  59. var $elements = array();
  60. var $element = '';
  61. var $count = 0;
  62. var $table = array();
  63. var $table_name = '';
  64. var $field = array();
  65. var $field_name = '';
  66. var $init = array();
  67. var $init_name = '';
  68. var $init_value = '';
  69. var $index = array();
  70. var $index_name = '';
  71. var $var_mode = false;
  72. var $variables = array();
  73. var $seq = array();
  74. var $seq_name = '';
  75. var $error;
  76. var $invalid_names = array(
  77. 'user' => array(),
  78. 'is' => array(),
  79. 'file' => array(
  80. 'oci' => array(),
  81. 'oracle' => array()
  82. ),
  83. 'notify' => array(
  84. 'pgsql' => array()
  85. ),
  86. 'restrict' => array(
  87. 'mysql' => array()
  88. ),
  89. 'password' => array(
  90. 'ibase' => array()
  91. )
  92. );
  93. var $fail_on_invalid_names = true;
  94. var $structure = false;
  95. function __construct($variables, $fail_on_invalid_names = true, $structure = false)
  96. {
  97. parent::XML_Parser();
  98. $this->variables = $variables;
  99. $this->fail_on_invalid_names = $fail_on_invalid_names;
  100. $this->structure = $structure;
  101. }
  102. function MDB2_Schema_Parser($variables, $fail_on_invalid_names = true, $structure = false)
  103. {
  104. $this->__construct($variables, $fail_on_invalid_names, $structure);
  105. }
  106. function startHandler($xp, $element, $attribs)
  107. {
  108. if (strtolower($element) == 'variable') {
  109. $this->var_mode = true;
  110. return;
  111. }
  112. $this->elements[$this->count++] = strtolower($element);
  113. $this->element = implode('-', $this->elements);
  114. switch ($this->element) {
  115. case 'database-table-initialization-insert':
  116. $this->init = array('type' => 'insert');
  117. break;
  118. case 'database-table-initialization-insert-field':
  119. $this->init_name = '';
  120. $this->init_value = '';
  121. break;
  122. case 'database-table':
  123. $this->table_name = '';
  124. $this->table = array();
  125. break;
  126. case 'database-table-declaration-field':
  127. $this->field_name = '';
  128. $this->field = array();
  129. break;
  130. case 'database-table-declaration-field-default':
  131. $this->field['default'] = '';
  132. break;
  133. case 'database-table-declaration-index':
  134. $this->index_name = '';
  135. $this->index = array();
  136. break;
  137. case 'database-sequence':
  138. $this->seq_name = '';
  139. $this->seq = array();
  140. break;
  141. case 'database-table-declaration-index-field':
  142. $this->field_name = '';
  143. $this->field = array();
  144. break;
  145. }
  146. }
  147. function endHandler($xp, $element)
  148. {
  149. if (strtolower($element) == 'variable') {
  150. $this->var_mode = false;
  151. return;
  152. }
  153. switch ($this->element) {
  154. /* Initialization */
  155. case 'database-table-initialization-insert-field':
  156. if (!$this->init_name) {
  157. $this->raiseError('field-name has to be specified', null, $xp);
  158. }
  159. if (isset($this->init['fields'][$this->init_name])) {
  160. $this->raiseError('field "'.$this->init_name.'" already filled', null, $xp);
  161. }
  162. if (!isset($this->table['fields'][$this->init_name])) {
  163. $this->raiseError('unknown field "'.$this->init_name.'"', null, $xp);
  164. }
  165. if ($this->init_value !== ''
  166. && !$this->validateFieldValue($this->init_name, $this->init_value, $xp)
  167. ) {
  168. $this->raiseError('field "'.$this->init_name.'" has wrong value', null, $xp);
  169. }
  170. $this->init['fields'][$this->init_name] = $this->init_value;
  171. break;
  172. case 'database-table-initialization-insert':
  173. $this->table['initialization'][] = $this->init;
  174. break;
  175. /* Table definition */
  176. case 'database-table':
  177. if (!array_key_exists('was', $this->table)) {
  178. $this->table['was'] = $this->table_name;
  179. }
  180. if (!$this->table_name) {
  181. $this->raiseError('tables need names', null, $xp);
  182. }
  183. if (isset($this->database_definition['tables'][$this->table_name])) {
  184. $this->raiseError('table "'.$this->table_name.'" already exists', null, $xp);
  185. }
  186. $autoinc = $primary = false;
  187. if (!array_key_exists('fields', $this->table)) {
  188. $this->raiseError('tables need one or more fields', null, $xp);
  189. } else {
  190. foreach ($this->table['fields'] as $field_name => $field) {
  191. if (array_key_exists('autoincrement', $field) && $field['autoincrement']) {
  192. if ($primary) {
  193. $this->raiseError('there was already an autoincrement field in "'.$this->table_name.'" before "'.$field_name.'"', null, $xp);
  194. } else {
  195. $autoinc = $primary = true;
  196. }
  197. if (!$this->table['fields'][$field_name]['notnull']) {
  198. $this->raiseError('all autoincrement fields must be defined notnull in "'.$this->table_name.'"', null, $xp);
  199. }
  200. if (!array_key_exists('default', $field)) {
  201. $this->table['fields'][$field_name]['default'] = '0';
  202. } elseif ($field['default'] !== '0' && $field['default'] !== 0) {
  203. $this->raiseError('all autoincrement fields must be defined default "0" in "'.$this->table_name.'"', null, $xp);
  204. }
  205. }
  206. }
  207. }
  208. if (array_key_exists('indexes', $this->table)) {
  209. foreach ($this->table['indexes'] as $name => $index) {
  210. $skip_index = false;
  211. if (array_key_exists('primary', $index) && $index['primary']) {
  212. /*
  213. * Lets see if we should skip this index since there is
  214. * already a auto increment on this field this implying
  215. * a primary key index.
  216. */
  217. if ($autoinc && count($index['fields']) == '1') {
  218. $skip_index = true;
  219. } else {
  220. if ($primary) {
  221. $this->raiseError('there was already an primary index or autoincrement field in "'.$this->table_name.'" before "'.$name.'"', null, $xp);
  222. } else {
  223. $primary = true;
  224. }
  225. }
  226. }
  227. if (!$skip_index) {
  228. foreach ($index['fields'] as $field_name => $field) {
  229. if (!isset($this->table['fields'][$field_name])) {
  230. $this->raiseError('index field "'.$field_name.'" does not exist', null, $xp);
  231. } elseif (array_key_exists('primary', $index) && $index['primary']) {
  232. if (!$this->table['fields'][$field_name]['notnull']) {
  233. $this->raiseError('all primary key fields must be defined notnull in "'.$this->table_name.'"', null, $xp);
  234. }
  235. }
  236. }
  237. } else {
  238. unset($this->table['indexes'][$name]);
  239. }
  240. }
  241. }
  242. $this->database_definition['tables'][$this->table_name] = $this->table;
  243. break;
  244. /* Field declaration */
  245. case 'database-table-declaration-field':
  246. if (!$this->field_name || !array_key_exists('type', $this->field)) {
  247. $this->raiseError('field "'.$this->field_name.'" was not properly specified', null, $xp);
  248. }
  249. if (isset($this->table['fields'][$this->field_name])) {
  250. $this->raiseError('field "'.$this->field_name.'" already exists', null, $xp);
  251. }
  252. /* Invalidname check */
  253. if ($this->fail_on_invalid_names && isset($this->invalid_names[$this->field_name])) {
  254. $this->raiseError('fieldname "'.$this->field_name.'" not allowed', null, $xp);
  255. }
  256. /* Type check */
  257. switch ($this->field['type']) {
  258. case 'integer':
  259. if (array_key_exists('unsigned', $this->field) && !$this->isBoolean($this->field['unsigned'])) {
  260. $this->raiseError('unsigned has to be a boolean value', null, $xp);
  261. }
  262. case 'text':
  263. case 'clob':
  264. case 'blob':
  265. if (array_key_exists('length', $this->field) && ((int)$this->field['length']) <= 0) {
  266. $this->raiseError('length has to be an integer greater 0', null, $xp);
  267. }
  268. break;
  269. case 'boolean':
  270. case 'date':
  271. case 'timestamp':
  272. case 'time':
  273. case 'float':
  274. case 'decimal':
  275. break;
  276. default:
  277. $this->raiseError('no valid field type ("'.$this->field['type'].'") specified', null, $xp);
  278. }
  279. if (!array_key_exists('was', $this->field)) {
  280. $this->field['was'] = $this->field_name;
  281. }
  282. if (!array_key_exists('notnull', $this->field)) {
  283. $this->field['notnull'] = false;
  284. }
  285. if (!$this->isBoolean($this->field['notnull'])) {
  286. $this->raiseError('field "notnull" has to be a boolean value', null, $xp);
  287. }
  288. if (!array_key_exists('default', $this->field)
  289. && $this->field['type'] != 'clob' && $this->field['type'] != 'blob'
  290. ) {
  291. $this->field['default'] = '';
  292. }
  293. if (array_key_exists('unsigned', $this->field) && !$this->isBoolean($this->field['unsigned'])) {
  294. $this->raiseError('field "unsigned" has to be a boolean value', null, $xp);
  295. }
  296. if (array_key_exists('default', $this->field)) {
  297. if ($this->field['type'] == 'clob' || $this->field['type'] == 'blob') {
  298. $this->raiseError('"'.$this->field['type'].
  299. '"-fields are not allowed to have a default value', null, $xp);
  300. }
  301. if ($this->field['default'] === '') {
  302. if (!$this->field['notnull']) {
  303. $this->field['default'] = null;
  304. }
  305. }
  306. }
  307. $this->table['fields'][$this->field_name] = $this->field;
  308. if (array_key_exists('default', $this->field) && isset($this->field['default'])
  309. && !$this->validateFieldValue($this->field_name,
  310. $this->table['fields'][$this->field_name]['default'], $xp
  311. )
  312. ) {
  313. $this->raiseError('default value of "'.$this->field_name.'" is of wrong type', null, $xp);
  314. }
  315. break;
  316. /* Index declaration */
  317. case 'database-table-declaration-index':
  318. if (!$this->index_name) {
  319. $this->raiseError('an index needs a name', null, $xp);
  320. }
  321. if (isset($this->table['indexes'][$this->index_name])) {
  322. $this->raiseError('index "'.$this->index_name.'" already exists', null, $xp);
  323. }
  324. if (array_key_exists('unique', $this->index) && !$this->isBoolean($this->index['unique'])) {
  325. $this->raiseError('field "unique" has to be a boolean value', null, $xp);
  326. }
  327. if (array_key_exists('primary', $this->index) && !$this->isBoolean($this->index['primary'])) {
  328. $this->raiseError('field "primary" has to be a boolean value', null, $xp);
  329. }
  330. if (!array_key_exists('was', $this->index)) {
  331. $this->index['was'] = $this->index_name;
  332. }
  333. $this->table['indexes'][$this->index_name] = $this->index;
  334. break;
  335. case 'database-table-declaration-index-field':
  336. if (!$this->field_name) {
  337. $this->raiseError('the index-field-name is required', null, $xp);
  338. }
  339. if (array_key_exists('sorting', $this->field)
  340. && $this->field['sorting'] !== 'ascending' && $this->field['sorting'] !== 'descending') {
  341. $this->raiseError('sorting type unknown', null, $xp);
  342. } else {
  343. $this->field['sorting'] = 'ascending';
  344. }
  345. $this->index['fields'][$this->field_name] = $this->field;
  346. break;
  347. case 'database-table-name':
  348. if (isset($this->structure['tables'][$this->table_name])) {
  349. $this->table = $this->structure['tables'][$this->table_name];
  350. }
  351. break;
  352. /* Sequence declaration */
  353. case 'database-sequence':
  354. if (!$this->seq_name) {
  355. $this->raiseError('a sequence has to have a name', null, $xp);
  356. }
  357. if (isset($this->database_definition['sequences'][$this->seq_name])) {
  358. $this->raiseError('sequence "'.$this->seq_name.'" already exists', null, $xp);
  359. }
  360. if (!array_key_exists('was', $this->seq)) {
  361. $this->seq['was'] = $this->seq_name;
  362. }
  363. if (array_key_exists('on', $this->seq)) {
  364. if ((!isset($this->seq['on']['table']) || !$this->seq['on']['table'])
  365. || (!isset($this->seq['on']['field']) || !$this->seq['on']['field'])
  366. ) {
  367. $this->raiseError('sequence "'.$this->seq_name.
  368. '" was not properly defined', null, $xp);
  369. }
  370. }
  371. $this->database_definition['sequences'][$this->seq_name] = $this->seq;
  372. break;
  373. /* End of File */
  374. case 'database':
  375. if (isset($this->database_definition['create'])
  376. && !$this->isBoolean($this->database_definition['create'])
  377. ) {
  378. $this->raiseError('field "create" has to be a boolean value', null, $xp);
  379. }
  380. if (isset($this->database_definition['overwrite'])
  381. && !$this->isBoolean($this->database_definition['overwrite'])
  382. ) {
  383. $this->raiseError('field "overwrite" has to be a boolean value', null, $xp);
  384. }
  385. if (!isset($this->database_definition['name'])
  386. || !$this->database_definition['name']
  387. ) {
  388. $this->raiseError('database needs a name', null, $xp);
  389. }
  390. if (isset($this->database_definition['sequences'])) {
  391. foreach ($this->database_definition['sequences'] as $seq_name => $seq) {
  392. if (array_key_exists('on', $seq)
  393. && !isset($this->database_definition['tables'][$seq['on']['table']]['fields'][$seq['on']['field']])
  394. ) {
  395. $this->raiseError('sequence "'.$seq_name.
  396. '" was assigned on unexisting field/table', null, $xp);
  397. }
  398. }
  399. }
  400. if (PEAR::isError($this->error)) {
  401. $this->database_definition = $this->error;
  402. }
  403. break;
  404. }
  405. unset($this->elements[--$this->count]);
  406. $this->element = implode('-', $this->elements);
  407. }
  408. function validateFieldValue($field_name, &$field_value, &$xp)
  409. {
  410. if (!isset($this->table['fields'][$field_name])) {
  411. return $this->raiseError('"'.$field_name.'" is not defined', null, $xp);
  412. }
  413. $field_def = $this->table['fields'][$field_name];
  414. switch ($field_def['type']) {
  415. case 'text':
  416. case 'clob':
  417. if (array_key_exists('length', $field_def) && strlen($field_value) > $field_def['length']) {
  418. return $this->raiseError('"'.$field_value.'" is not of type "'.
  419. $field_def['type'].'"', null, $xp);
  420. }
  421. break;
  422. case 'blob':
  423. /*
  424. if (!preg_match('/^([0-9a-f]{2})*$/i', $field_value)) {
  425. return $this->raiseError('"'.$field_value.'" is not of type "'.
  426. $field_def['type'].'"', null, $xp);
  427. }
  428. */
  429. $field_value = pack('H*', $field_value);
  430. if (array_key_exists('length', $field_def) && strlen($field_value) > $field_def['length']) {
  431. return $this->raiseError('"'.$field_value.'" is not of type "'.
  432. $field_def['type'].'"', null, $xp);
  433. }
  434. break;
  435. case 'integer':
  436. if ($field_value != ((int)$field_value)) {
  437. return $this->raiseError('"'.$field_value.'" is not of type "'.
  438. $field_def['type'].'"', null, $xp);
  439. }
  440. $field_value = (int) $field_value;
  441. if (array_key_exists('unsigned', $field_def) && $field_def['unsigned'] && $field_value < 0) {
  442. return $this->raiseError('"'.$field_value.'" is not of type "'.
  443. $field_def['type'].'"', null, $xp);
  444. }
  445. break;
  446. case 'boolean':
  447. if (!$this->isBoolean($field_value)) {
  448. return $this->raiseError('"'.$field_value.'" is not of type "'.
  449. $field_def['type'].'"', null, $xp);
  450. }
  451. break;
  452. case 'date':
  453. if (!preg_match('/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/', $field_value)) {
  454. return $this->raiseError('"'.$field_value.'" is not of type "'.
  455. $field_def['type'].'"', null, $xp);
  456. }
  457. break;
  458. case 'timestamp':
  459. if (!preg_match('/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/', $field_value)) {
  460. return $this->raiseError('"'.$field_value.'" is not of type "'.
  461. $field_def['type'].'"', null, $xp);
  462. }
  463. break;
  464. case 'time':
  465. if (!preg_match("/([0-9]{2}):([0-9]{2}):([0-9]{2})/", $field_value)) {
  466. return $this->raiseError('"'.$field_value.'" is not of type "'.
  467. $field_def['type'].'"', null, $xp);
  468. }
  469. break;
  470. case 'float':
  471. case 'double':
  472. if ($field_value != (double) $field_value) {
  473. return $this->raiseError('"'.$field_value.'" is not of type "'.
  474. $field_def['type'].'"', null, $xp);
  475. }
  476. $field_value = (double) $field_value;
  477. break;
  478. }
  479. return true;
  480. }
  481. function &raiseError($msg = null, $ecode = 0, $xp = null)
  482. {
  483. if (is_null($this->error)) {
  484. $error = '';
  485. if (is_resource($msg)) {
  486. $error .= 'Parser error: '.xml_error_string(xml_get_error_code($msg));
  487. $xp = $msg;
  488. } else {
  489. $error .= 'Parser error: '.$msg;
  490. if (!is_resource($xp)) {
  491. $xp = $this->parser;
  492. }
  493. }
  494. if ($error_string = xml_error_string($ecode)) {
  495. $error .= ' - '.$error_string;
  496. }
  497. if (is_resource($xp)) {
  498. $byte = @xml_get_current_byte_index($xp);
  499. $line = @xml_get_current_line_number($xp);
  500. $column = @xml_get_current_column_number($xp);
  501. $error .= " - Byte: $byte; Line: $line; Col: $column";
  502. }
  503. $error .= "\n";
  504. $this->error =& MDB2::raiseError(MDB2_SCHEMA_ERROR_PARSE, null, null, $error);
  505. }
  506. return $this->error;
  507. }
  508. function isBoolean(&$value)
  509. {
  510. if (is_bool($value)) {
  511. return true;
  512. }
  513. if ($value === 0 || $value === 1) {
  514. $value = (bool)$value;
  515. return true;
  516. }
  517. if (!is_string($value)) {
  518. return false;
  519. }
  520. switch ($value) {
  521. case '0':
  522. case 'N':
  523. case 'n':
  524. case 'no':
  525. case 'false':
  526. $value = false;
  527. break;
  528. case '1':
  529. case 'Y':
  530. case 'y':
  531. case 'yes':
  532. case 'true':
  533. $value = true;
  534. break;
  535. default:
  536. return false;
  537. }
  538. return true;
  539. }
  540. function cdataHandler($xp, $data)
  541. {
  542. if ($this->var_mode == true) {
  543. if (!isset($this->variables[$data])) {
  544. $this->raiseError('variable "'.$data.'" not found', null, $xp);
  545. return;
  546. }
  547. $data = $this->variables[$data];
  548. }
  549. switch ($this->element) {
  550. /* Initialization */
  551. case 'database-table-initialization-insert-field-name':
  552. if (isset($this->init_name)) {
  553. $this->init_name .= $data;
  554. } else {
  555. $this->init_name = $data;
  556. }
  557. break;
  558. case 'database-table-initialization-insert-field-value':
  559. if (isset($this->init_value)) {
  560. $this->init_value .= $data;
  561. } else {
  562. $this->init_value = $data;
  563. }
  564. break;
  565. /* Database */
  566. case 'database-name':
  567. if (isset($this->database_definition['name'])) {
  568. $this->database_definition['name'] .= $data;
  569. } else {
  570. $this->database_definition['name'] = $data;
  571. }
  572. break;
  573. case 'database-create':
  574. if (isset($this->database_definition['create'])) {
  575. $this->database_definition['create'] .= $data;
  576. } else {
  577. $this->database_definition['create'] = $data;
  578. }
  579. break;
  580. case 'database-overwrite':
  581. if (isset($this->database_definition['overwrite'])) {
  582. $this->database_definition['overwrite'] .= $data;
  583. } else {
  584. $this->database_definition['overwrite'] = $data;
  585. }
  586. break;
  587. case 'database-table-name':
  588. if (isset($this->table_name)) {
  589. $this->table_name .= $data;
  590. } else {
  591. $this->table_name = $data;
  592. }
  593. break;
  594. case 'database-table-was':
  595. if (array_key_exists('was', $this->table)) {
  596. $this->table['was'] .= $data;
  597. } else {
  598. $this->table['was'] = $data;
  599. }
  600. break;
  601. /* Field declaration */
  602. case 'database-table-declaration-field-name':
  603. if (isset($this->field_name)) {
  604. $this->field_name .= $data;
  605. } else {
  606. $this->field_name = $data;
  607. }
  608. break;
  609. case 'database-table-declaration-field-type':
  610. if (array_key_exists('type', $this->field)) {
  611. $this->field['type'] .= $data;
  612. } else {
  613. $this->field['type'] = $data;
  614. }
  615. break;
  616. case 'database-table-declaration-field-was':
  617. if (array_key_exists('was', $this->field)) {
  618. $this->field['was'] .= $data;
  619. } else {
  620. $this->field['was'] = $data;
  621. }
  622. break;
  623. case 'database-table-declaration-field-notnull':
  624. if (array_key_exists('notnull', $this->field)) {
  625. $this->field['notnull'] .= $data;
  626. } else {
  627. $this->field['notnull'] = $data;
  628. }
  629. break;
  630. case 'database-table-declaration-field-unsigned':
  631. if (array_key_exists('unsigned', $this->field)) {
  632. $this->field['unsigned'] .= $data;
  633. } else {
  634. $this->field['unsigned'] = $data;
  635. }
  636. break;
  637. case 'database-table-declaration-field-autoincrement':
  638. if (array_key_exists('autoincrement', $this->field)) {
  639. $this->field['autoincrement'] .= $data;
  640. } else {
  641. $this->field['autoincrement'] = $data;
  642. }
  643. break;
  644. case 'database-table-declaration-field-default':
  645. if (array_key_exists('default', $this->field)) {
  646. $this->field['default'] .= $data;
  647. } else {
  648. $this->field['default'] = $data;
  649. }
  650. break;
  651. case 'database-table-declaration-field-length':
  652. if (array_key_exists('length', $this->field)) {
  653. $this->field['length'] .= $data;
  654. } else {
  655. $this->field['length'] = $data;
  656. }
  657. break;
  658. /* Index declaration */
  659. case 'database-table-declaration-index-name':
  660. if (isset($this->index_name)) {
  661. $this->index_name .= $data;
  662. } else {
  663. $this->index_name = $data;
  664. }
  665. break;
  666. case 'database-table-declaration-index-primary':
  667. if (array_key_exists('primary', $this->index)) {
  668. $this->index['primary'] .= $data;
  669. } else {
  670. $this->index['primary'] = $data;
  671. }
  672. break;
  673. case 'database-table-declaration-index-unique':
  674. if (array_key_exists('unique', $this->index)) {
  675. $this->index['unique'] .= $data;
  676. } else {
  677. $this->index['unique'] = $data;
  678. }
  679. break;
  680. case 'database-table-declaration-index-was':
  681. if (array_key_exists('was', $this->index)) {
  682. $this->index['was'] .= $data;
  683. } else {
  684. $this->index['was'] = $data;
  685. }
  686. break;
  687. case 'database-table-declaration-index-field-name':
  688. if (isset($this->field_name)) {
  689. $this->field_name .= $data;
  690. } else {
  691. $this->field_name = $data;
  692. }
  693. break;
  694. case 'database-table-declaration-index-field-sorting':
  695. if (array_key_exists('sorting', $this->field)) {
  696. $this->field['sorting'] .= $data;
  697. } else {
  698. $this->field['sorting'] = $data;
  699. }
  700. break;
  701. /* Add by Leoncx */
  702. case 'database-table-declaration-index-field-length':
  703. if (array_key_exists('length', $this->field)) {
  704. $this->field['length'] .= $data;
  705. } else {
  706. $this->field['length'] = $data;
  707. }
  708. break;
  709. /* Sequence declaration */
  710. case 'database-sequence-name':
  711. if (isset($this->seq_name)) {
  712. $this->seq_name .= $data;
  713. } else {
  714. $this->seq_name = $data;
  715. }
  716. break;
  717. case 'database-sequence-was':
  718. if (array_key_exists('was', $this->seq)) {
  719. $this->seq['was'] .= $data;
  720. } else {
  721. $this->seq['was'] = $data;
  722. }
  723. break;
  724. case 'database-sequence-start':
  725. if (array_key_exists('start', $this->seq)) {
  726. $this->seq['start'] .= $data;
  727. } else {
  728. $this->seq['start'] = $data;
  729. }
  730. break;
  731. case 'database-sequence-on-table':
  732. if (isset($this->seq['on']['table'])) {
  733. $this->seq['on']['table'] .= $data;
  734. } else {
  735. $this->seq['on']['table'] = $data;
  736. }
  737. break;
  738. case 'database-sequence-on-field':
  739. if (isset($this->seq['on']['field'])) {
  740. $this->seq['on']['field'] .= $data;
  741. } else {
  742. $this->seq['on']['field'] = $data;
  743. }
  744. break;
  745. }
  746. }
  747. }
  748. ?>