Beispiel #1
0
 /**
  * 过滤数组键值
  *
  * @access private
  * @param string $str 待处理字段值
  * @return string
  */
 private function filterColumn($str)
 {
     $str = $str . ' 0';
     $length = strlen($str);
     $lastIsAlnum = false;
     $result = '';
     $word = '';
     $split = '';
     $quotes = 0;
     for ($i = 0; $i < $length; $i++) {
         $cha = $str[$i];
         if (ctype_alnum($cha) || false !== strpos('_*', $cha)) {
             if (!$lastIsAlnum) {
                 if ($quotes > 0 && !ctype_digit($word) && '.' != $split && false === strpos(self::KEYWORDS, strtoupper($word))) {
                     $word = $this->_adapter->quoteColumn($word);
                 } else {
                     if ('.' == $split && 'table' == $word) {
                         $word = $this->_prefix;
                         $split = '';
                     }
                 }
                 $result .= $word . $split;
                 $word = '';
                 $quotes = 0;
             }
             $word .= $cha;
             $lastIsAlnum = true;
         } else {
             if ($lastIsAlnum) {
                 if (0 == $quotes) {
                     if (false !== strpos(' ,)=<>.+-*/', $cha)) {
                         $quotes = 1;
                     } else {
                         if ('(' == $cha) {
                             $quotes = -1;
                         }
                     }
                 }
                 $split = '';
             }
             $split .= $cha;
             $lastIsAlnum = false;
         }
     }
     return $result;
 }