当前位置: 首页>>代码示例>>PHP>>正文


PHP CakeSchema::compare方法代码示例

本文整理汇总了PHP中CakeSchema::compare方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeSchema::compare方法的具体用法?PHP CakeSchema::compare怎么用?PHP CakeSchema::compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CakeSchema的用法示例。


在下文中一共展示了CakeSchema::compare方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _update

 /**
  * Update database with Schema object
  * Should be called via the run method
  *
  * @param CakeSchema $Schema
  * @param string $table
  * @return void
  */
 protected function _update(&$Schema, $table = null)
 {
     $db = ConnectionManager::getDataSource($this->Schema->connection);
     $this->out(__d('cake_console', 'Comparing Database to Schema...'));
     $options = array();
     if (isset($this->params['force'])) {
         $options['models'] = false;
     }
     $Old = $this->Schema->read($options);
     $compare = $this->Schema->compare($Old, $Schema);
     $contents = array();
     if (empty($table)) {
         foreach ($compare as $table => $changes) {
             $contents[$table] = $db->alterSchema(array($table => $changes), $table);
         }
     } elseif (isset($compare[$table])) {
         $contents[$table] = $db->alterSchema(array($table => $compare[$table]), $table);
     }
     if (empty($contents)) {
         $this->out(__d('cake_console', 'Schema is up to date.'));
         $this->_stop();
     }
     $this->out("\n" . __d('cake_console', 'The following statements will run.'));
     $this->out(array_map('trim', $contents));
     if ('y' == $this->in(__d('cake_console', 'Are you sure you want to alter the tables?'), array('y', 'n'), 'n')) {
         $this->out();
         $this->out(__d('cake_console', 'Updating Database...'));
         $this->_run($contents, 'update', $Schema);
     }
     $this->out(__d('cake_console', 'End update.'));
 }
开发者ID:sanyaade-machine-learning,项目名称:Catool,代码行数:39,代码来源:SchemaShell.php

示例2: testAlteringTwoTables

 /**
  * test alterSchema on two tables.
  *
  * @return void
  */
 public function testAlteringTwoTables()
 {
     $schema1 = new CakeSchema(array('name' => 'AlterTest1', 'connection' => 'test', 'altertest' => array('id' => array('type' => 'integer', 'null' => false, 'default' => 0), 'name' => array('type' => 'string', 'null' => false, 'length' => 50)), 'other_table' => array('id' => array('type' => 'integer', 'null' => false, 'default' => 0), 'name' => array('type' => 'string', 'null' => false, 'length' => 50))));
     $schema2 = new CakeSchema(array('name' => 'AlterTest1', 'connection' => 'test', 'altertest' => array('id' => array('type' => 'integer', 'null' => false, 'default' => 0), 'field_two' => array('type' => 'string', 'null' => false, 'length' => 50)), 'other_table' => array('id' => array('type' => 'integer', 'null' => false, 'default' => 0), 'field_two' => array('type' => 'string', 'null' => false, 'length' => 50))));
     $result = $this->db->alterSchema($schema2->compare($schema1));
     $this->assertEquals(2, substr_count($result, 'field_two'), 'Too many fields');
     $this->assertFalse(strpos(';ALTER', $result), 'Too many semi colons');
 }
开发者ID:jeffersongoncalves,项目名称:estudos,代码行数:13,代码来源:PostgresTest.php

