function apdqc_admin_change_table_engine in Asynchronous Prefetch Database Query Cache 7
Convert cache tables engine to InnoDB.
Parameters
bool $perform_alter: Set to TRUE to actually perform the alter.
array $cache_tables: Pass in a set of tables if you do not wish to operate on all cache tables.
Return value
mixed Returns an array of tables that need to be changed or that were changed. Will return FALSE if the alter failed.
3 calls to apdqc_admin_change_table_engine()
- apdqc_admin_convert_table_engine_to_innodb in ./
apdqc.admin.inc - Convert table engine to InnoDB.
- apdqc_admin_operations_form in ./
apdqc.admin.inc - Form builder; perform apdqc operations.
- apdqc_modules_installed in ./
apdqc.module - Implements hook_modules_installed().
File
- ./
apdqc.admin.inc, line 705 - Admin page callbacks for the apdqc module.
Code
function apdqc_admin_change_table_engine($perform_alter = FALSE, array $cache_tables = array()) {
if (empty($cache_tables)) {
$cache_tables = apdqc_get_cache_tables();
}
$db_type = Database::getConnection()
->databaseType();
$db = Database::getConnection()
->getConnectionOptions();
$tables_altered = array();
$results_after = array();
if ($db_type === 'mysql') {
// Get cache table engine.
$results_before = db_query("\n SELECT\n table_name,\n engine\n FROM information_schema.tables\n WHERE TABLE_SCHEMA = :dbname\n AND ENGINE <> 'InnoDB'\n AND TABLE_NAME IN (:tables)\n ", array(
':dbname' => $db['database'],
':tables' => $cache_tables,
))
->fetchAllAssoc('table_name');
if ($perform_alter) {
foreach ($results_before as $row) {
$table_name = $row->table_name;
db_query("ALTER TABLE {$table_name} ENGINE = InnoDB;");
$tables_altered[] = $row->table_name;
}
$results_after = db_query("\n SELECT\n table_name,\n engine\n FROM information_schema.tables\n WHERE TABLE_SCHEMA = :dbname\n AND ENGINE <> 'InnoDB'\n AND TABLE_NAME IN (:tables)\n ", array(
':dbname' => $db['database'],
':tables' => $cache_tables,
))
->fetchAllAssoc('table_name');
}
}
if ($perform_alter) {
if (empty($results_after)) {
return $tables_altered;
}
else {
return FALSE;
}
}
else {
return array_keys($results_before);
}
}