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.34 2006/06/30 10:11:02 lsmith Exp $
  46. //
  47.  
  48. require_once 'XML/Parser.php';
  49.  
  50. if (empty($GLOBALS['_MDB2_Schema_Reserved'])) {
  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.     var $force_defaults = true;
  86.  
  87.     function __construct($variables$fail_on_invalid_names = true$structure = false$valid_types = array()$force_defaults = true)
  88.     {
  89.         // force ISO-8859-1 due to different defaults for PHP4 and PHP5
  90.         // todo: this probably needs to be investigated some more andcleaned up
  91.         parent::XML_Parser('ISO-8859-1');
  92.         $this->variables = $variables;
  93.         if (is_array($fail_on_invalid_names)) {
  94.             $this->fail_on_invalid_names
  95.                 = array_intersect($fail_on_invalid_namesarray_keys($GLOBALS['_MDB2_Schema_Reserved']));
  96.         elseif ($this->fail_on_invalid_names === true{
  97.             $this->fail_on_invalid_names = array_keys($GLOBALS['_MDB2_Schema_Reserved']);
  98.         else {
  99.             $this->fail_on_invalid_names = false;
  100.         }
  101.         $this->structure = $structure;
  102.         $this->valid_types = $valid_types;
  103.         $this->force_defaults = $force_defaults;
  104.     }
  105.  
  106.     function MDB2_Schema_Parser($variables$fail_on_invalid_names = true$structure = false$valid_types = array()$force_defaults = true)
  107.     {
  108.         $this->__construct($variables$fail_on_invalid_names$structure$valid_types$force_defaults);
  109.     }
  110.  
  111.     function startHandler($xp$element$attribs)
  112.     {
  113.         if (strtolower($element== 'variable'{
  114.             $this->var_mode = true;
  115.             return;
  116.         }
  117.  
  118.         $this->elements[$this->count++strtolower($element);
  119.         $this->element = implode('-'$this->elements);
  120.  
  121.         switch ($this->element{
  122.         case 'database-table-initialization-insert':
  123.             $this->init = array('type' => 'insert');
  124.             break;
  125.         case 'database-table-initialization-insert-field':
  126.             $this->init_name = '';
  127.             $this->init_value = '';
  128.             break;
  129.         case 'database-table':
  130.             $this->table_name = '';
  131.             $this->table = array();
  132.             break;
  133.         case 'database-table-declaration-field':
  134.             $this->field_name = '';
  135.             $this->field = array();
  136.             break;
  137.         case 'database-table-declaration-field-default':
  138.             $this->field['default''';
  139.             break;
  140.         case 'database-table-declaration-index':
  141.             $this->index_name = '';
  142.             $this->index = array();
  143.             break;
  144.         case 'database-sequence':
  145.             $this->seq_name = '';
  146.             $this->seq = array();
  147.             break;
  148.         case 'database-table-declaration-index-field':
  149.             $this->field_name = '';
  150.             $this->field = array();
  151.             break;
  152.         }
  153.     }
  154.  
  155.     function endHandler($xp$element)
  156.     {
  157.         if (strtolower($element== 'variable'{
  158.             $this->var_mode = false;
  159.             return;
  160.         }
  161.  
  162.         switch ($this->element{
  163.         /* Initialization */
  164.         case 'database-table-initialization-insert-field':
  165.             if (!$this->init_name{
  166.                 $this->raiseError('field-name has to be specified'null$xp);
  167.             }
  168.             if (isset($this->init['fields'][$this->init_name])) {
  169.                 $this->raiseError('field "'.$this->init_name.'" already filled'null$xp);
  170.             }
  171.             if (!isset($this->table['fields'][$this->init_name])) {
  172.                 $this->raiseError('unknown field "'.$this->init_name.'"'null$xp);
  173.             }
  174.             if ($this->init_value !== ''
  175.                 && !$this->validateFieldValue($this->init_name$this->init_value$xp)
  176.             {
  177.                 $this->raiseError('field "'.$this->init_name.'" has wrong value'null$xp);
  178.             }
  179.             $this->init['fields'][$this->init_name$this->init_value;
  180.             break;
  181.         case 'database-table-initialization-insert':
  182.             $this->table['initialization'][$this->init;
  183.             break;
  184.  
  185.         /* Table definition */
  186.         case 'database-table':
  187.             if (!$this->table_name{
  188.                 $this->raiseError('a table has to have a name'null$xp);
  189.             elseif ($this->fail_on_invalid_names{
  190.                 $name strtoupper($this->table_name);
  191.                 foreach ($this->fail_on_invalid_names as $rdbms{
  192.                     if (in_array($name$GLOBALS['_MDB2_Schema_Reserved'][$rdbms])) {
  193.                         $this->raiseError('table name "'.$this->table_name.'" is a reserved word in: '.$rdbmsnull$xp);
  194.                         break;
  195.                     }
  196.                 }
  197.             }
  198.  
  199.             if (isset($this->database_definition['tables'][$this->table_name])) {
  200.                 $this->raiseError('table "'.$this->table_name.'" already exists'null$xp);
  201.             }
  202.  
  203.             if (empty($this->table['was'])) {
  204.                 $this->table['was'$this->table_name;
  205.             }
  206.  
  207.             $autoinc $primary = false;
  208.             if (empty($this->table['fields']|| !is_array($this->table['fields'])) {
  209.                 $this->raiseError('tables need one or more fields'null$xp);
  210.             else {
  211.                 foreach ($this->table['fields'as $field_name => $field{
  212.                     if (!empty($field['autoincrement'])) {
  213.                         if ($primary{
  214.                             $this->raiseError('there was already an autoincrement field in "'.$this->table_name.'" before "'.$field_name.'"'null$xp);
  215.                         else {
  216.                             $autoinc $primary = true;
  217.                         }
  218.  
  219.                         if (!$this->table['fields'][$field_name]['notnull']{
  220.                             $this->raiseError('all autoincrement fields must be defined notnull in "'.$this->table_name.'"'null$xp);
  221.                         }
  222.  
  223.                         if (empty($field['default'])) {
  224.                             $this->table['fields'][$field_name]['default''0';
  225.                         elseif ($field['default'!== '0' && $field['default'!== 0{
  226.                             $this->raiseError('all autoincrement fields must be defined default "0" in "'.$this->table_name.'"'null$xp);
  227.                         }
  228.                     }
  229.                 }
  230.             }
  231.             if (!empty($this->table['indexes']&& is_array($this->table['indexes'])) {
  232.                 foreach ($this->table['indexes'as $name => $index{
  233.                     $skip_index = false;
  234.                     if (!empty($index['primary'])) {
  235.                         /*
  236.                          * Lets see if we should skip this index since there is
  237.                          * already a auto increment on this field this implying
  238.                          * a primary key index.
  239.                          */
  240.                         if ($autoinc && count($index['fields']== '1'{
  241.                             $skip_index = true;
  242.                         elseif ($primary{
  243.                             $this->raiseError('there was already an primary index or autoincrement field in "'.$this->table_name.'" before "'.$name.'"'null$xp);
  244.                         else {
  245.                             $primary = true;
  246.                         }
  247.                     }
  248.  
  249.                     if (!$skip_index && is_array($index['fields'])) {
  250.                         foreach ($index['fields'as $field_name => $field{
  251.                             if (!isset($this->table['fields'][$field_name])) {
  252.                                 $this->raiseError('index field "'.$field_name.'" does not exist'null$xp);
  253.                             elseif (!empty($index['primary'])
  254.                                 && !$this->table['fields'][$field_name]['notnull']
  255.                             {
  256.                                 $this->raiseError('all primary key fields must be defined notnull in "'.$this->table_name.'"'null$xp);
  257.                             }
  258.                         }
  259.                     else {
  260.                         unset($this->table['indexes'][$name]);
  261.                     }
  262.                 }
  263.             }
  264.             $this->database_definition['tables'][$this->table_name$this->table;
  265.             break;
  266.  
  267.         /* Field declaration */
  268.         case 'database-table-declaration-field':
  269.             if (!$this->field_name{
  270.                 $this->raiseError('field name missing'null$xp);
  271.             elseif (isset($this->table['fields'][$this->field_name])) {
  272.                 $this->raiseError('field "'.$this->field_name.'" already exists'null$xp);
  273.             }
  274.  
  275.             if ($this->fail_on_invalid_names{
  276.                 $name strtoupper($this->field_name);
  277.                 foreach ($this->fail_on_invalid_names as $rdbms{
  278.                     if (in_array($name$GLOBALS['_MDB2_Schema_Reserved'][$rdbms])) {
  279.                         $this->raiseError('field name "'.$this->field_name.'" is a reserved word in: '.$rdbmsnull$xp);
  280.                         break;
  281.                     }
  282.                 }
  283.             }
  284.             /* Type check */
  285.             if (empty($this->field['type'])) {
  286.                 $this->raiseError('no field type specified'null$xp);
  287.             }
  288.             if (!empty($this->valid_types&& !array_key_exists($this->field['type']$this->valid_types)) {
  289.                 $this->raiseError('no valid field type ("'.$this->field['type'].'") specified'null$xp);
  290.             }
  291.             if (array_key_exists('unsigned'$this->field&& !$this->isBoolean($this->field['unsigned'])) {
  292.                 $this->raiseError('unsigned has to be a boolean value'null$xp);
  293.             }
  294.             if (array_key_exists('fixed'$this->field&& !$this->isBoolean($this->field['fixed'])) {
  295.                 $this->raiseError('fixed has to be a boolean value'null$xp);
  296.             }
  297.             if (array_key_exists('length'$this->field&& $this->field['length'<= 0{
  298.                 $this->raiseError('length has to be an integer greater 0'null$xp);
  299.             }
  300.             if (empty($this->field['was'])) {
  301.                 $this->field['was'$this->field_name;
  302.             }
  303.             if (empty($this->field['notnull'])) {
  304.                 $this->field['notnull'= false;
  305.             }
  306.             if (!$this->isBoolean($this->field['notnull'])) {
  307.                 $this->raiseError('field "notnull" has to be a boolean value'null$xp);
  308.             }
  309.             if ($this->force_defaults
  310.                 && !array_key_exists('default'$this->field)
  311.                 && $this->field['type'!= 'clob' && $this->field['type'!= 'blob'
  312.             {
  313.                 $this->field['default'$this->valid_types[$this->field['type']];
  314.             }
  315.  
  316.             if (array_key_exists('default'$this->field)) {
  317.                 if ($this->field['type'== 'clob' || $this->field['type'== 'blob'{
  318.                     $this->raiseError('"'.$this->field['type'].
  319.                         '"-fields are not allowed to have a default value'null$xp);
  320.                 }
  321.                 if ($this->field['default'=== ''{
  322.                     if (!$this->field['notnull']{
  323.                         $this->field['default'= null;
  324.                     }
  325.                 }
  326.             }
  327.  
  328.             $this->table['fields'][$this->field_name$this->field;
  329.  
  330.             if (isset($this->field['default'])
  331.                 && !$this->validateFieldValue($this->field_name,
  332.                     $this->table['fields'][$this->field_name]['default']$xp
  333.                 )
  334.             {
  335.                 $this->raiseError('default value of "'.$this->field_name.'" is of wrong type'null$xp);
  336.             }
  337.             break;
  338.  
  339.         /* Index declaration */
  340.         case 'database-table-declaration-index':
  341.             if (!$this->index_name{
  342.                 $this->raiseError('an index has to have a name'null$xp);
  343.             }
  344.             if (isset($this->table['indexes'][$this->index_name])) {
  345.                 $this->raiseError('index "'.$this->index_name.'" already exists'null$xp);
  346.             }
  347.             if (array_key_exists('unique'$this->index&& !$this->isBoolean($this->index['unique'])) {
  348.                 $this->raiseError('field "unique" has to be a boolean value'null$xp);
  349.             }
  350.             if (array_key_exists('primary'$this->index&& !$this->isBoolean($this->index['primary'])) {
  351.                 $this->raiseError('field "primary" has to be a boolean value'null$xp);
  352.             }
  353.  
  354.             if (empty($this->index['was'])) {
  355.                 $this->index['was'$this->index_name;
  356.             }
  357.             $this->table['indexes'][$this->index_name$this->index;
  358.             break;
  359.         case 'database-table-declaration-index-field':
  360.             if (!$this->field_name{
  361.                 $this->raiseError('the index-field-name is required'null$xp);
  362.             }
  363.             if (!empty($this->field['sorting'])
  364.                 && $this->field['sorting'!== 'ascending' && $this->field['sorting'!== 'descending'{
  365.                 $this->raiseError('sorting type unknown'null$xp);
  366.             else {
  367.                 $this->field['sorting''ascending';
  368.             }
  369.             $this->index['fields'][$this->field_name$this->field;
  370.             break;
  371.         case 'database-table-name':
  372.             if (isset($this->structure['tables'][$this->table_name])) {
  373.                 $this->table = $this->structure['tables'][$this->table_name];
  374.             }
  375.             break;
  376.  
  377.         /* Sequence declaration */
  378.         case 'database-sequence':
  379.             if (!$this->seq_name{
  380.                 $this->raiseError('a sequence has to have a name'null$xp);
  381.             elseif ($this->fail_on_invalid_names{
  382.                 $name strtoupper($this->seq_name);
  383.                 foreach ($this->fail_on_invalid_names as $rdbms{
  384.                     if (in_array($name$GLOBALS['_MDB2_Schema_Reserved'][$rdbms])) {
  385.                         $this->raiseError('sequence name "'.$this->seq_name.'" is a reserved word in: '.$rdbmsnull$xp);
  386.                         break;
  387.                     }
  388.                 }
  389.             }
  390.  
  391.             if (isset($this->database_definition['sequences'][$this->seq_name])) {
  392.                 $this->raiseError('sequence "'.$this->seq_name.'" already exists'null$xp);
  393.             }
  394.  
  395.             if (empty($this->seq['was'])) {
  396.                 $this->seq['was'$this->seq_name;
  397.             }
  398.  
  399.             if (!empty($this->seq['on'])) {
  400.                 if (empty($this->seq['on']['table']|| empty($this->seq['on']['field'])) {
  401.                     $this->raiseError('sequence "'.$this->seq_name.
  402.                         '" was not properly defined'null$xp);
  403.                 }
  404.             }
  405.             $this->database_definition['sequences'][$this->seq_name$this->seq;
  406.             break;
  407.  
  408.         /* End of File */
  409.         case 'database':
  410.             if (!isset($this->database_definition['name']|| !$this->database_definition['name']{
  411.                 $this->raiseError('a database has to have a name'null$xp);
  412.             elseif ($this->fail_on_invalid_names{
  413.                 $name strtoupper($this->database_definition['name']);
  414.                 foreach ($this->fail_on_invalid_names as $rdbms{
  415.                     if (in_array($name$GLOBALS['_MDB2_Schema_Reserved'][$rdbms])) {
  416.                         $this->raiseError('database name "'.$this->database_definition['name'].'" is a reserved word in: '.$rdbmsnull$xp);
  417.                         break;
  418.                     }
  419.                 }
  420.             }
  421.  
  422.             if (isset($this->database_definition['create'])
  423.                 && !$this->isBoolean($this->database_definition['create'])
  424.             {
  425.                 $this->raiseError('field "create" has to be a boolean value'null$xp);
  426.             }
  427.             if (isset($this->database_definition['overwrite'])
  428.                 && !$this->isBoolean($this->database_definition['overwrite'])
  429.             {
  430.                 $this->raiseError('field "overwrite" has to be a boolean value'null$xp);
  431.             }
  432.  
  433.             if (isset($this->database_definition['sequences'])) {
  434.                 foreach ($this->database_definition['sequences'as $seq_name => $seq{
  435.                     if (!empty($seq['on'])
  436.                         && empty($this->database_definition['tables'][$seq['on']['table']]['fields'][$seq['on']['field']])
  437.                     {
  438.                         $this->raiseError('sequence "'.$seq_name.
  439.                             '" was assigned on unexisting field/table'null$xp);
  440.                     }
  441.                 }
  442.             }
  443.             if (PEAR::isError($this->error)) {
  444.                 $this->database_definition = $this->error;
  445.             }
  446.             break;
  447.         }
  448.  
  449.         unset($this->elements[--$this->count]);
  450.         $this->element = implode('-'$this->elements);
  451.     }
  452.  
  453.     function validateFieldValue($field_name&$field_value&$xp)
  454.     {
  455.         if (!isset($this->table['fields'][$field_name])) {
  456.             return $this->raiseError('"'.$field_name.'" is not defined'null$xp);
  457.         }
  458.         $field_def $this->table['fields'][$field_name];
  459.         switch ($field_def['type']{
  460.         case 'text':
  461.         case 'clob':
  462.             if (!empty($field_def['length']&& strlen($field_value$field_def['length']{
  463.                 return $this->raiseError('"'.$field_value.'" is larger than "'.
  464.                     $field_def['length'].'"'null$xp);
  465.             }
  466.             break;
  467.         case 'blob':
  468.             /*
  469.             if (!preg_match('/^([0-9a-f]{2})*$/i', $field_value)) {
  470.                 return $this->raiseError('"'.$field_value.'" is not of type "'.
  471.                     $field_def['type'].'"', null, $xp);
  472.             }
  473.             */
  474.             $field_value pack('H*'$field_value);
  475.             if (!empty($field_def['length']&& strlen($field_value$field_def['length']{
  476.                 return $this->raiseError('"'.$field_value.'" is larger than "'.
  477.                     $field_def['type'].'"'null$xp);
  478.             }
  479.             break;
  480.         case 'integer':
  481.             if ($field_value != ((int)$field_value)) {
  482.                 return $this->raiseError('"'.$field_value.'" is not of type "'.
  483.                     $field_def['type'].'"'null$xp);
  484.             }
  485.             $field_value = (int) $field_value;
  486.             if (!empty($field_def['unsigned']&& $field_def['unsigned'&& $field_value < 0{
  487.                 return $this->raiseError('"'.$field_value.'" signed instead of unsigned'null$xp);
  488.             }
  489.             break;
  490.         case 'boolean':
  491.             if (!$this->isBoolean($field_value)) {
  492.                 return $this->raiseError('"'.$field_value.'" is not of type "'.
  493.                     $field_def['type'].'"'null$xp);
  494.             }
  495.             break;
  496.         case 'date':
  497.             if (!preg_match('/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/'$field_value)
  498.                 && $field_value !== 'CURRENT_DATE'
  499.             {
  500.                 return $this->raiseError('"'.$field_value.'" is not of type "'.
  501.                     $field_def['type'].'"'null$xp);
  502.             }
  503.             break;
  504.         case 'timestamp':
  505.             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)
  506.                 && $field_value !== 'CURRENT_TIMESTAMP'
  507.             {
  508.                 return $this->raiseError('"'.$field_value.'" is not of type "'.
  509.                     $field_def['type'].'"'null$xp);
  510.             }
  511.             break;
  512.         case 'time':
  513.             if (!preg_match("/([0-9]{2}):([0-9]{2}):([0-9]{2})/"$field_value)
  514.                 && $field_value !== 'CURRENT_TIME'
  515.             {
  516.                 return $this->raiseError('"'.$field_value.'" is not of type "'.
  517.                     $field_def['type'].'"'null$xp);
  518.             }
  519.             break;
  520.         case 'float':
  521.         case 'double':
  522.             if ($field_value != (double)$field_value{
  523.                 return $this->raiseError('"'.$field_value.'" is not of type "'.
  524.                     $field_def['type'].'"'null$xp);
  525.             }
  526.             $field_value = (double) $field_value;
  527.             break;
  528.         }
  529.         return true;
  530.     }
  531.  
  532.     function &raiseError($msg = null$ecode = 0$xp = null)
  533.     {
  534.         if (is_null($this->error)) {
  535.             $error '';
  536.             if (is_resource($msg)) {
  537.                 $error .= 'Parser error: '.xml_error_string(xml_get_error_code($msg));
  538.                 $xp $msg;
  539.             else {
  540.                 $error .= 'Parser error: '.$msg;
  541.                 if (!is_resource($xp)) {
  542.                     $xp $this->parser;
  543.                 }
  544.             }
  545.             if ($error_string xml_error_string($ecode)) {
  546.                 $error .= ' - '.$error_string;
  547.             }
  548.             if (is_resource($xp)) {
  549.                 $byte @xml_get_current_byte_index($xp);
  550.                 $line @xml_get_current_line_number($xp);
  551.                 $column @xml_get_current_column_number($xp);
  552.                 $error .= " - Byte: $byte; Line: $line; Col: $column";
  553.             }
  554.             $error .= "\n";
  555.             $this->error =MDB2::raiseError(MDB2_SCHEMA_ERROR_PARSEnullnull$error);
  556.         }
  557.         return $this->error;
  558.     }
  559.  
  560.     function isBoolean(&$value)
  561.     {
  562.         if (is_bool($value)) {
  563.             return true;
  564.         }
  565.         if ($value === 0 || $value === 1{
  566.             $value = (bool)$value;
  567.             return true;
  568.         }
  569.         if (!is_string($value)) {
  570.             return false;
  571.         }
  572.         switch ($value{
  573.         case '0':
  574.         case 'N':
  575.         case 'n':
  576.         case 'no':
  577.         case 'false':
  578.             $value = false;
  579.             break;
  580.         case '1':
  581.         case 'Y':
  582.         case 'y':
  583.         case 'yes':
  584.         case 'true':
  585.             $value = true;
  586.             break;
  587.         default:
  588.             return false;
  589.         }
  590.         return true;
  591.     }
  592.  
  593.     function cdataHandler($xp$data)
  594.     {
  595.         if ($this->var_mode == true{
  596.             if (!isset($this->variables[$data])) {
  597.                 $this->raiseError('variable "'.$data.'" not found'null$xp);
  598.                 return;
  599.             }
  600.             $data $this->variables[$data];
  601.         }
  602.  
  603.         switch ($this->element{
  604.         /* Initialization */
  605.         case 'database-table-initialization-insert-field-name':
  606.             if (isset($this->init_name)) {
  607.                 $this->init_name .= $data;
  608.             else {
  609.                 $this->init_name = $data;
  610.             }
  611.             break;
  612.         case 'database-table-initialization-insert-field-value':
  613.             if (isset($this->init_value)) {
  614.                 $this->init_value .= $data;
  615.             else {
  616.                 $this->init_value = $data;
  617.             }
  618.             break;
  619.  
  620.         /* Database */
  621.         case 'database-name':
  622.             if (isset($this->database_definition['name'])) {
  623.                 $this->database_definition['name'.= $data;
  624.             else {
  625.                 $this->database_definition['name'$data;
  626.             }
  627.             break;
  628.         case 'database-create':
  629.             if (isset($this->database_definition['create'])) {
  630.                 $this->database_definition['create'.= $data;
  631.             else {
  632.                 $this->database_definition['create'$data;
  633.             }
  634.             break;
  635.         case 'database-overwrite':
  636.             if (isset($this->database_definition['overwrite'])) {
  637.                 $this->database_definition['overwrite'.= $data;
  638.             else {
  639.                 $this->database_definition['overwrite'$data;
  640.             }
  641.             break;
  642.         case 'database-table-name':
  643.             if (isset($this->table_name)) {
  644.                 $this->table_name .= $data;
  645.             else {
  646.                 $this->table_name = $data;
  647.             }
  648.             break;
  649.         case 'database-table-was':
  650.             if (array_key_exists($this->table['was'])) {
  651.                 $this->table['was'.= $data;
  652.             else {
  653.                 $this->table['was'$data;
  654.             }
  655.             break;
  656.  
  657.         /* Field declaration */
  658.         case 'database-table-declaration-field-name':
  659.             if (isset($this->field_name)) {
  660.                 $this->field_name .= $data;
  661.             else {
  662.                 $this->field_name = $data;
  663.             }
  664.             break;
  665.         case 'database-table-declaration-field-type':
  666.             if (isset($this->field['type'])) {
  667.                 $this->field['type'.= $data;
  668.             else {
  669.                 $this->field['type'$data;
  670.             }
  671.             break;
  672.         case 'database-table-declaration-field-was':
  673.             if (isset($this->field['was'])) {
  674.                 $this->field['was'.= $data;
  675.             else {
  676.                 $this->field['was'$data;
  677.             }
  678.             break;
  679.         case 'database-table-declaration-field-notnull':
  680.             if (isset($this->field['notnull'])) {
  681.                 $this->field['notnull'.= $data;
  682.             else {
  683.                 $this->field['notnull'$data;
  684.             }
  685.             break;
  686.         case 'database-table-declaration-field-fixed':
  687.             if (isset($this->field['fixed'])) {
  688.                 $this->field['fixed'.= $data;
  689.             else {
  690.                 $this->field['fixed'$data;
  691.             }
  692.             break;
  693.         case 'database-table-declaration-field-unsigned':
  694.             if (isset($this->field['unsigned'])) {
  695.                 $this->field['unsigned'.= $data;
  696.             else {
  697.                 $this->field['unsigned'$data;
  698.             }
  699.             break;
  700.         case 'database-table-declaration-field-autoincrement':
  701.             if (isset($this->field['autoincrement'])) {
  702.                 $this->field['autoincrement'.= $data;
  703.             else {
  704.                 $this->field['autoincrement'$data;
  705.             }
  706.             break;
  707.         case 'database-table-declaration-field-default':
  708.             if (isset($this->field['default'])) {
  709.                 $this->field['default'.= $data;
  710.             else {
  711.                 $this->field['default'$data;
  712.             }
  713.             break;
  714.         case 'database-table-declaration-field-length':
  715.             if (isset($this->field['length'])) {
  716.                 $this->field['length'.= $data;
  717.             else {
  718.                 $this->field['length'$data;
  719.             }
  720.             break;
  721.  
  722.         /* Index declaration */
  723.         case 'database-table-declaration-index-name':
  724.             if (isset($this->index_name)) {
  725.                 $this->index_name .= $data;
  726.             else {
  727.                 $this->index_name = $data;
  728.             }
  729.             break;
  730.         case 'database-table-declaration-index-primary':
  731.             if (isset($this->index['primary'])) {
  732.                 $this->index['primary'.= $data;
  733.             else {
  734.                 $this->index['primary'$data;
  735.             }
  736.             break;
  737.         case 'database-table-declaration-index-unique':
  738.             if (isset($this->index['unique'])) {
  739.                 $this->index['unique'.= $data;
  740.             else {
  741.                 $this->index['unique'$data;
  742.             }
  743.             break;
  744.         case 'database-table-declaration-index-was':
  745.             if (isset($this->index['was'])) {
  746.                 $this->index['was'.= $data;
  747.             else {
  748.                 $this->index['was'$data;
  749.             }
  750.             break;
  751.         case 'database-table-declaration-index-field-name':
  752.             if (isset($this->field_name)) {
  753.                 $this->field_name .= $data;
  754.             else {
  755.                 $this->field_name = $data;
  756.             }
  757.             break;
  758.         case 'database-table-declaration-index-field-sorting':
  759.             if (isset($this->field['sorting'])) {
  760.                 $this->field['sorting'.= $data;
  761.             else {
  762.                 $this->field['sorting'$data;
  763.             }
  764.             break;
  765.         /* Add by Leoncx */
  766.         case 'database-table-declaration-index-field-length':
  767.             if (isset($this->field['length'])) {
  768.                 $this->field['length'.= $data;
  769.             else {
  770.                 $this->field['length'$data;
  771.             }
  772.             break;
  773.  
  774.         /* Sequence declaration */
  775.         case 'database-sequence-name':
  776.             if (isset($this->seq_name)) {
  777.                 $this->seq_name .= $data;
  778.             else {
  779.                 $this->seq_name = $data;
  780.             }
  781.             break;
  782.         case 'database-sequence-was':
  783.             if (isset($this->seq['was'])) {
  784.                 $this->seq['was'.= $data;
  785.             else {
  786.                 $this->seq['was'$data;
  787.             }
  788.             break;
  789.         case 'database-sequence-start':
  790.             if (isset($this->seq['start'])) {
  791.                 $this->seq['start'.= $data;
  792.             else {
  793.                 $this->seq['start'$data;
  794.             }
  795.             break;
  796.         case 'database-sequence-on-table':
  797.             if (isset($this->seq['on']['table'])) {
  798.                 $this->seq['on']['table'.= $data;
  799.             else {
  800.                 $this->seq['on']['table'$data;
  801.             }
  802.             break;
  803.         case 'database-sequence-on-field':
  804.             if (isset($this->seq['on']['field'])) {
  805.                 $this->seq['on']['field'.= $data;
  806.             else {
  807.                 $this->seq['on']['field'$data;
  808.             }
  809.             break;
  810.         }
  811.     }
  812. }
  813.  
  814. ?>

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