home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / MDB2 / Driver / Reverse / mssql.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  23.1 KB  |  591 lines

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP versions 4 and 5                                                 |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1998-2007 Manuel Lemos, Tomas V.V.Cox,                 |
  6. // | Stig. S. Bakken, Lukas Smith, Frank M. Kromann                       |
  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. // | Authors: Lukas Smith <smith@pooteeweet.org>                          |
  43. // |          Lorenzo Alberton <l.alberton@quipo.it>                      |
  44. // +----------------------------------------------------------------------+
  45. //
  46. // $Id: mssql.php,v 1.42 2007/03/29 18:18:06 quipo Exp $
  47. //
  48.  
  49. require_once 'MDB2/Driver/Reverse/Common.php';
  50.  
  51. /**
  52.  * MDB2 MSSQL driver for the schema reverse engineering module
  53.  *
  54.  * @package MDB2
  55.  * @category Database
  56.  * @author  Lukas Smith <smith@dybnet.de>
  57.  * @author  Lorenzo Alberton <l.alberton@quipo.it>
  58.  */
  59. class MDB2_Driver_Reverse_mssql extends MDB2_Driver_Reverse_Common
  60. {
  61.     // {{{ getTableFieldDefinition()
  62.  
  63.     /**
  64.      * Get the structure of a field into an array
  65.      *
  66.      * @param string    $table       name of table that should be used in method
  67.      * @param string    $field_name  name of field that should be used in method
  68.      * @return mixed data array on success, a MDB2 error on failure
  69.      * @access public
  70.      */
  71.     function getTableFieldDefinition($table, $field_name)
  72.     {
  73.         $db =& $this->getDBInstance();
  74.         if (PEAR::isError($db)) {
  75.             return $db;
  76.         }
  77.  
  78.         $result = $db->loadModule('Datatype', null, true);
  79.         if (PEAR::isError($result)) {
  80.             return $result;
  81.         }
  82.         $table = $db->quoteIdentifier($table, true);
  83.         $fldname = $db->quoteIdentifier($field_name, true);
  84.  
  85.         $query = "SELECT t.table_name,
  86.                          c.column_name 'name',
  87.                          c.data_type 'type',
  88.                          CASE c.is_nullable WHEN 'YES' THEN 1 ELSE 0 END AS 'is_nullable',
  89.                          c.column_default,
  90.                          c.character_maximum_length 'length',
  91.                          c.numeric_precision,
  92.                          c.numeric_scale,
  93.                          c.character_set_name,
  94.                          c.collation_name
  95.                     FROM INFORMATION_SCHEMA.TABLES t,
  96.                          INFORMATION_SCHEMA.COLUMNS c
  97.                    WHERE t.table_name = c.table_name
  98.                      AND t.table_name = '$table'
  99.                      AND c.column_name = '$fldname'
  100.                 ORDER BY t.table_name";
  101.         $column = $db->queryRow($query, null, MDB2_FETCHMODE_ASSOC);
  102.         if (PEAR::isError($column)) {
  103.             return $column;
  104.         }
  105.         if (empty($column)) {
  106.             return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  107.                 'it was not specified an existing table column', __FUNCTION__);
  108.         }
  109.  
  110.         if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  111.             if ($db->options['field_case'] == CASE_LOWER) {
  112.                 $column['name'] = strtolower($column['name']);
  113.             } else {
  114.                 $column['name'] = strtoupper($column['name']);
  115.             }
  116.         } else {
  117.             $column = array_change_key_case($column, $db->options['field_case']);
  118.         }
  119.         $mapped_datatype = $db->datatype->mapNativeDatatype($column);
  120.         if (PEAR::IsError($mapped_datatype)) {
  121.             return $mapped_datatype;
  122.         }
  123.         list($types, $length, $unsigned, $fixed) = $mapped_datatype;
  124.         $notnull = true;
  125.         if ($column['is_nullable']) {
  126.             $notnull = false;
  127.         }
  128.         $default = false;
  129.         if (array_key_exists('column_default', $column)) {
  130.             $default = $column['column_default'];
  131.             if (is_null($default) && $notnull) {
  132.                 $default = '';
  133.             } elseif (strlen($default) > 4
  134.                    && substr($default, 0, 1) == '('
  135.                    &&  substr($default, -1, 1) == ')'
  136.             ) {
  137.                 //mssql wraps the default value in parentheses: "((1234))", "(NULL)"
  138.                 $default = trim($default, '()');
  139.                 if ($default == 'NULL') {
  140.                     $default = null;
  141.                 }
  142.             }
  143.         }
  144.         $definition[0] = array(
  145.             'notnull' => $notnull,
  146.             'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type'])
  147.         );
  148.         if (!is_null($length)) {
  149.             $definition[0]['length'] = $length;
  150.         }
  151.         if (!is_null($unsigned)) {
  152.             $definition[0]['unsigned'] = $unsigned;
  153.         }
  154.         if (!is_null($fixed)) {
  155.             $definition[0]['fixed'] = $fixed;
  156.         }
  157.         if ($default !== false) {
  158.             $definition[0]['default'] = $default;
  159.         }
  160.         foreach ($types as $key => $type) {
  161.             $definition[$key] = $definition[0];
  162.             if ($type == 'clob' || $type == 'blob') {
  163.                 unset($definition[$key]['default']);
  164.             }
  165.             $definition[$key]['type'] = $type;
  166.             $definition[$key]['mdb2type'] = $type;
  167.         }
  168.         return $definition;
  169.     }
  170.  
  171.     // }}}
  172.     // {{{ getTableIndexDefinition()
  173.  
  174.     /**
  175.      * Get the structure of an index into an array
  176.      *
  177.      * @param string    $table      name of table that should be used in method
  178.      * @param string    $index_name name of index that should be used in method
  179.      * @return mixed data array on success, a MDB2 error on failure
  180.      * @access public
  181.      */
  182.     function getTableIndexDefinition($table, $index_name)
  183.     {
  184.         $db =& $this->getDBInstance();
  185.         if (PEAR::isError($db)) {
  186.             return $db;
  187.         }
  188.  
  189.         $table = $db->quoteIdentifier($table, true);
  190.         //$idxname = $db->quoteIdentifier($index_name, true);
  191.  
  192.         $query = "SELECT OBJECT_NAME(i.id) tablename,
  193.                          i.name indexname,
  194.                          c.name field_name,
  195.                          CASE INDEXKEY_PROPERTY(i.id, i.indid, ik.keyno, 'IsDescending')
  196.                            WHEN 1 THEN 'DESC' ELSE 'ASC'
  197.                          END 'collation',
  198.                          ik.keyno 'position'
  199.                     FROM sysindexes i
  200.                     JOIN sysindexkeys ik ON ik.id = i.id AND ik.indid = i.indid
  201.                     JOIN syscolumns c ON c.id = ik.id AND c.colid = ik.colid
  202.                    WHERE OBJECT_NAME(i.id) = '$table'
  203.                      AND i.name = '%s'
  204.                      AND NOT EXISTS (
  205.                             SELECT *
  206.                               FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE k
  207.                              WHERE k.table_name = OBJECT_NAME(i.id)
  208.                                AND k.constraint_name = i.name)
  209.                 ORDER BY tablename, indexname, ik.keyno";
  210.  
  211.         $index_name_mdb2 = $db->getIndexName($index_name);
  212.         $result = $db->queryRow(sprintf($query, $index_name_mdb2));
  213.         if (!PEAR::isError($result) && !is_null($result)) {
  214.             // apply 'idxname_format' only if the query succeeded, otherwise
  215.             // fallback to the given $index_name, without transformation
  216.             $index_name = $index_name_mdb2;
  217.         }
  218.         $result = $db->query(sprintf($query, $index_name));
  219.         if (PEAR::isError($result)) {
  220.             return $result;
  221.         }
  222.  
  223.         $definition = array();
  224.         while (is_array($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))) {
  225.             $column_name = $row['field_name'];
  226.             if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  227.                 if ($db->options['field_case'] == CASE_LOWER) {
  228.                     $column_name = strtolower($column_name);
  229.                 } else {
  230.                     $column_name = strtoupper($column_name);
  231.                 }
  232.             }
  233.             $definition['fields'][$column_name] = array(
  234.                 'position' => (int)$row['position'],
  235.             );
  236.             if (!empty($row['collation'])) {
  237.                 $definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'ASC'
  238.                     ? 'ascending' : 'descending');
  239.             }
  240.         }
  241.         $result->free();
  242.         if (empty($definition['fields'])) {
  243.             return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  244.                 'it was not specified an existing table index', __FUNCTION__);
  245.         }
  246.         return $definition;
  247.     }
  248.  
  249.     // }}}
  250.     // {{{ getTableConstraintDefinition()
  251.  
  252.     /**
  253.      * Get the structure of a constraint into an array
  254.      *
  255.      * @param string    $table      name of table that should be used in method
  256.      * @param string    $constraint_name name of constraint that should be used in method
  257.      * @return mixed data array on success, a MDB2 error on failure
  258.      * @access public
  259.      */
  260.     function getTableConstraintDefinition($table, $constraint_name)
  261.     {
  262.         $db =& $this->getDBInstance();
  263.         if (PEAR::isError($db)) {
  264.             return $db;
  265.         }
  266.  
  267.         $table = $db->quoteIdentifier($table, true);
  268.         $query = "SELECT k.table_name,
  269.                          k.column_name field_name,
  270.                          CASE c.constraint_type WHEN 'PRIMARY KEY' THEN 1 ELSE 0 END 'primary',
  271.                          CASE c.constraint_type WHEN 'UNIQUE' THEN 1 ELSE 0 END 'unique',
  272.                          CASE c.constraint_type WHEN 'FOREIGN KEY' THEN 1 ELSE 0 END 'foreign',
  273.                          CASE c.constraint_type WHEN 'CHECK' THEN 1 ELSE 0 END 'check',
  274.                          k.ordinal_position
  275.                     FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE k
  276.                     LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS c
  277.                       ON k.table_name = c.table_name
  278.                      AND k.constraint_name = c.constraint_name
  279.                      AND k.table_schema = c.table_schema
  280.                    WHERE k.constraint_catalog = DB_NAME()
  281.                     AND k.table_name = '$table'
  282.                     AND k.constraint_name = '%s'
  283.                ORDER BY k.constraint_name,
  284.                         k.ordinal_position";
  285.  
  286.         $constraint_name_mdb2 = $db->getIndexName($constraint_name);
  287.         $result = $db->queryRow(sprintf($query, $constraint_name_mdb2));
  288.         if (!PEAR::isError($result) && !is_null($result)) {
  289.             // apply 'idxname_format' only if the query succeeded, otherwise
  290.             // fallback to the given $index_name, without transformation
  291.             $constraint_name = $constraint_name_mdb2;
  292.         }
  293.         $result = $db->query(sprintf($query, $constraint_name));
  294.         if (PEAR::isError($result)) {
  295.             return $result;
  296.         }
  297.  
  298.         $definition = array();
  299.         while (is_array($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))) {
  300.             $column_name = $row['field_name'];
  301.             if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  302.                 if ($db->options['field_case'] == CASE_LOWER) {
  303.                     $column_name = strtolower($column_name);
  304.                 } else {
  305.                     $column_name = strtoupper($column_name);
  306.                 }
  307.             }
  308.             $definition['fields'][$column_name] = array(
  309.                 'position' => (int)$row['ordinal_position']
  310.             );
  311.             /*
  312.             if (!empty($row['collation'])) {
  313.                 $definition['fields'][$column_name]['sorting'] = ($row['collation'] == 'ASC'
  314.                     ? 'ascending' : 'descending');
  315.             }
  316.             */
  317.             $definition['primary'] = $row['primary'];
  318.             $definition['unique']  = $row['unique'];
  319.             $definition['foreign'] = $row['foreign'];
  320.             $definition['check']   = $row['check'];
  321.         }
  322.         $result->free();
  323.         if (empty($definition['fields'])) {
  324.             return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
  325.                 $constraint_name . ' is not an existing table constraint', __FUNCTION__);
  326.         }
  327.         return $definition;
  328.     }
  329.  
  330.     // }}}
  331.     // {{{ getTriggerDefinition()
  332.  
  333.     /**
  334.      * Get the structure of a trigger into an array
  335.      *
  336.      * EXPERIMENTAL
  337.      *
  338.      * WARNING: this function is experimental and may change the returned value
  339.      * at any time until labelled as non-experimental
  340.      *
  341.      * @param string    $trigger    name of trigger that should be used in method
  342.      * @return mixed data array on success, a MDB2 error on failure
  343.      * @access public
  344.      */
  345.     function getTriggerDefinition($trigger)
  346.     {
  347.         $db =& $this->getDBInstance();
  348.         if (PEAR::isError($db)) {
  349.             return $db;
  350.         }
  351.  
  352.         $query = "SELECT sys1.name trigger_name,
  353.                          sys2.name table_name,
  354.                          c.text trigger_body,
  355.                          c.encrypted is_encripted,
  356.                          CASE
  357.                            WHEN OBJECTPROPERTY(sys1.id, 'ExecIsTriggerDisabled') = 1
  358.                            THEN 0 ELSE 1
  359.                          END trigger_enabled,
  360.                          CASE
  361.                            WHEN OBJECTPROPERTY(sys1.id, 'ExecIsInsertTrigger') = 1
  362.                            THEN 'INSERT'
  363.                            WHEN OBJECTPROPERTY(sys1.id, 'ExecIsUpdateTrigger') = 1
  364.                            THEN 'UPDATE'
  365.                            WHEN OBJECTPROPERTY(sys1.id, 'ExecIsDeleteTrigger') = 1
  366.                            THEN 'DELETE'
  367.                          END trigger_event,
  368.                          CASE WHEN OBJECTPROPERTY(sys1.id, 'ExecIsInsteadOfTrigger') = 1
  369.                            THEN 'INSTEAD OF' ELSE 'AFTER'
  370.                          END trigger_type,
  371.                          '' trigger_comment
  372.                     FROM sysobjects sys1
  373.                     JOIN sysobjects sys2 ON sys1.parent_obj = sys2.id
  374.                     JOIN syscomments c ON sys1.id = c.id
  375.                    WHERE sys1.xtype = 'TR'
  376.                      AND sys1.name = ". $db->quote($trigger, 'text');
  377.  
  378.         $types = array(
  379.             'trigger_name'    => 'text',
  380.             'table_name'      => 'text',
  381.             'trigger_body'    => 'text',
  382.             'trigger_type'    => 'text',
  383.             'trigger_event'   => 'text',
  384.             'trigger_comment' => 'text',
  385.             'trigger_enabled' => 'boolean',
  386.             'is_encripted'    => 'boolean',
  387.         );
  388.  
  389.         $def = $db->queryRow($query, $types, MDB2_FETCHMODE_ASSOC);
  390.         if (PEAR::isError($def)) {
  391.             return $def;
  392.         }
  393.         $trg_body = $db->queryCol('EXEC sp_helptext '. $db->quote($trigger, 'text'), 'text');
  394.         if (!PEAR::isError($trg_body)) {
  395.             $def['trigger_body'] = implode('', $trg_body);
  396.         }
  397.         return $def;
  398.     }
  399.  
  400.     // }}}
  401.     // {{{ tableInfo()
  402.  
  403.     /**
  404.      * Returns information about a table or a result set
  405.      *
  406.      * NOTE: only supports 'table' and 'flags' if <var>$result</var>
  407.      * is a table name.
  408.      *
  409.      * @param object|string  $result  MDB2_result object from a query or a
  410.      *                                 string containing the name of a table.
  411.      *                                 While this also accepts a query result
  412.      *                                 resource identifier, this behavior is
  413.      *                                 deprecated.
  414.      * @param int            $mode    a valid tableInfo mode
  415.      *
  416.      * @return array  an associative array with the information requested.
  417.      *                 A MDB2_Error object on failure.
  418.      *
  419.      * @see MDB2_Driver_Common::tableInfo()
  420.      */
  421.     function tableInfo($result, $mode = null)
  422.     {
  423.         if (is_string($result)) {
  424.            return parent::tableInfo($result, $mode);
  425.         }
  426.  
  427.         $db =& $this->getDBInstance();
  428.         if (PEAR::isError($db)) {
  429.             return $db;
  430.         }
  431.  
  432.         $resource = MDB2::isResultCommon($result) ? $result->getResource() : $result;
  433.         if (!is_resource($resource)) {
  434.             return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
  435.                 'Could not generate result resource', __FUNCTION__);
  436.         }
  437.  
  438.         if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
  439.             if ($db->options['field_case'] == CASE_LOWER) {
  440.                 $case_func = 'strtolower';
  441.             } else {
  442.                 $case_func = 'strtoupper';
  443.             }
  444.         } else {
  445.             $case_func = 'strval';
  446.         }
  447.  
  448.         $count = @mssql_num_fields($resource);
  449.         $res   = array();
  450.  
  451.         if ($mode) {
  452.             $res['num_fields'] = $count;
  453.         }
  454.  
  455.         $db->loadModule('Datatype', null, true);
  456.         for ($i = 0; $i < $count; $i++) {
  457.             $res[$i] = array(
  458.                 'table' => '',
  459.                 'name'  => $case_func(@mssql_field_name($resource, $i)),
  460.                 'type'  => @mssql_field_type($resource, $i),
  461.                 'length'   => @mssql_field_length($resource, $i),
  462.                 'flags' => '',
  463.             );
  464.             $mdb2type_info = $db->datatype->mapNativeDatatype($res[$i]);
  465.             if (PEAR::isError($mdb2type_info)) {
  466.                return $mdb2type_info;
  467.             }
  468.             $res[$i]['mdb2type'] = $mdb2type_info[0][0];
  469.             if ($mode & MDB2_TABLEINFO_ORDER) {
  470.                 $res['order'][$res[$i]['name']] = $i;
  471.             }
  472.             if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
  473.                 $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
  474.             }
  475.         }
  476.  
  477.         return $res;
  478.     }
  479.  
  480.     // }}}
  481.     // {{{ _mssql_field_flags()
  482.  
  483.     /**
  484.      * Get a column's flags
  485.      *
  486.      * Supports "not_null", "primary_key",
  487.      * "auto_increment" (mssql identity), "timestamp" (mssql timestamp),
  488.      * "unique_key" (mssql unique index, unique check or primary_key) and
  489.      * "multiple_key" (multikey index)
  490.      *
  491.      * mssql timestamp is NOT similar to the mysql timestamp so this is maybe
  492.      * not useful at all - is the behaviour of mysql_field_flags that primary
  493.      * keys are alway unique? is the interpretation of multiple_key correct?
  494.      *
  495.      * @param string $table   the table name
  496.      * @param string $column  the field name
  497.      *
  498.      * @return string  the flags
  499.      *
  500.      * @access protected
  501.      * @author Joern Barthel <j_barthel@web.de>
  502.      */
  503.     function _mssql_field_flags($table, $column)
  504.     {
  505.         $db =& $this->getDBInstance();
  506.         if (PEAR::isError($db)) {
  507.             return $db;
  508.         }
  509.  
  510.         static $tableName = null;
  511.         static $flags = array();
  512.  
  513.         if ($table != $tableName) {
  514.  
  515.             $flags = array();
  516.             $tableName = $table;
  517.  
  518.             // get unique and primary keys
  519.             $res = $db->queryAll("EXEC SP_HELPINDEX[$table]", null, MDB2_FETCHMODE_ASSOC);
  520.  
  521.             foreach ($res as $val) {
  522.                 $val = array_change_key_case($val, CASE_LOWER);
  523.                 $keys = explode(', ', $val['index_keys']);
  524.  
  525.                 if (sizeof($keys) > 1) {
  526.                     foreach ($keys as $key) {
  527.                         $this->_add_flag($flags[$key], 'multiple_key');
  528.                     }
  529.                 }
  530.  
  531.                 if (strpos($val['index_description'], 'primary key')) {
  532.                     foreach ($keys as $key) {
  533.                         $this->_add_flag($flags[$key], 'primary_key');
  534.                     }
  535.                 } elseif (strpos($val['index_description'], 'unique')) {
  536.                     foreach ($keys as $key) {
  537.                         $this->_add_flag($flags[$key], 'unique_key');
  538.                     }
  539.                 }
  540.             }
  541.  
  542.             // get auto_increment, not_null and timestamp
  543.             $res = $db->queryAll("EXEC SP_COLUMNS[$table]", null, MDB2_FETCHMODE_ASSOC);
  544.  
  545.             foreach ($res as $val) {
  546.                 $val = array_change_key_case($val, CASE_LOWER);
  547.                 if ($val['nullable'] == '0') {
  548.                     $this->_add_flag($flags[$val['column_name']], 'not_null');
  549.                 }
  550.                 if (strpos($val['type_name'], 'identity')) {
  551.                     $this->_add_flag($flags[$val['column_name']], 'auto_increment');
  552.                 }
  553.                 if (strpos($val['type_name'], 'timestamp')) {
  554.                     $this->_add_flag($flags[$val['column_name']], 'timestamp');
  555.                 }
  556.             }
  557.         }
  558.  
  559.         if (!empty($flags[$column])) {
  560.             return(implode(' ', $flags[$column]));
  561.         }
  562.         return '';
  563.     }
  564.  
  565.     // }}}
  566.     // {{{ _add_flag()
  567.  
  568.     /**
  569.      * Adds a string to the flags array if the flag is not yet in there
  570.      * - if there is no flag present the array is created
  571.      *
  572.      * @param array  &$array  the reference to the flag-array
  573.      * @param string $value   the flag value
  574.      *
  575.      * @return void
  576.      *
  577.      * @access protected
  578.      * @author Joern Barthel <j_barthel@web.de>
  579.      */
  580.     function _add_flag(&$array, $value)
  581.     {
  582.         if (!is_array($array)) {
  583.             $array = array($value);
  584.         } elseif (!in_array($value, $array)) {
  585.             array_push($array, $value);
  586.         }
  587.     }
  588.  
  589.     // }}}
  590. }
  591. ?>