Parser.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. <?php /* vim: se et ts=4 sw=4 sts=4 fdm=marker tw=80: */
  2. /**
  3. * Copyright (c) 1998-2010 Manuel Lemos, Tomas V.V.Cox,
  4. * Stig. S. Bakken, Lukas Smith, Igor Feghali
  5. * All rights reserved.
  6. *
  7. * MDB2_Schema enables users to maintain RDBMS independant schema files
  8. * in XML that can be used to manipulate both data and database schemas
  9. * This LICENSE is in the BSD license style.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. *
  18. * Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. *
  22. * Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
  23. * Lukas Smith, Igor Feghali nor the names of his contributors may be
  24. * used to endorse or promote products derived from this software
  25. * without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  30. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  31. * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  32. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  33. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  34. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  35. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
  37. * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * PHP version 5
  41. *
  42. * @category Database
  43. * @package MDB2_Schema
  44. * @author Christian Dickmann <dickmann@php.net>
  45. * @author Igor Feghali <ifeghali@php.net>
  46. * @license BSD http://www.opensource.org/licenses/bsd-license.php
  47. * @version SVN: $Id$
  48. * @link http://pear.php.net/packages/MDB2_Schema
  49. */
  50. require_once 'XML/Parser.php';
  51. require_once 'MDB2/Schema/Validate.php';
  52. /**
  53. * Parses an XML schema file
  54. *
  55. * @category Database
  56. * @package MDB2_Schema
  57. * @author Christian Dickmann <dickmann@php.net>
  58. * @license BSD http://www.opensource.org/licenses/bsd-license.php
  59. * @link http://pear.php.net/packages/MDB2_Schema
  60. */
  61. class MDB2_Schema_Parser extends XML_Parser
  62. {
  63. var $database_definition = array();
  64. var $elements = array();
  65. var $element = '';
  66. var $count = 0;
  67. var $table = array();
  68. var $table_name = '';
  69. var $field = array();
  70. var $field_name = '';
  71. var $init = array();
  72. var $init_function = array();
  73. var $init_expression = array();
  74. var $init_field = array();
  75. var $index = array();
  76. var $index_name = '';
  77. var $constraint = array();
  78. var $constraint_name = '';
  79. var $var_mode = false;
  80. var $variables = array();
  81. var $sequence = array();
  82. var $sequence_name = '';
  83. var $error;
  84. var $structure = false;
  85. var $val;
  86. /**
  87. * PHP 5 constructor
  88. *
  89. * @param array $variables mixed array with user defined schema
  90. * variables
  91. * @param bool $fail_on_invalid_names array with reserved words per RDBMS
  92. * @param array $structure multi dimensional array with
  93. * database schema and data
  94. * @param array $valid_types information of all valid fields
  95. * types
  96. * @param bool $force_defaults if true sets a default value to
  97. * field when not explicit
  98. * @param int $max_identifiers_length maximum allowed size for entities
  99. * name
  100. *
  101. * @return void
  102. *
  103. * @access public
  104. * @static
  105. */
  106. function __construct($variables, $fail_on_invalid_names = true,
  107. $structure = false, $valid_types = array(), $force_defaults = true,
  108. $max_identifiers_length = null
  109. ) {
  110. // force ISO-8859-1 due to different defaults for PHP4 and PHP5
  111. // todo: this probably needs to be investigated some more andcleaned up
  112. parent::__construct('ISO-8859-1');
  113. $this->variables = $variables;
  114. $this->structure = $structure;
  115. $this->val = new MDB2_Schema_Validate(
  116. $fail_on_invalid_names,
  117. $valid_types,
  118. $force_defaults,
  119. $max_identifiers_length
  120. );
  121. }
  122. /**
  123. * Triggered when reading a XML open tag <element>
  124. *
  125. * @param resource $xp xml parser resource
  126. * @param string $element element name
  127. * @param array $attribs attributes
  128. *
  129. * @return void
  130. * @access private
  131. * @static
  132. */
  133. function startHandler($xp, $element, &$attribs)
  134. {
  135. if (strtolower($element) == 'variable') {
  136. $this->var_mode = true;
  137. return;
  138. }
  139. $this->elements[$this->count++] = strtolower($element);
  140. $this->element = implode('-', $this->elements);
  141. switch ($this->element) {
  142. /* Initialization */
  143. case 'database-table-initialization':
  144. $this->table['initialization'] = array();
  145. break;
  146. /* Insert */
  147. /* insert: field+ */
  148. case 'database-table-initialization-insert':
  149. $this->init = array('type' => 'insert', 'data' => array('field' => array()));
  150. break;
  151. /* insert-select: field+, table, where? */
  152. case 'database-table-initialization-insert-select':
  153. $this->init['data']['table'] = '';
  154. break;
  155. /* Update */
  156. /* update: field+, where? */
  157. case 'database-table-initialization-update':
  158. $this->init = array('type' => 'update', 'data' => array('field' => array()));
  159. break;
  160. /* Delete */
  161. /* delete: where */
  162. case 'database-table-initialization-delete':
  163. $this->init = array('type' => 'delete', 'data' => array('where' => array()));
  164. break;
  165. /* Insert and Update */
  166. case 'database-table-initialization-insert-field':
  167. case 'database-table-initialization-insert-select-field':
  168. case 'database-table-initialization-update-field':
  169. $this->init_field = array('name' => '', 'group' => array());
  170. break;
  171. case 'database-table-initialization-insert-field-value':
  172. case 'database-table-initialization-insert-select-field-value':
  173. case 'database-table-initialization-update-field-value':
  174. /* if value tag is empty cdataHandler is not called so we must force value element creation here */
  175. $this->init_field['group'] = array('type' => 'value', 'data' => '');
  176. break;
  177. case 'database-table-initialization-insert-field-null':
  178. case 'database-table-initialization-insert-select-field-null':
  179. case 'database-table-initialization-update-field-null':
  180. $this->init_field['group'] = array('type' => 'null');
  181. break;
  182. case 'database-table-initialization-insert-field-function':
  183. case 'database-table-initialization-insert-select-field-function':
  184. case 'database-table-initialization-update-field-function':
  185. $this->init_function = array('name' => '');
  186. break;
  187. case 'database-table-initialization-insert-field-expression':
  188. case 'database-table-initialization-insert-select-field-expression':
  189. case 'database-table-initialization-update-field-expression':
  190. $this->init_expression = array();
  191. break;
  192. /* All */
  193. case 'database-table-initialization-insert-select-where':
  194. case 'database-table-initialization-update-where':
  195. case 'database-table-initialization-delete-where':
  196. $this->init['data']['where'] = array('type' => '', 'data' => array());
  197. break;
  198. case 'database-table-initialization-insert-select-where-expression':
  199. case 'database-table-initialization-update-where-expression':
  200. case 'database-table-initialization-delete-where-expression':
  201. $this->init_expression = array();
  202. break;
  203. /* One level simulation of expression-function recursion */
  204. case 'database-table-initialization-insert-field-expression-function':
  205. case 'database-table-initialization-insert-select-field-expression-function':
  206. case 'database-table-initialization-insert-select-where-expression-function':
  207. case 'database-table-initialization-update-field-expression-function':
  208. case 'database-table-initialization-update-where-expression-function':
  209. case 'database-table-initialization-delete-where-expression-function':
  210. $this->init_function = array('name' => '');
  211. break;
  212. /* One level simulation of function-expression recursion */
  213. case 'database-table-initialization-insert-field-function-expression':
  214. case 'database-table-initialization-insert-select-field-function-expression':
  215. case 'database-table-initialization-insert-select-where-function-expression':
  216. case 'database-table-initialization-update-field-function-expression':
  217. case 'database-table-initialization-update-where-function-expression':
  218. case 'database-table-initialization-delete-where-function-expression':
  219. $this->init_expression = array();
  220. break;
  221. /* Definition */
  222. case 'database':
  223. $this->database_definition = array(
  224. 'name' => '',
  225. 'create' => '',
  226. 'overwrite' => '',
  227. 'charset' => '',
  228. 'description' => '',
  229. 'comments' => '',
  230. 'tables' => array(),
  231. 'sequences' => array()
  232. );
  233. break;
  234. case 'database-table':
  235. $this->table_name = '';
  236. $this->table = array(
  237. 'was' => '',
  238. 'description' => '',
  239. 'comments' => '',
  240. 'fields' => array(),
  241. 'indexes' => array(),
  242. 'constraints' => array(),
  243. 'initialization' => array()
  244. );
  245. break;
  246. case 'database-table-declaration-field':
  247. case 'database-table-declaration-foreign-field':
  248. case 'database-table-declaration-foreign-references-field':
  249. $this->field_name = '';
  250. $this->field = array();
  251. break;
  252. case 'database-table-declaration-index-field':
  253. $this->field_name = '';
  254. $this->field = array('sorting' => '', 'length' => '');
  255. break;
  256. /* force field attributes to be initialized when the tag is empty in the XML */
  257. case 'database-table-declaration-field-was':
  258. $this->field['was'] = '';
  259. break;
  260. case 'database-table-declaration-field-type':
  261. $this->field['type'] = '';
  262. break;
  263. case 'database-table-declaration-field-fixed':
  264. $this->field['fixed'] = '';
  265. break;
  266. case 'database-table-declaration-field-default':
  267. $this->field['default'] = '';
  268. break;
  269. case 'database-table-declaration-field-notnull':
  270. $this->field['notnull'] = '';
  271. break;
  272. case 'database-table-declaration-field-autoincrement':
  273. $this->field['autoincrement'] = '';
  274. break;
  275. case 'database-table-declaration-field-unsigned':
  276. $this->field['unsigned'] = '';
  277. break;
  278. case 'database-table-declaration-field-length':
  279. $this->field['length'] = '';
  280. break;
  281. case 'database-table-declaration-field-description':
  282. $this->field['description'] = '';
  283. break;
  284. case 'database-table-declaration-field-comments':
  285. $this->field['comments'] = '';
  286. break;
  287. case 'database-table-declaration-index':
  288. $this->index_name = '';
  289. $this->index = array(
  290. 'was' => '',
  291. 'unique' =>'',
  292. 'primary' => '',
  293. 'fields' => array()
  294. );
  295. break;
  296. case 'database-table-declaration-foreign':
  297. $this->constraint_name = '';
  298. $this->constraint = array(
  299. 'was' => '',
  300. 'match' => '',
  301. 'ondelete' => '',
  302. 'onupdate' => '',
  303. 'deferrable' => '',
  304. 'initiallydeferred' => '',
  305. 'foreign' => true,
  306. 'fields' => array(),
  307. 'references' => array('table' => '', 'fields' => array())
  308. );
  309. break;
  310. case 'database-sequence':
  311. $this->sequence_name = '';
  312. $this->sequence = array(
  313. 'was' => '',
  314. 'start' => '',
  315. 'description' => '',
  316. 'comments' => '',
  317. );
  318. break;
  319. }
  320. }
  321. /**
  322. * Triggered when reading a XML close tag </element>
  323. *
  324. * @param resource $xp xml parser resource
  325. * @param string $element element name
  326. *
  327. * @return void
  328. * @access private
  329. * @static
  330. */
  331. function endHandler($xp, $element)
  332. {
  333. if (strtolower($element) == 'variable') {
  334. $this->var_mode = false;
  335. return;
  336. }
  337. switch ($this->element) {
  338. /* Initialization */
  339. /* Insert */
  340. case 'database-table-initialization-insert-select':
  341. $this->init['data'] = array('select' => $this->init['data']);
  342. break;
  343. /* Insert and Delete */
  344. case 'database-table-initialization-insert-field':
  345. case 'database-table-initialization-insert-select-field':
  346. case 'database-table-initialization-update-field':
  347. $result = $this->val->validateDataField($this->table['fields'], $this->init['data']['field'], $this->init_field);
  348. if (PEAR::isError($result)) {
  349. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  350. } else {
  351. $this->init['data']['field'][] = $this->init_field;
  352. }
  353. break;
  354. case 'database-table-initialization-insert-field-function':
  355. case 'database-table-initialization-insert-select-field-function':
  356. case 'database-table-initialization-update-field-function':
  357. $this->init_field['group'] = array('type' => 'function', 'data' => $this->init_function);
  358. break;
  359. case 'database-table-initialization-insert-field-expression':
  360. case 'database-table-initialization-insert-select-field-expression':
  361. case 'database-table-initialization-update-field-expression':
  362. $this->init_field['group'] = array('type' => 'expression', 'data' => $this->init_expression);
  363. break;
  364. /* All */
  365. case 'database-table-initialization-insert-select-where-expression':
  366. case 'database-table-initialization-update-where-expression':
  367. case 'database-table-initialization-delete-where-expression':
  368. $this->init['data']['where']['type'] = 'expression';
  369. $this->init['data']['where']['data'] = $this->init_expression;
  370. break;
  371. case 'database-table-initialization-insert':
  372. case 'database-table-initialization-delete':
  373. case 'database-table-initialization-update':
  374. $this->table['initialization'][] = $this->init;
  375. break;
  376. /* One level simulation of expression-function recursion */
  377. case 'database-table-initialization-insert-field-expression-function':
  378. case 'database-table-initialization-insert-select-field-expression-function':
  379. case 'database-table-initialization-insert-select-where-expression-function':
  380. case 'database-table-initialization-update-field-expression-function':
  381. case 'database-table-initialization-update-where-expression-function':
  382. case 'database-table-initialization-delete-where-expression-function':
  383. $this->init_expression['operants'][] = array('type' => 'function', 'data' => $this->init_function);
  384. break;
  385. /* One level simulation of function-expression recursion */
  386. case 'database-table-initialization-insert-field-function-expression':
  387. case 'database-table-initialization-insert-select-field-function-expression':
  388. case 'database-table-initialization-insert-select-where-function-expression':
  389. case 'database-table-initialization-update-field-function-expression':
  390. case 'database-table-initialization-update-where-function-expression':
  391. case 'database-table-initialization-delete-where-function-expression':
  392. $this->init_function['arguments'][] = array('type' => 'expression', 'data' => $this->init_expression);
  393. break;
  394. /* Table definition */
  395. case 'database-table':
  396. $result = $this->val->validateTable($this->database_definition['tables'], $this->table, $this->table_name);
  397. if (PEAR::isError($result)) {
  398. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  399. } else {
  400. $this->database_definition['tables'][$this->table_name] = $this->table;
  401. }
  402. break;
  403. case 'database-table-name':
  404. if (isset($this->structure['tables'][$this->table_name])) {
  405. $this->table = $this->structure['tables'][$this->table_name];
  406. }
  407. break;
  408. /* Field declaration */
  409. case 'database-table-declaration-field':
  410. $result = $this->val->validateField($this->table['fields'], $this->field, $this->field_name);
  411. if (PEAR::isError($result)) {
  412. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  413. } else {
  414. $this->table['fields'][$this->field_name] = $this->field;
  415. }
  416. break;
  417. /* Index declaration */
  418. case 'database-table-declaration-index':
  419. $result = $this->val->validateIndex($this->table['indexes'], $this->index, $this->index_name);
  420. if (PEAR::isError($result)) {
  421. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  422. } else {
  423. $this->table['indexes'][$this->index_name] = $this->index;
  424. }
  425. break;
  426. case 'database-table-declaration-index-field':
  427. $result = $this->val->validateIndexField($this->index['fields'], $this->field, $this->field_name);
  428. if (PEAR::isError($result)) {
  429. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  430. } else {
  431. $this->index['fields'][$this->field_name] = $this->field;
  432. }
  433. break;
  434. /* Foreign Key declaration */
  435. case 'database-table-declaration-foreign':
  436. $result = $this->val->validateConstraint($this->table['constraints'], $this->constraint, $this->constraint_name);
  437. if (PEAR::isError($result)) {
  438. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  439. } else {
  440. $this->table['constraints'][$this->constraint_name] = $this->constraint;
  441. }
  442. break;
  443. case 'database-table-declaration-foreign-field':
  444. $result = $this->val->validateConstraintField($this->constraint['fields'], $this->field_name);
  445. if (PEAR::isError($result)) {
  446. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  447. } else {
  448. $this->constraint['fields'][$this->field_name] = '';
  449. }
  450. break;
  451. case 'database-table-declaration-foreign-references-field':
  452. $result = $this->val->validateConstraintReferencedField($this->constraint['references']['fields'], $this->field_name);
  453. if (PEAR::isError($result)) {
  454. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  455. } else {
  456. $this->constraint['references']['fields'][$this->field_name] = '';
  457. }
  458. break;
  459. /* Sequence declaration */
  460. case 'database-sequence':
  461. $result = $this->val->validateSequence($this->database_definition['sequences'], $this->sequence, $this->sequence_name);
  462. if (PEAR::isError($result)) {
  463. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  464. } else {
  465. $this->database_definition['sequences'][$this->sequence_name] = $this->sequence;
  466. }
  467. break;
  468. /* End of File */
  469. case 'database':
  470. $result = $this->val->validateDatabase($this->database_definition);
  471. if (PEAR::isError($result)) {
  472. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  473. }
  474. break;
  475. }
  476. unset($this->elements[--$this->count]);
  477. $this->element = implode('-', $this->elements);
  478. }
  479. /**
  480. * Pushes a MDB2_Schema_Error into stack and returns it
  481. *
  482. * @param string $msg textual message
  483. * @param int $xmlecode PHP's XML parser error code
  484. * @param resource $xp xml parser resource
  485. * @param int $ecode MDB2_Schema's error code
  486. *
  487. * @return object
  488. * @access private
  489. * @static
  490. */
  491. static function &raiseError($msg = null, $xmlecode = 0, $xp = null, $ecode = MDB2_SCHEMA_ERROR_PARSE, $userinfo = null,
  492. $error_class = null,
  493. $skipmsg = false)
  494. {
  495. if (is_null($this->error)) {
  496. $error = '';
  497. if (is_resource($msg)) {
  498. $error .= 'Parser error: '.xml_error_string(xml_get_error_code($msg));
  499. $xp = $msg;
  500. } else {
  501. $error .= 'Parser error: '.$msg;
  502. if (!is_resource($xp)) {
  503. $xp = $this->parser;
  504. }
  505. }
  506. if ($error_string = xml_error_string($xmlecode)) {
  507. $error .= ' - '.$error_string;
  508. }
  509. if (is_resource($xp)) {
  510. $byte = @xml_get_current_byte_index($xp);
  511. $line = @xml_get_current_line_number($xp);
  512. $column = @xml_get_current_column_number($xp);
  513. $error .= " - Byte: $byte; Line: $line; Col: $column";
  514. }
  515. $error .= "\n";
  516. $this->error = MDB2_Schema::raiseError($ecode, null, null, $error);
  517. }
  518. return $this->error;
  519. }
  520. /**
  521. * Triggered when reading data in a XML element (text between tags)
  522. *
  523. * @param resource $xp xml parser resource
  524. * @param string $data text
  525. *
  526. * @return void
  527. * @access private
  528. * @static
  529. */
  530. function cdataHandler($xp, $data)
  531. {
  532. if ($this->var_mode == true) {
  533. if (!isset($this->variables[$data])) {
  534. $this->raiseError('variable "'.$data.'" not found', null, $xp);
  535. return;
  536. }
  537. $data = $this->variables[$data];
  538. }
  539. switch ($this->element) {
  540. /* Initialization */
  541. /* Insert */
  542. case 'database-table-initialization-insert-select-table':
  543. $this->init['data']['table'] = $data;
  544. break;
  545. /* Insert and Update */
  546. case 'database-table-initialization-insert-field-name':
  547. case 'database-table-initialization-insert-select-field-name':
  548. case 'database-table-initialization-update-field-name':
  549. $this->init_field['name'] .= $data;
  550. break;
  551. case 'database-table-initialization-insert-field-value':
  552. case 'database-table-initialization-insert-select-field-value':
  553. case 'database-table-initialization-update-field-value':
  554. $this->init_field['group']['data'] .= $data;
  555. break;
  556. case 'database-table-initialization-insert-field-function-name':
  557. case 'database-table-initialization-insert-select-field-function-name':
  558. case 'database-table-initialization-update-field-function-name':
  559. $this->init_function['name'] .= $data;
  560. break;
  561. case 'database-table-initialization-insert-field-function-value':
  562. case 'database-table-initialization-insert-select-field-function-value':
  563. case 'database-table-initialization-update-field-function-value':
  564. $this->init_function['arguments'][] = array('type' => 'value', 'data' => $data);
  565. break;
  566. case 'database-table-initialization-insert-field-function-column':
  567. case 'database-table-initialization-insert-select-field-function-column':
  568. case 'database-table-initialization-update-field-function-column':
  569. $this->init_function['arguments'][] = array('type' => 'column', 'data' => $data);
  570. break;
  571. case 'database-table-initialization-insert-field-column':
  572. case 'database-table-initialization-insert-select-field-column':
  573. case 'database-table-initialization-update-field-column':
  574. $this->init_field['group'] = array('type' => 'column', 'data' => $data);
  575. break;
  576. /* All */
  577. case 'database-table-initialization-insert-field-expression-operator':
  578. case 'database-table-initialization-insert-select-field-expression-operator':
  579. case 'database-table-initialization-insert-select-where-expression-operator':
  580. case 'database-table-initialization-update-field-expression-operator':
  581. case 'database-table-initialization-update-where-expression-operator':
  582. case 'database-table-initialization-delete-where-expression-operator':
  583. $this->init_expression['operator'] = $data;
  584. break;
  585. case 'database-table-initialization-insert-field-expression-value':
  586. case 'database-table-initialization-insert-select-field-expression-value':
  587. case 'database-table-initialization-insert-select-where-expression-value':
  588. case 'database-table-initialization-update-field-expression-value':
  589. case 'database-table-initialization-update-where-expression-value':
  590. case 'database-table-initialization-delete-where-expression-value':
  591. $this->init_expression['operants'][] = array('type' => 'value', 'data' => $data);
  592. break;
  593. case 'database-table-initialization-insert-field-expression-column':
  594. case 'database-table-initialization-insert-select-field-expression-column':
  595. case 'database-table-initialization-insert-select-where-expression-column':
  596. case 'database-table-initialization-update-field-expression-column':
  597. case 'database-table-initialization-update-where-expression-column':
  598. case 'database-table-initialization-delete-where-expression-column':
  599. $this->init_expression['operants'][] = array('type' => 'column', 'data' => $data);
  600. break;
  601. case 'database-table-initialization-insert-field-function-function':
  602. case 'database-table-initialization-insert-field-function-expression':
  603. case 'database-table-initialization-insert-field-expression-expression':
  604. case 'database-table-initialization-update-field-function-function':
  605. case 'database-table-initialization-update-field-function-expression':
  606. case 'database-table-initialization-update-field-expression-expression':
  607. case 'database-table-initialization-update-where-expression-expression':
  608. case 'database-table-initialization-delete-where-expression-expression':
  609. /* Recursion to be implemented yet */
  610. break;
  611. /* One level simulation of expression-function recursion */
  612. case 'database-table-initialization-insert-field-expression-function-name':
  613. case 'database-table-initialization-insert-select-field-expression-function-name':
  614. case 'database-table-initialization-insert-select-where-expression-function-name':
  615. case 'database-table-initialization-update-field-expression-function-name':
  616. case 'database-table-initialization-update-where-expression-function-name':
  617. case 'database-table-initialization-delete-where-expression-function-name':
  618. $this->init_function['name'] .= $data;
  619. break;
  620. case 'database-table-initialization-insert-field-expression-function-value':
  621. case 'database-table-initialization-insert-select-field-expression-function-value':
  622. case 'database-table-initialization-insert-select-where-expression-function-value':
  623. case 'database-table-initialization-update-field-expression-function-value':
  624. case 'database-table-initialization-update-where-expression-function-value':
  625. case 'database-table-initialization-delete-where-expression-function-value':
  626. $this->init_function['arguments'][] = array('type' => 'value', 'data' => $data);
  627. break;
  628. case 'database-table-initialization-insert-field-expression-function-column':
  629. case 'database-table-initialization-insert-select-field-expression-function-column':
  630. case 'database-table-initialization-insert-select-where-expression-function-column':
  631. case 'database-table-initialization-update-field-expression-function-column':
  632. case 'database-table-initialization-update-where-expression-function-column':
  633. case 'database-table-initialization-delete-where-expression-function-column':
  634. $this->init_function['arguments'][] = array('type' => 'column', 'data' => $data);
  635. break;
  636. /* One level simulation of function-expression recursion */
  637. case 'database-table-initialization-insert-field-function-expression-operator':
  638. case 'database-table-initialization-insert-select-field-function-expression-operator':
  639. case 'database-table-initialization-update-field-function-expression-operator':
  640. $this->init_expression['operator'] = $data;
  641. break;
  642. case 'database-table-initialization-insert-field-function-expression-value':
  643. case 'database-table-initialization-insert-select-field-function-expression-value':
  644. case 'database-table-initialization-update-field-function-expression-value':
  645. $this->init_expression['operants'][] = array('type' => 'value', 'data' => $data);
  646. break;
  647. case 'database-table-initialization-insert-field-function-expression-column':
  648. case 'database-table-initialization-insert-select-field-function-expression-column':
  649. case 'database-table-initialization-update-field-function-expression-column':
  650. $this->init_expression['operants'][] = array('type' => 'column', 'data' => $data);
  651. break;
  652. /* Database */
  653. case 'database-name':
  654. $this->database_definition['name'] .= $data;
  655. break;
  656. case 'database-create':
  657. $this->database_definition['create'] .= $data;
  658. break;
  659. case 'database-overwrite':
  660. $this->database_definition['overwrite'] .= $data;
  661. break;
  662. case 'database-charset':
  663. $this->database_definition['charset'] .= $data;
  664. break;
  665. case 'database-description':
  666. $this->database_definition['description'] .= $data;
  667. break;
  668. case 'database-comments':
  669. $this->database_definition['comments'] .= $data;
  670. break;
  671. /* Table declaration */
  672. case 'database-table-name':
  673. $this->table_name .= $data;
  674. break;
  675. case 'database-table-was':
  676. $this->table['was'] .= $data;
  677. break;
  678. case 'database-table-description':
  679. $this->table['description'] .= $data;
  680. break;
  681. case 'database-table-comments':
  682. $this->table['comments'] .= $data;
  683. break;
  684. /* Field declaration */
  685. case 'database-table-declaration-field-name':
  686. $this->field_name .= $data;
  687. break;
  688. case 'database-table-declaration-field-was':
  689. $this->field['was'] .= $data;
  690. break;
  691. case 'database-table-declaration-field-type':
  692. $this->field['type'] .= $data;
  693. break;
  694. case 'database-table-declaration-field-fixed':
  695. $this->field['fixed'] .= $data;
  696. break;
  697. case 'database-table-declaration-field-default':
  698. $this->field['default'] .= $data;
  699. break;
  700. case 'database-table-declaration-field-notnull':
  701. $this->field['notnull'] .= $data;
  702. break;
  703. case 'database-table-declaration-field-autoincrement':
  704. $this->field['autoincrement'] .= $data;
  705. break;
  706. case 'database-table-declaration-field-unsigned':
  707. $this->field['unsigned'] .= $data;
  708. break;
  709. case 'database-table-declaration-field-length':
  710. $this->field['length'] .= $data;
  711. break;
  712. case 'database-table-declaration-field-description':
  713. $this->field['description'] .= $data;
  714. break;
  715. case 'database-table-declaration-field-comments':
  716. $this->field['comments'] .= $data;
  717. break;
  718. /* Index declaration */
  719. case 'database-table-declaration-index-name':
  720. $this->index_name .= $data;
  721. break;
  722. case 'database-table-declaration-index-was':
  723. $this->index['was'] .= $data;
  724. break;
  725. case 'database-table-declaration-index-unique':
  726. $this->index['unique'] .= $data;
  727. break;
  728. case 'database-table-declaration-index-primary':
  729. $this->index['primary'] .= $data;
  730. break;
  731. case 'database-table-declaration-index-field-name':
  732. $this->field_name .= $data;
  733. break;
  734. case 'database-table-declaration-index-field-sorting':
  735. $this->field['sorting'] .= $data;
  736. break;
  737. /* Add by Leoncx */
  738. case 'database-table-declaration-index-field-length':
  739. $this->field['length'] .= $data;
  740. break;
  741. /* Foreign Key declaration */
  742. case 'database-table-declaration-foreign-name':
  743. $this->constraint_name .= $data;
  744. break;
  745. case 'database-table-declaration-foreign-was':
  746. $this->constraint['was'] .= $data;
  747. break;
  748. case 'database-table-declaration-foreign-match':
  749. $this->constraint['match'] .= $data;
  750. break;
  751. case 'database-table-declaration-foreign-ondelete':
  752. $this->constraint['ondelete'] .= $data;
  753. break;
  754. case 'database-table-declaration-foreign-onupdate':
  755. $this->constraint['onupdate'] .= $data;
  756. break;
  757. case 'database-table-declaration-foreign-deferrable':
  758. $this->constraint['deferrable'] .= $data;
  759. break;
  760. case 'database-table-declaration-foreign-initiallydeferred':
  761. $this->constraint['initiallydeferred'] .= $data;
  762. break;
  763. case 'database-table-declaration-foreign-field':
  764. $this->field_name .= $data;
  765. break;
  766. case 'database-table-declaration-foreign-references-table':
  767. $this->constraint['references']['table'] .= $data;
  768. break;
  769. case 'database-table-declaration-foreign-references-field':
  770. $this->field_name .= $data;
  771. break;
  772. /* Sequence declaration */
  773. case 'database-sequence-name':
  774. $this->sequence_name .= $data;
  775. break;
  776. case 'database-sequence-was':
  777. $this->sequence['was'] .= $data;
  778. break;
  779. case 'database-sequence-start':
  780. $this->sequence['start'] .= $data;
  781. break;
  782. case 'database-sequence-description':
  783. $this->sequence['description'] .= $data;
  784. break;
  785. case 'database-sequence-comments':
  786. $this->sequence['comments'] .= $data;
  787. break;
  788. case 'database-sequence-on':
  789. $this->sequence['on'] = array('table' => '', 'field' => '');
  790. break;
  791. case 'database-sequence-on-table':
  792. $this->sequence['on']['table'] .= $data;
  793. break;
  794. case 'database-sequence-on-field':
  795. $this->sequence['on']['field'] .= $data;
  796. break;
  797. }
  798. }
  799. }