Exemple #1
0
function CheckOQL($sOQL, ModelReflection $oModelReflection)
{
    $aRes = array('status' => 'ok', 'message' => '');
    try {
        $oOql = new OqlInterpreter($sOQL);
        $oOqlQuery = $oOql->ParseQuery();
        // Exceptions thrown in case of issue
        $oOqlQuery->Check($oModelReflection, $sOQL);
        // Exceptions thrown in case of issue
    } catch (Exception $e) {
        $aRes['status'] = 'error';
        $aRes['message'] = $e->getMessage();
    }
    return $aRes;
}
 /**
  * @param string $sQuery
  * @param array $aParams
  * @return DBSearch
  * @throws OQLException
  */
 public static function FromOQL($sQuery, $aParams = null)
 {
     if (empty($sQuery)) {
         return null;
     }
     // Query caching
     $sQueryId = md5($sQuery);
     $bOQLCacheEnabled = true;
     if ($bOQLCacheEnabled) {
         if (array_key_exists($sQueryId, self::$m_aOQLQueries)) {
             // hit!
             $oResultFilter = self::$m_aOQLQueries[$sQueryId]->DeepClone();
         } elseif (self::$m_bUseAPCCache) {
             // Note: For versions of APC older than 3.0.17, fetch() accepts only one parameter
             //
             $sAPCCacheId = 'itop-' . MetaModel::GetEnvironmentId() . '-dbsearch-cache-' . $sQueryId;
             $oKPI = new ExecutionKPI();
             $result = apc_fetch($sAPCCacheId);
             $oKPI->ComputeStats('Search APC (fetch)', $sQuery);
             if (is_object($result)) {
                 $oResultFilter = $result;
                 self::$m_aOQLQueries[$sQueryId] = $oResultFilter->DeepClone();
             }
         }
     }
     if (!isset($oResultFilter)) {
         $oKPI = new ExecutionKPI();
         $oOql = new OqlInterpreter($sQuery);
         $oOqlQuery = $oOql->ParseQuery();
         $oMetaModel = new ModelReflectionRuntime();
         $oOqlQuery->Check($oMetaModel, $sQuery);
         // Exceptions thrown in case of issue
         $oResultFilter = $oOqlQuery->ToDBSearch($sQuery);
         $oKPI->ComputeStats('Parse OQL', $sQuery);
         if ($bOQLCacheEnabled) {
             self::$m_aOQLQueries[$sQueryId] = $oResultFilter->DeepClone();
             if (self::$m_bUseAPCCache) {
                 $oKPI = new ExecutionKPI();
                 apc_store($sAPCCacheId, $oResultFilter, self::$m_iQueryCacheTTL);
                 $oKPI->ComputeStats('Search APC (store)', $sQueryId);
             }
         }
     }
     if (!is_null($aParams)) {
         $oResultFilter->SetInternalParams($aParams);
     }
     return $oResultFilter;
 }