MDB2_Schema
[ class tree: MDB2_Schema ] [ index: MDB2_Schema ] [ all elements ]

Source for file Parser.php

Documentation is available at Parser.php

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

Documentation generated on Mon, 11 Mar 2019 14:39:18 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.