Changeset trunk,185

Show
Ignore:
Timestamp:
02/24/10 02:58:48 (5 months ago)
Author:
Suren A. Chilingaryan <csa@dside.dyndns.org>
revision id:
csa@dside.dyndns.org-20100224025848-pq272i8uayd4rhg2
branch-nick:
adei
Message:

Support for the masks table in DBReader

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/classes/database.php

    r181 r185  
    2828    each($this->arr);     
    2929 } 
     30 
    3031 function valid() { 
    3132        // We don't expect 'false' elements in array (all are arrays) 
    3233    return current($this->arr)?true:false; 
    3334 } 
    34  
     35  
     36 function rowCount() { 
     37    return sizeof($this->arr); 
     38 } 
    3539} 
    3640 
     
    4347 var $dbname; 
    4448  
    45  var $text_quote = "\'"
     49 var $text_quote = '\''
    4650 var $col_quote = "\""; 
    4751 var $tbl_quote = ""; 
     
    415419 } 
    416420 
     421 function FixTableName($table) { 
     422    switch ($this->driver) { 
     423        case "mssql": 
     424            $table = preg_replace("/^\[?mda\]?\./", "", $table); 
     425            $table = preg_replace("/(^\[|\]$)/", "", $table); 
     426        break; 
     427    } 
     428    return $table; 
     429 } 
     430 
    417431 function ShowColumns($table) { 
    418432    switch ($this->driver) { 
     
    422436                /* we could get here problems if several non-equal tables with  
    423437                different prefixes (mda,dbo) are present */ 
    424             $table = preg_replace("/^\[?mda\]?\./", "", $table); 
    425             $table = preg_replace("/(^\[|\]$)/", "", $table); 
     438            $table = $this->FixTableName($table); 
     439/*          $table = preg_replace("/^\[?mda\]?\./", "", $table); 
     440            $table = preg_replace("/(^\[|\]$)/", "", $table);*/ 
    426441            return $this->Query("SELECT name FROM (SELECT DISTINCT TOP 65535 name=syscolumns.name, type=systypes.name, length=syscolumns.length, objname=sysobjects.name, colid=syscolumns.colid 
    427442                FROM sysobjects  
  • trunk/classes/readers/dbreader.php

    r181 r185  
    110110    $this->monitor_timings = $this->opts->Get("monitor_timings"); 
    111111 } 
     112 
     113 
     114 function GetFilteredMaskList(LOGGROUP $grp = NULL, $maskid = false, $flags = 0) { 
     115    $grp = $this->CheckGroup($grp, $flags); 
     116 
     117    $info = $this->req->GetGroupOption("mask_table", $grp); 
     118//    $info = $this->opts->Get("mask_table"); 
     119    if (!$info) return parent::GetMaskList($grp, $flags); 
     120     
     121    if (!is_array($info)) 
     122        throw new ADEIException(translate("Invalid mask table specified in the reader configuration, the array with information should be provided")); 
     123 
     124    if (!$info['table'])  
     125        throw new ADEIException(translate("The mask table is not specified in the reader configuration")); 
     126 
     127    if (!$info['id'])  
     128        throw new ADEIException(translate("The id column for mask table is not specified in the reader configuration")); 
     129 
     130 
     131    $query = ""; 
     132    if (is_array($info['properties'])) { 
     133        foreach ($info['properties'] as $prop => $col) { 
     134            $query.= ", {$this->db->col_quote}$col{$this->db->col_quote} AS ${prop}"; 
     135        } 
     136    } 
     137     
     138    if ($maskid) { 
     139        $cond = " WHERE {$this->db->col_quote}{$info['id']}{$this->db->col_quote} = {$this->db->text_quote}{$maskid}{$this->db->text_quote}"; 
     140    } elseif ($info['gid']) { 
     141        $table = $this->db->FixTableName($grp->table); 
     142        $cond = " WHERE {$this->db->col_quote}{$info['gid']}{$this->db->col_quote} = {$this->db->text_quote}{$table}{$this->db->text_quote}"; 
     143    } else { 
     144        $cond = ""; 
     145    } 
     146    $query = "SELECT {$this->db->col_quote}{$info['id']}{$this->db->col_quote} AS id{$query} FROM {$this->db->tbl_quote}{$info['table']}{$this->db->tbl_quote}" . $cond; 
     147 
     148    $masks = $this->db->Query($query); 
     149 
     150    if ($masks->rowCount()) { 
     151        $items = $this->GetItemList($grp, NULL, $flags); 
     152        $hash = array(); 
     153        foreach ($items as $item) { 
     154            $hash[$item['name']] = $item; 
     155        } 
     156    } else if ($maskid) { 
     157        throw new ADEIException(translate("Mask \"%s\" is not found for group \"%s\"", $maskid, $grp->gid)); 
     158    } 
     159     
     160    $list = array(); 
     161    foreach ($masks as $mask) { 
     162        $items = explode(",", $mask['mask']); 
     163        foreach ($items as &$item) { 
     164            if (!is_numeric($item)) { 
     165                if (isset($hash[$item])) { 
     166                    $item = $hash[$item]['id']; 
     167                } else { 
     168                    throw new ADEIException(translate("Item \"%s\" specified in the mask \"%s\" is not available in the group \"%s\"", $item, $mask['id'], $grp->gid)); 
     169                } 
     170            } 
     171        } 
     172 
     173        $mask['mask'] = implode(",", $items); 
     174        $mask['id'] =   "maskid" . $mask['id']; 
     175 
     176        $list[$mask['id']] = $mask; 
     177    } 
     178 
     179    return array_merge( 
     180        parent::GetMaskList($grp, $flags), 
     181        $list 
     182    ); 
     183 } 
     184 
     185 function GetMaskList(LOGGROUP $grp = NULL, $flags = 0) { 
     186    return $this->GetFilteredMaskList($grp, false, $flags); 
     187 } 
     188 
     189 function CreateMask(LOGGROUP $grp = NULL, array &$minfo = NULL, $flags = 0) { 
     190    if ($minfo === NULL) { 
     191        if ($this->req instanceof ITEMGroupRequest) 
     192            $minfo = $this->req->GetMaskInfo($flags); 
     193    } 
     194 
     195    if (preg_match("/^maskid(\d+)$/", $minfo["db_mask"], $m)) { 
     196        $res = new MASK(array(), $this, $grp, $flags); 
     197     
     198        $masks = $this->GetFilteredMaskList($grp, $m[1], $flags); 
     199        $mask = $masks->current(); 
     200 
     201        if ($mask) { 
     202            $res->SetIDs($mask['mask'], $mask['id']); 
     203        }  
     204        return $res; 
     205    } else { 
     206        return new MASK($minfo, $this, $grp, $flags); 
     207    } 
     208 } 
     209 
    112210 
    113211 function CreateAxes($flags = 0) {