IndexColumn.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * holds the database index columns class
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin;
  9. /**
  10. * Index column wrapper
  11. *
  12. * @package PhpMyAdmin
  13. */
  14. class IndexColumn
  15. {
  16. /**
  17. * @var string The column name
  18. */
  19. private $_name = '';
  20. /**
  21. * @var integer The column sequence number in the index, starting with 1.
  22. */
  23. private $_seq_in_index = 1;
  24. /**
  25. * @var string How the column is sorted in the index. “A” (Ascending) or
  26. * NULL (Not sorted)
  27. */
  28. private $_collation = null;
  29. /**
  30. * The number of indexed characters if the column is only partly indexed,
  31. * NULL if the entire column is indexed.
  32. *
  33. * @var integer
  34. */
  35. private $_sub_part = null;
  36. /**
  37. * Contains YES if the column may contain NULL.
  38. * If not, the column contains NO.
  39. *
  40. * @var string
  41. */
  42. private $_null = '';
  43. /**
  44. * An estimate of the number of unique values in the index. This is updated
  45. * by running ANALYZE TABLE or myisamchk -a. Cardinality is counted based on
  46. * statistics stored as integers, so the value is not necessarily exact even
  47. * for small tables. The higher the cardinality, the greater the chance that
  48. * MySQL uses the index when doing joins.
  49. *
  50. * @var integer
  51. */
  52. private $_cardinality = null;
  53. /**
  54. * Constructor
  55. *
  56. * @param array $params an array containing the parameters of the index column
  57. */
  58. public function __construct(array $params = array())
  59. {
  60. $this->set($params);
  61. }
  62. /**
  63. * Sets parameters of the index column
  64. *
  65. * @param array $params an array containing the parameters of the index column
  66. *
  67. * @return void
  68. */
  69. public function set(array $params)
  70. {
  71. if (isset($params['Column_name'])) {
  72. $this->_name = $params['Column_name'];
  73. }
  74. if (isset($params['Seq_in_index'])) {
  75. $this->_seq_in_index = $params['Seq_in_index'];
  76. }
  77. if (isset($params['Collation'])) {
  78. $this->_collation = $params['Collation'];
  79. }
  80. if (isset($params['Cardinality'])) {
  81. $this->_cardinality = $params['Cardinality'];
  82. }
  83. if (isset($params['Sub_part'])) {
  84. $this->_sub_part = $params['Sub_part'];
  85. }
  86. if (isset($params['Null'])) {
  87. $this->_null = $params['Null'];
  88. }
  89. }
  90. /**
  91. * Returns the column name
  92. *
  93. * @return string column name
  94. */
  95. public function getName()
  96. {
  97. return $this->_name;
  98. }
  99. /**
  100. * Return the column collation
  101. *
  102. * @return string column collation
  103. */
  104. public function getCollation()
  105. {
  106. return $this->_collation;
  107. }
  108. /**
  109. * Returns the cardinality of the column
  110. *
  111. * @return int cardinality of the column
  112. */
  113. public function getCardinality()
  114. {
  115. return $this->_cardinality;
  116. }
  117. /**
  118. * Returns whether the column is nullable
  119. *
  120. * @param boolean $as_text whether to returned the string representation
  121. *
  122. * @return mixed nullability of the column. True/false or Yes/No depending
  123. * on the value of the $as_text parameter
  124. */
  125. public function getNull($as_text = false)
  126. {
  127. if ($as_text) {
  128. if (!$this->_null || $this->_null == 'NO') {
  129. return __('No');
  130. }
  131. return __('Yes');
  132. }
  133. return $this->_null;
  134. }
  135. /**
  136. * Returns the sequence number of the column in the index
  137. *
  138. * @return int sequence number of the column in the index
  139. */
  140. public function getSeqInIndex()
  141. {
  142. return $this->_seq_in_index;
  143. }
  144. /**
  145. * Returns the number of indexed characters if the column is only
  146. * partly indexed
  147. *
  148. * @return int the number of indexed characters
  149. */
  150. public function getSubPart()
  151. {
  152. return $this->_sub_part;
  153. }
  154. /**
  155. * Gets the properties in an array for comparison purposes
  156. *
  157. * @return array an array containing the properties of the index column
  158. */
  159. public function getCompareData()
  160. {
  161. return array(
  162. 'Column_name' => $this->_name,
  163. 'Seq_in_index' => $this->_seq_in_index,
  164. 'Collation' => $this->_collation,
  165. 'Sub_part' => $this->_sub_part,
  166. 'Null' => $this->_null,
  167. );
  168. }
  169. }