PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB » Bug #2669

DB ODBC Table Info

Details

Request #2669DB ODBC Table Info
Submitted2004-11-02 03:20 UTC
Fromsymbol1 at gmail dot com
Assigneddanielc
StatusClosed
PackageDB
PHP Version4.3.9
OSwin32
Roadmaps(Not assigned)

Comments

[2004-11-02 03:20 UTC] symbol1 at gmail dot com

Description:
------------
Is there a reason the DB ODBC cannot do tableInfo() and getListOf('tables').

I apologize if this isn't the correct place to request this.

[2004-11-13 04:26 UTC] symbol1 at gmail dot com

Why not do this:
function getListOf($type)
{
$key = '';

switch(strtolower($type))
{
case 'tables':
case 'table':
$dbres = odbc_tables($this->connection);
$key = 'TABLE_NAME';
break;

default:
return $this->raiseError(DB_ERROR_UNSUPPORTED);

}
$res = array();
while ($dbinfo=odbc_fetch_array($dbres)) {
$res[] = $dbinfo[$key];
}
return $res;
}

// }}}

[2004-11-13 04:26 UTC] symbol1 at gmail dot com

and do this:

function tableInfo($result, $mode = null)
{
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
$case_func = 'strtolower';
} else {
$case_func = 'strval';
}

if (is_string($result))
{
$colRes = odbc_columns($this->connection,'','',$result);

$res = array();
if (!$colRes)
{
// some error
return $this->raiseError(DB_ERROR_NOT_CAPABLE);

}
else
{

$i=0;
while ($aCol = odbc_fetch_array($colRes))
{

$res[$i]['table'] = $case_func($aCol['TABLE_NAME']);
$res[$i]['name'] = $case_func($aCol['COLUMN_NAME']);
$res[$i]['type'] = $case_func($aCol['TYPE_NAME']);
$res[$i]['len'] = $aCol['COLUMN_SIZE'];
$res[$i]['flags'] = (!$aCol['NULLABLE']) ? 'not_null' : '';

if ($mode & DB_TABLEINFO_ORDER)
{
$res['order'][$res[$i]['name']] = $i;
}
if ($mode & DB_TABLEINFO_ORDERTABLE)
{
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
}

$i++;
}

odbc_free_result($colRes);
if ($mode)
{
$res['num_fields'] = $i;
}
}

}
else
{
if (isset($result->result))
{
/*
* Probably received a result object.
* Extract the result resource identifier.
*/
$result = $result->result;
} else {
/*
* ELSE, probably received a result resource identifier.
* Deprecated. Here for compatibility only.
*/
}

$count = odbc_num_fields($result);

for ($i=0; $i<$count; $i++)
{
$res[$i]['table'] = '';
$res[$i]['name'] = $case_func(odbc_field_name($result, $i+1));
$res[$i]['type'] = odbc_field_type($result, $i+1);
$res[$i]['len'] = odbc_field_len($result, $i+1);
$res[$i]['flags'] = '';

if ($mode & DB_TABLEINFO_ORDER) {
$res['order'][$res[$i]['name']] = $i;
}
if ($mode & DB_TABLEINFO_ORDERTABLE) {
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
}
}

if ($mode) {
$res['num_fields'] = $count;
}

}
return $res;
}

[2004-11-13 04:28 UTC] symbol1 at gmail dot com

I used the oci8 functions and modified them to work with the odbc_xxx functions. It works well for the 3 drivers i've tried it on.