You are here

function _optimizedb_tables_list in OptimizeDB 7

Same name and namespace in other branches
  1. 8 optimizedb.module \_optimizedb_tables_list()
  2. 6 optimizedb.module \_optimizedb_tables_list()

List and the size of the database tables.

Return value

array An array with a list of database tables.

6 calls to _optimizedb_tables_list()
OptimizedbFunctionsTestCase::testButtonsExecutingCommands in ./optimizedb.test
Testing module admin page buttons.
OptimizedbFunctionsTestCase::testTablesList in ./optimizedb.test
Sizes tables.
OptimizedbListTablesOperationExecuteTestCase::testListTablesOperationExecute in ./optimizedb.test
Performing operations on tables.
optimizedb_enable in ./optimizedb.install
Implements hook_enable().
optimizedb_list_tables in ./optimizedb.module
List of tables in the database with the size and sorting.

... See full list

File

./optimizedb.module, line 599
Database Optimization.

Code

function _optimizedb_tables_list() {
  $tables = FALSE;
  switch (db_driver()) {
    case 'mysql':
      $tables = db_query("SHOW TABLE STATUS", array(), array(
        'fetch' => PDO::FETCH_OBJ,
      ));
      break;
    case 'pgsql':
      $tables = db_query("SELECT table_name as \"Name\",\n        pg_total_relation_size(table_name) AS \"Data_length\",\n        0 as \"Index_length\"\n        FROM information_schema.tables\n        WHERE table_schema = 'public'\n        ORDER BY table_name", array(), array(
        'fetch' => PDO::FETCH_OBJ,
      ));
      break;
  }
  $result = array();
  if ($tables) {
    $size_tables = 0;
    foreach ($tables as $table) {
      $length = $table->Data_length + $table->Index_length;
      $result[$table->Name] = array(
        'name' => $table->Name,
        'size' => format_size($length),
        'size_byte' => $length,
      );
      $size_tables += $length;
    }

    // The total size of the tables.
    variable_set('optimizedb_tables_size', $size_tables);
  }
  return (array) $result;
}