Parser.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  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. * PHP 4 compatible constructor
  124. *
  125. * @param array $variables mixed array with user defined schema
  126. * variables
  127. * @param bool $fail_on_invalid_names array with reserved words per RDBMS
  128. * @param array $structure multi dimensional array with
  129. * database schema and data
  130. * @param array $valid_types information of all valid fields
  131. * types
  132. * @param bool $force_defaults if true sets a default value to
  133. * field when not explicit
  134. * @param int $max_identifiers_length maximum allowed size for entities
  135. * name
  136. *
  137. * @return void
  138. *
  139. * @access public
  140. * @static
  141. */
  142. function MDB2_Schema_Parser($variables, $fail_on_invalid_names = true,
  143. $structure = false, $valid_types = array(), $force_defaults = true,
  144. $max_identifiers_length = null
  145. ) {
  146. $this->__construct($variables, $fail_on_invalid_names, $structure, $valid_types, $force_defaults);
  147. }
  148. /**
  149. * Triggered when reading a XML open tag <element>
  150. *
  151. * @param resource $xp xml parser resource
  152. * @param string $element element name
  153. * @param array $attribs attributes
  154. *
  155. * @return void
  156. * @access private
  157. * @static
  158. */
  159. function startHandler($xp, $element, &$attribs)
  160. {
  161. if (strtolower($element) == 'variable') {
  162. $this->var_mode = true;
  163. return;
  164. }
  165. $this->elements[$this->count++] = strtolower($element);
  166. $this->element = implode('-', $this->elements);
  167. switch ($this->element) {
  168. /* Initialization */
  169. case 'database-table-initialization':
  170. $this->table['initialization'] = array();
  171. break;
  172. /* Insert */
  173. /* insert: field+ */
  174. case 'database-table-initialization-insert':
  175. $this->init = array('type' => 'insert', 'data' => array('field' => array()));
  176. break;
  177. /* insert-select: field+, table, where? */
  178. case 'database-table-initialization-insert-select':
  179. $this->init['data']['table'] = '';
  180. break;
  181. /* Update */
  182. /* update: field+, where? */
  183. case 'database-table-initialization-update':
  184. $this->init = array('type' => 'update', 'data' => array('field' => array()));
  185. break;
  186. /* Delete */
  187. /* delete: where */
  188. case 'database-table-initialization-delete':
  189. $this->init = array('type' => 'delete', 'data' => array('where' => array()));
  190. break;
  191. /* Insert and Update */
  192. case 'database-table-initialization-insert-field':
  193. case 'database-table-initialization-insert-select-field':
  194. case 'database-table-initialization-update-field':
  195. $this->init_field = array('name' => '', 'group' => array());
  196. break;
  197. case 'database-table-initialization-insert-field-value':
  198. case 'database-table-initialization-insert-select-field-value':
  199. case 'database-table-initialization-update-field-value':
  200. /* if value tag is empty cdataHandler is not called so we must force value element creation here */
  201. $this->init_field['group'] = array('type' => 'value', 'data' => '');
  202. break;
  203. case 'database-table-initialization-insert-field-null':
  204. case 'database-table-initialization-insert-select-field-null':
  205. case 'database-table-initialization-update-field-null':
  206. $this->init_field['group'] = array('type' => 'null');
  207. break;
  208. case 'database-table-initialization-insert-field-function':
  209. case 'database-table-initialization-insert-select-field-function':
  210. case 'database-table-initialization-update-field-function':
  211. $this->init_function = array('name' => '');
  212. break;
  213. case 'database-table-initialization-insert-field-expression':
  214. case 'database-table-initialization-insert-select-field-expression':
  215. case 'database-table-initialization-update-field-expression':
  216. $this->init_expression = array();
  217. break;
  218. /* All */
  219. case 'database-table-initialization-insert-select-where':
  220. case 'database-table-initialization-update-where':
  221. case 'database-table-initialization-delete-where':
  222. $this->init['data']['where'] = array('type' => '', 'data' => array());
  223. break;
  224. case 'database-table-initialization-insert-select-where-expression':
  225. case 'database-table-initialization-update-where-expression':
  226. case 'database-table-initialization-delete-where-expression':
  227. $this->init_expression = array();
  228. break;
  229. /* One level simulation of expression-function recursion */
  230. case 'database-table-initialization-insert-field-expression-function':
  231. case 'database-table-initialization-insert-select-field-expression-function':
  232. case 'database-table-initialization-insert-select-where-expression-function':
  233. case 'database-table-initialization-update-field-expression-function':
  234. case 'database-table-initialization-update-where-expression-function':
  235. case 'database-table-initialization-delete-where-expression-function':
  236. $this->init_function = array('name' => '');
  237. break;
  238. /* One level simulation of function-expression recursion */
  239. case 'database-table-initialization-insert-field-function-expression':
  240. case 'database-table-initialization-insert-select-field-function-expression':
  241. case 'database-table-initialization-insert-select-where-function-expression':
  242. case 'database-table-initialization-update-field-function-expression':
  243. case 'database-table-initialization-update-where-function-expression':
  244. case 'database-table-initialization-delete-where-function-expression':
  245. $this->init_expression = array();
  246. break;
  247. /* Definition */
  248. case 'database':
  249. $this->database_definition = array(
  250. 'name' => '',
  251. 'create' => '',
  252. 'overwrite' => '',
  253. 'charset' => '',
  254. 'description' => '',
  255. 'comments' => '',
  256. 'tables' => array(),
  257. 'sequences' => array()
  258. );
  259. break;
  260. case 'database-table':
  261. $this->table_name = '';
  262. $this->table = array(
  263. 'was' => '',
  264. 'description' => '',
  265. 'comments' => '',
  266. 'fields' => array(),
  267. 'indexes' => array(),
  268. 'constraints' => array(),
  269. 'initialization' => array()
  270. );
  271. break;
  272. case 'database-table-declaration-field':
  273. case 'database-table-declaration-foreign-field':
  274. case 'database-table-declaration-foreign-references-field':
  275. $this->field_name = '';
  276. $this->field = array();
  277. break;
  278. case 'database-table-declaration-index-field':
  279. $this->field_name = '';
  280. $this->field = array('sorting' => '', 'length' => '');
  281. break;
  282. /* force field attributes to be initialized when the tag is empty in the XML */
  283. case 'database-table-declaration-field-was':
  284. $this->field['was'] = '';
  285. break;
  286. case 'database-table-declaration-field-type':
  287. $this->field['type'] = '';
  288. break;
  289. case 'database-table-declaration-field-fixed':
  290. $this->field['fixed'] = '';
  291. break;
  292. case 'database-table-declaration-field-default':
  293. $this->field['default'] = '';
  294. break;
  295. case 'database-table-declaration-field-notnull':
  296. $this->field['notnull'] = '';
  297. break;
  298. case 'database-table-declaration-field-autoincrement':
  299. $this->field['autoincrement'] = '';
  300. break;
  301. case 'database-table-declaration-field-unsigned':
  302. $this->field['unsigned'] = '';
  303. break;
  304. case 'database-table-declaration-field-length':
  305. $this->field['length'] = '';
  306. break;
  307. case 'database-table-declaration-field-description':
  308. $this->field['description'] = '';
  309. break;
  310. case 'database-table-declaration-field-comments':
  311. $this->field['comments'] = '';
  312. break;
  313. case 'database-table-declaration-index':
  314. $this->index_name = '';
  315. $this->index = array(
  316. 'was' => '',
  317. 'unique' =>'',
  318. 'primary' => '',
  319. 'fields' => array()
  320. );
  321. break;
  322. case 'database-table-declaration-foreign':
  323. $this->constraint_name = '';
  324. $this->constraint = array(
  325. 'was' => '',
  326. 'match' => '',
  327. 'ondelete' => '',
  328. 'onupdate' => '',
  329. 'deferrable' => '',
  330. 'initiallydeferred' => '',
  331. 'foreign' => true,
  332. 'fields' => array(),
  333. 'references' => array('table' => '', 'fields' => array())
  334. );
  335. break;
  336. case 'database-sequence':
  337. $this->sequence_name = '';
  338. $this->sequence = array(
  339. 'was' => '',
  340. 'start' => '',
  341. 'description' => '',
  342. 'comments' => '',
  343. );
  344. break;
  345. }
  346. }
  347. /**
  348. * Triggered when reading a XML close tag </element>
  349. *
  350. * @param resource $xp xml parser resource
  351. * @param string $element element name
  352. *
  353. * @return void
  354. * @access private
  355. * @static
  356. */
  357. function endHandler($xp, $element)
  358. {
  359. if (strtolower($element) == 'variable') {
  360. $this->var_mode = false;
  361. return;
  362. }
  363. switch ($this->element) {
  364. /* Initialization */
  365. /* Insert */
  366. case 'database-table-initialization-insert-select':
  367. $this->init['data'] = array('select' => $this->init['data']);
  368. break;
  369. /* Insert and Delete */
  370. case 'database-table-initialization-insert-field':
  371. case 'database-table-initialization-insert-select-field':
  372. case 'database-table-initialization-update-field':
  373. $result = $this->val->validateDataField($this->table['fields'], $this->init['data']['field'], $this->init_field);
  374. if (PEAR::isError($result)) {
  375. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  376. } else {
  377. $this->init['data']['field'][] = $this->init_field;
  378. }
  379. break;
  380. case 'database-table-initialization-insert-field-function':
  381. case 'database-table-initialization-insert-select-field-function':
  382. case 'database-table-initialization-update-field-function':
  383. $this->init_field['group'] = array('type' => 'function', 'data' => $this->init_function);
  384. break;
  385. case 'database-table-initialization-insert-field-expression':
  386. case 'database-table-initialization-insert-select-field-expression':
  387. case 'database-table-initialization-update-field-expression':
  388. $this->init_field['group'] = array('type' => 'expression', 'data' => $this->init_expression);
  389. break;
  390. /* All */
  391. case 'database-table-initialization-insert-select-where-expression':
  392. case 'database-table-initialization-update-where-expression':
  393. case 'database-table-initialization-delete-where-expression':
  394. $this->init['data']['where']['type'] = 'expression';
  395. $this->init['data']['where']['data'] = $this->init_expression;
  396. break;
  397. case 'database-table-initialization-insert':
  398. case 'database-table-initialization-delete':
  399. case 'database-table-initialization-update':
  400. $this->table['initialization'][] = $this->init;
  401. break;
  402. /* One level simulation of expression-function recursion */
  403. case 'database-table-initialization-insert-field-expression-function':
  404. case 'database-table-initialization-insert-select-field-expression-function':
  405. case 'database-table-initialization-insert-select-where-expression-function':
  406. case 'database-table-initialization-update-field-expression-function':
  407. case 'database-table-initialization-update-where-expression-function':
  408. case 'database-table-initialization-delete-where-expression-function':
  409. $this->init_expression['operants'][] = array('type' => 'function', 'data' => $this->init_function);
  410. break;
  411. /* One level simulation of function-expression recursion */
  412. case 'database-table-initialization-insert-field-function-expression':
  413. case 'database-table-initialization-insert-select-field-function-expression':
  414. case 'database-table-initialization-insert-select-where-function-expression':
  415. case 'database-table-initialization-update-field-function-expression':
  416. case 'database-table-initialization-update-where-function-expression':
  417. case 'database-table-initialization-delete-where-function-expression':
  418. $this->init_function['arguments'][] = array('type' => 'expression', 'data' => $this->init_expression);
  419. break;
  420. /* Table definition */
  421. case 'database-table':
  422. $result = $this->val->validateTable($this->database_definition['tables'], $this->table, $this->table_name);
  423. if (PEAR::isError($result)) {
  424. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  425. } else {
  426. $this->database_definition['tables'][$this->table_name] = $this->table;
  427. }
  428. break;
  429. case 'database-table-name':
  430. if (isset($this->structure['tables'][$this->table_name])) {
  431. $this->table = $this->structure['tables'][$this->table_name];
  432. }
  433. break;
  434. /* Field declaration */
  435. case 'database-table-declaration-field':
  436. $result = $this->val->validateField($this->table['fields'], $this->field, $this->field_name);
  437. if (PEAR::isError($result)) {
  438. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  439. } else {
  440. $this->table['fields'][$this->field_name] = $this->field;
  441. }
  442. break;
  443. /* Index declaration */
  444. case 'database-table-declaration-index':
  445. $result = $this->val->validateIndex($this->table['indexes'], $this->index, $this->index_name);
  446. if (PEAR::isError($result)) {
  447. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  448. } else {
  449. $this->table['indexes'][$this->index_name] = $this->index;
  450. }
  451. break;
  452. case 'database-table-declaration-index-field':
  453. $result = $this->val->validateIndexField($this->index['fields'], $this->field, $this->field_name);
  454. if (PEAR::isError($result)) {
  455. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  456. } else {
  457. $this->index['fields'][$this->field_name] = $this->field;
  458. }
  459. break;
  460. /* Foreign Key declaration */
  461. case 'database-table-declaration-foreign':
  462. $result = $this->val->validateConstraint($this->table['constraints'], $this->constraint, $this->constraint_name);
  463. if (PEAR::isError($result)) {
  464. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  465. } else {
  466. $this->table['constraints'][$this->constraint_name] = $this->constraint;
  467. }
  468. break;
  469. case 'database-table-declaration-foreign-field':
  470. $result = $this->val->validateConstraintField($this->constraint['fields'], $this->field_name);
  471. if (PEAR::isError($result)) {
  472. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  473. } else {
  474. $this->constraint['fields'][$this->field_name] = '';
  475. }
  476. break;
  477. case 'database-table-declaration-foreign-references-field':
  478. $result = $this->val->validateConstraintReferencedField($this->constraint['references']['fields'], $this->field_name);
  479. if (PEAR::isError($result)) {
  480. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  481. } else {
  482. $this->constraint['references']['fields'][$this->field_name] = '';
  483. }
  484. break;
  485. /* Sequence declaration */
  486. case 'database-sequence':
  487. $result = $this->val->validateSequence($this->database_definition['sequences'], $this->sequence, $this->sequence_name);
  488. if (PEAR::isError($result)) {
  489. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  490. } else {
  491. $this->database_definition['sequences'][$this->sequence_name] = $this->sequence;
  492. }
  493. break;
  494. /* End of File */
  495. case 'database':
  496. $result = $this->val->validateDatabase($this->database_definition);
  497. if (PEAR::isError($result)) {
  498. $this->raiseError($result->getUserinfo(), 0, $xp, $result->getCode());
  499. }
  500. break;
  501. }
  502. unset($this->elements[--$this->count]);
  503. $this->element = implode('-', $this->elements);
  504. }
  505. /**
  506. * Pushes a MDB2_Schema_Error into stack and returns it
  507. *
  508. * @param string $msg textual message
  509. * @param int $xmlecode PHP's XML parser error code
  510. * @param resource $xp xml parser resource
  511. * @param int $ecode MDB2_Schema's error code
  512. *
  513. * @return object
  514. * @access private
  515. * @static
  516. */
  517. static function &raiseError($msg = null, $xmlecode = 0, $xp = null, $ecode = MDB2_SCHEMA_ERROR_PARSE, $userinfo = null,
  518. $error_class = null,
  519. $skipmsg = false)
  520. {
  521. if (is_null($this->error)) {
  522. $error = '';
  523. if (is_resource($msg)) {
  524. $error .= 'Parser error: '.xml_error_string(xml_get_error_code($msg));
  525. $xp = $msg;
  526. } else {
  527. $error .= 'Parser error: '.$msg;
  528. if (!is_resource($xp)) {
  529. $xp = $this->parser;
  530. }
  531. }
  532. if ($error_string = xml_error_string($xmlecode)) {
  533. $error .= ' - '.$error_string;
  534. }
  535. if (is_resource($xp)) {
  536. $byte = @xml_get_current_byte_index($xp);
  537. $line = @xml_get_current_line_number($xp);
  538. $column = @xml_get_current_column_number($xp);
  539. $error .= " - Byte: $byte; Line: $line; Col: $column";
  540. }
  541. $error .= "\n";
  542. $this->error = MDB2_Schema::raiseError($ecode, null, null, $error);
  543. }
  544. return $this->error;
  545. }
  546. /**
  547. * Triggered when reading data in a XML element (text between tags)
  548. *
  549. * @param resource $xp xml parser resource
  550. * @param string $data text
  551. *
  552. * @return void
  553. * @access private
  554. * @static
  555. */
  556. function cdataHandler($xp, $data)
  557. {
  558. if ($this->var_mode == true) {
  559. if (!isset($this->variables[$data])) {
  560. $this->raiseError('variable "'.$data.'" not found', null, $xp);
  561. return;
  562. }
  563. $data = $this->variables[$data];
  564. }
  565. switch ($this->element) {
  566. /* Initialization */
  567. /* Insert */
  568. case 'database-table-initialization-insert-select-table':
  569. $this->init['data']['table'] = $data;
  570. break;
  571. /* Insert and Update */
  572. case 'database-table-initialization-insert-field-name':
  573. case 'database-table-initialization-insert-select-field-name':
  574. case 'database-table-initialization-update-field-name':
  575. $this->init_field['name'] .= $data;
  576. break;
  577. case 'database-table-initialization-insert-field-value':
  578. case 'database-table-initialization-insert-select-field-value':
  579. case 'database-table-initialization-update-field-value':
  580. $this->init_field['group']['data'] .= $data;
  581. break;
  582. case 'database-table-initialization-insert-field-function-name':
  583. case 'database-table-initialization-insert-select-field-function-name':
  584. case 'database-table-initialization-update-field-function-name':
  585. $this->init_function['name'] .= $data;
  586. break;
  587. case 'database-table-initialization-insert-field-function-value':
  588. case 'database-table-initialization-insert-select-field-function-value':
  589. case 'database-table-initialization-update-field-function-value':
  590. $this->init_function['arguments'][] = array('type' => 'value', 'data' => $data);
  591. break;
  592. case 'database-table-initialization-insert-field-function-column':
  593. case 'database-table-initialization-insert-select-field-function-column':
  594. case 'database-table-initialization-update-field-function-column':
  595. $this->init_function['arguments'][] = array('type' => 'column', 'data' => $data);
  596. break;
  597. case 'database-table-initialization-insert-field-column':
  598. case 'database-table-initialization-insert-select-field-column':
  599. case 'database-table-initialization-update-field-column':
  600. $this->init_field['group'] = array('type' => 'column', 'data' => $data);
  601. break;
  602. /* All */
  603. case 'database-table-initialization-insert-field-expression-operator':
  604. case 'database-table-initialization-insert-select-field-expression-operator':
  605. case 'database-table-initialization-insert-select-where-expression-operator':
  606. case 'database-table-initialization-update-field-expression-operator':
  607. case 'database-table-initialization-update-where-expression-operator':
  608. case 'database-table-initialization-delete-where-expression-operator':
  609. $this->init_expression['operator'] = $data;
  610. break;
  611. case 'database-table-initialization-insert-field-expression-value':
  612. case 'database-table-initialization-insert-select-field-expression-value':
  613. case 'database-table-initialization-insert-select-where-expression-value':
  614. case 'database-table-initialization-update-field-expression-value':
  615. case 'database-table-initialization-update-where-expression-value':
  616. case 'database-table-initialization-delete-where-expression-value':
  617. $this->init_expression['operants'][] = array('type' => 'value', 'data' => $data);
  618. break;
  619. case 'database-table-initialization-insert-field-expression-column':
  620. case 'database-table-initialization-insert-select-field-expression-column':
  621. case 'database-table-initialization-insert-select-where-expression-column':
  622. case 'database-table-initialization-update-field-expression-column':
  623. case 'database-table-initialization-update-where-expression-column':
  624. case 'database-table-initialization-delete-where-expression-column':
  625. $this->init_expression['operants'][] = array('type' => 'column', 'data' => $data);
  626. break;
  627. case 'database-table-initialization-insert-field-function-function':
  628. case 'database-table-initialization-insert-field-function-expression':
  629. case 'database-table-initialization-insert-field-expression-expression':
  630. case 'database-table-initialization-update-field-function-function':
  631. case 'database-table-initialization-update-field-function-expression':
  632. case 'database-table-initialization-update-field-expression-expression':
  633. case 'database-table-initialization-update-where-expression-expression':
  634. case 'database-table-initialization-delete-where-expression-expression':
  635. /* Recursion to be implemented yet */
  636. break;
  637. /* One level simulation of expression-function recursion */
  638. case 'database-table-initialization-insert-field-expression-function-name':
  639. case 'database-table-initialization-insert-select-field-expression-function-name':
  640. case 'database-table-initialization-insert-select-where-expression-function-name':
  641. case 'database-table-initialization-update-field-expression-function-name':
  642. case 'database-table-initialization-update-where-expression-function-name':
  643. case 'database-table-initialization-delete-where-expression-function-name':
  644. $this->init_function['name'] .= $data;
  645. break;
  646. case 'database-table-initialization-insert-field-expression-function-value':
  647. case 'database-table-initialization-insert-select-field-expression-function-value':
  648. case 'database-table-initialization-insert-select-where-expression-function-value':
  649. case 'database-table-initialization-update-field-expression-function-value':
  650. case 'database-table-initialization-update-where-expression-function-value':
  651. case 'database-table-initialization-delete-where-expression-function-value':
  652. $this->init_function['arguments'][] = array('type' => 'value', 'data' => $data);
  653. break;
  654. case 'database-table-initialization-insert-field-expression-function-column':
  655. case 'database-table-initialization-insert-select-field-expression-function-column':
  656. case 'database-table-initialization-insert-select-where-expression-function-column':
  657. case 'database-table-initialization-update-field-expression-function-column':
  658. case 'database-table-initialization-update-where-expression-function-column':
  659. case 'database-table-initialization-delete-where-expression-function-column':
  660. $this->init_function['arguments'][] = array('type' => 'column', 'data' => $data);
  661. break;
  662. /* One level simulation of function-expression recursion */
  663. case 'database-table-initialization-insert-field-function-expression-operator':
  664. case 'database-table-initialization-insert-select-field-function-expression-operator':
  665. case 'database-table-initialization-update-field-function-expression-operator':
  666. $this->init_expression['operator'] = $data;
  667. break;
  668. case 'database-table-initialization-insert-field-function-expression-value':
  669. case 'database-table-initialization-insert-select-field-function-expression-value':
  670. case 'database-table-initialization-update-field-function-expression-value':
  671. $this->init_expression['operants'][] = array('type' => 'value', 'data' => $data);
  672. break;
  673. case 'database-table-initialization-insert-field-function-expression-column':
  674. case 'database-table-initialization-insert-select-field-function-expression-column':
  675. case 'database-table-initialization-update-field-function-expression-column':
  676. $this->init_expression['operants'][] = array('type' => 'column', 'data' => $data);
  677. break;
  678. /* Database */
  679. case 'database-name':
  680. $this->database_definition['name'] .= $data;
  681. break;
  682. case 'database-create':
  683. $this->database_definition['create'] .= $data;
  684. break;
  685. case 'database-overwrite':
  686. $this->database_definition['overwrite'] .= $data;
  687. break;
  688. case 'database-charset':
  689. $this->database_definition['charset'] .= $data;
  690. break;
  691. case 'database-description':
  692. $this->database_definition['description'] .= $data;
  693. break;
  694. case 'database-comments':
  695. $this->database_definition['comments'] .= $data;
  696. break;
  697. /* Table declaration */
  698. case 'database-table-name':
  699. $this->table_name .= $data;
  700. break;
  701. case 'database-table-was':
  702. $this->table['was'] .= $data;
  703. break;
  704. case 'database-table-description':
  705. $this->table['description'] .= $data;
  706. break;
  707. case 'database-table-comments':
  708. $this->table['comments'] .= $data;
  709. break;
  710. /* Field declaration */
  711. case 'database-table-declaration-field-name':
  712. $this->field_name .= $data;
  713. break;
  714. case 'database-table-declaration-field-was':
  715. $this->field['was'] .= $data;
  716. break;
  717. case 'database-table-declaration-field-type':
  718. $this->field['type'] .= $data;
  719. break;
  720. case 'database-table-declaration-field-fixed':
  721. $this->field['fixed'] .= $data;
  722. break;
  723. case 'database-table-declaration-field-default':
  724. $this->field['default'] .= $data;
  725. break;
  726. case 'database-table-declaration-field-notnull':
  727. $this->field['notnull'] .= $data;
  728. break;
  729. case 'database-table-declaration-field-autoincrement':
  730. $this->field['autoincrement'] .= $data;
  731. break;
  732. case 'database-table-declaration-field-unsigned':
  733. $this->field['unsigned'] .= $data;
  734. break;
  735. case 'database-table-declaration-field-length':
  736. $this->field['length'] .= $data;
  737. break;
  738. case 'database-table-declaration-field-description':
  739. $this->field['description'] .= $data;
  740. break;
  741. case 'database-table-declaration-field-comments':
  742. $this->field['comments'] .= $data;
  743. break;
  744. /* Index declaration */
  745. case 'database-table-declaration-index-name':
  746. $this->index_name .= $data;
  747. break;
  748. case 'database-table-declaration-index-was':
  749. $this->index['was'] .= $data;
  750. break;
  751. case 'database-table-declaration-index-unique':
  752. $this->index['unique'] .= $data;
  753. break;
  754. case 'database-table-declaration-index-primary':
  755. $this->index['primary'] .= $data;
  756. break;
  757. case 'database-table-declaration-index-field-name':
  758. $this->field_name .= $data;
  759. break;
  760. case 'database-table-declaration-index-field-sorting':
  761. $this->field['sorting'] .= $data;
  762. break;
  763. /* Add by Leoncx */
  764. case 'database-table-declaration-index-field-length':
  765. $this->field['length'] .= $data;
  766. break;
  767. /* Foreign Key declaration */
  768. case 'database-table-declaration-foreign-name':
  769. $this->constraint_name .= $data;
  770. break;
  771. case 'database-table-declaration-foreign-was':
  772. $this->constraint['was'] .= $data;
  773. break;
  774. case 'database-table-declaration-foreign-match':
  775. $this->constraint['match'] .= $data;
  776. break;
  777. case 'database-table-declaration-foreign-ondelete':
  778. $this->constraint['ondelete'] .= $data;
  779. break;
  780. case 'database-table-declaration-foreign-onupdate':
  781. $this->constraint['onupdate'] .= $data;
  782. break;
  783. case 'database-table-declaration-foreign-deferrable':
  784. $this->constraint['deferrable'] .= $data;
  785. break;
  786. case 'database-table-declaration-foreign-initiallydeferred':
  787. $this->constraint['initiallydeferred'] .= $data;
  788. break;
  789. case 'database-table-declaration-foreign-field':
  790. $this->field_name .= $data;
  791. break;
  792. case 'database-table-declaration-foreign-references-table':
  793. $this->constraint['references']['table'] .= $data;
  794. break;
  795. case 'database-table-declaration-foreign-references-field':
  796. $this->field_name .= $data;
  797. break;
  798. /* Sequence declaration */
  799. case 'database-sequence-name':
  800. $this->sequence_name .= $data;
  801. break;
  802. case 'database-sequence-was':
  803. $this->sequence['was'] .= $data;
  804. break;
  805. case 'database-sequence-start':
  806. $this->sequence['start'] .= $data;
  807. break;
  808. case 'database-sequence-description':
  809. $this->sequence['description'] .= $data;
  810. break;
  811. case 'database-sequence-comments':
  812. $this->sequence['comments'] .= $data;
  813. break;
  814. case 'database-sequence-on':
  815. $this->sequence['on'] = array('table' => '', 'field' => '');
  816. break;
  817. case 'database-sequence-on-table':
  818. $this->sequence['on']['table'] .= $data;
  819. break;
  820. case 'database-sequence-on-field':
  821. $this->sequence['on']['field'] .= $data;
  822. break;
  823. }
  824. }
  825. }