summaryrefslogtreecommitdiff
path: root/client/mysqldump.c
diff options
context:
space:
mode:
authorunknown <peter@linux.local>2002-06-14 15:24:22 +0400
committerunknown <peter@linux.local>2002-06-14 15:24:22 +0400
commit501839ae29e00c98982039c11392a3a3572571fe (patch)
tree078f96d1dbfa166494f8a15402a1a84ecbc31d10 /client/mysqldump.c
parent9cac831800272642f4c0783985c9a8a022a250dc (diff)
parent8451d47ac70f5840ec1d5fcfee2982f2a8cedc49 (diff)
downloadmariadb-git-501839ae29e00c98982039c11392a3a3572571fe.tar.gz
Merge
BitKeeper/etc/logging_ok: auto-union sql/item_create.cc: Auto merged sql/item_strfunc.cc: Auto merged sql/lex.h: Auto merged client/mysqldump.c: SCCS merged
Diffstat (limited to 'client/mysqldump.c')
-rw-r--r--client/mysqldump.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c
index 93352e96335..0ebf0727a58 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -33,6 +33,7 @@
** Tõnu Samuel <tonu@please.do.not.remove.this.spam.ee>
** XML by Gary Huntress <ghuntress@mediaone.net> 10/10/01, cleaned up
** and adapted to mysqldump 05/11/01 by Jani Tolonen
+** Added --single-transaction option 06/06/2002 by Peter Zaitsev
*/
#define DUMP_VERSION "9.06"
@@ -76,7 +77,7 @@ static my_bool verbose=0,tFlag=0,cFlag=0,dFlag=0,quick=0, extended_insert = 0,
opt_delayed=0,create_options=0,opt_quoted=0,opt_databases=0,
opt_alldbs=0,opt_create_db=0,opt_first_slave=0,
opt_autocommit=0,opt_master_data,opt_disable_keys=0,opt_xml=0,
- tty_password=0;
+ tty_password=0,opt_single_transaction=0;
static MYSQL mysql_connection,*sock=0;
static char insert_pat[12 * 1024],*opt_password=0,*current_user=0,
*current_host=0,*path=0,*fields_terminated=0,
@@ -171,6 +172,10 @@ static struct my_option my_long_options[] =
"Wrap tables with autocommit/commit statements.",
(gptr*) &opt_autocommit, (gptr*) &opt_autocommit, 0, GET_BOOL, NO_ARG,
0, 0, 0, 0, 0, 0},
+ {"single-transaction", OPT_TRANSACTION,
+ "Dump all tables in single transaction to get consistent snapshot. Mutually exclusive with --lock-tables.",
+ (gptr*) &opt_single_transaction, (gptr*) &opt_single_transaction, 0, GET_BOOL, NO_ARG,
+ 0, 0, 0, 0, 0, 0},
{"no-create-db", 'n',
"'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}",
(gptr*) &opt_create_db, (gptr*) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
@@ -340,8 +345,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
usage();
exit(0);
case (int) OPT_OPTIMIZE:
- extended_insert=opt_drop=opt_lock=lock_tables=quick=create_options=
- opt_disable_keys=1;
+ extended_insert=opt_drop=opt_lock=quick=create_options=opt_disable_keys=
+ lock_tables=1;
+ if (opt_single_transaction) lock_tables=0;
break;
case (int) OPT_TABLES:
opt_databases=0;
@@ -371,6 +377,12 @@ static int get_options(int *argc, char ***argv)
"%s: You must use option --tab with --fields-...\n", my_progname);
return(1);
}
+
+ if (opt_single_transaction && lock_tables)
+ {
+ fprintf(stderr, "%s: You can't use --lock-tables and --single-transaction at the same time.\n", my_progname);
+ return(1);
+ }
if (enclosed && opt_enclosed)
{
@@ -1369,6 +1381,17 @@ int main(int argc, char **argv)
return(first_error);
}
}
+ else if (opt_single_transaction)
+ {
+ /* There is no sense to start transaction if all tables are locked */
+ if (mysql_query(sock, "BEGIN"))
+ {
+ my_printf_error(0, "Error: Couldn't execute 'BEGIN': %s",
+ MYF(0), mysql_error(sock));
+ my_end(0);
+ return(first_error);
+ }
+ }
if (opt_alldbs)
dump_all_databases();
else if (argc > 1 && !opt_databases)
@@ -1412,6 +1435,20 @@ int main(int argc, char **argv)
my_printf_error(0, "Error: Couldn't execute 'UNLOCK TABLES': %s",
MYF(0), mysql_error(sock));
}
+ else if (opt_single_transaction) /* Just to make it beautiful enough */
+ {
+ /*
+ In case we were locking all tables, we did not start transaction
+ so there is no need to commit it.
+ */
+
+ /* This should just free locks as we did not change anything */
+ if (mysql_query(sock, "COMMIT"))
+ {
+ my_printf_error(0, "Error: Couldn't execute 'COMMIT': %s",
+ MYF(0), mysql_error(sock));
+ }
+ }
dbDisconnect(current_host);
fputs("\n", md_result_file);
if (md_result_file != stdout)