cvs: pear /MDB2/MDB2/Driver/Reverse ibase.php

From: Date: Wed, 12 Oct 2005 17:07:01 +0000
Subject: cvs: pear /MDB2/MDB2/Driver/Reverse ibase.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-35457@lists.php.net to get a copy of this message
quipo Wed Oct 12 13:07:01 2005 EDT Modified files: /pear/MDB2/MDB2/Driver/Reverse ibase.php Log: implemented getTableIndexDefinition() http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Reverse/ibase.php?r1=1.18&r2=1.19&ty=u Index: pear/MDB2/MDB2/Driver/Reverse/ibase.php diff -u pear/MDB2/MDB2/Driver/Reverse/ibase.php:1.18 pear/MDB2/MDB2/Driver/Reverse/ibase.php:1.19 --- pear/MDB2/MDB2/Driver/Reverse/ibase.php:1.18 Wed Oct 12 10:40:12 2005 +++ pear/MDB2/MDB2/Driver/Reverse/ibase.php Wed Oct 12 13:06:59 2005 @@ -42,7 +42,7 @@ // | Author: Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.18 2005/10/12 14:40:12 quipo Exp $ +// $Id: ibase.php,v 1.19 2005/10/12 17:06:59 quipo Exp $ // require_once 'MDB2/Driver/Reverse/Common.php'; @@ -204,6 +204,76 @@ } // }}} + // {{{ getTableIndexDefinition() + + /** + * get the stucture of an index into an array + * + * @param string $table name of table that should be used in method + * @param string $index_name name of index that should be used in method + * @return mixed data array on success, a MDB2 error on failure + * @access public + */ + function getTableIndexDefinition($table, $index_name) + { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + $table = strtoupper($table); + $index_name = strtoupper($index_name); + $query = "SELECT RDB\$INDEX_SEGMENTS.RDB\$FIELD_NAME AS field_name, + RDB\$INDICES.RDB\$UNIQUE_FLAG AS unique_flag, + RDB\$INDICES.RDB\$FOREIGN_KEY AS foreign_key, + RDB\$INDICES.RDB\$DESCRIPTION AS description, + RDB\$RELATION_CONSTRAINTS.RDB\$CONSTRAINT_TYPE as constraint_type + FROM RDB\$INDEX_SEGMENTS + LEFT JOIN RDB\$INDICES ON RDB\$INDICES.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME + LEFT JOIN RDB\$RELATION_CONSTRAINTS ON RDB\$RELATION_CONSTRAINTS.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME + WHERE UPPER(RDB\$INDICES.RDB\$RELATION_NAME)='$table' + AND UPPER(RDB\$INDICES.RDB\$INDEX_NAME)='$index_name' + ORDER BY RDB\$INDEX_SEGMENTS.RDB\$FIELD_POSITION;"; + $result = $db->query($query); + if (PEAR::isError($result)) { + return $result; + } + + $index = $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC); + if (empty($index)) { + return $db->raiseError(MDB2_ERROR, null, null, + 'getTableIndexDefinition: it was not specified an existing table index'); + } + $fields = array(); + do { + $fields[] = $row['field_name']; + } while (is_array($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))); + $result->free(); + + if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { + $fields = array_map(($db->options['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $fields); + } + + $definition = array(); + if ($index['unique_flag']) { + $definition['unique'] = true; + } + if ($index['constraint_type'] == 'PRIMARY KEY') { + $definition['primary'] = true; + } + foreach ($fields as $field) { + $definition['fields'][$field] = array(); + //collation?!? + /* + if (array_key_exists('collation', $row)) { + $definition['fields'][$field]['sorting'] = ($row['collation'] == 'A' + ? 'ascending' : 'descending'); + } + */ + } + return $definition; + } + + // }}} // {{{ tableInfo() /**

« previous php.pear.cvs (#35457) next »