Exemplo n.º 1
0
 /**
  * 分类
  */
 private function categorySitemap()
 {
     $criteria = new CDbCriteria();
     $criteria->condition = 'classify=:category';
     $criteria->params = array(':category' => $this->classify);
     $criteria->limit = $this->limitPerPage;
     $criteria->offset = $this->pageStart;
     $result = Column::model()->findAll($criteria);
     foreach ($result as $k => $v) {
         $this->categoryItems[] = array('url' => $this->webSiteTitle . '/posts/col-' . $v->id . '.html', 'date' => date(DATE_W3C, time()));
     }
 }
Exemplo n.º 2
0
 /**
  * Loads the current table.
  *
  * @return	Table
  */
 public function loadTable()
 {
     if (is_null($this->_table)) {
         $pk = array('TABLE_SCHEMA' => $this->schema, 'TABLE_NAME' => $this->table);
         $this->_table = Table::model()->findByPk($pk);
         $this->_table->columns = Column::model()->findAllByAttributes($pk);
         if (is_null($this->_table)) {
             throw new CHttpException(500, 'The requested table does not exist.');
         }
     }
     return $this->_table;
 }
Exemplo n.º 3
0
	/**
	 * Returns the data model based on the primary key given in the GET variable.
	 * If the data model is not found, an HTTP exception will be raised.
	 * @param integer the ID of the model to be loaded
	 */
	public function loadModel($id)
	{
		$model=Column::model()->findByPk((int)$id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}
Exemplo n.º 4
0
 /**
  * Exports all rows of the given array and writes the dump to the output buffer.
  *
  * @param	array					array with identifiers of rows
  */
 private function exportRowData()
 {
     $db = Yii::app()->db;
     $pdo = $db->getPdoInstance();
     // Columns
     $cols = Column::model()->findAllByAttributes(array('TABLE_NAME' => $this->table, 'TABLE_SCHEMA' => $this->schema));
     $blobCols = array();
     // Create insert statement
     if ($this->settings['completeInserts']) {
         $columns = array();
         $i = 0;
         foreach ($cols as $col) {
             $columns[] = $db->quoteColumnName($col->COLUMN_NAME);
             if (in_array(DataType::getBaseType($col->DATA_TYPE), array('smallblob', 'blob', 'mediumblob', 'longblob'))) {
                 $blobCols[] = $i;
             }
             $i++;
         }
         $columns = ' (' . implode(', ', $columns) . ')';
     } else {
         $columns = '';
     }
     $insert = $this->settings['insertCommand'] . ($this->settings['delayedInserts'] ? ' DELAYED' : '') . ($this->settings['ignoreInserts'] ? ' IGNORE' : '') . ' INTO ' . $db->quoteTableName($this->table) . $columns . ' VALUES';
     // Find all rows
     $rowCount = count($this->rows);
     // Settings
     $hexBlobs = $this->settings['hexBlobs'];
     $rowsPerInsert = (int) $this->settings['rowsPerInsert'];
     // Cycle rows
     $i = 0;
     $k = 1;
     foreach ($this->rows as $row) {
         // Add comment
         if ($i == 0) {
             $this->comment('Data for table ' . $db->quoteTableName($this->table));
             echo "\n\n";
             echo $insert;
         }
         $attributes = $row->getAttributes();
         SqlUtil::FixRow($attributes);
         // Escape all contents
         foreach ($attributes as $key => $value) {
             if ($value === null) {
                 $attributes[$key] = 'NULL';
             } elseif ($hexBlobs && in_array($key, $blobCols) && $value) {
                 $attributes[$key] = '0x' . bin2hex($value);
             } else {
                 $attributes[$key] = $pdo->quote($value);
             }
         }
         // Add this row
         echo "\n  (", implode(', ', $attributes), ')';
         if ($i == $rowCount - 1) {
             echo ";\n\n";
         } elseif ($k == $rowsPerInsert) {
             echo ";\n\n", $insert;
             $k = 0;
         } else {
             echo ',';
         }
         $i++;
         $k++;
     }
 }
Exemplo n.º 5
0
 /**
  * Loads the current view.
  *
  * @return	View
  */
 public function loadView()
 {
     if (is_null($this->_view)) {
         $pk = array('TABLE_SCHEMA' => $this->schema, 'TABLE_NAME' => $this->view);
         $this->_view = View::model()->findByPk($pk);
         $this->_view->columns = Column::model()->findAllByAttributes($pk);
         if (is_null($this->_view)) {
             throw new CHttpException(500, 'The requested view does not exist.');
         }
     }
     return $this->_view;
 }
Exemplo n.º 6
0
 /**
  * Exports all rows of the given array and writes the dump to the output buffer.
  *
  * @param	array					array with identifiers of rows
  */
 private function exportRowData()
 {
     $db = Yii::app()->db;
     $pdo = $db->getPdoInstance();
     // Columns
     $cols = Column::model()->findAllByAttributes(array('TABLE_NAME' => $this->table, 'TABLE_SCHEMA' => $this->schema));
     $blobCols = array();
     $columns = array();
     $i = 0;
     foreach ($cols as $col) {
         $columns[] = $db->quoteColumnName($col->COLUMN_NAME);
         if (in_array(DataType::getBaseType($col->DATA_TYPE), array('smallblob', 'blob', 'mediumblob', 'longblob'))) {
             $blobCols[] = $i;
         }
         $i++;
     }
     $columns = implode($this->settings['fieldTerminator'], $columns);
     $insert = "";
     // Find all rows
     $rowCount = count($this->rows);
     // Settings
     $hexBlobs = $this->settings['hexBlobs'];
     $rowsPerInsert = (int) $this->settings['rowsPerInsert'];
     // Cycle rows
     $i = 0;
     $k = 1;
     foreach ($this->rows as $row) {
         if ($i == 0 && $this->settings['fieldsFirstRow']) {
             echo $columns;
         }
         $attributes = $row->getAttributes();
         SqlUtil::FixRow($attributes);
         // Escape all contents
         foreach ($attributes as $key => $value) {
             if ($value === null) {
                 $attributes[$key] = 'NULL';
             } elseif ($hexBlobs && in_array($key, $blobCols) && $value) {
                 $attributes[$key] = '0x' . bin2hex($value);
             } else {
                 $attributes[$key] = $this->settings['fieldEncloseString'] . addcslashes($value, $this->settings['fieldEncloseString']) . $this->settings['fieldEncloseString'];
             }
         }
         echo "\n", implode($this->settings['fieldTerminator'], $attributes);
         if ($i == $rowCount - 1) {
             echo "\n\n";
         }
         $i++;
         $k++;
     }
 }
Exemplo n.º 7
0
 public function getOne($keyid, $return = '')
 {
     if (!$keyid) {
         return false;
     }
     $item = Column::model()->findByPk($keyid);
     if ($return != '') {
         return $item[$return];
     }
     return $item;
 }
Exemplo n.º 8
0
 public function actionDrop()
 {
     $columns = (array) $_POST['column'];
     $response = new AjaxResponse();
     $droppedColumns = $droppedSqls = array();
     foreach ($columns as $column) {
         $pk = array('TABLE_SCHEMA' => $this->schema, 'TABLE_NAME' => $this->table, 'COLUMN_NAME' => $column);
         $column = Column::model()->findByPk($pk);
         $column->throwExceptions = true;
         try {
             $sql = $column->delete();
             $droppedColumns[] = $column->COLUMN_NAME;
             $droppedSqls[] = $sql;
         } catch (DbException $ex) {
             $response->addNotification('error', Yii::t('core', 'errorDropColumn', array('{col}' => $column->COLUMN_NAME)), null, $ex->getText());
             $response->refresh = true;
         }
     }
     $count = count($droppedColumns);
     if ($count > 0) {
         $response->addNotification('success', Yii::t('core', 'successDropColumn', array($count, '{col}' => $droppedColumns[0], '{colCount}' => $count)), $count > 1 ? implode(', ', $droppedColumns) : null, implode("\n", $droppedSqls));
     }
     $this->sendJSON($response);
 }
Exemplo n.º 9
0
 /**
  * Test to create a Table
  */
 public function testCreateTable()
 {
     $col1 = new Column();
     $col1->COLUMN_NAME = 'test1';
     $col1->setDataType('int');
     $col1->setAutoIncrement(true);
     $col1->setIsNullable(false);
     $col1->size = 20;
     $col1->createPrimaryKey = true;
     $col2 = new Column();
     $col2->COLUMN_NAME = 'test2';
     $col2->setDataType('varchar');
     $col2->setCollation('utf8_general_ci');
     $col2->size = 250;
     $columns = array($col1, $col2);
     $table = new Table();
     // Set some properties and save
     $table->TABLE_NAME = 'innodb2';
     $table->TABLE_SCHEMA = 'tabletest';
     $table->optionChecksum = 1;
     $table->optionDelayKeyWrite = 1;
     $table->optionPackKeys = 0;
     $table->ENGINE = 'MyISAM';
     $table->TABLE_COLLATION = 'utf8_general_ci';
     $table->comment = 'mein testkommentar';
     $table->columns = $columns;
     $table->insert();
     $this->assertTrue(is_string($table->showCreateTable));
     $pk = array('TABLE_SCHEMA' => 'tabletest', 'TABLE_NAME' => 'innodb2', 'COLUMN_NAME' => 'test1');
     // Load column definition
     $col = Column::model()->findByPk($pk);
     $this->assertEquals('test1', $col->COLUMN_NAME);
     $this->assertEquals('int', $col->getDataType());
     $this->assertTrue($col->getAutoIncrement());
     $this->assertFalse($col->getIsNullable());
     $this->assertTrue($col->getIsPartOfPrimaryKey());
     $this->assertEquals(20, $col->size);
     $pk = array('TABLE_SCHEMA' => 'tabletest', 'TABLE_NAME' => 'innodb2', 'COLUMN_NAME' => 'test2');
     // Load column definition
     $col = Column::model()->findByPk($pk);
     $this->assertEquals('test2', $col->COLUMN_NAME);
     $this->assertEquals('varchar', $col->getDataType());
     $this->assertFalse($col->getAutoIncrement());
     $this->assertFalse($col->getIsNullable());
     $this->assertFalse($col->getIsPartOfPrimaryKey());
     $this->assertEquals('utf8_general_ci', $col->getCollation());
     $this->assertEquals(250, $col->size);
 }
Exemplo n.º 10
0
 /**
  * Record can't be inserted cause its not new
  *
  * @expectedException CDbException
  */
 public function testInsertNotNew()
 {
     $pk = array('TABLE_SCHEMA' => 'columntest', 'TABLE_NAME' => 'test', 'COLUMN_NAME' => 'test5');
     // Load column definition
     $col = Column::model()->findByPk($pk);
     $col->insert();
 }