當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Doctrine_Query::sqlExplode方法代碼示例

本文整理匯總了PHP中Doctrine_Query::sqlExplode方法的典型用法代碼示例。如果您正苦於以下問題:PHP Doctrine_Query::sqlExplode方法的具體用法?PHP Doctrine_Query::sqlExplode怎麽用?PHP Doctrine_Query::sqlExplode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine_Query的用法示例。


在下文中一共展示了Doctrine_Query::sqlExplode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: load

 /**
  * load
  * returns the parsed query part
  *
  * @param string $where
  * @return string
  */
 public function load($where)
 {
     $where = trim($where);
     $conn = $this->query->getConnection();
     $e = Doctrine_Tokenizer::sqlExplode($where);
     if (count($e) > 1) {
         $tmp = $e[0] . ' ' . $e[1];
         if (substr($tmp, 0, 6) == 'EXISTS') {
             return $this->parseExists($where, true);
         } elseif (substr($where, 0, 10) == 'NOT EXISTS') {
             return $this->parseExists($where, false);
         }
     }
     if (count($e) < 3) {
         $e = Doctrine_Tokenizer::sqlExplode($where, array('=', '<', '>', '!='));
     }
     $r = array_shift($e);
     $a = explode('.', $r);
     if (count($a) > 1) {
         $field = array_pop($a);
         $count = count($e);
         $slice = array_slice($e, -1, 1);
         $value = implode('', $slice);
         $operator = trim(substr($where, strlen($r), -strlen($value)));
         $reference = implode('.', $a);
         $count = count($a);
         $pos = strpos($field, '(');
         if ($pos !== false) {
             $func = substr($field, 0, $pos);
             $value = trim(substr($field, $pos + 1, -1));
             $values = Doctrine_Query::sqlExplode($value, ',');
             $field = array_pop($a);
             $reference = implode('.', $a);
             $table = $this->query->load($reference, false);
             $field = $table->getColumnName($field);
             array_pop($a);
             $reference2 = implode('.', $a);
             $alias = $this->query->getTableAlias($reference2);
             $stack = $this->query->getRelationStack();
             $relation = end($stack);
             $stack = $this->query->getTableStack();
             switch ($func) {
                 case 'contains':
                 case 'regexp':
                 case 'like':
                     $operator = $this->getOperator($func);
                     if (empty($relation)) {
                         throw new Doctrine_Query_Exception('DQL functions contains/regexp/like can only be used for fields of related components');
                     }
                     $where = array();
                     foreach ($values as $value) {
                         $where[] = $conn->quoteIdentifier($alias . '.' . $relation->getLocal()) . ' IN (SELECT ' . $conn->quoteIdentifier($relation->getForeign()) . ' FROM ' . $conn->quoteIdentifier($relation->getTable()->getTableName()) . ' WHERE ' . $field . $operator . $value . ')';
                     }
                     $where = implode(' AND ', $where);
                     break;
                 default:
                     throw new Doctrine_Query_Exception('Unknown DQL function: ' . $func);
             }
         } else {
             $map = $this->query->load($reference, false);
             $alias = $this->query->getTableAlias($reference);
             $table = $map['table'];
             $field = $table->getColumnName($field);
             // check if value is enumerated value
             $enumIndex = $table->enumIndex($field, trim($value, "'"));
             if (substr($value, 0, 1) == '(') {
                 // trim brackets
                 $trimmed = Doctrine_Tokenizer::bracketTrim($value);
                 if (substr($trimmed, 0, 4) == 'FROM' || substr($trimmed, 0, 6) == 'SELECT') {
                     // subquery found
                     $q = new Doctrine_Query();
                     $value = '(' . $q->isSubquery(true)->parseQuery($trimmed)->getQuery() . ')';
                 } elseif (substr($trimmed, 0, 4) == 'SQL:') {
                     $value = '(' . substr($trimmed, 4) . ')';
                 } else {
                     // simple in expression found
                     $e = Doctrine_Tokenizer::sqlExplode($trimmed, ',');
                     $value = array();
                     foreach ($e as $part) {
                         $index = $table->enumIndex($field, trim($part, "'"));
                         if ($index !== false) {
                             $value[] = $index;
                         } else {
                             $value[] = $this->parseLiteralValue($part);
                         }
                     }
                     $value = '(' . implode(', ', $value) . ')';
                 }
             } elseif (substr($value, 0, 1) == ':' || $value === '?') {
                 // placeholder found
                 if ($table->getTypeOf($field) == 'enum') {
                     $this->query->addEnumParam($value, $table, $field);
                 } else {
//.........這裏部分代碼省略.........
開發者ID:snouhaud,項目名稱:camptocamp.org,代碼行數:101,代碼來源:Where.php


注:本文中的Doctrine_Query::sqlExplode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。