Example #1
0
 /**
  * Enter description here...
  *
  * @param unknown_type $results
  */
 function resultSet(&$results)
 {
     $this->map = array();
     $numFields = $results->columnCount();
     $index = 0;
     $j = 0;
     while ($j < $numFields) {
         $column = $results->getColumnMeta($j);
         if (strpos($column['name'], '__')) {
             list($table, $name) = explode('__', $column['name']);
             $this->map[$index++] = array($table, $name, $column['native_type']);
         } else {
             $this->map[$index++] = array(0, $column['name'], $column['native_type']);
         }
         $j++;
     }
 }
Example #2
0
 /**
  * Enter description here...
  *
  * @param unknown_type $results
  * @return string
  * @access public
  */
 public function resultSet($results)
 {
     $this->results = $results;
     $this->map = array();
     $numFields = $results->columnCount();
     $index = 0;
     $j = 0;
     //PDO::getColumnMeta is experimental and does not work with sqlite3,
     //	so try to figure it out based on the querystring
     $querystring = $results->queryString;
     if (stripos($querystring, 'SELECT') === 0) {
         $last = strripos($querystring, 'FROM');
         if ($last !== false) {
             $selectpart = substr($querystring, 7, $last - 8);
             $selects = String::tokenize($selectpart, ',', '(', ')');
         }
     } elseif (strpos($querystring, 'PRAGMA table_info') === 0) {
         $selects = array('cid', 'name', 'type', 'notnull', 'dflt_value', 'pk');
     } elseif (strpos($querystring, 'PRAGMA index_list') === 0) {
         $selects = array('seq', 'name', 'unique');
     } elseif (strpos($querystring, 'PRAGMA index_info') === 0) {
         $selects = array('seqno', 'cid', 'name');
     }
     while ($j < $numFields) {
         if (!isset($selects[$j])) {
             $j++;
             continue;
         }
         if (preg_match('/\\bAS\\s+(.*)/i', $selects[$j], $matches)) {
             $columnName = trim($matches[1], '"');
         } else {
             $columnName = trim(str_replace('"', '', $selects[$j]));
         }
         if (strpos($selects[$j], 'DISTINCT') === 0) {
             $columnName = str_ireplace('DISTINCT', '', $columnName);
         }
         $metaType = false;
         try {
             $metaData = (array) $results->getColumnMeta($j);
             if (!empty($metaData['sqlite:decl_type'])) {
                 $metaType = trim($metaData['sqlite:decl_type']);
             }
         } catch (Exception $e) {
         }
         if (strpos($columnName, '.')) {
             $parts = explode('.', $columnName);
             $this->map[$index++] = array(trim($parts[0]), trim($parts[1]), $metaType);
         } else {
             $this->map[$index++] = array(0, $columnName, $metaType);
         }
         $j++;
     }
 }