Commit 7aba7853 authored by peter@mysql.com's avatar peter@mysql.com

Merge mysql.com:/home/pz/mysql/mysql-4.1-root

into mysql.com:/home/pz/mysql/mysql-4.1
parents 90ff32ab 5f4a7c19
......@@ -580,3 +580,4 @@ vio/test-sslclient
vio/test-sslserver
vio/viotest-ssl
libmysqld/protocol.cc
test_xml
......@@ -34,6 +34,7 @@ typedef struct xml_stack_st
const char *beg;
const char *cur;
const char *end;
void *user_data;
int (*enter)(struct xml_stack_st *st,const char *val, uint len);
int (*value)(struct xml_stack_st *st,const char *val, uint len);
int (*leave)(struct xml_stack_st *st,const char *val, uint len);
......@@ -46,6 +47,7 @@ int my_xml_parse(MY_XML_PARSER *st,const char *str, uint len);
void my_xml_set_value_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *, const char *, uint len));
void my_xml_set_enter_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *, const char *, uint len));
void my_xml_set_leave_handler(MY_XML_PARSER *st, int (*)(MY_XML_PARSER *, const char *, uint len));
void my_xml_set_user_data(MY_XML_PARSER *st, void *);
uint my_xml_error_pos(MY_XML_PARSER *st);
uint my_xml_error_lineno(MY_XML_PARSER *st);
......
......@@ -510,7 +510,7 @@ MYSQL_RES *STDCALL mysql_prepare_result(MYSQL_STMT *stmt);
#define MYSQL_STATUS_ERROR 2
#define MYSQL_NO_DATA 100
#define MYSQL_NEED_DATA 99
#define MYSQL_LONG_DATA_END 0xFF
#define MYSQL_NULL_DATA (-1)
#define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
......
......@@ -58,7 +58,7 @@ mysysobjects1 = my_init.lo my_static.lo my_malloc.lo my_realloc.lo \
mf_loadpath.lo my_pthread.lo my_thr_init.lo \
thr_mutex.lo mulalloc.lo string.lo default.lo \
my_compress.lo array.lo my_once.lo list.lo my_net.lo \
charset.lo hash.lo mf_iocache.lo \
charset.lo xml.lo hash.lo mf_iocache.lo \
mf_iocache2.lo my_seek.lo \
my_pread.lo mf_cache.lo my_vsnprintf.lo md5.lo sha1.lo\
my_getopt.lo my_gethostbyname.lo my_port.lo
......
This diff is collapsed.
......@@ -19,7 +19,9 @@
#include <m_ctype.h>
#include <m_string.h>
#include <my_dir.h>
#include <my_xml.h>
#define MY_CHARSET_INDEX "Index.xml"
const char *charsets_dir = NULL;
static int charset_initialized=0;
......@@ -85,53 +87,166 @@ char *get_charsets_dir(char *buf)
}
static my_bool read_charset_index(myf myflags)
#define MAX_BUF 1024*16
static void mstr(char *str,const char *src,uint l1,uint l2)
{
struct simpleconfig_buf_st fb;
char buf[MAX_LINE], num_buf[MAX_LINE];
strmov(get_charsets_dir(buf), "Index");
l1 = l1<l2 ? l1 : l2;
memcpy(str,src,l1);
str[l1]='\0';
}
if ((fb.f = my_fopen(buf, O_RDONLY, myflags)) == NULL)
return TRUE;
fb.buf[0] = '\0';
fb.p = fb.buf;
struct my_cs_file_section_st
{
int state;
const char *str;
};
#define _CS_MISC 1
#define _CS_ID 2
#define _CS_NAME 3
#define _CS_FAMILY 4
#define _CS_ORDER 5
#define _CS_COLNAME 6
#define _CS_FLAG 7
#define _CS_CHARSET 8
#define _CS_COLLATION 9
static struct my_cs_file_section_st sec[] =
{
{_CS_MISC, "xml"},
{_CS_MISC, "xml.version"},
{_CS_MISC, "xml.encoding"},
{_CS_MISC, "charsets"},
{_CS_MISC, "charsets.max-id"},
{_CS_MISC, "charsets.description"},
{_CS_CHARSET, "charsets.charset"},
{_CS_NAME, "charsets.charset.name"},
{_CS_FAMILY, "charsets.charset.family"},
{_CS_MISC, "charsets.charset.alias"},
{_CS_COLLATION, "charsets.charset.collation"},
{_CS_COLNAME, "charsets.charset.collation.name"},
{_CS_ID, "charsets.charset.collation.id"},
{_CS_ORDER, "charsets.charset.collation.order"},
{_CS_FLAG, "charsets.charset.collation.flag"},
{0, NULL}
};
static struct my_cs_file_section_st * cs_file_sec(const char *attr, uint len)
{
struct my_cs_file_section_st *s;
for (s=sec; s->str; s++)
if (!strncmp(attr,s->str,len))
return s;
return NULL;
}
struct my_cs_file_info
{
CHARSET_INFO cs;
myf myflags;
};
static int cs_enter(MY_XML_PARSER *st,const char *attr, uint len)
{
struct my_cs_file_info *i = (struct my_cs_file_info *)st->user_data;
struct my_cs_file_section_st *s = cs_file_sec(attr,len);
while (!get_word(&fb, buf) && !get_word(&fb, num_buf))
if ( s && (s->state == _CS_CHARSET))
{
uint csnum;
uint length;
CHARSET_INFO *cs;
bzero(&i->cs,sizeof(i->cs));
}
return MY_XML_OK;
}
if (!(csnum = atoi(num_buf)))
{
/* corrupt Index file */
my_fclose(fb.f,myflags);
return TRUE;
}
if (all_charsets[csnum])
continue;
if (!(cs=(CHARSET_INFO*) my_once_alloc(sizeof(cs[0]),myflags)))
{
my_fclose(fb.f,myflags);
return TRUE;
}
bzero(cs,sizeof(cs[0]));
if (!(cs->name= (char*)my_once_alloc(length=(uint)strlen(buf)+1,myflags)))
static int cs_leave(MY_XML_PARSER *st,const char *attr, uint len)
{
struct my_cs_file_info *i = (struct my_cs_file_info *)st->user_data;
struct my_cs_file_section_st *s = cs_file_sec(attr,len);
if (s && (s->state == _CS_COLLATION) && !all_charsets[i->cs.number])
{
if (!(all_charsets[i->cs.number]=
(CHARSET_INFO*) my_once_alloc(sizeof(CHARSET_INFO),i->myflags)))
{
my_fclose(fb.f,myflags);
return TRUE;
return MY_XML_ERROR;
}
memcpy((char*)cs->name,buf,length);
cs->number=csnum;
all_charsets[csnum]=cs;
all_charsets[i->cs.number][0]=i->cs;
}
return MY_XML_OK;
}
static int cs_value(MY_XML_PARSER *st,const char *attr, uint len)
{
struct my_cs_file_info *i = (struct my_cs_file_info *)st->user_data;
struct my_cs_file_section_st *s;
int state = (s=cs_file_sec(st->attr,strlen(st->attr))) ? s->state : 0;
if(0)
{
char str[256];
mstr(str,attr,len,sizeof(str)-1);
printf("VALUE %d %s='%s'\n",state,st->attr,str);
}
switch (state)
{
case _CS_ID:
i->cs.number = my_strntoul(my_charset_latin1,attr,len,(char**)NULL,0);
break;
case _CS_COLNAME:
if ((i->cs.name = (char*) my_once_alloc(len+1,i->myflags)))
{
memcpy((char*)i->cs.name,attr,len);
((char*)(i->cs.name))[len]='\0';
}
break;
}
my_fclose(fb.f,myflags);
return MY_XML_OK;
}
static my_bool read_charset_index(myf myflags)
{
char *buf;
int fd;
uint len;
MY_XML_PARSER p;
struct my_cs_file_info i;
if (! (buf = (char *)my_malloc(MAX_BUF,myflags)))
return FALSE;
strmov(get_charsets_dir(buf),MY_CHARSET_INDEX);
if ((fd=my_open(buf,O_RDONLY,myflags)) < 0)
{
my_free(buf,myflags);
return TRUE;
}
len=read(fd,buf,MAX_BUF);
my_xml_parser_create(&p);
my_close(fd,myflags);
my_xml_set_enter_handler(&p,cs_enter);
my_xml_set_value_handler(&p,cs_value);
my_xml_set_leave_handler(&p,cs_leave);
my_xml_set_user_data(&p,(void*)&i);
if (MY_XML_OK!=my_xml_parse(&p,buf,len))
{
/*
printf("ERROR at line %d pos %d '%s'\n",
my_xml_error_lineno(&p)+1,
my_xml_error_pos(&p),
my_xml_error_string(&p));
*/
}
my_xml_parser_free(&p);
return FALSE;
}
......@@ -472,7 +587,7 @@ CHARSET_INFO *get_charset(uint cs_number, myf flags)
if (!cs && (flags & MY_WME))
{
char index_file[FN_REFLEN], cs_string[23];
strmov(get_charsets_dir(index_file), "Index");
strmov(get_charsets_dir(index_file),MY_CHARSET_INDEX);
cs_string[0]='#';
int10_to_str(cs_number, cs_string+1, 10);
my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_string, index_file);
......@@ -505,7 +620,7 @@ CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags)
if (!cs && (flags & MY_WME))
{
char index_file[FN_REFLEN];
strmov(get_charsets_dir(index_file), "Index");
strmov(get_charsets_dir(index_file),MY_CHARSET_INDEX);
my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_name, index_file);
}
......
......@@ -342,6 +342,11 @@ void my_xml_set_leave_handler(MY_XML_PARSER *p, int (*action)(MY_XML_PARSER *p,
p->leave=action;
}
void my_xml_set_user_data(MY_XML_PARSER *p, void *user_data)
{
p->user_data=user_data;
}
const char *my_xml_error_string(MY_XML_PARSER *p)
{
return p->errstr;
......
......@@ -2599,7 +2599,7 @@ String *Field_double::val_str(String *val_buffer,
bool Field_double::send_binary(Protocol *protocol)
{
return protocol->store((float) Field_double::val_real(), dec, (String*) 0);
return protocol->store((double) Field_double::val_real(), dec, (String*) 0);
}
......@@ -3169,7 +3169,7 @@ bool Field_time::send_binary(Protocol *protocol)
Field_time::get_time(&tm);
tm.day= tm.hour/3600; // Move hours to days
tm.hour-= tm.day*3600;
return protocol->store(&tm);
return protocol->store_time(&tm);
}
......@@ -3254,6 +3254,13 @@ int Field_year::store(longlong nr)
return 0;
}
bool Field_year::send_binary(Protocol *protocol)
{
ulonglong tmp= Field_year::val_int();
TIME tm;
tm.year= (uint32) tmp;
return protocol->store_date(&tm);
}
double Field_year::val_real(void)
{
......@@ -3371,6 +3378,16 @@ int Field_date::store(longlong nr)
return error;
}
bool Field_date::send_binary(Protocol *protocol)
{
longlong tmp= Field_date::val_int();
TIME tm;
tm.year= (uint32) tmp/10000L % 10000;
tm.month= (uint32) tmp/100 % 100;
tm.day= (uint32) tmp % 100;
return protocol->store_date(&tm);
}
double Field_date::val_real(void)
{
......@@ -3544,7 +3561,12 @@ void Field_newdate::store_time(TIME *ltime,timestamp_type type)
int3store(ptr,tmp);
}
bool Field_newdate::send_binary(Protocol *protocol)
{
TIME tm;
Field_newdate::get_date(&tm,0);
return protocol->store_date(&tm);
}
double Field_newdate::val_real(void)
{
......@@ -3705,6 +3727,13 @@ void Field_datetime::store_time(TIME *ltime,timestamp_type type)
longlongstore(ptr,tmp);
}
bool Field_datetime::send_binary(Protocol *protocol)
{
TIME tm;
Field_datetime::get_date(&tm, 1);
return protocol->store(&tm);
}
double Field_datetime::val_real(void)
{
......
......@@ -166,7 +166,7 @@ class Field
ptr-=row_offset;
return tmp;
}
bool send_binary(Protocol *protocol);
virtual bool send_binary(Protocol *protocol);
virtual char *pack(char* to, const char *from, uint max_length=~(uint) 0)
{
uint32 length=pack_length();
......@@ -792,7 +792,6 @@ class Field_string :public Field_str {
double val_real(void);
longlong val_int(void);
String *val_str(String*,String *);
bool send_binary(Protocol *protocol);
int cmp(const char *,const char*);
void sort_string(char *buff,uint length);
void sql_type(String &str) const;
......@@ -833,7 +832,6 @@ class Field_varstring :public Field_str {
double val_real(void);
longlong val_int(void);
String *val_str(String*,String *);
bool send_binary(Protocol *protocol);
int cmp(const char *,const char*);
void sort_string(char *buff,uint length);
void get_key_image(char *buff,uint length, CHARSET_INFO *cs, imagetype type);
......@@ -876,7 +874,6 @@ class Field_blob :public Field_str {
double val_real(void);
longlong val_int(void);
String *val_str(String*,String *);
bool send_binary(Protocol *protocol);
int cmp(const char *,const char*);
int cmp(const char *a, uint32 a_length, const char *b, uint32 b_length);
int cmp_offset(uint offset);
......@@ -982,7 +979,6 @@ class Field_enum :public Field_str {
double val_real(void);
longlong val_int(void);
String *val_str(String*,String *);
bool send_binary(Protocol *protocol);
int cmp(const char *,const char*);
void sort_string(char *buff,uint length);
uint32 pack_length() const { return (uint32) packlength; }
......
......@@ -616,7 +616,7 @@ bool Protocol_simple::store_null()
field_pos++;
#endif
char buff[1];
buff[0]= 251;
buff[0]= (char)251;
return packet->append(buff, sizeof(buff), PACKET_BUFFET_EXTRA_ALLOC);
}
......@@ -774,13 +774,27 @@ bool Protocol_simple::store_time(TIME *tm)
/****************************************************************************
Functions to handle the binary protocol used with prepared statements
Data format:
[ok:1] <-- reserved ok packet
[null_field:(field_count+7+2)/8] <-- reserved to send null data. The size is
calculated using:
bit_fields= (field_count+7+2)/8;
2 bits are reserved
[[length]data] <-- data field (the length applies only for
string/binary/time/timestamp fields and
rest of them are not sent as they have
the default length that client understands
based on the field type
[..]..[[length]data] <-- data
****************************************************************************/
bool Protocol_prep::prepare_for_send(List<Item> *item_list)
{
field_count=item_list->elements;
bit_fields= (field_count+3)/8;
if (packet->alloc(bit_fields))
field_count= item_list->elements;
bit_fields= (field_count+9)/8;
if (packet->alloc(bit_fields+1))
return 1;
/* prepare_for_resend will be called after this one */
return 0;
......@@ -789,9 +803,8 @@ bool Protocol_prep::prepare_for_send(List<Item> *item_list)
void Protocol_prep::prepare_for_resend()
{
packet->length(bit_fields);
bzero((char*) packet->ptr()+1, bit_fields-1);
packet[0]=1; // Marker for ok packet
packet->length(bit_fields+1);
bzero((char*) packet->ptr(), 1+bit_fields);
field_pos=0;
}
......@@ -813,7 +826,7 @@ bool Protocol_prep::store(const char *from,uint length)
bool Protocol_prep::store_null()
{
uint offset=(field_pos+2)/8, bit= (1 << ((field_pos+2) & 7));
uint offset= (field_pos+2)/8+1, bit= (1 << ((field_pos+2) & 7));
/* Room for this as it's allocated in prepare_for_send */
char *to= (char*) packet->ptr()+offset;
*to= (char) ((uchar) *to | (uchar) bit);
......@@ -926,6 +939,7 @@ bool Protocol_prep::store(TIME *tm)
{
#ifndef DEBUG_OFF
DBUG_ASSERT(field_types == 0 ||
field_types[field_pos] == MYSQL_TYPE_YEAR ||
field_types[field_pos] == MYSQL_TYPE_DATETIME ||
field_types[field_pos] == MYSQL_TYPE_DATE ||
field_types[field_pos] == MYSQL_TYPE_TIMESTAMP);
......@@ -987,3 +1001,10 @@ bool Protocol_prep::store_time(TIME *tm)
buff[0]=(char) length; // Length is stored first
return packet->append(buff, length+1, PACKET_BUFFET_EXTRA_ALLOC);
}
#if 0
bool Protocol_prep::send_fields(List<Item> *list, uint flag)
{
return prepare_for_send(list);
};
#endif
......@@ -7,7 +7,7 @@ dist-hook:
done; \
sleep 1 ; touch $(srcdir)/*/errmsg.sys
$(INSTALL_DATA) $(srcdir)/charsets/README $(distdir)/charsets
$(INSTALL_DATA) $(srcdir)/charsets/Index $(distdir)/charsets
$(INSTALL_DATA) $(srcdir)/charsets/Index.xml $(distdir)/charsets
all: @AVAILABLE_LANGUAGES_ERRORS@
......@@ -25,7 +25,7 @@ install-data-local:
done
$(mkinstalldirs) $(DESTDIR)$(pkgdatadir)/charsets
$(INSTALL_DATA) $(srcdir)/charsets/README $(DESTDIR)$(pkgdatadir)/charsets/README
$(INSTALL_DATA) $(srcdir)/charsets/Index $(DESTDIR)$(pkgdatadir)/charsets/Index
$(INSTALL_DATA) $(srcdir)/charsets/Index.xml $(DESTDIR)$(pkgdatadir)/charsets/Index.xml
$(INSTALL_DATA) $(srcdir)/charsets/*.conf $(DESTDIR)$(pkgdatadir)/charsets
fix_errors:
......
This diff is collapsed.
......@@ -440,10 +440,9 @@ static bool mysql_test_upd_fields(PREP_STMT *stmt, TABLE_LIST *table_list,
COND *conds)
{
THD *thd= stmt->thd;
TABLE *table;
DBUG_ENTER("mysql_test_upd_fields");
if (!(table = open_ltable(thd,table_list,table_list->lock_type)))
if (open_and_lock_tables(thd, table_list))
DBUG_RETURN(1);
if (setup_tables(table_list) || setup_fields(thd,table_list,fields,1,0,0) ||
......@@ -477,13 +476,12 @@ static bool mysql_test_select_fields(PREP_STMT *stmt, TABLE_LIST *tables,
COND *conds, ORDER *order, ORDER *group,
Item *having)
{
TABLE *table;
bool hidden_group_fields;
THD *thd= stmt->thd;
List<Item> all_fields(fields);
DBUG_ENTER("mysql_test_select_fields");
if (!(table = open_ltable(thd,tables,TL_READ)))
if (open_and_lock_tables(thd, tables))
DBUG_RETURN(1);
thd->used_tables=0; // Updated by setup_fields
......@@ -512,7 +510,7 @@ static bool mysql_test_select_fields(PREP_STMT *stmt, TABLE_LIST *tables,
sending any info on where clause.
*/
if (send_prep_stmt(stmt, fields.elements) ||
thd->protocol_prep.send_fields(&fields,0) ||
thd->protocol_simple.send_fields(&fields,0) ||
send_item_params(stmt))
DBUG_RETURN(1);
DBUG_RETURN(0);
......@@ -626,14 +624,17 @@ static bool parse_prepare_query(PREP_STMT *stmt,
/*
Initialize parameter items in statement
*/
static bool init_param_items(THD *thd, PREP_STMT *stmt)
static bool init_param_items( PREP_STMT *stmt)
{
List<Item> &params= stmt->thd->lex.param_list;
Item_param **to;
if (!(stmt->param= to= (Item_param **)
my_malloc(sizeof(Item_param *)*(stmt->param_count+1),
MYF(MY_WME))))
return 1;
List_iterator<Item> param_iterator(thd->lex.param_list);
List_iterator<Item> param_iterator(params);
while ((*(to++) = (Item_param *)param_iterator++));
return 0;
}
......@@ -659,29 +660,32 @@ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length)
DBUG_ENTER("mysql_stmt_prepare");
bzero((char*) &stmt, sizeof(stmt));
stmt.thd= thd;
stmt.stmt_id= ++thd->current_stmt_id;
init_sql_alloc(&stmt.mem_root, 8192, 8192);
stmt.thd= thd;
stmt.thd->mem_root= stmt.mem_root;
thd->mem_root= stmt.mem_root;
if (alloc_query(thd, packet, packet_length))
if (alloc_query(stmt.thd, packet, packet_length))
goto err;
if (parse_prepare_query(&stmt, thd->query, thd->query_length))
goto err;
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),WAIT_PRIOR);
if (init_param_items(thd, &stmt))
if (init_param_items(&stmt))
goto err;
stmt.mem_root= thd->mem_root;
stmt.mem_root= stmt.thd->mem_root;
tree_insert(&thd->prepared_statements, (void *)&stmt, 0, (void *)0);
thd->mem_root= thd_root; // restore main mem_root
DBUG_RETURN(0);
err:
stmt.mem_root= thd->mem_root;
stmt.mem_root= stmt.thd->mem_root;
free_prep_stmt(&stmt, free_free, (void*) 0);
thd->mem_root = thd_root; // restore main mem_root
DBUG_RETURN(1);
......@@ -727,9 +731,9 @@ void mysql_stmt_execute(THD *thd, char *packet)
mysql_delete(), mysql_update() and mysql_select() to not to
have re-check on setup_* and other things ..
*/
thd->protocol= &thd->protocol_prep; // Switch to binary protocol
stmt->thd->protocol= &thd->protocol_prep; // Switch to binary protocol
mysql_execute_command(stmt->thd);
thd->protocol= &thd->protocol_simple; // Use normal protocol
stmt->thd->protocol= &thd->protocol_simple; // Use normal protocol
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(), WAIT_PRIOR);
......
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