You are here

function _optimizedb_tables_list in OptimizeDB 6

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

List and the size of the database tables.

Return value

array An array with a list of database tables.

3 calls to _optimizedb_tables_list()
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.
_optimizedb_clear_table in ./optimizedb.module
Cleaning table cache_form and cleaning time record.

File

./optimizedb.module, line 508
Database Optimization.

Code

function _optimizedb_tables_list() {
  switch (optimizedb_db_driver()) {
    case 'mysql':
      $tables = db_query("SHOW TABLE STATUS");
      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");
      break;
  }
  $result = array();
  if ($tables) {
    $size_tables = 0;
    while ($table = db_fetch_object($tables)) {
      $length = $table->Data_length + $table->Index_length;
      $result[$table->Name] = array(
        'name' => $table->Name,
        'size' => _optimizedb_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;
}