Parser.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. <?php
  2. /**
  3. * PHP versions 4 and 5
  4. *
  5. * Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
  6. * Stig. S. Bakken, Lukas Smith, Igor Feghali
  7. * All rights reserved.
  8. *
  9. * MDB2_Schema enables users to maintain RDBMS independant schema files
  10. * in XML that can be used to manipulate both data and database schemas
  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, Igor Feghali nor the names of his contributors may be
  26. * used to endorse or promote products derived from this software
  27. * without specific prior 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. * Author: Igor Feghali <ifeghali@php.net>
  44. *
  45. * $Id: Parser.php,v 1.68 2008/11/30 03:34:00 clockwerx Exp $
  46. *
  47. * @category Database
  48. * @package MDB2_Schema
  49. * @author Christian Dickmann <dickmann@php.net>
  50. * @author Igor Feghali <ifeghali@php.net>
  51. * @license BSD http://www.opensource.org/licenses/bsd-license.php
  52. * @version CVS: $Id: Parser.php,v 1.68 2008/11/30 03:34:00 clockwerx Exp $
  53. * @link http://pear.php.net/packages/MDB2_Schema
  54. */
  55. require_once('XML/Parser.php');
  56. require_once('MDB2/Schema/Validate.php');
  57. /**
  58. * Parses an XML schema file
  59. *
  60. * @category Database
  61. * @package MDB2_Schema
  62. * @author Christian Dickmann <dickmann@php.net>
  63. * @license BSD http://www.opensource.org/licenses/bsd-license.php
  64. * @link http://pear.php.net/packages/MDB2_Schema
  65. */
  66. class MDB2_Schema_Parser extends XML_Parser
  67. {
  68. var $database_definition = array();
  69. var $elements = array();
  70. var $element = '';
  71. var $count = 0;
  72. var $table = array();
  73. var $table_name = '';
  74. var $field = array();
  75. var $field_name = '';
  76. var $init = array();
  77. var $init_function = array();
  78. var $init_expression = array();
  79. var $init_field = array();
  80. var $index = array();
  81. var $index_name = '';
  82. var $constraint = array();
  83. var $constraint_name = '';
  84. var $var_mode = false;
  85. var $variables = array();
  86. var $sequence = array();
  87. var $sequence_name = '';
  88. var $error;
  89. var $structure = false;
  90. var $val;
  91. function __construct($variables, $fail_on_invalid_names = true,
  92. $structure = false, $valid_types = array(),
  93. $force_defaults = true)
  94. {
  95. // force ISO-8859-1 due to different defaults for PHP4 and PHP5
  96. // todo: this probably needs to be investigated some more andcleaned up
  97. parent::__construct('ISO-8859-1');
  98. $this->variables = $variables;
  99. $this->structure = $structure;
  100. $this->val =new MDB2_Schema_Validate($fail_on_invalid_names, $valid_types, $force_defaults);
  101. }
  102. function startHandler($xp, $element, $attribs)
  103. {
  104. if (strtolower($element) == 'variable') {
  105. $this->var_mode = true;
  106. return;
  107. }
  108. $this->elements[$this->count++] = strtolower($element);
  109. $this->element = implode('-', $this->elements);
  110. switch ($this->element) {
  111. /* Initialization */
  112. case 'database-table-initialization':
  113. $this->table['initialization'] = array();
  114. break;
  115. /* Insert */
  116. /* insert: field+ */
  117. case 'database-table-initialization-insert':
  118. $this->init = array('type' => 'insert', 'data' => array('field' => array()));
  119. break;
  120. /* insert-select: field+, table, where? */
  121. case 'database-table-initialization-insert-select':
  122. $this->init['data']['table'] = '';
  123. break;
  124. /* Update */
  125. /* update: field+, where? */
  126. case 'database-table-initialization-update':
  127. $this->init = array('type' => 'update', 'data' => array('field' => array()));
  128. break;
  129. /* Delete */
  130. /* delete: where */
  131. case 'database-table-initialization-delete':
  132. $this->init = array('type' => 'delete', 'data' => array('where' => array()));
  133. break;
  134. /* Insert and Update */
  135. case 'database-table-initialization-insert-field':
  136. case 'database-table-initialization-insert-select-field':
  137. case 'database-table-initialization-update-field':
  138. $this->init_field = array('name' => '', 'group' => array());
  139. break;
  140. case 'database-table-initialization-insert-field-value':
  141. case 'database-table-initialization-insert-select-field-value':
  142. case 'database-table-initialization-update-field-value':
  143. /* if value tag is empty cdataHandler is not called so we must force value element creation here */
  144. $this->init_field['group'] = array('type' => 'value', 'data' => '');
  145. break;
  146. case 'database-table-initialization-insert-field-null':
  147. case 'database-table-initialization-insert-select-field-null':
  148. case 'database-table-initialization-update-field-null':
  149. $this->init_field['group'] = array('type' => 'null');
  150. break;
  151. case 'database-table-initialization-insert-field-function':
  152. case 'database-table-initialization-insert-select-field-function':
  153. case 'database-table-initialization-update-field-function':
  154. $this->init_function = array('name' => '');
  155. break;
  156. case 'database-table-initialization-insert-field-expression':
  157. case 'database-table-initialization-insert-select-field-expression':
  158. case 'database-table-initialization-update-field-expression':
  159. $this->init_expression = array();
  160. break;
  161. /* All */
  162. case 'database-table-initialization-insert-select-where':
  163. case 'database-table-initialization-update-where':
  164. case 'database-table-initialization-delete-where':
  165. $this->init['data']['where'] = array('type' => '', 'data' => array());
  166. break;
  167. case 'database-table-initialization-insert-select-where-expression':
  168. case 'database-table-initialization-update-where-expression':
  169. case 'database-table-initialization-delete-where-expression':
  170. $this->init_expression = array();
  171. break;
  172. /* One level simulation of expression-function recursion */
  173. case 'database-table-initialization-insert-field-expression-function':
  174. case 'database-table-initialization-insert-select-field-expression-function':
  175. case 'database-table-initialization-insert-select-where-expression-function':
  176. case 'database-table-initialization-update-field-expression-function':
  177. case 'database-table-initialization-update-where-expression-function':
  178. case 'database-table-initialization-delete-where-expression-function':
  179. $this->init_function = array('name' => '');
  180. break;
  181. /* One level simulation of function-expression recursion */
  182. case 'database-table-initialization-insert-field-function-expression':
  183. case 'database-table-initialization-insert-select-field-function-expression':
  184. case 'database-table-initialization-insert-select-where-function-expression':
  185. case 'database-table-initialization-update-field-function-expression':
  186. case 'database-table-initialization-update-where-function-expression':
  187. case 'database-table-initialization-delete-where-function-expression':
  188. $this->init_expression = array();
  189. break;
  190. /* Definition */
  191. case 'database':
  192. $this->database_definition = array(
  193. 'name' => '',
  194. 'create' => '',
  195. 'overwrite' => '',
  196. 'charset' => '',
  197. 'description' => '',
  198. 'comments' => '',
  199. 'tables' => array(),
  200. 'sequences' => array()
  201. );
  202. break;
  203. case 'database-table':
  204. $this->table_name = '';
  205. $this->table = array(
  206. 'was' => '',
  207. 'description' => '',
  208. 'comments' => '',
  209. 'fields' => array(),
  210. 'indexes' => array(),
  211. 'constraints' => array(),
  212. 'initialization' => array()
  213. );
  214. break;
  215. case 'database-table-declaration-field':
  216. case 'database-table-declaration-foreign-field':
  217. case 'database-table-declaration-foreign-references-field':
  218. $this->field_name = '';
  219. $this->field = array();
  220. break;
  221. case 'database-table-declaration-index-field':
  222. $this->field_name = '';
  223. $this->field = array('sorting' => '', 'length' => '');
  224. break;
  225. /* force field attributes to be initialized when the tag is empty in the XML */
  226. case 'database-table-declaration-field-was':
  227. $this->field['was'] = '';
  228. break;
  229. case 'database-table-declaration-field-type':
  230. $this->field['type'] = '';
  231. break;
  232. case 'database-table-declaration-field-fixed':
  233. $this->field['fixed'] = '';
  234. break;
  235. case 'database-table-declaration-field-default':
  236. $this->field['default'] = '';
  237. break;
  238. case 'database-table-declaration-field-notnull':
  239. $this->field['notnull'] = '';
  240. break;
  241. case 'database-table-declaration-field-autoincrement':
  242. $this->field['autoincrement'] = '';
  243. break;
  244. case 'database-table-declaration-field-unsigned':
  245. $this->field['unsigned'] = '';
  246. break;
  247. case 'database-table-declaration-field-length':
  248. $this->field['length'] = '';
  249. break;
  250. case 'database-table-declaration-field-description':
  251. $this->field['description'] = '';
  252. break;
  253. case 'database-table-declaration-field-comments':
  254. $this->field['comments'] = '';
  255. break;
  256. case 'database-table-declaration-index':
  257. $this->index_name = '';
  258. $this->index = array(
  259. 'was' => '',
  260. 'unique' =>'',
  261. 'primary' => '',
  262. 'fields' => array()
  263. );
  264. break;
  265. case 'database-table-declaration-foreign':
  266. $this->constraint_name = '';
  267. $this->constraint = array(
  268. 'was' => '',
  269. 'match' => '',
  270. 'ondelete' => '',
  271. 'onupdate' => '',
  272. 'deferrable' => '',
  273. 'initiallydeferred' => '',
  274. 'foreign' => true,
  275. 'fields' => array(),
  276. 'references' => array('table' => '', 'fields' => array())
  277. );
  278. break;
  279. case 'database-sequence':
  280. $this->sequence_name = '';
  281. $this->sequence = array(
  282. 'was' => '',
  283. 'start' => '',
  284. 'description' => '',
  285. 'comments' => '',
  286. 'on' => array('table' => '', 'field' => '')
  287. );
  288. break;
  289. }
  290. }
  291. function endHandler($xp, $element)
  292. {
  293. if (strtolower($element) == 'variable') {
  294. $this->var_mode = false;
  295. return;
  296. }
  297. switch ($this->element) {
  298. /* Initialization */
  299. /* Insert */
  300. case 'database-table-initialization-insert-select':
  301. $this->init['data'] = array('select' => $this->init['data']);
  302. break;
  303. /* Insert and Delete */
  304. case 'database-table-initialization-insert-field':
  305. case 'database-table-initialization-insert-select-field':
  306. case 'database-table-initialization-update-field':
  307. $result = $this->val->validateDataField($this->table['fields'], $this->init['data']['field'], $this->init_field);
  308. if (PEAR::isError($result)) {
  309. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  310. } else {
  311. $this->init['data']['field'][] = $this->init_field;
  312. }
  313. break;
  314. case 'database-table-initialization-insert-field-function':
  315. case 'database-table-initialization-insert-select-field-function':
  316. case 'database-table-initialization-update-field-function':
  317. $this->init_field['group'] = array('type' => 'function', 'data' => $this->init_function);
  318. break;
  319. case 'database-table-initialization-insert-field-expression':
  320. case 'database-table-initialization-insert-select-field-expression':
  321. case 'database-table-initialization-update-field-expression':
  322. $this->init_field['group'] = array('type' => 'expression', 'data' => $this->init_expression);
  323. break;
  324. /* All */
  325. case 'database-table-initialization-insert-select-where-expression':
  326. case 'database-table-initialization-update-where-expression':
  327. case 'database-table-initialization-delete-where-expression':
  328. $this->init['data']['where']['type'] = 'expression';
  329. $this->init['data']['where']['data'] = $this->init_expression;
  330. break;
  331. case 'database-table-initialization-insert':
  332. case 'database-table-initialization-delete':
  333. case 'database-table-initialization-update':
  334. $this->table['initialization'][] = $this->init;
  335. break;
  336. /* One level simulation of expression-function recursion */
  337. case 'database-table-initialization-insert-field-expression-function':
  338. case 'database-table-initialization-insert-select-field-expression-function':
  339. case 'database-table-initialization-insert-select-where-expression-function':
  340. case 'database-table-initialization-update-field-expression-function':
  341. case 'database-table-initialization-update-where-expression-function':
  342. case 'database-table-initialization-delete-where-expression-function':
  343. $this->init_expression['operants'][] = array('type' => 'function', 'data' => $this->init_function);
  344. break;
  345. /* One level simulation of function-expression recursion */
  346. case 'database-table-initialization-insert-field-function-expression':
  347. case 'database-table-initialization-insert-select-field-function-expression':
  348. case 'database-table-initialization-insert-select-where-function-expression':
  349. case 'database-table-initialization-update-field-function-expression':
  350. case 'database-table-initialization-update-where-function-expression':
  351. case 'database-table-initialization-delete-where-function-expression':
  352. $this->init_function['arguments'][] = array('type' => 'expression', 'data' => $this->init_expression);
  353. break;
  354. /* Table definition */
  355. case 'database-table':
  356. $result = $this->val->validateTable($this->database_definition['tables'], $this->table, $this->table_name);
  357. if (PEAR::isError($result)) {
  358. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  359. } else {
  360. $this->database_definition['tables'][$this->table_name] = $this->table;
  361. }
  362. break;
  363. case 'database-table-name':
  364. if (isset($this->structure['tables'][$this->table_name])) {
  365. $this->table = $this->structure['tables'][$this->table_name];
  366. }
  367. break;
  368. /* Field declaration */
  369. case 'database-table-declaration-field':
  370. $result = $this->val->validateField($this->table['fields'], $this->field, $this->field_name);
  371. if (PEAR::isError($result)) {
  372. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  373. } else {
  374. $this->table['fields'][$this->field_name] = $this->field;
  375. }
  376. break;
  377. /* Index declaration */
  378. case 'database-table-declaration-index':
  379. $result = $this->val->validateIndex($this->table['indexes'], $this->index, $this->index_name);
  380. if (PEAR::isError($result)) {
  381. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  382. } else {
  383. $this->table['indexes'][$this->index_name] = $this->index;
  384. }
  385. break;
  386. case 'database-table-declaration-index-field':
  387. $result = $this->val->validateIndexField($this->index['fields'], $this->field, $this->field_name);
  388. if (PEAR::isError($result)) {
  389. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  390. } else {
  391. $this->index['fields'][$this->field_name] = $this->field;
  392. }
  393. break;
  394. /* Foreign Key declaration */
  395. case 'database-table-declaration-foreign':
  396. $result = $this->val->validateConstraint($this->table['constraints'], $this->constraint, $this->constraint_name);
  397. if (PEAR::isError($result)) {
  398. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  399. } else {
  400. $this->table['constraints'][$this->constraint_name] = $this->constraint;
  401. }
  402. break;
  403. case 'database-table-declaration-foreign-field':
  404. $result = $this->val->validateConstraintField($this->constraint['fields'], $this->field_name);
  405. if (PEAR::isError($result)) {
  406. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  407. } else {
  408. $this->constraint['fields'][$this->field_name] = '';
  409. }
  410. break;
  411. case 'database-table-declaration-foreign-references-field':
  412. $result = $this->val->validateConstraintReferencedField($this->constraint['references']['fields'], $this->field_name);
  413. if (PEAR::isError($result)) {
  414. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  415. } else {
  416. $this->constraint['references']['fields'][$this->field_name] = '';
  417. }
  418. break;
  419. /* Sequence declaration */
  420. case 'database-sequence':
  421. $result = $this->val->validateSequence($this->database_definition['sequences'], $this->sequence, $this->sequence_name);
  422. if (PEAR::isError($result)) {
  423. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  424. } else {
  425. $this->database_definition['sequences'][$this->sequence_name] = $this->sequence;
  426. }
  427. break;
  428. /* End of File */
  429. case 'database':
  430. $result = $this->val->validateDatabase($this->database_definition);
  431. if (PEAR::isError($result)) {
  432. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  433. }
  434. break;
  435. }
  436. unset($this->elements[--$this->count]);
  437. $this->element = implode('-', $this->elements);
  438. }
  439. function raiseError($msg = null, $xmlecode = 0, $xp = null, $ecode = MDB2_SCHEMA_ERROR_PARSE,$a=null,$b=null,$c=null)
  440. {
  441. if (is_null($this->error)) {
  442. $error = '';
  443. if (is_resource($msg)) {
  444. $error .= 'Parser error: '.xml_error_string(xml_get_error_code($msg));
  445. $xp = $msg;
  446. } else {
  447. $error .= 'Parser error: '.$msg;
  448. if (!is_resource($xp)) {
  449. $xp = $this->parser;
  450. }
  451. }
  452. if ($error_string = xml_error_string($xmlecode)) {
  453. $error .= ' - '.$error_string;
  454. }
  455. if (is_resource($xp)) {
  456. $byte = @xml_get_current_byte_index($xp);
  457. $line = @xml_get_current_line_number($xp);
  458. $column = @xml_get_current_column_number($xp);
  459. $error .= " - Byte: $byte; Line: $line; Col: $column";
  460. }
  461. $error .= "\n";
  462. $this->error =& MDB2_Schema::raiseError($ecode, null, null, $error);
  463. }
  464. return $this->error;
  465. }
  466. function cdataHandler($xp, $data)
  467. {
  468. if ($this->var_mode == true) {
  469. if (!isset($this->variables[$data])) {
  470. $this->raiseError('variable "'.$data.'" not found', null, $xp);
  471. return;
  472. }
  473. $data = $this->variables[$data];
  474. }
  475. switch ($this->element) {
  476. /* Initialization */
  477. /* Insert */
  478. case 'database-table-initialization-insert-select-table':
  479. $this->init['data']['table'] = $data;
  480. break;
  481. /* Insert and Update */
  482. case 'database-table-initialization-insert-field-name':
  483. case 'database-table-initialization-insert-select-field-name':
  484. case 'database-table-initialization-update-field-name':
  485. $this->init_field['name'] .= $data;
  486. break;
  487. case 'database-table-initialization-insert-field-value':
  488. case 'database-table-initialization-insert-select-field-value':
  489. case 'database-table-initialization-update-field-value':
  490. $this->init_field['group']['data'] .= $data;
  491. break;
  492. case 'database-table-initialization-insert-field-function-name':
  493. case 'database-table-initialization-insert-select-field-function-name':
  494. case 'database-table-initialization-update-field-function-name':
  495. $this->init_function['name'] .= $data;
  496. break;
  497. case 'database-table-initialization-insert-field-function-value':
  498. case 'database-table-initialization-insert-select-field-function-value':
  499. case 'database-table-initialization-update-field-function-value':
  500. $this->init_function['arguments'][] = array('type' => 'value', 'data' => $data);
  501. break;
  502. case 'database-table-initialization-insert-field-function-column':
  503. case 'database-table-initialization-insert-select-field-function-column':
  504. case 'database-table-initialization-update-field-function-column':
  505. $this->init_function['arguments'][] = array('type' => 'column', 'data' => $data);
  506. break;
  507. case 'database-table-initialization-insert-field-column':
  508. case 'database-table-initialization-insert-select-field-column':
  509. case 'database-table-initialization-update-field-column':
  510. $this->init_field['group'] = array('type' => 'column', 'data' => $data);
  511. break;
  512. /* All */
  513. case 'database-table-initialization-insert-field-expression-operator':
  514. case 'database-table-initialization-insert-select-field-expression-operator':
  515. case 'database-table-initialization-insert-select-where-expression-operator':
  516. case 'database-table-initialization-update-field-expression-operator':
  517. case 'database-table-initialization-update-where-expression-operator':
  518. case 'database-table-initialization-delete-where-expression-operator':
  519. $this->init_expression['operator'] = $data;
  520. break;
  521. case 'database-table-initialization-insert-field-expression-value':
  522. case 'database-table-initialization-insert-select-field-expression-value':
  523. case 'database-table-initialization-insert-select-where-expression-value':
  524. case 'database-table-initialization-update-field-expression-value':
  525. case 'database-table-initialization-update-where-expression-value':
  526. case 'database-table-initialization-delete-where-expression-value':
  527. $this->init_expression['operants'][] = array('type' => 'value', 'data' => $data);
  528. break;
  529. case 'database-table-initialization-insert-field-expression-column':
  530. case 'database-table-initialization-insert-select-field-expression-column':
  531. case 'database-table-initialization-insert-select-where-expression-column':
  532. case 'database-table-initialization-update-field-expression-column':
  533. case 'database-table-initialization-update-where-expression-column':
  534. case 'database-table-initialization-delete-where-expression-column':
  535. $this->init_expression['operants'][] = array('type' => 'column', 'data' => $data);
  536. break;
  537. case 'database-table-initialization-insert-field-function-function':
  538. case 'database-table-initialization-insert-field-function-expression':
  539. case 'database-table-initialization-insert-field-expression-expression':
  540. case 'database-table-initialization-update-field-function-function':
  541. case 'database-table-initialization-update-field-function-expression':
  542. case 'database-table-initialization-update-field-expression-expression':
  543. case 'database-table-initialization-update-where-expression-expression':
  544. case 'database-table-initialization-delete-where-expression-expression':
  545. /* Recursion to be implemented yet */
  546. break;
  547. /* One level simulation of expression-function recursion */
  548. case 'database-table-initialization-insert-field-expression-function-name':
  549. case 'database-table-initialization-insert-select-field-expression-function-name':
  550. case 'database-table-initialization-insert-select-where-expression-function-name':
  551. case 'database-table-initialization-update-field-expression-function-name':
  552. case 'database-table-initialization-update-where-expression-function-name':
  553. case 'database-table-initialization-delete-where-expression-function-name':
  554. $this->init_function['name'] .= $data;
  555. break;
  556. case 'database-table-initialization-insert-field-expression-function-value':
  557. case 'database-table-initialization-insert-select-field-expression-function-value':
  558. case 'database-table-initialization-insert-select-where-expression-function-value':
  559. case 'database-table-initialization-update-field-expression-function-value':
  560. case 'database-table-initialization-update-where-expression-function-value':
  561. case 'database-table-initialization-delete-where-expression-function-value':
  562. $this->init_function['arguments'][] = array('type' => 'value', 'data' => $data);
  563. break;
  564. case 'database-table-initialization-insert-field-expression-function-column':
  565. case 'database-table-initialization-insert-select-field-expression-function-column':
  566. case 'database-table-initialization-insert-select-where-expression-function-column':
  567. case 'database-table-initialization-update-field-expression-function-column':
  568. case 'database-table-initialization-update-where-expression-function-column':
  569. case 'database-table-initialization-delete-where-expression-function-column':
  570. $this->init_function['arguments'][] = array('type' => 'column', 'data' => $data);
  571. break;
  572. /* One level simulation of function-expression recursion */
  573. case 'database-table-initialization-insert-field-function-expression-operator':
  574. case 'database-table-initialization-insert-select-field-function-expression-operator':
  575. case 'database-table-initialization-update-field-function-expression-operator':
  576. $this->init_expression['operator'] = $data;
  577. break;
  578. case 'database-table-initialization-insert-field-function-expression-value':
  579. case 'database-table-initialization-insert-select-field-function-expression-value':
  580. case 'database-table-initialization-update-field-function-expression-value':
  581. $this->init_expression['operants'][] = array('type' => 'value', 'data' => $data);
  582. break;
  583. case 'database-table-initialization-insert-field-function-expression-column':
  584. case 'database-table-initialization-insert-select-field-function-expression-column':
  585. case 'database-table-initialization-update-field-function-expression-column':
  586. $this->init_expression['operants'][] = array('type' => 'column', 'data' => $data);
  587. break;
  588. /* Database */
  589. case 'database-name':
  590. $this->database_definition['name'] .= $data;
  591. break;
  592. case 'database-create':
  593. $this->database_definition['create'] .= $data;
  594. break;
  595. case 'database-overwrite':
  596. $this->database_definition['overwrite'] .= $data;
  597. break;
  598. case 'database-charset':
  599. $this->database_definition['charset'] .= $data;
  600. break;
  601. case 'database-description':
  602. $this->database_definition['description'] .= $data;
  603. break;
  604. case 'database-comments':
  605. $this->database_definition['comments'] .= $data;
  606. break;
  607. /* Table declaration */
  608. case 'database-table-name':
  609. $this->table_name .= $data;
  610. break;
  611. case 'database-table-was':
  612. $this->table['was'] .= $data;
  613. break;
  614. case 'database-table-description':
  615. $this->table['description'] .= $data;
  616. break;
  617. case 'database-table-comments':
  618. $this->table['comments'] .= $data;
  619. break;
  620. /* Field declaration */
  621. case 'database-table-declaration-field-name':
  622. $this->field_name .= $data;
  623. break;
  624. case 'database-table-declaration-field-was':
  625. $this->field['was'] .= $data;
  626. break;
  627. case 'database-table-declaration-field-type':
  628. $this->field['type'] .= $data;
  629. break;
  630. case 'database-table-declaration-field-fixed':
  631. $this->field['fixed'] .= $data;
  632. break;
  633. case 'database-table-declaration-field-default':
  634. $this->field['default'] .= $data;
  635. break;
  636. case 'database-table-declaration-field-notnull':
  637. $this->field['notnull'] .= $data;
  638. break;
  639. case 'database-table-declaration-field-autoincrement':
  640. $this->field['autoincrement'] .= $data;
  641. break;
  642. case 'database-table-declaration-field-unsigned':
  643. $this->field['unsigned'] .= $data;
  644. break;
  645. case 'database-table-declaration-field-length':
  646. $this->field['length'] .= $data;
  647. break;
  648. case 'database-table-declaration-field-description':
  649. $this->field['description'] .= $data;
  650. break;
  651. case 'database-table-declaration-field-comments':
  652. $this->field['comments'] .= $data;
  653. break;
  654. /* Index declaration */
  655. case 'database-table-declaration-index-name':
  656. $this->index_name .= $data;
  657. break;
  658. case 'database-table-declaration-index-was':
  659. $this->index['was'] .= $data;
  660. break;
  661. case 'database-table-declaration-index-unique':
  662. $this->index['unique'] .= $data;
  663. break;
  664. case 'database-table-declaration-index-primary':
  665. $this->index['primary'] .= $data;
  666. break;
  667. case 'database-table-declaration-index-field-name':
  668. $this->field_name .= $data;
  669. break;
  670. case 'database-table-declaration-index-field-sorting':
  671. $this->field['sorting'] .= $data;
  672. break;
  673. /* Add by Leoncx */
  674. case 'database-table-declaration-index-field-length':
  675. $this->field['length'] .= $data;
  676. break;
  677. /* Foreign Key declaration */
  678. case 'database-table-declaration-foreign-name':
  679. $this->constraint_name .= $data;
  680. break;
  681. case 'database-table-declaration-foreign-was':
  682. $this->constraint['was'] .= $data;
  683. break;
  684. case 'database-table-declaration-foreign-match':
  685. $this->constraint['match'] .= $data;
  686. break;
  687. case 'database-table-declaration-foreign-ondelete':
  688. $this->constraint['ondelete'] .= $data;
  689. break;
  690. case 'database-table-declaration-foreign-onupdate':
  691. $this->constraint['onupdate'] .= $data;
  692. break;
  693. case 'database-table-declaration-foreign-deferrable':
  694. $this->constraint['deferrable'] .= $data;
  695. break;
  696. case 'database-table-declaration-foreign-initiallydeferred':
  697. $this->constraint['initiallydeferred'] .= $data;
  698. break;
  699. case 'database-table-declaration-foreign-field':
  700. $this->field_name .= $data;
  701. break;
  702. case 'database-table-declaration-foreign-references-table':
  703. $this->constraint['references']['table'] .= $data;
  704. break;
  705. case 'database-table-declaration-foreign-references-field':
  706. $this->field_name .= $data;
  707. break;
  708. /* Sequence declaration */
  709. case 'database-sequence-name':
  710. $this->sequence_name .= $data;
  711. break;
  712. case 'database-sequence-was':
  713. $this->sequence['was'] .= $data;
  714. break;
  715. case 'database-sequence-start':
  716. $this->sequence['start'] .= $data;
  717. break;
  718. case 'database-sequence-description':
  719. $this->sequence['description'] .= $data;
  720. break;
  721. case 'database-sequence-comments':
  722. $this->sequence['comments'] .= $data;
  723. break;
  724. case 'database-sequence-on-table':
  725. $this->sequence['on']['table'] .= $data;
  726. break;
  727. case 'database-sequence-on-field':
  728. $this->sequence['on']['field'] .= $data;
  729. break;
  730. }
  731. }
  732. }
  733. ?>