? 696962_docs_skip_tables_4.patch ? drush_better_db_tables.patch ? strip_trail_spaces.sh ? includes/table.inc Index: commands/sql/sql.drush.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/sql/sql.drush.inc,v retrieving revision 1.36 diff -u -p -r1.36 sql.drush.inc --- commands/sql/sql.drush.inc 20 Jan 2010 18:10:11 -0000 1.36 +++ commands/sql/sql.drush.inc 28 Jan 2010 19:37:20 -0000 @@ -53,7 +53,7 @@ function sql_drush_command() { $items['sql-dump'] = array( 'callback' => 'drush_sql_dump_execute', 'description' => 'Exports the Drupal DB as SQL using mysqldump.', - 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION, + 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_DATABASE, 'examples' => array( 'drush sql-dump --result-file=../18.sql' => 'Save SQL dump to the directory above Drupal root.', 'drush sql-dump --skip-tables-key=common' => 'Skip standard tables. @see example.drushrc.com', @@ -311,10 +311,67 @@ function _drush_sql_get_table_list($opti } } + // Get the existing table names contained in the current database. + $db_tables = _drush_sql_get_db_table_list(); + + // Table name expansion based on * wildcard. + $expanded_db_tables = array(); + foreach ($tables as $k => $table) { + // Only deal with table names containing a wildcard. + if (strpos($table, '*') !== FALSE) { + $pattern = '/^' . str_replace('*', '.*', $table) . '$/i'; + // Merge those existing tables which match the pattern with the rest of + // the expanded table names. + $expanded_db_tables += preg_grep($pattern, $db_tables); + // Drop the wildcard table, this is not a valid table name. + unset($tables[$k]); + } + } + + + // Ensure all the tables actually exist in the database. + foreach ($tables as $k => $table) { + if (!in_array($table, $db_tables)) { + unset($tables[$k]); + } + } + + // Merge expanded and validated table names. + $tables += $expanded_db_tables; + + // Make sure each table name is unique and sort them. + $tables = array_unique($tables); + sort($tables); + return $tables; } /** + * Extract the name of all existing tables in the current database. + * + * @return array + * A list of table names which exist in the database. + */ +function _drush_sql_get_db_table_list() { + static $db_tables = array(); + + if (!empty($db_tables)) { + return $db_tables; + } + + $query = 'show tables'; + if ($scheme == 'pgsql') { + $query = "select tablename from pg_tables where schemaname='public';"; + } + $results = db_query($query); + while ($db_table = drush_db_fetch_object($results)) { + $db_tables[] = current((array)$db_table); + } + + return $db_tables; +} + +/** * Command callback. Executes the given SQL query on the Drupal database. */ function drush_sql_query($query) {