View Issue Details

IDProjectCategoryView StatusLast Update
0008384mantisbtdb db2public2007-10-04 01:37
Reportervboctor Assigned Tovboctor  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
OSi5 
Product Version1.1.0a4 
Target Version1.1.0rc1Fixed in Version1.1.0rc1 
Summary0008384: db_table_exists() doesn't work in case of DB2
Description

The db_table_exists() doesn't work for db2 since it doesn't pass the schema to ADODB driver. Following is the fix that is proposed by Alan Seiden.

--------------------

function db_table_exists( $p_table_name) {
global $g_db, $g_db_schema; // DB2 added $g_db_schema

// DB2 Alan Seiden was: return in_array ( $p_table_name ,
$g_db->MetaTables( "TABLE" ) ) ;
// must pass schema
// can't use in_array because it's case sensitive.
$t_tables = implode(",", $g_db->MetaTables( "TABLE", false, '',
$g_db_schema ));
if (empty($p_table_name)) {
return false; // no tables found
} else {
return (false !== stripos($t_tables, $p_table_name)); //
find table name in imploded list, return true or false
} //(if (empty($p_table_name)))

}

TagsNo tags attached.

Activities

vboctor

vboctor

2007-09-22 04:05

manager   ~0015690

Fixed, however, used a different implementation. See below:

# --------------------
# Check if the specified table exists.
# @param $p_table_name  Table name.
# @returns true: table found, false: table not found.
function db_table_exists( $p_table_name ) {
    global $g_db, $g_db_schema;

    if ( is_blank( $p_table_name ) ) {
        return false; // no tables found
    }

    if ( db_is_db2() ) {
        // must pass schema
        $t_tables = $g_db->MetaTables( 'TABLE', false, '', $g_db_schema );
    } else {
        $t_tables = $g_db->MetaTables( 'TABLE' );
    }

    # Can't use in_array() since it is case sensitive
    $t_table_name = strtolower( $p_table_name );
    foreach ( $t_tables as $t_current_table ) {
        if ( strtolower( $t_current_table ) == $t_table_name ) {
            return true;
        }
    }

    return false;
}
vboctor

vboctor

2007-09-22 04:40

manager   ~0015691

Also in core/adodb/drivers/adodb-db2.inc.php:

Update the implementation of MetaTables based on the changes highlighted by @@@.

    // @@@ original: function MetaTables($ttype=false,$schema=false)
    // DB2/400 Allow table and schema as optional parameters. 
function MetaTables($ttype=false,$showSchema=false, $qtable="%", $qschema="%")
{
global $ADODB_FETCH_MODE;

    $savem = $ADODB_FETCH_MODE;
    $ADODB_FETCH_MODE = ADODB_FETCH_NUM;

            // @@@ original: $qid = db2_tables($this->_connectionID);
    $qid = db2_tables($this->_connectionID, null, $qschema, $qtable);       

    $rs = new ADORecordSet_db2($qid);

    $ADODB_FETCH_MODE = $savem;
    if (!$rs) {
        $false = false;
        return $false;
    }

    $arr =& $rs->GetArray();

    $rs->Close();
    $arr2 = array();

    if ($ttype) {
        $isview = strncmp($ttype,'V',1) === 0;
    }
    for ($i=0; $i < sizeof($arr); $i++) {
        if (!$arr[$i][2]) continue;
        $type = $arr[$i][3];
                    // @@@ original: DB2/400 $schemaval = ($schema) ? $arr[$i][1].'.' : '';
                    // use $showSchema instead of $schema, for consistency with odbc_db2.inc.php
        $schemaval = ($showSchema) ? $arr[$i][1].'.' : '';
        if ($ttype) { 
            if ($isview) {
                if (strncmp($type,'V',1) === 0) $arr2[] = $schemaval.$arr[$i][2];
            } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $schemaval.$arr[$i][2];
        } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $schemaval.$arr[$i][2];
    }
    return $arr2;
}

Issue History

Date Modified Username Field Change
2007-09-22 03:49 vboctor New Issue
2007-09-22 03:49 vboctor Status new => assigned
2007-09-22 03:49 vboctor Assigned To => vboctor
2007-09-22 04:05 vboctor Status assigned => resolved
2007-09-22 04:05 vboctor Fixed in Version => 1.1.0rc1
2007-09-22 04:05 vboctor Resolution open => fixed
2007-09-22 04:05 vboctor Note Added: 0015690
2007-09-22 04:40 vboctor Note Added: 0015691
2007-10-04 01:37 vboctor Status resolved => closed