Commit 3cca6ad8 authored by brian@zim.(none)'s avatar brian@zim.(none)

Fixed a warning. Added the -A option so that the autoincrement could be set outside of the file.

parent 9d06ba72
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <m_ctype.h>
#include <my_getopt.h> #include <my_getopt.h>
#include <mysql_version.h> #include <mysql_version.h>
...@@ -15,10 +16,12 @@ static void get_options(int *argc,char * * *argv); ...@@ -15,10 +16,12 @@ static void get_options(int *argc,char * * *argv);
static void print_version(void); static void print_version(void);
static void usage(void); static void usage(void);
static const char *opt_tmpdir; static const char *opt_tmpdir;
static const char *new_auto_increment_value; static const char *new_auto_increment;
unsigned long long new_auto_increment_value;
static const char *load_default_groups[]= { "archive_reader", 0 }; static const char *load_default_groups[]= { "archive_reader", 0 };
static char **default_argv; static char **default_argv;
int opt_check, opt_force, opt_quiet, opt_backup= 0, opt_extract_frm; int opt_check, opt_force, opt_quiet, opt_backup= 0, opt_extract_frm;
int opt_autoincrement;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -40,6 +43,35 @@ int main(int argc, char *argv[]) ...@@ -40,6 +43,35 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
if (opt_autoincrement)
{
azio_stream writer_handle;
if (new_auto_increment_value)
{
if (reader_handle.auto_increment >= new_auto_increment_value)
{
printf("Value is lower then current value\n");
goto end;
}
}
else
{
new_auto_increment_value= reader_handle.auto_increment + 1;
}
if (!(ret= azopen(&writer_handle, argv[0], O_CREAT|O_RDWR|O_BINARY)))
{
printf("Could not open file for update: %s\n", argv[0]);
goto end;
}
writer_handle.auto_increment= new_auto_increment_value;
azclose(&writer_handle);
azflush(&reader_handle, Z_SYNC_FLUSH);
}
printf("Version %u\n", reader_handle.version); printf("Version %u\n", reader_handle.version);
if (reader_handle.version > 2) if (reader_handle.version > 2)
{ {
...@@ -272,7 +304,11 @@ get_one_option(int optid, ...@@ -272,7 +304,11 @@ get_one_option(int optid,
printf("Not implemented yet\n"); printf("Not implemented yet\n");
break; break;
case 'A': case 'A':
printf("Not implemented yet\n"); opt_autoincrement= 1;
if (argument)
new_auto_increment_value= strtoull(argument, NULL, 0);
else
new_auto_increment_value= 0;
break; break;
case '?': case '?':
usage(); usage();
...@@ -317,9 +353,9 @@ static struct my_option my_long_options[] = ...@@ -317,9 +353,9 @@ static struct my_option my_long_options[] =
{"repair", 'r', "Repair a damaged Archive version 3 or above file.", {"repair", 'r', "Repair a damaged Archive version 3 or above file.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"set-auto-increment", 'A', {"set-auto-increment", 'A',
"Force auto_increment to start at this or higher value.", "Force auto_increment to start at this or higher value. If no value is given, then sets the next auto_increment value to the highest used value for the auto key + 1.",
(gptr*) &new_auto_increment_value, (gptr*) &new_auto_increment,
(gptr*) &new_auto_increment_value, (gptr*) &new_auto_increment,
0, GET_ULL, OPT_ARG, 0, 0, 0, 0, 0, 0}, 0, GET_ULL, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"silent", 's', {"silent", 's',
"Only print errors. One can use two -s to make archive_reader very silent.", "Only print errors. One can use two -s to make archive_reader very silent.",
......
...@@ -587,7 +587,7 @@ int ha_archive::create(const char *name, TABLE *table_arg, ...@@ -587,7 +587,7 @@ int ha_archive::create(const char *name, TABLE *table_arg,
azio_stream create_stream; /* Archive file we are working with */ azio_stream create_stream; /* Archive file we are working with */
File frm_file; /* File handler for readers */ File frm_file; /* File handler for readers */
MY_STAT file_stat; // Stat information for the data file MY_STAT file_stat; // Stat information for the data file
char *frm_ptr; byte *frm_ptr;
DBUG_ENTER("ha_archive::create"); DBUG_ENTER("ha_archive::create");
...@@ -659,7 +659,7 @@ int ha_archive::create(const char *name, TABLE *table_arg, ...@@ -659,7 +659,7 @@ int ha_archive::create(const char *name, TABLE *table_arg,
VOID(my_fstat(frm_file, &file_stat, MYF(MY_WME))); VOID(my_fstat(frm_file, &file_stat, MYF(MY_WME)));
frm_ptr= (char *)my_malloc(sizeof(char) * file_stat.st_size , MYF(0)); frm_ptr= (char *)my_malloc(sizeof(char) * file_stat.st_size , MYF(0));
my_read(frm_file, frm_ptr, file_stat.st_size, MYF(0)); my_read(frm_file, frm_ptr, file_stat.st_size, MYF(0));
azwrite_frm(&create_stream, frm_ptr, file_stat.st_size); azwrite_frm(&create_stream, (char *)frm_ptr, file_stat.st_size);
my_close(frm_file, MYF(0)); my_close(frm_file, MYF(0));
my_free(frm_ptr, MYF(0)); my_free(frm_ptr, MYF(0));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment