Ejemplo n.º 1
0
 protected function getInternalColumns()
 {
     if (is_null($this->columns)) {
         $this->columns = array();
         $keyLength = $this->getKeyLength();
         if (is_null($keyLength)) {
             throw new ErrorException("Cannot create meta-table-schema for indicies when no key-length is specified!");
         }
         $columnPage = new Column();
         for ($i = 1; $i <= 33; $i++) {
             $columnPage->setName("ref{$i}");
             $columnPage->setDataType(DataType::INT());
             $columnPage->setLength($keyLength);
             $columnPage->setExtraFlags(Column::EXTRA_PRIMARY_KEY);
             $this->columns[] = clone $columnPage;
             $columnPage->setName("val{$i}");
             $columnPage->setDataType(DataType::INT());
             $columnPage->setLength($keyLength);
             $columnPage->setExtraFlags(Column::EXTRA_PRIMARY_KEY);
             $this->columns[] = clone $columnPage;
             $columnPage->setName("row{$i}");
             $columnPage->setDataType(DataType::INT());
             $columnPage->setLength($keyLength);
             $columnPage->setExtraFlags(Column::EXTRA_PRIMARY_KEY);
             $this->columns[] = clone $columnPage;
         }
     }
     return $this->columns;
 }
 /**
  * Constructs an instance from a list of column headers as returned by the
  * Google Analytics API.
  *
  * @param array $headers
  * @param Google\Analytics\API $api
  */
 public function __construct(array $headers, API $api)
 {
     $headerCount = count($headers);
     for ($i = 0; $i < $headerCount; $i++) {
         self::_validateHeader($headers[$i]);
         try {
             $column = $api->getColumn($headers[$i]['name']);
         } catch (InvalidArgumentException $e) {
             /* I don't expect this to happen but in case it does, we can
             			create a representation of the column by building it on the
             			fly, though it will be missing most of the available
             			properties. */
             $column = new Column();
             $column->setID(API::addPrefix($headers[$i]['name']));
             $column->setType($headers[$i]['columnType']);
             $column->setDataType($headers[$i]['dataType']);
         }
         $this->_columns[] = $column;
         $this->_columnIndicesByName[$column->getName()] = $i;
     }
 }
Ejemplo n.º 3
0
 /**
  * Obtiene el detalle de columnas de la tabla o vista actual
  * @return Array
  */
 public function checkColumnDetail()
 {
     $sql = "select ut.column_name, data_type, data_length, nullable, data_default, comments " . "from user_tab_columns ut inner join user_col_comments uc " . "on ut.table_name = uc.table_name " . "and ut.column_name = uc.column_name " . "where ut.table_name = upper(:v_table)";
     $stmt = oci_parse($this->getConnection(), $sql);
     oci_bind_by_name($stmt, ":v_table", $this->objectName);
     if (!@oci_execute($stmt)) {
         $e = oci_error();
         $this->setMensaje("Error al obtener el detalle de las columnas de la tabla o vista '{$this->objectName}' - {$e['message']}");
         $this->setEstado(false);
     }
     while ($row = oci_fetch_array($stmt, OCI_ASSOC | OCI_RETURN_NULLS)) {
         $column = new Column();
         $column->setColumnName($row['COLUMN_NAME']);
         $column->setDataType($row['DATA_TYPE']);
         $column->setDataLength($row['DATA_LENGTH']);
         $column->setIsNullable($row['NULLABLE']);
         $column->setDefaultValue($row['DATA_DEFAULT']);
         $column->setComment($row['COMMENTS']);
         $this->aColumns[] = $column;
     }
     return $this->aColumns;
 }
