cvs: pear /DB/DB mssql.php

From: Date: Sun, 14 Sep 2003 19:34:19 +0000
Subject: cvs: pear /DB/DB mssql.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-12729@lists.php.net to get a copy of this message
cox Sun Sep 14 15:34:19 2003 EDT Modified files: /pear/DB/DB mssql.php Log: Added support for "isnullable" and "primary_key" for field flags in tableInfo() (currently only if you pass a table name to the method) Index: pear/DB/DB/mssql.php diff -u pear/DB/DB/mssql.php:1.13 pear/DB/DB/mssql.php:1.14 --- pear/DB/DB/mssql.php:1.13 Tue Jul 22 17:54:16 2003 +++ pear/DB/DB/mssql.php Sun Sep 14 15:34:19 2003 @@ -16,7 +16,7 @@ // | Author: Sterling Hughes <sterling@php.net> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.13 2003/07/22 21:54:16 ssb Exp $ +// $Id: mssql.php,v 1.14 2003/09/14 19:34:19 cox Exp $ // // Database independent query interface definition for PHP's Microsoft SQL Server // extension. @@ -497,7 +497,8 @@ $res[$i]['name'] = @mssql_field_name($id, $i); $res[$i]['type'] = @mssql_field_type($id, $i); $res[$i]['len'] = @mssql_field_length($id, $i); - $res[$i]['flags'] = ''; + // We only support flags for tables + $res[$i]['flags'] = is_string($result) ? $this->_mssql_field_flags($result, $res[$i]['name']) : ''; } } else { // full @@ -508,7 +509,8 @@ $res[$i]['name'] = @mssql_field_name($id, $i); $res[$i]['type'] = @mssql_field_type($id, $i); $res[$i]['len'] = @mssql_field_length($id, $i); - $res[$i]['flags'] = ''; + // We only support flags for tables + $res[$i]['flags'] = is_string($result) ? $this->_mssql_field_flags($result, $res[$i]['name']) : ''; if ($mode & DB_TABLEINFO_ORDER) { $res['order'][$res[$i]['name']] = $i; } @@ -549,6 +551,44 @@ } // }}} - + // {{{ _mssql_field_flags() + /** + * Get the flags for a field, currently only supports "isnullable" and "primary_key" + * + * @param string The table name + * @param string The field + * @access private + */ + function _mssql_field_flags($table, $column) + { + static $flags = false; + // At the first call we discover the flags for all fields + if ($flags === false) { + $flags = array(); + // find nullable fields + $q_nulls = "SELECT syscolumns.name, syscolumns.isnullable + FROM sysobjects + INNER JOIN syscolumns ON sysobjects.id = syscolumns.id + WHERE sysobjects.name ='$table' AND syscolumns.isnullable = 1"; + $res = $this->getAll($q_nulls, DB_FETCHMODE_ASSOC); + foreach ($res as $data) { + if ($data['isnullable'] == 1) { + $flags[$data['name']][] = 'isnullable'; + } + } + // find primary keys + $res2 = $this->getAll("EXEC SP_PKEYS[$table]", DB_FETCHMODE_ASSOC); + foreach ($res2 as $data) { + if (!empty($data['COLUMN_NAME'])) { + $flags[$data['COLUMN_NAME']][] = 'primary_key'; + } + } + } + if (isset($flags[$column])) { + return implode(',', $flags[$column]); + } + return ''; + } + // }}} } ?>

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