mirror of
https://github.com/MariaDB/server.git
synced 2026-04-22 00:05:33 +02:00
merge
BitKeeper/etc/ignore: auto-union acinclude.m4: Auto merged Docs/manual.texi: Auto merged include/my_sys.h: Auto merged include/mysql.h: Auto merged libmysqld/libmysqld.c: Auto merged mysql-test/mysql-test-run.sh: Auto merged mysql-test/t/count_distinct2.test: Auto merged mysql-test/t/flush.test: Auto merged mysql-test/t/rpl000017.test: Auto merged libmysql/libmysql.c: Auto merged mysys/Makefile.am: Auto merged sql/Makefile.am: Auto merged sql/handler.cc: Auto merged sql/item_func.cc: Auto merged sql/mysql_priv.h: Auto merged sql/mysqld.cc: Auto merged libmysqld/Makefile.am: Added back md5.c
This commit is contained in:
commit
515c747dcf
118 changed files with 1793 additions and 820 deletions
|
|
@ -47,10 +47,12 @@ int completion_hash_init(HashTable *ht, uint nSize)
|
|||
ht->arBuckets = (Bucket **) my_malloc(nSize* sizeof(Bucket *),
|
||||
MYF(MY_ZEROFILL | MY_WME));
|
||||
|
||||
if (!ht->arBuckets) {
|
||||
if (!ht->arBuckets)
|
||||
{
|
||||
ht->initialized = 0;
|
||||
return FAILURE;
|
||||
}
|
||||
init_alloc_root(&ht->mem_root, 8192, 0);
|
||||
ht->pHashFunction = hashpjw;
|
||||
ht->nTableSize = nSize;
|
||||
ht->initialized = 1;
|
||||
|
|
@ -78,8 +80,7 @@ int completion_hash_update(HashTable *ht, char *arKey, uint nKeyLength,
|
|||
if (!memcmp(p->arKey, arKey, nKeyLength)) {
|
||||
entry *n;
|
||||
|
||||
n = (entry *) my_malloc(sizeof(entry),
|
||||
MYF(MY_WME));
|
||||
n = (entry *) alloc_root(&ht->mem_root,sizeof(entry));
|
||||
n->pNext = p->pData;
|
||||
n->str = str;
|
||||
p->pData = n;
|
||||
|
|
@ -91,20 +92,16 @@ int completion_hash_update(HashTable *ht, char *arKey, uint nKeyLength,
|
|||
p = p->pNext;
|
||||
}
|
||||
|
||||
p = (Bucket *) my_malloc(sizeof(Bucket),MYF(MY_WME));
|
||||
|
||||
if (!p) {
|
||||
if (!(p = (Bucket *) alloc_root(&ht->mem_root, sizeof(Bucket))))
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
p->arKey = arKey;
|
||||
p->nKeyLength = nKeyLength;
|
||||
p->h = h;
|
||||
|
||||
p->pData = (entry*) my_malloc(sizeof(entry),MYF(MY_WME));
|
||||
if (!p->pData) {
|
||||
my_free((gptr) p,MYF(0));
|
||||
if (!(p->pData = (entry*) alloc_root(&ht->mem_root, sizeof(entry))))
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
p->pData->str = str;
|
||||
p->pData->pNext = 0;
|
||||
p->count = 1;
|
||||
|
|
@ -209,24 +206,7 @@ Bucket *find_longest_match(HashTable *ht, char *str, uint length,
|
|||
|
||||
void completion_hash_clean(HashTable *ht)
|
||||
{
|
||||
uint i;
|
||||
entry *e, *t;
|
||||
Bucket *b, *tmp;
|
||||
|
||||
for (i=0; i<ht->nTableSize; i++) {
|
||||
b = ht->arBuckets[i];
|
||||
while (b) {
|
||||
e = b->pData;
|
||||
while (e) {
|
||||
t = e;
|
||||
e = e->pNext;
|
||||
my_free((gptr) t,MYF(0));
|
||||
}
|
||||
tmp = b;
|
||||
b = b->pNext;
|
||||
my_free((gptr) tmp,MYF(0));
|
||||
}
|
||||
}
|
||||
free_root(&ht->mem_root,MYF(0));
|
||||
bzero((char*) ht->arBuckets,ht->nTableSize*sizeof(Bucket *));
|
||||
}
|
||||
|
||||
|
|
@ -241,9 +221,7 @@ void completion_hash_free(HashTable *ht)
|
|||
void add_word(HashTable *ht,char *str)
|
||||
{
|
||||
int i;
|
||||
int length= (int) strlen(str);
|
||||
|
||||
for (i=1; i<=length; i++) {
|
||||
char *pos=str;
|
||||
for (i=1; *pos; i++, pos++)
|
||||
completion_hash_update(ht, str, i, str);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,26 +22,29 @@
|
|||
#define FAILURE 1
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <my_sys.h>
|
||||
|
||||
typedef struct _entry {
|
||||
char *str;
|
||||
struct _entry *pNext;
|
||||
} entry;
|
||||
|
||||
typedef struct bucket {
|
||||
uint h; /* Used for numeric indexing */
|
||||
char *arKey;
|
||||
uint nKeyLength;
|
||||
uint count;
|
||||
entry *pData;
|
||||
struct bucket *pNext;
|
||||
typedef struct bucket
|
||||
{
|
||||
uint h; /* Used for numeric indexing */
|
||||
char *arKey;
|
||||
uint nKeyLength;
|
||||
uint count;
|
||||
entry *pData;
|
||||
struct bucket *pNext;
|
||||
} Bucket;
|
||||
|
||||
typedef struct hashtable {
|
||||
uint nTableSize;
|
||||
uint initialized;
|
||||
uint(*pHashFunction) (char *arKey, uint nKeyLength);
|
||||
Bucket **arBuckets;
|
||||
uint nTableSize;
|
||||
uint initialized;
|
||||
MEM_ROOT mem_root;
|
||||
uint(*pHashFunction) (char *arKey, uint nKeyLength);
|
||||
Bucket **arBuckets;
|
||||
} HashTable;
|
||||
|
||||
extern int completion_hash_init(HashTable *ht, uint nSize);
|
||||
|
|
@ -54,4 +57,4 @@ extern void completion_hash_clean(HashTable *ht);
|
|||
extern int completion_hash_exists(HashTable *ht, char *arKey, uint nKeyLength);
|
||||
extern void completion_hash_free(HashTable *ht);
|
||||
|
||||
#endif /* _HASH_ */
|
||||
#endif /* _HASH_ */
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ static const char *xmlmeta[] = {
|
|||
static char default_pager[FN_REFLEN];
|
||||
char pager[FN_REFLEN], outfile[FN_REFLEN];
|
||||
FILE *PAGER, *OUTFILE;
|
||||
MEM_ROOT hash_mem_root;
|
||||
|
||||
#include "sslopt-vars.h"
|
||||
|
||||
|
|
@ -302,8 +303,9 @@ int main(int argc,char *argv[])
|
|||
!(status.line_buff=batch_readline_init(max_allowed_packet+512,stdin)))
|
||||
exit(1);
|
||||
glob_buffer.realloc(512);
|
||||
mysql_server_init(0, NULL, server_default_groups);
|
||||
completion_hash_init(&ht,50);
|
||||
mysql_server_init(0, NULL, (char**) server_default_groups);
|
||||
completion_hash_init(&ht, 128);
|
||||
init_alloc_root(&hash_mem_root, 16384, 0);
|
||||
bzero((char*) &mysql, sizeof(mysql));
|
||||
if (sql_connect(current_host,current_db,current_user,opt_password,
|
||||
opt_silent))
|
||||
|
|
@ -387,6 +389,8 @@ sig_handler mysql_end(int sig)
|
|||
}
|
||||
batch_readline_end(status.line_buff);
|
||||
completion_hash_free(&ht);
|
||||
free_root(&hash_mem_root,MYF(0));
|
||||
|
||||
#endif
|
||||
if (sig >= 0)
|
||||
put_info(sig ? "Aborted" : "Bye", INFO_RESULT);
|
||||
|
|
@ -1170,7 +1174,8 @@ static char *new_command_generator(char *text,int state)
|
|||
static void build_completion_hash(bool skip_rehash,bool write_info)
|
||||
{
|
||||
COMMANDS *cmd=commands;
|
||||
static MYSQL_RES *databases=0,*tables=0,*fields;
|
||||
MYSQL_RES *databases=0,*tables=0;
|
||||
MYSQL_RES *fields;
|
||||
static char ***field_names= 0;
|
||||
MYSQL_ROW database_row,table_row;
|
||||
MYSQL_FIELD *sql_field;
|
||||
|
|
@ -1181,16 +1186,11 @@ static void build_completion_hash(bool skip_rehash,bool write_info)
|
|||
if (status.batch || quick || !current_db)
|
||||
DBUG_VOID_RETURN; // We don't need completion in batches
|
||||
|
||||
completion_hash_clean(&ht);
|
||||
if (tables)
|
||||
{
|
||||
mysql_free_result(tables);
|
||||
tables=0;
|
||||
}
|
||||
if (databases) {
|
||||
mysql_free_result(databases);
|
||||
databases=0;
|
||||
}
|
||||
|
||||
/* hash SQL commands */
|
||||
while (cmd->name) {
|
||||
|
|
@ -1200,16 +1200,28 @@ static void build_completion_hash(bool skip_rehash,bool write_info)
|
|||
if (skip_rehash)
|
||||
DBUG_VOID_RETURN;
|
||||
|
||||
/* Free old used memory */
|
||||
if (field_names)
|
||||
field_names=0;
|
||||
completion_hash_clean(&ht);
|
||||
free_root(&hash_mem_root,MYF(0));
|
||||
|
||||
/* hash MySQL functions (to be implemented) */
|
||||
|
||||
/* hash all database names */
|
||||
if (mysql_query(&mysql,"show databases")==0) {
|
||||
if (mysql_query(&mysql,"show databases") == 0)
|
||||
{
|
||||
if (!(databases = mysql_store_result(&mysql)))
|
||||
put_info(mysql_error(&mysql),INFO_INFO);
|
||||
else
|
||||
{
|
||||
while ((database_row=mysql_fetch_row(databases)))
|
||||
add_word(&ht,(char*) database_row[0]);
|
||||
{
|
||||
char *str=strdup_root(&hash_mem_root, (char*) database_row[0]);
|
||||
if (str)
|
||||
add_word(&ht,(char*) str);
|
||||
}
|
||||
mysql_free_result(databases);
|
||||
}
|
||||
}
|
||||
/* hash all table names */
|
||||
|
|
@ -1227,23 +1239,13 @@ You can turn off this feature to get a quicker startup with -A\n\n");
|
|||
}
|
||||
while ((table_row=mysql_fetch_row(tables)))
|
||||
{
|
||||
if (!completion_hash_exists(&ht,(char*) table_row[0],
|
||||
(uint) strlen((const char*) table_row[0])))
|
||||
add_word(&ht,table_row[0]);
|
||||
char *str=strdup_root(&hash_mem_root, (char*) table_row[0]);
|
||||
if (str &&
|
||||
!completion_hash_exists(&ht,(char*) str, (uint) strlen(str)))
|
||||
add_word(&ht,str);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* FIXME: free() on small chunks is sloooowwww. glibc bug */
|
||||
if (field_names) {
|
||||
for (i=0; field_names[i]; i++) {
|
||||
for (j=0; field_names[i][j]; j++) {
|
||||
my_free(field_names[i][j],MYF(0));
|
||||
}
|
||||
my_free((gptr) field_names[i],MYF(0));
|
||||
}
|
||||
my_free((gptr) field_names,MYF(0));
|
||||
}
|
||||
field_names=0;
|
||||
|
||||
/* hash all field names, both with the table prefix and without it */
|
||||
if (!tables) /* no tables */
|
||||
|
|
@ -1251,36 +1253,37 @@ You can turn off this feature to get a quicker startup with -A\n\n");
|
|||
DBUG_VOID_RETURN;
|
||||
}
|
||||
mysql_data_seek(tables,0);
|
||||
field_names = (char ***) my_malloc(sizeof(char **) *
|
||||
(uint) (mysql_num_rows(tables)+1),
|
||||
MYF(MY_WME));
|
||||
if (!field_names)
|
||||
if (!(field_names= (char ***) alloc_root(&hash_mem_root,sizeof(char **) *
|
||||
(uint) (mysql_num_rows(tables)+1))))
|
||||
{
|
||||
mysql_free_result(tables);
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
i=0;
|
||||
while ((table_row=mysql_fetch_row(tables)))
|
||||
{
|
||||
if ((fields=mysql_list_fields(&mysql,(const char*) table_row[0],NullS)))
|
||||
{
|
||||
num_fields=mysql_num_fields(fields);
|
||||
field_names[i] = (char **) my_malloc(sizeof(char *)*(num_fields*2+1),
|
||||
MYF(0));
|
||||
if (!field_names[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!(field_names[i] = (char **) alloc_root(&hash_mem_root,
|
||||
sizeof(char *) *
|
||||
(num_fields*2+1))))
|
||||
break;
|
||||
field_names[i][num_fields*2]='\0';
|
||||
j=0;
|
||||
while ((sql_field=mysql_fetch_field(fields)))
|
||||
{
|
||||
sprintf(buf,"%s.%s",table_row[0],sql_field->name);
|
||||
field_names[i][j] = my_strdup(buf,MYF(0));
|
||||
field_names[i][j] = strdup_root(&hash_mem_root,buf);
|
||||
add_word(&ht,field_names[i][j]);
|
||||
field_names[i][num_fields+j] = my_strdup(sql_field->name,MYF(0));
|
||||
field_names[i][num_fields+j] = strdup_root(&hash_mem_root,
|
||||
sql_field->name);
|
||||
if (!completion_hash_exists(&ht,field_names[i][num_fields+j],
|
||||
(uint) strlen(field_names[i][num_fields+j])))
|
||||
add_word(&ht,field_names[i][num_fields+j]);
|
||||
j++;
|
||||
}
|
||||
mysql_free_result(fields);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1290,6 +1293,7 @@ You can turn off this feature to get a quicker startup with -A\n\n");
|
|||
}
|
||||
i++;
|
||||
}
|
||||
mysql_free_result(tables);
|
||||
field_names[i]=0; // End pointer
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -643,8 +643,7 @@ static uint getTableStructure(char *table, char* db)
|
|||
if (path)
|
||||
{
|
||||
char filename[FN_REFLEN], tmp_path[FN_REFLEN];
|
||||
strmov(tmp_path,path);
|
||||
convert_dirname(tmp_path);
|
||||
convert_dirname(tmp_path,path,NullS);
|
||||
sql_file= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4),
|
||||
O_WRONLY, MYF(MY_WME));
|
||||
if (!sql_file) /* If file couldn't be opened */
|
||||
|
|
@ -716,8 +715,7 @@ static uint getTableStructure(char *table, char* db)
|
|||
if (path)
|
||||
{
|
||||
char filename[FN_REFLEN], tmp_path[FN_REFLEN];
|
||||
strmov(tmp_path,path);
|
||||
convert_dirname(tmp_path);
|
||||
convert_dirname(tmp_path,path,NullS);
|
||||
sql_file= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4),
|
||||
O_WRONLY, MYF(MY_WME));
|
||||
if (!sql_file) /* If file couldn't be opened */
|
||||
|
|
@ -949,8 +947,7 @@ static void dumpTable(uint numFields, char *table)
|
|||
if (path)
|
||||
{
|
||||
char filename[FN_REFLEN], tmp_path[FN_REFLEN];
|
||||
strmov(tmp_path, path);
|
||||
convert_dirname(tmp_path);
|
||||
convert_dirname(tmp_path,path,NullS);
|
||||
my_load_path(tmp_path, tmp_path, NULL);
|
||||
fn_format(filename, table, tmp_path, ".txt", 4);
|
||||
my_delete(filename, MYF(0)); /* 'INTO OUTFILE' doesn't work, if
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ enum {OPT_MANAGER_USER=256,OPT_MANAGER_HOST,OPT_MANAGER_PASSWD,
|
|||
|
||||
static int record = 0, verbose = 0, silent = 0, opt_sleep=0;
|
||||
static char *db = 0, *pass=0;
|
||||
const char* user = 0, *host = 0, *unix_sock = 0;
|
||||
const char* user = 0, *host = 0, *unix_sock = 0, *opt_basedir="./";
|
||||
static int port = 0, opt_big_test=0, opt_compress=0;
|
||||
static uint start_lineno, *lineno;
|
||||
const char* manager_user="root",*manager_host="localhost";
|
||||
|
|
@ -134,6 +134,8 @@ typedef struct
|
|||
int read_lines,current_line;
|
||||
} PARSER;
|
||||
|
||||
MYSQL_RES *last_result=0;
|
||||
|
||||
PARSER parser;
|
||||
MASTER_POS master_pos;
|
||||
int* block_ok; /* set to 0 if the current block should not be executed */
|
||||
|
|
@ -235,6 +237,7 @@ void reject_dump(const char* record_file, char* buf, int size);
|
|||
int close_connection(struct st_query* q);
|
||||
VAR* var_get(const char* var_name, const char** var_name_end, int raw);
|
||||
int eval_expr(VAR* v, const char* p, const char** p_end);
|
||||
static int read_server_arguments(const char* name);
|
||||
|
||||
/* Definitions for replace */
|
||||
|
||||
|
|
@ -271,6 +274,19 @@ int mysql_rpl_parse_enabled(MYSQL* mysql __attribute__((unused))) { return 1; }
|
|||
int mysql_rpl_probe(MYSQL *mysql __attribute__((unused))) { return 1; }
|
||||
#endif
|
||||
|
||||
#define MAX_SERVER_ARGS 20
|
||||
|
||||
static int embedded_server_arg_count=0;
|
||||
static char *embedded_server_args[MAX_SERVER_ARGS];
|
||||
|
||||
static const char *embedded_server_groups[] = {
|
||||
"server",
|
||||
"embedded",
|
||||
"mysqltest_SERVER",
|
||||
NullS
|
||||
};
|
||||
|
||||
|
||||
static void do_eval(DYNAMIC_STRING* query_eval, const char* query)
|
||||
{
|
||||
const char* p;
|
||||
|
|
@ -314,6 +330,8 @@ static void do_eval(DYNAMIC_STRING* query_eval, const char* query)
|
|||
static void close_cons()
|
||||
{
|
||||
DBUG_ENTER("close_cons");
|
||||
if (last_result)
|
||||
mysql_free_result(last_result);
|
||||
for (--next_con; next_con >= cons; --next_con)
|
||||
{
|
||||
mysql_close(&next_con->mysql);
|
||||
|
|
@ -356,6 +374,8 @@ static void free_used_memory()
|
|||
if(var_reg[i].alloced_len)
|
||||
my_free(var_reg[i].str_val, MYF(MY_WME));
|
||||
}
|
||||
while (embedded_server_arg_count > 1)
|
||||
my_free(embedded_server_args[--embedded_server_arg_count],MYF(0));
|
||||
delete_dynamic(&q_lines);
|
||||
dynstr_free(&ds_res);
|
||||
my_free(pass,MYF(MY_ALLOW_ZERO_PTR));
|
||||
|
|
@ -382,6 +402,8 @@ static void die(const char* fmt, ...)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
/* Note that we will get some memory leaks when calling this! */
|
||||
|
||||
static void abort_not_supported_test()
|
||||
{
|
||||
DBUG_ENTER("abort_not_supported_test");
|
||||
|
|
@ -436,13 +458,22 @@ int dyn_string_cmp(DYNAMIC_STRING* ds, const char* fname)
|
|||
DYNAMIC_STRING res_ds;
|
||||
DBUG_ENTER("dyn_string_cmp");
|
||||
|
||||
if (!my_stat(fname, &stat_info, MYF(MY_WME)))
|
||||
if (!test_if_hard_path(fname))
|
||||
{
|
||||
strxmov(eval_file, opt_basedir, fname, NullS);
|
||||
fn_format(eval_file, eval_file,"","",4);
|
||||
}
|
||||
else
|
||||
fn_format(eval_file, fname,"","",4);
|
||||
|
||||
if (!my_stat(eval_file, &stat_info, MYF(MY_WME)))
|
||||
die(NullS);
|
||||
if (!eval_result && stat_info.st_size != ds->length)
|
||||
DBUG_RETURN(2);
|
||||
if (!(tmp = (char*) my_malloc(stat_info.st_size + 1, MYF(MY_WME))))
|
||||
die(NullS);
|
||||
if ((fd = my_open(fname, O_RDONLY, MYF(MY_WME))) < 0)
|
||||
|
||||
if ((fd = my_open(eval_file, O_RDONLY, MYF(MY_WME))) < 0)
|
||||
die(NullS);
|
||||
if (my_read(fd, (byte*)tmp, stat_info.st_size, MYF(MY_WME|MY_NABP)))
|
||||
die(NullS);
|
||||
|
|
@ -591,9 +622,17 @@ int var_set(char* var_name, char* var_name_end, char* var_val,
|
|||
|
||||
int open_file(const char* name)
|
||||
{
|
||||
char buff[FN_REFLEN];
|
||||
if (!test_if_hard_path(name))
|
||||
{
|
||||
strxmov(buff, opt_basedir, name, NullS);
|
||||
name=buff;
|
||||
}
|
||||
fn_format(buff,name,"","",4);
|
||||
|
||||
if (*cur_file && cur_file == file_stack_end)
|
||||
die("Source directives are nesting too deep");
|
||||
if (!(*(cur_file+1) = my_fopen(name, O_RDONLY, MYF(MY_WME))))
|
||||
if (!(*(cur_file+1) = my_fopen(buff, O_RDONLY, MYF(MY_WME))))
|
||||
die(NullS);
|
||||
cur_file++;
|
||||
*++lineno=1;
|
||||
|
|
@ -818,14 +857,13 @@ int do_sync_with_master(struct st_query* q)
|
|||
die("At line %u: failed in %s: %d: %s", start_lineno, query_buf,
|
||||
mysql_errno(mysql), mysql_error(mysql));
|
||||
|
||||
if(!(res = mysql_store_result(mysql)))
|
||||
if(!(last_result = res = mysql_store_result(mysql)))
|
||||
die("line %u: mysql_store_result() retuned NULL", start_lineno);
|
||||
if(!(row = mysql_fetch_row(res)))
|
||||
die("line %u: empty result in %s", start_lineno, query_buf);
|
||||
if(!row[0])
|
||||
die("Error on slave while syncing with master");
|
||||
mysql_free_result(res);
|
||||
|
||||
mysql_free_result(res); last_result=0;
|
||||
if(rpl_parse)
|
||||
mysql_enable_rpl_parse(mysql);
|
||||
|
||||
|
|
@ -846,13 +884,13 @@ int do_save_master_pos()
|
|||
die("At line %u: failed in show master status: %d: %s", start_lineno,
|
||||
mysql_errno(mysql), mysql_error(mysql));
|
||||
|
||||
if(!(res = mysql_store_result(mysql)))
|
||||
if(!(last_result =res = mysql_store_result(mysql)))
|
||||
die("line %u: mysql_store_result() retuned NULL", start_lineno);
|
||||
if(!(row = mysql_fetch_row(res)))
|
||||
die("line %u: empty result in show master status", start_lineno);
|
||||
strncpy(master_pos.file, row[0], sizeof(master_pos.file));
|
||||
master_pos.pos = strtoul(row[1], (char**) 0, 10);
|
||||
mysql_free_result(res);
|
||||
mysql_free_result(res); last_result=0;
|
||||
|
||||
if(rpl_parse)
|
||||
mysql_enable_rpl_parse(mysql);
|
||||
|
|
@ -1595,6 +1633,7 @@ struct option long_options[] =
|
|||
{
|
||||
{"debug", optional_argument, 0, '#'},
|
||||
{"database", required_argument, 0, 'D'},
|
||||
{"basedir", required_argument, 0, 'b'},
|
||||
{"big-test", no_argument, 0, 'B'},
|
||||
{"compress", no_argument, 0, 'C'},
|
||||
{"help", no_argument, 0, '?'},
|
||||
|
|
@ -1606,10 +1645,12 @@ struct option long_options[] =
|
|||
{"manager-wait-timeout",required_argument,0,OPT_MANAGER_WAIT_TIMEOUT},
|
||||
{"password", optional_argument, 0, 'p'},
|
||||
{"port", required_argument, 0, 'P'},
|
||||
{"quiet", no_argument, 0, 'q'},
|
||||
{"quiet", no_argument, 0, 's'},
|
||||
{"record", no_argument, 0, 'r'},
|
||||
{"result-file", required_argument, 0, 'R'},
|
||||
{"silent", no_argument, 0, 'q'},
|
||||
{"server-arg", required_argument, 0, 'A'},
|
||||
{"server-file", required_argument, 0, 'F'},
|
||||
{"silent", no_argument, 0, 's'},
|
||||
{"sleep", required_argument, 0, 'T'},
|
||||
{"socket", required_argument, 0, 'S'},
|
||||
{"test-file", required_argument, 0, 'x'},
|
||||
|
|
@ -1645,10 +1686,14 @@ void usage()
|
|||
-u, --user=... User for login.\n\
|
||||
-p[password], --password[=...]\n\
|
||||
Password to use when connecting to server.\n\
|
||||
-b, --basedir=... Basedir for tests\n\
|
||||
-B, --big-test Define BIG_TEST to 1\n\
|
||||
-C, --compress Use the compressed server/client protocol\n\
|
||||
-D, --database=... Database to use.\n\
|
||||
-P, --port=... Port number to use for connection.\n\
|
||||
--server-arg=... Send enbedded server this as a paramenter\n\
|
||||
--server-file=... Read embedded server arguments from file\n\
|
||||
-s, --silent, --quiet Suppress all normal output.\n\
|
||||
-S, --socket=... Socket file to use for connection.\n\
|
||||
-t, --tmpdir=... Temporary directory where sockets are put\n\
|
||||
-T, --sleep=# Sleep always this many seconds on sleep commands\n\
|
||||
|
|
@ -1656,7 +1701,6 @@ void usage()
|
|||
-R, --result-file=... Read/Store result from/in this file.\n\
|
||||
-x, --test-file=... Read test from/in this file (default stdin).\n\
|
||||
-v, --verbose Write more.\n\
|
||||
-q, --quiet, --silent Suppress all normal output.\n\
|
||||
-V, --version Output version information and exit.\n\
|
||||
--no-defaults Don't read default options from any options file.\n\n");
|
||||
}
|
||||
|
|
@ -1669,12 +1713,12 @@ int parse_args(int argc, char **argv)
|
|||
load_defaults("my",load_default_groups,&argc,&argv);
|
||||
default_argv= argv;
|
||||
|
||||
while ((c = getopt_long(argc, argv, "h:p::u:BCP:D:S:R:x:t:T:#:?rvVq",
|
||||
while ((c = getopt_long(argc, argv, "A:h:p::u:b:BCF:P:D:S:R:x:t:T:#:?rvVs",
|
||||
long_options, &option_index)) != EOF)
|
||||
{
|
||||
switch(c) {
|
||||
case '#':
|
||||
DBUG_PUSH(optarg ? optarg : "d:t:O,/tmp/mysqltest.trace");
|
||||
DBUG_PUSH(optarg ? optarg : "d:t:i:O,/tmp/mysqltest.trace");
|
||||
break;
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
|
|
@ -1706,9 +1750,18 @@ int parse_args(int argc, char **argv)
|
|||
result_file = optarg;
|
||||
break;
|
||||
case 'x':
|
||||
if (!(*cur_file = my_fopen(optarg, O_RDONLY, MYF(MY_WME))))
|
||||
{
|
||||
char buff[FN_REFLEN];
|
||||
if (!test_if_hard_path(optarg))
|
||||
{
|
||||
strxmov(buff, opt_basedir, optarg, NullS);
|
||||
optarg=buff;
|
||||
}
|
||||
fn_format(buff,optarg,"","",4);
|
||||
if (!(*++cur_file = my_fopen(buff, O_RDONLY, MYF(MY_WME))))
|
||||
die("Could not open %s: errno = %d", optarg, errno);
|
||||
break;
|
||||
}
|
||||
case 'p':
|
||||
if (optarg)
|
||||
{
|
||||
|
|
@ -1719,6 +1772,9 @@ int parse_args(int argc, char **argv)
|
|||
else
|
||||
tty_password=1;
|
||||
break;
|
||||
case 'b':
|
||||
opt_basedir= optarg;
|
||||
break;
|
||||
case 'B':
|
||||
opt_big_test=1;
|
||||
break;
|
||||
|
|
@ -1737,7 +1793,7 @@ int parse_args(int argc, char **argv)
|
|||
case 'h':
|
||||
host = optarg;
|
||||
break;
|
||||
case 'q':
|
||||
case 's':
|
||||
silent = 1;
|
||||
break;
|
||||
case 't':
|
||||
|
|
@ -1746,6 +1802,24 @@ int parse_args(int argc, char **argv)
|
|||
case 'T':
|
||||
opt_sleep=atoi(optarg);
|
||||
break;
|
||||
case 'A':
|
||||
if (!embedded_server_arg_count)
|
||||
{
|
||||
embedded_server_arg_count=1;
|
||||
embedded_server_args[0]= (char*) "";
|
||||
}
|
||||
embedded_server_args[embedded_server_arg_count++]=
|
||||
my_strdup(optarg,MYF(MY_FAE));
|
||||
if (embedded_server_arg_count == MAX_SERVER_ARGS ||
|
||||
!embedded_server_args[embedded_server_arg_count-1])
|
||||
{
|
||||
die("Can't use server argument");
|
||||
}
|
||||
break;
|
||||
case 'F':
|
||||
if (read_server_arguments(optarg))
|
||||
die(NullS);
|
||||
break;
|
||||
case 'V':
|
||||
print_version();
|
||||
exit(0);
|
||||
|
|
@ -1753,6 +1827,7 @@ int parse_args(int argc, char **argv)
|
|||
usage();
|
||||
exit(1); /* Unknown option */
|
||||
default:
|
||||
fprintf(stderr,"Unknown option '%c'\n",c);
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -1785,9 +1860,17 @@ char* safe_str_append(char* buf, const char* str, int size)
|
|||
void str_to_file(const char* fname, char* str, int size)
|
||||
{
|
||||
int fd;
|
||||
if ((fd = my_open(fname, O_WRONLY | O_CREAT | O_TRUNC,
|
||||
char buff[FN_REFLEN];
|
||||
if (!test_if_hard_path(fname))
|
||||
{
|
||||
strxmov(buff, opt_basedir, fname, NullS);
|
||||
fname=buff;
|
||||
}
|
||||
fn_format(buff,fname,"","",4);
|
||||
|
||||
if ((fd = my_open(buff, O_WRONLY | O_CREAT | O_TRUNC,
|
||||
MYF(MY_WME | MY_FFNF))) < 0)
|
||||
die("Could not open %s: errno = %d", fname, errno);
|
||||
die("Could not open %s: errno = %d", buff, errno);
|
||||
if (my_write(fd, (byte*)str, size, MYF(MY_WME|MY_FNABP)))
|
||||
die("write failed");
|
||||
my_close(fd, MYF(0));
|
||||
|
|
@ -1849,14 +1932,17 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
|
|||
dynstr_append_mem(ds,query,query_len);
|
||||
dynstr_append_mem(ds,";\n",2);
|
||||
}
|
||||
if(!(flags & QUERY_REAP))
|
||||
return 0;
|
||||
if (!(flags & QUERY_REAP))
|
||||
DBUG_RETURN(0);
|
||||
|
||||
if (mysql_read_query_result(mysql) ||
|
||||
(!(res = mysql_store_result(mysql)) && mysql_field_count(mysql)))
|
||||
(!(last_result = res = mysql_store_result(mysql)) &&
|
||||
mysql_field_count(mysql)))
|
||||
{
|
||||
if (q->require_file)
|
||||
{
|
||||
abort_not_supported_test();
|
||||
}
|
||||
if (q->abort_on_error)
|
||||
die("At line %u: query '%s' failed: %d: %s", start_lineno, query,
|
||||
mysql_errno(mysql), mysql_error(mysql));
|
||||
|
|
@ -1961,6 +2047,7 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
|
|||
|
||||
end:
|
||||
if (res) mysql_free_result(res);
|
||||
last_result=0;
|
||||
if (ds == &ds_tmp)
|
||||
dynstr_free(&ds_tmp);
|
||||
if(q->type == Q_EVAL)
|
||||
|
|
@ -2059,17 +2146,6 @@ static void init_var_hash()
|
|||
var_from_env("BIG_TEST", opt_big_test ? "1" : "0");
|
||||
}
|
||||
|
||||
static const char *embedded_server_args[] = {
|
||||
"", /* XXX: argv[0] is program name - we should fix the API */
|
||||
"--datadir=.",
|
||||
"--language=/usr/local/mysql/share/mysql/english",
|
||||
"--skip-innodb",
|
||||
NullS
|
||||
};
|
||||
static const char *embedded_server_groups[] = {
|
||||
"mysql-test-server",
|
||||
NullS
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
|
@ -2107,8 +2183,9 @@ int main(int argc, char** argv)
|
|||
*block_ok = 1;
|
||||
init_dynamic_string(&ds_res, "", 0, 65536);
|
||||
parse_args(argc, argv);
|
||||
if (mysql_server_init(sizeof(embedded_server_args) / sizeof(char *) - 1,
|
||||
embedded_server_args, embedded_server_groups))
|
||||
if (mysql_server_init(embedded_server_arg_count,
|
||||
embedded_server_args,
|
||||
(char**) embedded_server_groups))
|
||||
die("Can't initialize MySQL server");
|
||||
init_var_hash();
|
||||
if (cur_file == file_stack)
|
||||
|
|
@ -2265,6 +2342,51 @@ int main(int argc, char** argv)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Read arguments for embedded server and put them into
|
||||
embedded_server_args_count and embedded_server_args[]
|
||||
*/
|
||||
|
||||
|
||||
static int read_server_arguments(const char* name)
|
||||
{
|
||||
char argument[1024],buff[FN_REFLEN], *str=0;
|
||||
FILE *file;
|
||||
|
||||
if (!test_if_hard_path(name))
|
||||
{
|
||||
strxmov(buff, opt_basedir, name, NullS);
|
||||
name=buff;
|
||||
}
|
||||
fn_format(buff,name,"","",4);
|
||||
|
||||
if (!embedded_server_arg_count)
|
||||
{
|
||||
embedded_server_arg_count=1;
|
||||
embedded_server_args[0]= (char*) ""; /* Progname */
|
||||
}
|
||||
if (!(file=my_fopen(buff, O_RDONLY | O_BINARY, MYF(MY_WME))))
|
||||
return 1;
|
||||
while (embedded_server_arg_count < MAX_SERVER_ARGS &&
|
||||
(str=fgets(argument,sizeof(argument), file)))
|
||||
{
|
||||
*(strend(str)-1)=0; /* Remove end newline */
|
||||
if (!(embedded_server_args[embedded_server_arg_count]=
|
||||
(char*) my_strdup(str,MYF(MY_WME))))
|
||||
{
|
||||
my_fclose(file,MYF(0));
|
||||
return 1;
|
||||
}
|
||||
embedded_server_arg_count++;
|
||||
}
|
||||
my_fclose(file,MYF(0));
|
||||
if (str)
|
||||
{
|
||||
fprintf(stderr,"Too many arguments in option file: %s\n",name);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Handle replacement of strings
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue