Index.class.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * holds the database index class
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /**
  12. *
  13. * @package PhpMyAdmin
  14. * @since phpMyAdmin 3.0.0
  15. */
  16. class PMA_Index
  17. {
  18. /**
  19. * Class-wide storage container for indexes (caching, singleton)
  20. *
  21. * @var array
  22. */
  23. private static $_registry = array();
  24. /**
  25. * @var string The name of the schema
  26. */
  27. private $_schema = '';
  28. /**
  29. * @var string The name of the table
  30. */
  31. private $_table = '';
  32. /**
  33. * @var string The name of the index
  34. */
  35. private $_name = '';
  36. /**
  37. * Columns in index
  38. *
  39. * @var array
  40. */
  41. private $_columns = array();
  42. /**
  43. * The index method used (BTREE, SPATIAL, FULLTEXT, HASH, RTREE).
  44. *
  45. * @var string
  46. */
  47. private $_type = '';
  48. /**
  49. * The index choice (PRIMARY, UNIQUE, INDEX, SPATIAL, FULLTEXT)
  50. *
  51. * @var string
  52. */
  53. private $_choice = '';
  54. /**
  55. * Various remarks.
  56. *
  57. * @var string
  58. */
  59. private $_remarks = '';
  60. /**
  61. * Any comment provided for the index with a COMMENT attribute when the
  62. * index was created.
  63. *
  64. * @var string
  65. */
  66. private $_comment = '';
  67. /**
  68. * @var integer 0 if the index cannot contain duplicates, 1 if it can.
  69. */
  70. private $_non_unique = 0;
  71. /**
  72. * Indicates how the key is packed. NULL if it is not.
  73. *
  74. * @var string
  75. */
  76. private $_packed = null;
  77. /**
  78. * Constructor
  79. *
  80. * @param array $params parameters
  81. */
  82. public function __construct($params = array())
  83. {
  84. $this->set($params);
  85. }
  86. /**
  87. * Creates(if not already created) and returns the corresponding Index object
  88. *
  89. * @param string $schema database name
  90. * @param string $table table name
  91. * @param string $index_name index name
  92. *
  93. * @return object corresponding Index object
  94. */
  95. static public function singleton($schema, $table, $index_name = '')
  96. {
  97. PMA_Index::_loadIndexes($table, $schema);
  98. if (! isset(PMA_Index::$_registry[$schema][$table][$index_name])) {
  99. $index = new PMA_Index;
  100. if (strlen($index_name)) {
  101. $index->setName($index_name);
  102. PMA_Index::$_registry[$schema][$table][$index->getName()] = $index;
  103. }
  104. return $index;
  105. } else {
  106. return PMA_Index::$_registry[$schema][$table][$index_name];
  107. }
  108. }
  109. /**
  110. * returns an array with all indexes from the given table
  111. *
  112. * @param string $table table
  113. * @param string $schema schema
  114. *
  115. * @return array array of indexes
  116. */
  117. static public function getFromTable($table, $schema)
  118. {
  119. PMA_Index::_loadIndexes($table, $schema);
  120. if (isset(PMA_Index::$_registry[$schema][$table])) {
  121. return PMA_Index::$_registry[$schema][$table];
  122. } else {
  123. return array();
  124. }
  125. }
  126. /**
  127. * return primary if set, false otherwise
  128. *
  129. * @param string $table table
  130. * @param string $schema schema
  131. *
  132. * @return mixed primary index or false if no one exists
  133. */
  134. static public function getPrimary($table, $schema)
  135. {
  136. PMA_Index::_loadIndexes($table, $schema);
  137. if (isset(PMA_Index::$_registry[$schema][$table]['PRIMARY'])) {
  138. return PMA_Index::$_registry[$schema][$table]['PRIMARY'];
  139. } else {
  140. return false;
  141. }
  142. }
  143. /**
  144. * Load index data for table
  145. *
  146. * @param string $table table
  147. * @param string $schema schema
  148. *
  149. * @return boolean whether loading was successful
  150. */
  151. static private function _loadIndexes($table, $schema)
  152. {
  153. if (isset(PMA_Index::$_registry[$schema][$table])) {
  154. return true;
  155. }
  156. $_raw_indexes = PMA_DBI_get_table_indexes($schema, $table);
  157. foreach ($_raw_indexes as $_each_index) {
  158. $_each_index['Schema'] = $schema;
  159. if (! isset(PMA_Index::$_registry[$schema][$table][$_each_index['Key_name']])) {
  160. $key = new PMA_Index($_each_index);
  161. PMA_Index::$_registry[$schema][$table][$_each_index['Key_name']] = $key;
  162. } else {
  163. $key = PMA_Index::$_registry[$schema][$table][$_each_index['Key_name']];
  164. }
  165. $key->addColumn($_each_index);
  166. }
  167. return true;
  168. }
  169. /**
  170. * Add column to index
  171. *
  172. * @param array $params column params
  173. *
  174. * @return void
  175. */
  176. public function addColumn($params)
  177. {
  178. if (strlen($params['Column_name'])) {
  179. $this->_columns[$params['Column_name']] = new PMA_Index_Column($params);
  180. }
  181. }
  182. /**
  183. * Adds a list of columns to the index
  184. *
  185. * @param array $columns array containing details about the columns
  186. *
  187. * @return void
  188. */
  189. public function addColumns($columns)
  190. {
  191. $_columns = array();
  192. if (isset($columns['names'])) {
  193. // coming from form
  194. // $columns[names][]
  195. // $columns[sub_parts][]
  196. foreach ($columns['names'] as $key => $name) {
  197. $sub_part = isset($columns['sub_parts'][$key])
  198. ? $columns['sub_parts'][$key] : '';
  199. $_columns[] = array(
  200. 'Column_name' => $name,
  201. 'Sub_part' => $sub_part,
  202. );
  203. }
  204. } else {
  205. // coming from SHOW INDEXES
  206. // $columns[][name]
  207. // $columns[][sub_part]
  208. // ...
  209. $_columns = $columns;
  210. }
  211. foreach ($_columns as $column) {
  212. $this->addColumn($column);
  213. }
  214. }
  215. /**
  216. * Returns true if $column indexed in this index
  217. *
  218. * @param string $column the column
  219. *
  220. * @return boolean true if $column indexed in this index
  221. */
  222. public function hasColumn($column)
  223. {
  224. return isset($this->_columns[$column]);
  225. }
  226. /**
  227. * Sets index details
  228. *
  229. * @param array $params index details
  230. *
  231. * @return void
  232. */
  233. public function set($params)
  234. {
  235. if (isset($params['columns'])) {
  236. $this->addColumns($params['columns']);
  237. }
  238. if (isset($params['Schema'])) {
  239. $this->_schema = $params['Schema'];
  240. }
  241. if (isset($params['Table'])) {
  242. $this->_table = $params['Table'];
  243. }
  244. if (isset($params['Key_name'])) {
  245. $this->_name = $params['Key_name'];
  246. }
  247. if (isset($params['Index_type'])) {
  248. $this->_type = $params['Index_type'];
  249. }
  250. if (isset($params['Comment'])) {
  251. $this->_remarks = $params['Comment'];
  252. }
  253. if (isset($params['Index_comment'])) {
  254. $this->_comment = $params['Index_comment'];
  255. }
  256. if (isset($params['Non_unique'])) {
  257. $this->_non_unique = $params['Non_unique'];
  258. }
  259. if (isset($params['Packed'])) {
  260. $this->_packed = $params['Packed'];
  261. }
  262. if ('PRIMARY' == $this->_name) {
  263. $this->_choice = 'PRIMARY';
  264. } elseif ('FULLTEXT' == $this->_type) {
  265. $this->_choice = 'FULLTEXT';
  266. } elseif ('SPATIAL' == $this->_type) {
  267. $this->_choice = 'SPATIAL';
  268. } elseif ('0' == $this->_non_unique) {
  269. $this->_choice = 'UNIQUE';
  270. } else {
  271. $this->_choice = 'INDEX';
  272. }
  273. }
  274. /**
  275. * Returns the number of columns of the index
  276. *
  277. * @return integer the number of the columns
  278. */
  279. public function getColumnCount()
  280. {
  281. return count($this->_columns);
  282. }
  283. /**
  284. * Returns the index comment
  285. *
  286. * @return string index comment
  287. */
  288. public function getComment()
  289. {
  290. return $this->_comment;
  291. }
  292. /**
  293. * Returns index remarks
  294. *
  295. * @return string index remarks
  296. */
  297. public function getRemarks()
  298. {
  299. return $this->_remarks;
  300. }
  301. /**
  302. * Returns concatenated remarks and comment
  303. *
  304. * @return string concatenated remarks and comment
  305. */
  306. public function getComments()
  307. {
  308. $comments = $this->getRemarks();
  309. if (strlen($comments)) {
  310. $comments .= "\n";
  311. }
  312. $comments .= $this->getComment();
  313. return $comments;
  314. }
  315. /**
  316. * Returns index type ((BTREE, SPATIAL, FULLTEXT, HASH, RTREE)
  317. *
  318. * @return string index type
  319. */
  320. public function getType()
  321. {
  322. return $this->_type;
  323. }
  324. /**
  325. * Returns index choice (PRIMARY, UNIQUE, INDEX, SPATIAL, FULLTEXT)
  326. *
  327. * @return index choice
  328. */
  329. public function getChoice()
  330. {
  331. return $this->_choice;
  332. }
  333. /**
  334. * Return a list of all index choices
  335. *
  336. * @return array index choices
  337. */
  338. static public function getIndexChoices()
  339. {
  340. return array(
  341. 'PRIMARY',
  342. 'INDEX',
  343. 'UNIQUE',
  344. 'SPATIAL',
  345. 'FULLTEXT',
  346. );
  347. }
  348. /**
  349. * Returns HTML for the index choice selector
  350. *
  351. * @return string HTML for the index choice selector
  352. */
  353. public function generateIndexSelector()
  354. {
  355. $html_options = '';
  356. foreach (PMA_Index::getIndexChoices() as $each_index_choice) {
  357. if ($each_index_choice === 'PRIMARY'
  358. && $this->_choice !== 'PRIMARY'
  359. && PMA_Index::getPrimary($this->_table, $this->_schema)
  360. ) {
  361. // skip PRIMARY if there is already one in the table
  362. continue;
  363. }
  364. $html_options .= '<option value="' . $each_index_choice . '"'
  365. . (($this->_choice == $each_index_choice) ? ' selected="selected"' : '')
  366. . '>'. $each_index_choice . '</option>' . "\n";
  367. }
  368. return $html_options;
  369. }
  370. /**
  371. * Returns how the index is packed
  372. *
  373. * @return string how the index is packed
  374. */
  375. public function getPacked()
  376. {
  377. return $this->_packed;
  378. }
  379. /**
  380. * Returns 'No'/false if the index is not packed,
  381. * how the index is packed if packed
  382. *
  383. * @param boolean $as_text whether to output should be in text
  384. *
  385. * @return mixed how index is paked
  386. */
  387. public function isPacked($as_text = false)
  388. {
  389. if ($as_text) {
  390. $r = array(
  391. '0' => __('No'),
  392. '1' => __('Yes'),
  393. );
  394. } else {
  395. $r = array(
  396. '0' => false,
  397. '1' => true,
  398. );
  399. }
  400. if (null === $this->_packed) {
  401. return $r[0];
  402. }
  403. return $this->_packed;
  404. }
  405. /**
  406. * Returns integer 0 if the index cannot contain duplicates, 1 if it can
  407. *
  408. * @return integer 0 if the index cannot contain duplicates, 1 if it can
  409. */
  410. public function getNonUnique()
  411. {
  412. return $this->_non_unique;
  413. }
  414. /**
  415. * Returns whether the index is a 'Unique' index
  416. *
  417. * @param boolean $as_text whether to output should be in text
  418. *
  419. * @return mixed whether the index is a 'Unique' index
  420. */
  421. public function isUnique($as_text = false)
  422. {
  423. if ($as_text) {
  424. $r = array(
  425. '0' => __('Yes'),
  426. '1' => __('No'),
  427. );
  428. } else {
  429. $r = array(
  430. '0' => true,
  431. '1' => false,
  432. );
  433. }
  434. return $r[$this->_non_unique];
  435. }
  436. /**
  437. * Returns the name of the index
  438. *
  439. * @return string the name of the index
  440. */
  441. public function getName()
  442. {
  443. return $this->_name;
  444. }
  445. /**
  446. * Sets the name of the index
  447. *
  448. * @param string $name index name
  449. *
  450. * @return void
  451. */
  452. public function setName($name)
  453. {
  454. $this->_name = (string) $name;
  455. }
  456. /**
  457. * Returns the columns of the index
  458. *
  459. * @return array the columns of the index
  460. */
  461. public function getColumns()
  462. {
  463. return $this->_columns;
  464. }
  465. /**
  466. * Show index data
  467. *
  468. * @param string $table The table name
  469. * @param string $schema The schema name
  470. * @param boolean $print_mode Whether the output is for the print mode
  471. *
  472. * @return array Index collection array
  473. *
  474. * @access public
  475. */
  476. static public function getView($table, $schema, $print_mode = false)
  477. {
  478. $indexes = PMA_Index::getFromTable($table, $schema);
  479. $no_indexes_class = count($indexes) > 0 ? ' hide' : '';
  480. $no_indexes = "<div class='no_indexes_defined$no_indexes_class'>";
  481. $no_indexes .= PMA_Message::notice(__('No index defined!'))->getDisplay();
  482. $no_indexes .= '</div>';
  483. if (! $print_mode) {
  484. $r = '<fieldset class="index_info">';
  485. $r .= '<legend id="index_header">' . __('Indexes');
  486. $r .= PMA_Util::showMySQLDocu(
  487. 'optimization', 'optimizing-database-structure'
  488. );
  489. $r .= '</legend>';
  490. $r .= $no_indexes;
  491. if (count($indexes) < 1) {
  492. $r .= '</fieldset>';
  493. return $r;
  494. }
  495. $r .= PMA_Index::findDuplicates($table, $schema);
  496. } else {
  497. $r = '<h3>' . __('Indexes') . '</h3>';
  498. $r .= $no_indexes;
  499. if (count($indexes) < 1) {
  500. return $r;
  501. }
  502. }
  503. $r .= '<table id="table_index">';
  504. $r .= '<thead>';
  505. $r .= '<tr>';
  506. if (! $print_mode) {
  507. $r .= '<th colspan="2">' . __('Action') . '</th>';
  508. }
  509. $r .= '<th>' . __('Keyname') . '</th>';
  510. $r .= '<th>' . __('Type') . '</th>';
  511. $r .= '<th>' . __('Unique') . '</th>';
  512. $r .= '<th>' . __('Packed') . '</th>';
  513. $r .= '<th>' . __('Column') . '</th>';
  514. $r .= '<th>' . __('Cardinality') . '</th>';
  515. $r .= '<th>' . __('Collation') . '</th>';
  516. $r .= '<th>' . __('Null') . '</th>';
  517. if (PMA_MYSQL_INT_VERSION > 50500) {
  518. $r .= '<th>' . __('Comment') . '</th>';
  519. }
  520. $r .= '</tr>';
  521. $r .= '</thead>';
  522. $r .= '<tbody>';
  523. $odd_row = true;
  524. foreach ($indexes as $index) {
  525. $row_span = ' rowspan="' . $index->getColumnCount() . '" ';
  526. $r .= '<tr class="noclick ' . ($odd_row ? 'odd' : 'even') . '">';
  527. if (! $print_mode) {
  528. $this_params = $GLOBALS['url_params'];
  529. $this_params['index'] = $index->getName();
  530. $r .= '<td class="edit_index';
  531. $r .= ' ajax';
  532. $r .= '" ' . $row_span . '>'
  533. . ' <a class="';
  534. $r .= 'ajax';
  535. $r .= '" href="tbl_indexes.php' . PMA_generate_common_url($this_params)
  536. . '">' . PMA_Util::getIcon('b_edit.png', __('Edit')) . '</a>'
  537. . '</td>' . "\n";
  538. $this_params = $GLOBALS['url_params'];
  539. if ($index->getName() == 'PRIMARY') {
  540. $this_params['sql_query'] = 'ALTER TABLE '
  541. . PMA_Util::backquote($table)
  542. . ' DROP PRIMARY KEY;';
  543. $this_params['message_to_show']
  544. = __('The primary key has been dropped');
  545. $js_msg = PMA_jsFormat(
  546. 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY'
  547. );
  548. } else {
  549. $this_params['sql_query'] = 'ALTER TABLE '
  550. . PMA_Util::backquote($table) . ' DROP INDEX '
  551. . PMA_Util::backquote($index->getName()) . ';';
  552. $this_params['message_to_show'] = sprintf(
  553. __('Index %s has been dropped'), $index->getName()
  554. );
  555. $js_msg = PMA_jsFormat(
  556. 'ALTER TABLE ' . $table . ' DROP INDEX '
  557. . $index->getName() . ';'
  558. );
  559. }
  560. $r .= '<td ' . $row_span . '>';
  561. $r .= '<input type="hidden" class="drop_primary_key_index_msg"'
  562. . ' value="' . $js_msg . '" />';
  563. $r .= ' <a class="drop_primary_key_index_anchor';
  564. $r .= ' ajax';
  565. $r .= '" href="sql.php' . PMA_generate_common_url($this_params)
  566. . '" >'
  567. . PMA_Util::getIcon('b_drop.png', __('Drop')) . '</a>'
  568. . '</td>' . "\n";
  569. }
  570. if (! $print_mode) {
  571. $r .= '<th ' . $row_span . '>'
  572. . htmlspecialchars($index->getName())
  573. . '</th>';
  574. } else {
  575. $r .= '<td ' . $row_span . '>'
  576. . htmlspecialchars($index->getName())
  577. . '</td>';
  578. }
  579. $r .= '<td ' . $row_span . '>'
  580. . htmlspecialchars($index->getType())
  581. . '</td>';
  582. $r .= '<td ' . $row_span . '>' . $index->isUnique(true) . '</td>';
  583. $r .= '<td ' . $row_span . '>' . $index->isPacked(true) . '</td>';
  584. foreach ($index->getColumns() as $column) {
  585. if ($column->getSeqInIndex() > 1) {
  586. $r .= '<tr class="noclick ' . ($odd_row ? 'odd' : 'even') . '">';
  587. }
  588. $r .= '<td>' . htmlspecialchars($column->getName());
  589. if ($column->getSubPart()) {
  590. $r .= ' (' . $column->getSubPart() . ')';
  591. }
  592. $r .= '</td>';
  593. $r .= '<td>'
  594. . htmlspecialchars($column->getCardinality())
  595. . '</td>';
  596. $r .= '<td>'
  597. . htmlspecialchars($column->getCollation())
  598. . '</td>';
  599. $r .= '<td>'
  600. . htmlspecialchars($column->getNull(true))
  601. . '</td>';
  602. if (PMA_MYSQL_INT_VERSION > 50500
  603. && $column->getSeqInIndex() == 1) {
  604. $r .= '<td ' . $row_span . '>'
  605. . htmlspecialchars($index->getComments()) . '</td>';
  606. }
  607. $r .= '</tr>';
  608. } // end foreach $index['Sequences']
  609. $odd_row = ! $odd_row;
  610. } // end while
  611. $r .= '</tbody>';
  612. $r .= '</table>';
  613. if (! $print_mode) {
  614. $r .= '</fieldset>';
  615. }
  616. return $r;
  617. }
  618. public function getCompareData()
  619. {
  620. $data = array(
  621. // 'Non_unique' => $this->_non_unique,
  622. 'Packed' => $this->_packed,
  623. 'Index_type' => $this->_type,
  624. );
  625. foreach ($this->_columns as $column) {
  626. $data['columns'][] = $column->getCompareData();
  627. }
  628. return $data;
  629. }
  630. /**
  631. * Function to check over array of indexes and look for common problems
  632. *
  633. * @param string $table table name
  634. * @param string $schema schema name
  635. *
  636. * @return string Output HTML
  637. * @access public
  638. */
  639. static public function findDuplicates($table, $schema)
  640. {
  641. $indexes = PMA_Index::getFromTable($table, $schema);
  642. $output = '';
  643. // count($indexes) < 2:
  644. // there is no need to check if there less than two indexes
  645. if (count($indexes) < 2) {
  646. return $output;
  647. }
  648. // remove last index from stack and ...
  649. while ($while_index = array_pop($indexes)) {
  650. // ... compare with every remaining index in stack
  651. foreach ($indexes as $each_index) {
  652. if ($each_index->getCompareData() !== $while_index->getCompareData()) {
  653. continue;
  654. }
  655. // did not find any difference
  656. // so it makes no sense to have this two equal indexes
  657. $message = PMA_Message::notice(
  658. __('The indexes %1$s and %2$s seem to be equal and one of them could possibly be removed.')
  659. );
  660. $message->addParam($each_index->getName());
  661. $message->addParam($while_index->getName());
  662. $output .= $message->getDisplay();
  663. // there is no need to check any further indexes if we have already
  664. // found that this one has a duplicate
  665. continue 2;
  666. }
  667. }
  668. return $output;
  669. }
  670. }
  671. /**
  672. * @package PhpMyAdmin
  673. */
  674. class PMA_Index_Column
  675. {
  676. /**
  677. * @var string The column name
  678. */
  679. private $_name = '';
  680. /**
  681. * @var integer The column sequence number in the index, starting with 1.
  682. */
  683. private $_seq_in_index = 1;
  684. /**
  685. * @var string How the column is sorted in the index. “A” (Ascending) or
  686. * NULL (Not sorted)
  687. */
  688. private $_collation = null;
  689. /**
  690. * The number of indexed characters if the column is only partly indexed,
  691. * NULL if the entire column is indexed.
  692. *
  693. * @var integer
  694. */
  695. private $_sub_part = null;
  696. /**
  697. * Contains YES if the column may contain NULL.
  698. * If not, the column contains NO.
  699. *
  700. * @var string
  701. */
  702. private $_null = '';
  703. /**
  704. * An estimate of the number of unique values in the index. This is updated
  705. * by running ANALYZE TABLE or myisamchk -a. Cardinality is counted based on
  706. * statistics stored as integers, so the value is not necessarily exact even
  707. * for small tables. The higher the cardinality, the greater the chance that
  708. * MySQL uses the index when doing joins.
  709. *
  710. * @var integer
  711. */
  712. private $_cardinality = null;
  713. public function __construct($params = array())
  714. {
  715. $this->set($params);
  716. }
  717. public function set($params)
  718. {
  719. if (isset($params['Column_name'])) {
  720. $this->_name = $params['Column_name'];
  721. }
  722. if (isset($params['Seq_in_index'])) {
  723. $this->_seq_in_index = $params['Seq_in_index'];
  724. }
  725. if (isset($params['Collation'])) {
  726. $this->_collation = $params['Collation'];
  727. }
  728. if (isset($params['Cardinality'])) {
  729. $this->_cardinality = $params['Cardinality'];
  730. }
  731. if (isset($params['Sub_part'])) {
  732. $this->_sub_part = $params['Sub_part'];
  733. }
  734. if (isset($params['Null'])) {
  735. $this->_null = $params['Null'];
  736. }
  737. }
  738. public function getName()
  739. {
  740. return $this->_name;
  741. }
  742. public function getCollation()
  743. {
  744. return $this->_collation;
  745. }
  746. public function getCardinality()
  747. {
  748. return $this->_cardinality;
  749. }
  750. public function getNull($as_text = false)
  751. {
  752. return $as_text
  753. ? (!$this->_null || $this->_null == 'NO' ? __('No') : __('Yes'))
  754. : $this->_null;
  755. }
  756. public function getSeqInIndex()
  757. {
  758. return $this->_seq_in_index;
  759. }
  760. public function getSubPart()
  761. {
  762. return $this->_sub_part;
  763. }
  764. public function getCompareData()
  765. {
  766. return array(
  767. 'Column_name' => $this->_name,
  768. 'Seq_in_index' => $this->_seq_in_index,
  769. 'Collation' => $this->_collation,
  770. 'Sub_part' => $this->_sub_part,
  771. 'Null' => $this->_null,
  772. );
  773. }
  774. }
  775. ?>