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


PHP xmldb_index::setFields方法代码示例

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


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

示例1: check_table

 protected function check_table(xmldb_table $xmldb_table, array $metacolumns)
 {
     global $DB;
     $dbman = $DB->get_manager();
     $o = '';
     $missing_indexes = array();
     // Keys
     if ($xmldb_keys = $xmldb_table->getKeys()) {
         $o .= '        <ul>';
         foreach ($xmldb_keys as $xmldb_key) {
             $o .= '            <li>' . $this->str['key'] . ': ' . $xmldb_key->readableInfo() . ' ';
             // Primaries are skipped
             if ($xmldb_key->getType() == XMLDB_KEY_PRIMARY) {
                 $o .= '<font color="green">' . $this->str['ok'] . '</font></li>';
                 continue;
             }
             // If we aren't creating the keys or the key is a XMLDB_KEY_FOREIGN (not underlying index generated
             // automatically by the RDBMS) create the underlying (created by us) index (if doesn't exists)
             if (!$dbman->generator->getKeySQL($xmldb_table, $xmldb_key) || $xmldb_key->getType() == XMLDB_KEY_FOREIGN) {
                 // Create the interim index
                 $xmldb_index = new xmldb_index('anyname');
                 $xmldb_index->setFields($xmldb_key->getFields());
                 switch ($xmldb_key->getType()) {
                     case XMLDB_KEY_UNIQUE:
                     case XMLDB_KEY_FOREIGN_UNIQUE:
                         $xmldb_index->setUnique(true);
                         break;
                     case XMLDB_KEY_FOREIGN:
                         $xmldb_index->setUnique(false);
                         break;
                 }
                 // Check if the index exists in DB
                 if ($dbman->index_exists($xmldb_table, $xmldb_index)) {
                     $o .= '<font color="green">' . $this->str['ok'] . '</font>';
                 } else {
                     $o .= '<font color="red">' . $this->str['missing'] . '</font>';
                     // Add the missing index to the list
                     $obj = new stdClass();
                     $obj->table = $xmldb_table;
                     $obj->index = $xmldb_index;
                     $missing_indexes[] = $obj;
                 }
             }
             $o .= '</li>';
         }
         $o .= '        </ul>';
     }
     // Indexes
     if ($xmldb_indexes = $xmldb_table->getIndexes()) {
         $o .= '        <ul>';
         foreach ($xmldb_indexes as $xmldb_index) {
             $o .= '            <li>' . $this->str['index'] . ': ' . $xmldb_index->readableInfo() . ' ';
             // Check if the index exists in DB
             if ($dbman->index_exists($xmldb_table, $xmldb_index)) {
                 $o .= '<font color="green">' . $this->str['ok'] . '</font>';
             } else {
                 $o .= '<font color="red">' . $this->str['missing'] . '</font>';
                 // Add the missing index to the list
                 $obj = new stdClass();
                 $obj->table = $xmldb_table;
                 $obj->index = $xmldb_index;
                 $missing_indexes[] = $obj;
             }
             $o .= '</li>';
         }
         $o .= '        </ul>';
     }
     return array($o, $missing_indexes);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:69,代码来源:check_indexes.class.php

示例2: getRenameKeySQL

 /**
  * Given one xmldb_table and one xmldb_key, return the SQL statements needed to rename the key in the table
  * Experimental! Shouldn't be used at all!
  *
  * @param xmldb_table $xmldb_table The table related to $xmldb_key.
  * @param xmldb_key $xmldb_key The xmldb_key to rename.
  * @param string $newname The xmldb_key's new name.
  * @return array SQL statement to rename the xmldb_key.
  */
 public function getRenameKeySQL($xmldb_table, $xmldb_key, $newname)
 {
     $results = array();
     /// Get the real key name
     $dbkeyname = $this->mdb->get_manager()->find_key_name($xmldb_table, $xmldb_key);
     /// Check we are really generating this type of keys
     if ($xmldb_key->getType() == XMLDB_KEY_PRIMARY && !$this->primary_keys || $xmldb_key->getType() == XMLDB_KEY_UNIQUE && !$this->unique_keys || $xmldb_key->getType() == XMLDB_KEY_FOREIGN && !$this->foreign_keys || $xmldb_key->getType() == XMLDB_KEY_FOREIGN_UNIQUE && !$this->unique_keys && !$this->foreign_keys) {
         /// We aren't generating this type of keys, delegate to child indexes
         $xmldb_index = new xmldb_index($xmldb_key->getName());
         $xmldb_index->setFields($xmldb_key->getFields());
         return $this->getRenameIndexSQL($xmldb_table, $xmldb_index, $newname);
     }
     /// Arrived here so we are working with keys, lets rename them
     /// Replace TABLENAME and KEYNAME as needed
     $renamesql = str_replace('TABLENAME', $this->getTableName($xmldb_table), $this->rename_key_sql);
     $renamesql = str_replace('OLDKEYNAME', $dbkeyname, $renamesql);
     $renamesql = str_replace('NEWKEYNAME', $newname, $renamesql);
     /// Some DB doesn't support key renaming so this can be empty
     if ($renamesql) {
         $results[] = $renamesql;
     }
     return $results;
 }
开发者ID:,项目名称:,代码行数:32,代码来源:

示例3: invoke


//.........这里部分代码省略.........
         $uniquearr = array_unique($fieldsarr);
         if (count($fieldsarr) != count($uniquearr)) {
             $errors[] = $this->str['duplicatefieldsused'];
         }
         /// Check that all the fields in belong to the table
         foreach ($fieldsarr as $field) {
             if (!$table->getField($field)) {
                 $errors[] = $this->str['fieldsnotintable'];
                 break;
             }
         }
         /// Check that there isn't any key using exactly the same fields
         $tablekeys = $table->getKeys();
         if ($tablekeys) {
             foreach ($tablekeys as $tablekey) {
                 $keyfieldsarr = $tablekey->getFields();
                 /// Compare both arrays, looking for diferences
                 $diferences = array_merge(array_diff($fieldsarr, $keyfieldsarr), array_diff($keyfieldsarr, $fieldsarr));
                 if (empty($diferences)) {
                     $errors[] = $this->str['fieldsusedinkey'];
                     break;
                 }
             }
         }
         /// Check that there isn't any index using exactlt the same fields
         $tableindexes = $table->getIndexes();
         if ($tableindexes) {
             foreach ($tableindexes as $tableindex) {
                 /// Skip checking against itself
                 if ($indexparam == $tableindex->getName()) {
                     continue;
                 }
                 $indexfieldsarr = $tableindex->getFields();
                 /// Compare both arrays, looking for diferences
                 $diferences = array_merge(array_diff($fieldsarr, $indexfieldsarr), array_diff($indexfieldsarr, $fieldsarr));
                 if (empty($diferences)) {
                     $errors[] = $this->str['fieldsusedinindex'];
                     break;
                 }
             }
         }
     }
     if (!empty($errors)) {
         $tempindex = new xmldb_index($name);
         $tempindex->setUnique($unique);
         $tempindex->setFields($fieldsarr);
         /// Prepare the output
         $site = get_site();
         $navlinks = array();
         $navlinks[] = array('name' => $this->str['administration'], 'link' => '../index.php', 'type' => 'misc');
         $navlinks[] = array('name' => 'XMLDB', 'link' => 'index.php', 'type' => 'misc');
         $navigation = build_navigation($navlinks);
         print_header("{$site->shortname}: XMLDB", "{$site->fullname}", $navigation);
         notice('<p>' . implode(', ', $errors) . '</p>
                  <p>' . $tempindex->readableInfo() . '</p>', 'index.php?action=edit_index&amp;index=' . $index->getName() . '&amp;table=' . $table->getName() . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)));
         die;
         /// re-die :-P
     }
     /// Continue if we aren't under errors
     if (empty($errors)) {
         /// If there is one name change, do it, changing the prev and next
         /// atributes of the adjacent fields
         if ($indexparam != $name) {
             $index->setName($name);
             if ($index->getPrevious()) {
                 $prev =& $table->getIndex($index->getPrevious());
                 $prev->setNext($name);
                 $prev->setChanged(true);
             }
             if ($index->getNext()) {
                 $next =& $table->getIndex($index->getNext());
                 $next->setPrevious($name);
                 $next->setChanged(true);
             }
         }
         /// Set comment
         $index->setComment($comment);
         /// Set the rest of fields
         $index->setUnique($unique);
         $index->setFields($fieldsarr);
         /// If the hash has changed from the old one, change the version
         /// and mark the structure as changed
         $index->calculateHash(true);
         if ($oldhash != $index->getHash()) {
             $index->setChanged(true);
             $table->setChanged(true);
             /// Recalculate the structure hash
             $structure->calculateHash(true);
             $structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
             /// Mark as changed
             $structure->setChanged(true);
         }
         /// Launch postaction if exists (leave this here!)
         if ($this->getPostAction() && $result) {
             return $this->launch($this->getPostAction());
         }
     }
     /// Return ok if arrived here
     return $result;
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:101,代码来源:edit_index_save.class.php


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