? 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.65
diff -u -p -r1.65 sql.drush.inc
--- commands/sql/sql.drush.inc	15 Nov 2010 16:09:22 -0000	1.65
+++ commands/sql/sql.drush.inc	30 Nov 2010 19:11:57 -0000
@@ -63,7 +63,7 @@ function sql_drush_command() {
   );
   $items['sql-dump'] = array(
     'callback' => 'drush_sql_dump_execute',
-    'description' => 'Exports the Drupal DB as SQL using mysqldump.',
+    'description' => 'Exports the Drupal DB as SQL using mysqldump or equivalent.',
     'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION,
     'examples' => array(
       'drush sql-dump --result-file=../18.sql' => 'Save SQL dump to the directory above Drupal root.',
@@ -250,11 +250,29 @@ function drush_sql_build_dump_command($t
     $db_spec = _drush_sql_get_db_spec();
   }
   $database = $db_spec['database'];
+  
+  // Get the setting of --result-file.  If the user
+  // has set $options['result-file'] = TRUE, then we
+  // will generate an SQL dump file in the same backup
+  // directory that pm-updatecode uses.
+  if ($file = drush_get_option('result-file', FALSE)) {
+    if ($file === TRUE) {
+      // User did not pass a specific value for --result-file. Make one.
+      drush_include_engine('version_control', 'backup');
+      $backup = new drush_pm_version_control_backup();
+      $backup_dir = $backup->prepare_backup_dir();
+      if (empty($backup_dir)) {
+        $backup_dir = "/tmp";
+      }
+      $file = $backup_dir . '/@DATABASE_@DATE.sql';
+    }
+    $file = str_replace(array('@DATABASE', '@DATE'), array($database, date('Ymd_his')), $file);
+  }
 
   switch (_drush_sql_get_scheme($db_spec)) {
     case 'mysql':
       $exec = 'mysqldump';
-      if ($file = drush_get_option('result-file')) {
+      if ($file) {
         $exec .= ' --result-file '. $file;
       }
       // mysqldump wants 'databasename' instead of 'database=databasename' for no good reason.
@@ -289,7 +307,7 @@ function drush_sql_build_dump_command($t
     case 'pgsql':
       $create_db = drush_get_option('create-db');
       $exec = 'pg_dump ';
-      if ($file = drush_get_option('result-file')) {
+      if ($file) {
         $exec .= ' --file '. $file;
       }
       // Unlike psql, pg_dump does not take a '-d' flag before the database name.
Index: examples/example.drushrc.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/examples/example.drushrc.php,v
retrieving revision 1.11
diff -u -p -r1.11 example.drushrc.php
--- examples/example.drushrc.php	21 Nov 2010 15:10:56 -0000	1.11
+++ examples/example.drushrc.php	30 Nov 2010 19:11:57 -0000
@@ -75,6 +75,18 @@
 // is not specified, then sql-sync will store dumps in temporary files.
 # $options['dump-dir'] = '/path/to/dumpdir';
 
+// Specify directory where sql-dump should store backups of database
+// dumps.  @DATABASE is replaced with the name of the database being
+// dumped, and @DATE is replaced with the current time and date of the
+// dump.  TRUE will cause sql-dump to use the same backup directory that
+// pm-updatecode does.
+//
+// If set, this can be explicitly overridden by specifying --result-file
+// on the commandline.  The default behavior of dumping to
+// STDOUT can be achieved via --result-file=0
+# $options['result-file'] = '/path/to/backup/dir/@DATABASE_@DATE.sql';
+# $options['result-file'] = TRUE;
+
 // Enable verbose mode.
 # $options['v'] = 1;
 
