Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

MySqlBuilder.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace Illuminate\Database\Schema;
  3. class MySqlBuilder extends Builder
  4. {
  5. /**
  6. * Determine if the given table exists.
  7. *
  8. * @param string $table
  9. * @return bool
  10. */
  11. public function hasTable($table)
  12. {
  13. $table = $this->connection->getTablePrefix().$table;
  14. return count($this->connection->select(
  15. $this->grammar->compileTableExists(), [$this->connection->getDatabaseName(), $table]
  16. )) > 0;
  17. }
  18. /**
  19. * Get the column listing for a given table.
  20. *
  21. * @param string $table
  22. * @return array
  23. */
  24. public function getColumnListing($table)
  25. {
  26. $table = $this->connection->getTablePrefix().$table;
  27. $results = $this->connection->select(
  28. $this->grammar->compileColumnListing(), [$this->connection->getDatabaseName(), $table]
  29. );
  30. return $this->connection->getPostProcessor()->processColumnListing($results);
  31. }
  32. /**
  33. * Drop all tables from the database.
  34. *
  35. * @return void
  36. */
  37. public function dropAllTables()
  38. {
  39. $tables = [];
  40. foreach ($this->getAllTables() as $row) {
  41. $row = (array) $row;
  42. $tables[] = reset($row);
  43. }
  44. if (empty($tables)) {
  45. return;
  46. }
  47. $this->disableForeignKeyConstraints();
  48. $this->connection->statement(
  49. $this->grammar->compileDropAllTables($tables)
  50. );
  51. $this->enableForeignKeyConstraints();
  52. }
  53. /**
  54. * Drop all views from the database.
  55. *
  56. * @return void
  57. */
  58. public function dropAllViews()
  59. {
  60. $views = [];
  61. foreach ($this->getAllViews() as $row) {
  62. $row = (array) $row;
  63. $views[] = reset($row);
  64. }
  65. if (empty($views)) {
  66. return;
  67. }
  68. $this->connection->statement(
  69. $this->grammar->compileDropAllViews($views)
  70. );
  71. }
  72. /**
  73. * Get all of the table names for the database.
  74. *
  75. * @return array
  76. */
  77. protected function getAllTables()
  78. {
  79. return $this->connection->select(
  80. $this->grammar->compileGetAllTables()
  81. );
  82. }
  83. /**
  84. * Get all of the view names for the database.
  85. *
  86. * @return array
  87. */
  88. protected function getAllViews()
  89. {
  90. return $this->connection->select(
  91. $this->grammar->compileGetAllViews()
  92. );
  93. }
  94. }