Ejemplo n.º 4
0
 /**
  * Populates the properties that store cached dimensions and metrics,
  * either from the database or from the API directly, depending on when
  * the data that we have was last fetched.
  */
 private function _refreshColumnMetadata()
 {
     /* If we're not using a database, the best we can do is to cache the
        column metadata for the duration of this process' existence. */
     if (self::$_dbConn) {
         try {
             $lastFetchData = self::_getLastFetchData('google_analytics_api_columns');
             if ($lastFetchData) {
                 $fetchDate = (int) $lastFetchData['fetch_date'];
                 $etag = $lastFetchData['etag'];
             } else {
                 $fetchDate = null;
                 $etag = null;
             }
             $columns = null;
             $newETag = null;
             if ($this->_bypassColumnCache || !$fetchDate || $fetchDate <= time() - GOOGLE_ANALYTICS_API_METADATA_CACHE_DURATION) {
                 $this->_bypassColumnCache = false;
                 $request = new APIRequest('metadata/ga/columns');
                 if ($etag) {
                     $request->setHeader('If-None-Match: ' . $etag);
                 }
                 $columns = $this->_makeRequest($request);
                 if ($columns) {
                     $stmt = self::$_DB_STATEMENTS['google_analytics_api_columns']['insert'];
                     foreach ($columns as $column) {
                         $stmt->bindValue(':name', $column->getName(), \PDO::PARAM_STR);
                         $stmt->bindValue(':type', $column->getType(), \PDO::PARAM_STR);
                         $stmt->bindValue(':data_type', $column->getDataType(), \PDO::PARAM_STR);
                         $stmt->bindValue(':replaced_by', $column->getReplacementColumn(), \PDO::PARAM_STR);
                         $stmt->bindValue(':group', $column->getGroup(), \PDO::PARAM_STR);
                         $stmt->bindValue(':ui_name', $column->getUIName(), \PDO::PARAM_STR);
                         $stmt->bindValue(':description', $column->getDescription(), \PDO::PARAM_STR);
                         $stmt->bindValue(':calculation', $column->getCalculation(), \PDO::PARAM_STR);
                         $stmt->bindValue(':min_template_index', $column->getMinTemplateIndex(), \PDO::PARAM_INT);
                         $stmt->bindValue(':max_template_index', $column->getMaxTemplateIndex(), \PDO::PARAM_INT);
                         $stmt->bindValue(':min_template_index_premium', $column->getPremiumMinTemplateIndex(), \PDO::PARAM_INT);
                         $stmt->bindValue(':max_template_index_premium', $column->getPremiumMaxTemplateIndex(), \PDO::PARAM_INT);
                         $stmt->bindValue(':allowed_in_segments', $column->isAllowedInSegments(), \PDO::PARAM_INT);
                         $stmt->bindValue(':deprecated', $column->isDeprecated(), \PDO::PARAM_INT);
                         $stmt->execute();
                     }
                     $stmt = null;
                 }
                 if (array_key_exists('etag', $this->_responseParsed) && $this->_responseParsed['etag']) {
                     $newETag = $this->_responseParsed['etag'];
                 } else {
                     $responseHeader = $this->getResponseHeaderAsAssociativeArray();
                     if (array_key_exists('ETag', $responseHeader) && $responseHeader['ETag']) {
                         $newETag = $responseHeader['ETag'];
                     }
                 }
                 if ($newETag) {
                     self::_storeFetchData('google_analytics_api_columns', count($columns), $newETag);
                 }
             }
             if (!$columns) {
                 $columns = array();
                 $stmt = self::$_dbConn->query('SELECT * FROM google_analytics_api_columns');
                 $stmt->bindColumn('name', $name, \PDO::PARAM_STR);
                 $stmt->bindColumn('type', $type, \PDO::PARAM_STR);
                 $stmt->bindColumn('data_type', $dataType, \PDO::PARAM_STR);
                 $stmt->bindColumn('replaced_by', $replacement, \PDO::PARAM_STR);
                 $stmt->bindColumn('group', $group, \PDO::PARAM_STR);
                 $stmt->bindColumn('ui_name', $uiName, \PDO::PARAM_STR);
                 $stmt->bindColumn('description', $description, \PDO::PARAM_STR);
                 $stmt->bindColumn('calculation', $calculation, \PDO::PARAM_STR);
                 /* Null values get cast to zeros if I bind them as
                    integers, so we'll rely on the object's setter to take care
                    of the type casting. */
                 $stmt->bindColumn('min_template_index', $minTemplateIndex, \PDO::PARAM_STR);
                 $stmt->bindColumn('max_template_index', $maxTemplateIndex, \PDO::PARAM_STR);
                 $stmt->bindColumn('min_template_index_premium', $minTemplateIndexPremium, \PDO::PARAM_STR);
                 $stmt->bindColumn('max_template_index_premium', $maxTemplateIndexPremium, \PDO::PARAM_STR);
                 $stmt->bindColumn('allowed_in_segments', $allowedInSegments, \PDO::PARAM_BOOL);
                 $stmt->bindColumn('deprecated', $deprecated, \PDO::PARAM_BOOL);
                 while ($stmt->fetch(\PDO::FETCH_BOUND)) {
                     $column = new Column();
                     $column->setID('ga:' . $name);
                     $column->setReplacementColumn($replacement);
                     $column->setType($type);
                     $column->setDataType($dataType);
                     $column->setGroup($group);
                     $column->setUIName($uiName);
                     $column->setDescription($description);
                     $column->setCalculation($calculation);
                     if ($minTemplateIndex !== null) {
                         $column->setMinTemplateIndex($minTemplateIndex);
                     }
                     if ($maxTemplateIndex !== null) {
                         $column->setMaxTemplateIndex($maxTemplateIndex);
                     }
                     if ($minTemplateIndexPremium !== null) {
                         $column->setPremiumMinTemplateIndex($minTemplateIndexPremium);
                     }
                     if ($maxTemplateIndexPremium !== null) {
                         $column->setPremiumMaxTemplateIndex($maxTemplateIndexPremium);
                     }
                     $column->isAllowedInSegments($allowedInSegments);
                     $column->isDeprecated($deprecated);
                     $columns[] = $column;
                 }
             }
         } catch (\PDOException $e) {
             throw new RuntimeException('Caught database error while refreshing column metadata.', null, $e);
         }
     } else {
         $columns = $this->_makeRequest(new APIRequest('metadata/ga/columns'));
     }
     foreach ($columns as $column) {
         if ($column->getType() == 'DIMENSION') {
             $table =& self::$_dimensions;
             $list =& self::$_dimensionNames;
         } else {
             $table =& self::$_metrics;
             $list =& self::$_metricNames;
         }
         $name = $column->getName();
         $table[$name] = $column;
         if (!$column->isDeprecated()) {
             $list[] = $name;
         }
     }
     usort(self::$_dimensionNames, 'strcasecmp');
     usort(self::$_metricNames, 'strcasecmp');
 }