示例3: testAlterIndexes

 /**
  * Test the alter index capabilities of postgres
  *
  * @access public
  * @return void
  */
 function testAlterIndexes()
 {
     $this->db->cacheSources = false;
     $schema1 = new CakeSchema(array('name' => 'AlterTest1', 'connection' => 'test_suite', 'altertest' => array('id' => array('type' => 'integer', 'null' => false, 'default' => 0), 'name' => array('type' => 'string', 'null' => false, 'length' => 50), 'group1' => array('type' => 'integer', 'null' => true), 'group2' => array('type' => 'integer', 'null' => true))));
     $this->db->query($this->db->createSchema($schema1));
     $schema2 = new CakeSchema(array('name' => 'AlterTest2', 'connection' => 'test_suite', 'altertest' => array('id' => array('type' => 'integer', 'null' => false, 'default' => 0), 'name' => array('type' => 'string', 'null' => false, 'length' => 50), 'group1' => array('type' => 'integer', 'null' => true), 'group2' => array('type' => 'integer', 'null' => true), 'indexes' => array('name_idx' => array('column' => 'name', 'unique' => 0), 'group_idx' => array('column' => 'group1', 'unique' => 0), 'compound_idx' => array('column' => array('group1', 'group2'), 'unique' => 0), 'PRIMARY' => array('column' => 'id', 'unique' => 1)))));
     $this->db->query($this->db->alterSchema($schema2->compare($schema1)));
     $indexes = $this->db->index('altertest');
     $this->assertEqual($schema2->tables['altertest']['indexes'], $indexes);
     // Change three indexes, delete one and add another one
     $schema3 = new CakeSchema(array('name' => 'AlterTest3', 'connection' => 'test_suite', 'altertest' => array('id' => array('type' => 'integer', 'null' => false, 'default' => 0), 'name' => array('type' => 'string', 'null' => false, 'length' => 50), 'group1' => array('type' => 'integer', 'null' => true), 'group2' => array('type' => 'integer', 'null' => true), 'indexes' => array('name_idx' => array('column' => 'name', 'unique' => 1), 'group_idx' => array('column' => 'group2', 'unique' => 0), 'compound_idx' => array('column' => array('group2', 'group1'), 'unique' => 0), 'another_idx' => array('column' => array('group1', 'name'), 'unique' => 0)))));
     $this->db->query($this->db->alterSchema($schema3->compare($schema2)));
     $indexes = $this->db->index('altertest');
     $this->assertEqual($schema3->tables['altertest']['indexes'], $indexes);
     // Compare us to ourself.
     $this->assertEqual($schema3->compare($schema3), array());
     // Drop the indexes
     $this->db->query($this->db->alterSchema($schema1->compare($schema3)));
     $indexes = $this->db->index('altertest');
     $this->assertEqual(array(), $indexes);
     $this->db->query($this->db->dropSchema($schema1));
 }
开发者ID:evrard,项目名称:cakephp2x,代码行数:28,代码来源:dbo_postgres.test.php

示例4: testCompareEmptyStringAndNull

 /**
  * test comparing '' and null and making sure they are different.
  *
  * @return void
  */
 public function testCompareEmptyStringAndNull()
 {
     $One = new CakeSchema(array('posts' => array('id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), 'name' => array('type' => 'string', 'null' => false, 'default' => ''))));
     $Two = new CakeSchema(array('posts' => array('id' => array('type' => 'integer', 'null' => false, 'default' => null, 'key' => 'primary'), 'name' => array('type' => 'string', 'null' => false, 'default' => null))));
     $compare = $One->compare($Two);
     $expected = array('posts' => array('change' => array('name' => array('type' => 'string', 'null' => false, 'default' => null))));
     $this->assertEquals($expected, $compare);
 }
开发者ID:jgera,项目名称:orangescrum,代码行数:13,代码来源:CakeSchemaTest.php

示例5: afterSave

 /**
  * afterSave method
  *
  * If a default has just been saved check the db and update the table if the db default is different.
  *
  * @return void
  * @access public
  */
 function afterSave()
 {
     if (isset($this->data['Enum']['default']) && $this->data['Enum']['default']) {
         $conditions['type'] = isset($this->data['Enum']['type']) ? $this->data['Enum']['type'] : $this->field('type');
         $conditions['NOT']['Enum.id'] = $this->id;
         $this->updateAll(array('default' => 'false'), $conditions);
         $default = isset($this->data['Enum']['value']) ? $this->data['Enum']['value'] : $this->field('value');
         if ($default) {
             $db =& ConnectionManager::getDataSource($this->useDbConfig);
             App::import('Model', 'CakeSchema');
             $Schema = new CakeSchema(array('connection' => $this->useDbConfig));
             $update = $current = $Schema->read(array('models' => false));
             list($model, $field) = explode('.', $conditions['type']);
             $table = Inflector::tableize($model);
             if (isset($update['tables'][$table][$field])) {
                 $update['tables'][$table][$field]['default'] = $default;
                 $update['tables'][$table][$field]['null'] = true;
                 $compare = $Schema->compare($current, $update);
                 foreach ($compare as $table => $changes) {
                     $db->execute($db->alterSchema(array($table => $changes), $table));
                 }
                 Cache::delete($this->useDbConfig . '_' . $table, '_cake_model_');
             }
         }
     }
 }
开发者ID:razzman,项目名称:mi_enums,代码行数:34,代码来源:Enum.php


注:本文中的CakeSchema::compare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。