當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DboSource::readTableParameters方法代碼示例

本文整理匯總了PHP中DboSource::readTableParameters方法的典型用法代碼示例。如果您正苦於以下問題:PHP DboSource::readTableParameters方法的具體用法?PHP DboSource::readTableParameters怎麽用?PHP DboSource::readTableParameters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DboSource的用法示例。


在下文中一共展示了DboSource::readTableParameters方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testReadTableParameters

 /**
  * testReadTableParameters method
  *
  * @access public
  * @return void
  */
 function testReadTableParameters()
 {
     $this->Dbo->cacheSources = $this->Dbo->testing = false;
     $tableName = 'tinyint_' . uniqid();
     $this->Dbo->rawQuery('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;');
     $result = $this->Dbo->readTableParameters($tableName);
     $this->Dbo->rawQuery('DROP TABLE ' . $this->Dbo->fullTableName($tableName));
     $expected = array('charset' => 'utf8', 'collate' => 'utf8_unicode_ci', 'engine' => 'InnoDB');
     $this->assertEqual($result, $expected);
     $this->Dbo->rawQuery('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=MyISAM DEFAULT CHARSET=cp1250 COLLATE=cp1250_general_ci;');
     $result = $this->Dbo->readTableParameters($tableName);
     $this->Dbo->rawQuery('DROP TABLE ' . $this->Dbo->fullTableName($tableName));
     $expected = array('charset' => 'cp1250', 'collate' => 'cp1250_general_ci', 'engine' => 'MyISAM');
     $this->assertEqual($result, $expected);
 }
開發者ID:no2key,項目名稱:Web-Framework-Benchmark,代碼行數:21,代碼來源:dbo_mysql.test.php

示例2: _alterTable

 /**
  * Alter Table method
  *
  * @param string $type Type of operation to be done
  * @param array $tables List of tables and fields
  * @return bool Return true in case of success, otherwise false
  * @throws MigrationException
  */
 protected function _alterTable($type, $tables)
 {
     foreach ($tables as $table => $fields) {
         $indexes = array();
         if (isset($fields['indexes'])) {
             $indexes = $fields['indexes'];
             unset($fields['indexes']);
         }
         if ($type === 'drop') {
             $this->_alterIndexes($indexes, $type, $table);
         }
         foreach ($fields as $field => $col) {
             $model = new Model(array('table' => $table, 'ds' => $this->connection));
             $tableFields = $this->db->describe($model);
             $tableFields['indexes'] = $this->db->index($model);
             $tableFields['tableParameters'] = $this->db->readTableParameters($this->db->fullTableName($model, false, false));
             if ($type === 'drop') {
                 $field = $col;
             }
             if ($type === 'rename') {
                 $data = array('table' => $table, 'old_name' => $field, 'new_name' => $col);
             } else {
                 $data = array('table' => $table, 'field' => $field);
             }
             $callbackData = $data;
             if ($this->_invokePrecheck('beforeAction', $type . '_field', $data)) {
                 switch ($type) {
                     case 'add':
                         $sql = $this->db->alterSchema(array($table => array('add' => array($field => $col))));
                         break;
                     case 'drop':
                         $sql = $this->db->alterSchema(array($table => array('drop' => array($field => array()))));
                         break;
                     case 'change':
                         if (!isset($col['type']) || $col['type'] == $tableFields[$field]['type']) {
                             $def = array_merge($tableFields[$field], $col);
                         } else {
                             $def = $col;
                         }
                         if (!empty($def['length']) && !empty($col['type']) && (substr($col['type'], 0, 4) === 'date' || substr($col['type'], 0, 4) === 'time')) {
                             $def['length'] = null;
                         }
                         $sql = $this->db->alterSchema(array($table => array('change' => array($field => $def))));
                         break;
                     case 'rename':
                         $data = array();
                         if (array_key_exists($field, $tableFields)) {
                             $data = $tableFields[$field];
                         }
                         $sql = $this->db->alterSchema(array($table => array('change' => array($field => array_merge($data, array('name' => $col))))));
                         break;
                 }
                 if ($this->dry) {
                     $this->logQuery($sql);
                     continue;
                 }
                 $this->_invokeCallbacks('beforeAction', $type . '_field', $callbackData);
                 if (@$this->db->execute($sql) === false) {
                     throw new MigrationException($this, sprintf(__d('migrations', 'SQL Error: %s'), $this->db->error));
                 }
                 $this->_invokeCallbacks('afterAction', $type . '_field', $callbackData);
             }
         }
         if ($type !== 'drop') {
             $this->_alterIndexes($indexes, $type, $table);
         }
     }
     return true;
 }
開發者ID:rogeriogarcia,項目名稱:migrations,代碼行數:77,代碼來源:CakeMigration.php


注:本文中的DboSource::readTableParameters方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。