Ejemplo n.º 5
0
 /**
  * Record can't be inserted cause its not new
  *
  * @expectedException CDbException
  */
 public function testInsertException1()
 {
     $col2 = new Column();
     $col2->COLUMN_NAME = 'test2';
     $col2->setDataType('varchar');
     $col2->setCollation('utf8_general_ci');
     $col2->size = 250;
     $column = array($col2);
     $table = array('TABLE_SCHEMA' => 'tabletest', 'TABLE_NAME' => 'tabletest3');
     // Load column definition
     $ta = Table::model()->findByPk($table);
     $ta->insert($column);
 }
Ejemplo n.º 6
0
 protected function getInternalColumns()
 {
     $columns = array();
     $columnPage = new Column();
     $columnPage->setName("TABLE_CATALOG");
     $columnPage->setDataType(DataType::VARCHAR());
     $columnPage->setLength(512);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("TABLE_SCHEMA");
     $columnPage->setDataType(DataType::VARCHAR());
     $columnPage->setLength(64);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("TABLE_NAME");
     $columnPage->setDataType(DataType::VARCHAR());
     $columnPage->setLength(64);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("TABLE_TYPE");
     $columnPage->setDataType(DataType::VARCHAR());
     $columnPage->setLength(64);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("ENGINE");
     $columnPage->setDataType(DataType::VARCHAR());
     $columnPage->setLength(64);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("VERSION");
     $columnPage->setDataType(DataType::BIGINT());
     $columnPage->setLength(21);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("ROW_FORMAT");
     $columnPage->setDataType(DataType::VARCHAR());
     $columnPage->setLength(10);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("TABLE_ROWS");
     $columnPage->setDataType(DataType::BIGINT());
     $columnPage->setLength(21);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("AVG_ROW_LENGTH");
     $columnPage->setDataType(DataType::BIGINT());
     $columnPage->setLength(21);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("DATA_LENGTH");
     $columnPage->setDataType(DataType::BIGINT());
     $columnPage->setLength(21);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("MAX_DATA_LENGTH");
     $columnPage->setDataType(DataType::BIGINT());
     $columnPage->setLength(21);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("INDEX_LENGTH");
     $columnPage->setDataType(DataType::BIGINT());
     $columnPage->setLength(21);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("DATA_FREE");
     $columnPage->setDataType(DataType::BIGINT());
     $columnPage->setLength(21);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("AUTO_INCREMENT");
     $columnPage->setDataType(DataType::BIGINT());
     $columnPage->setLength(21);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("CREATE_TIME");
     $columnPage->setDataType(DataType::DATETIME());
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("UPDATE_TIME");
     $columnPage->setDataType(DataType::DATETIME());
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("CHECK_TIME");
     $columnPage->setDataType(DataType::DATETIME());
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("TABLE_COLLATION");
     $columnPage->setDataType(DataType::VARCHAR());
     $columnPage->setLength(32);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("CHECKSUM");
     $columnPage->setDataType(DataType::BIGINT());
     $columnPage->setLength(21);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("CREATE_OPTIONS");
     $columnPage->setDataType(DataType::VARCHAR());
     $columnPage->setLength(32);
     $columns[$columnPage->getName()] = clone $columnPage;
     $columnPage->setName("TABLE_COMMENT");
     $columnPage->setDataType(DataType::VARCHAR());
     $columnPage->setLength(32);
     $columns[$columnPage->getName()] = clone $columnPage;
     return $columns;
 }
Ejemplo n.º 7
0
 /**
  * tests to insert a new Column with wrong Name
  */
 public function testAlterWrongCOLUMNNAME()
 {
     $col = new Column();
     $col->TABLE_SCHEMA = 'columntest';
     $col->TABLE_NAME = 'test';
     $col->COLUMN_NAME = 'test \'`';
     $col->setDataType('float');
     $col->COLUMN_DEFAULT = 1;
     $col->size = 10;
     $col->scale = 5;
     $this->assertFalse($col->insert());
 }