Exemplo n.º 1
0
 private function _getData()
 {
     if (isset($this->_data)) {
         return $this->_data;
     }
     $data = array();
     $query = new CM_Db_Query_Describe($this->_client, $this->_table, $this->_column);
     $result = $query->execute();
     $columns = $result->fetch();
     if (false === $columns) {
         throw new CM_Db_Exception('Column `' . $this->_column . '` not found');
     }
     foreach ($columns as $var => $value) {
         if ($var === 'Type') {
             if (preg_match("/^(\\w++)(?:\\((\\d+|'[^']*(?:''[^']*)*'(?:,'[^']*(?:''[^']*)*')*)\\))?(?: (\\w++))?\$/", $value, $matches)) {
                 $data['type'] = $matches[1];
                 if (isset($matches[2])) {
                     if (preg_match('/\\d+/', $matches[2])) {
                         $data['size'] = (int) $matches[2];
                     } elseif (strlen($matches[2])) {
                         preg_match_all("/,'([^']*(?:''[^']*)*)'/", ',' . $matches[2], $enumMatches);
                         $data['enum'] = array_map(function ($value) {
                             return str_replace("''", "'", $value);
                         }, $enumMatches[1]);
                     }
                 }
                 $data['unsigned'] = isset($matches[3]) && $matches[3] === 'unsigned';
             }
         } else {
             $data[$var] = $value;
         }
     }
     return $data;
 }
Exemplo n.º 2
0
 public function testWithoutColumn()
 {
     $client = CM_Service_Manager::getInstance()->getDatabases()->getMaster();
     $query = new CM_Db_Query_Describe($client, 't`est table');
     $this->assertSame('DESCRIBE `t``est table`', $query->getSqlTemplate());
 }