Commit fa741bbc authored by unknown's avatar unknown

Merge sinisa@bk-internal.mysql.com:/home/bk/mysql-4.1

into sinisa.nasamreza.org:/mnt/work/mysql-4.1


sql/item.cc:
  Auto merged
sql/item_strfunc.cc:
  Auto merged
parents 78113354 430a3291
......@@ -2393,10 +2393,11 @@ can only start with 255 if it's an error packet.
@section 4.1 prepared statement init packet
This is the return packet when one sends a query with the COM_PREPARE
command.
command (packet length is always '9').
@multitable @columnfractions .10 .90
@item Size @tab Comment
@item 1 @tab 0 ; Marker for OK packet
@item 4 @tab Statement handler id
@item 2 @tab Number of columns in result set
@item 2 @tab Number of parameters in query
......
......@@ -144,10 +144,6 @@ SOURCE="..\strings\ctype-latin1.c"
# End Source File
# Begin Source File
SOURCE="..\strings\ctype-latin1_de.c"
# End Source File
# Begin Source File
SOURCE="..\strings\ctype-mb.c"
# End Source File
# Begin Source File
......
......@@ -58,8 +58,8 @@ LINK32=link.exe
# SUBTRACT LINK32 /pdb:none
# Begin Special Build Tool
SOURCE="$(InputPath)"
PostBuild_Desc=Copy .lib file
PostBuild_Cmds=xcopy release\libmysql.lib ..\lib_release\
PostBuild_Desc=Move DLL export lib
PostBuild_Cmds=xcopy release\libmysql.lib ..\lib_release /y
# End Special Build Tool
!ELSEIF "$(CFG)" == "libmysql - Win32 Debug"
......@@ -91,8 +91,8 @@ LINK32=link.exe
# SUBTRACT LINK32 /pdb:none
# Begin Special Build Tool
SOURCE="$(InputPath)"
PostBuild_Desc=Copy .lib file
PostBuild_Cmds=xcopy ..\lib_debug\libmysql.dll C:\winnt\system32\ xcopy debug\libmysql.lib ..\lib_debug\
PostBuild_Desc=Move DLL export lib
PostBuild_Cmds=xcopy ..\lib_debug\libmysql.dll C:\winnt\system32\ /y xcopy debug\libmysql.lib ..\lib_debug\ /y
# End Special Build Tool
!ENDIF
......@@ -155,10 +155,6 @@ SOURCE="..\strings\ctype-latin1.c"
# End Source File
# Begin Source File
SOURCE="..\strings\ctype-latin1_de.c"
# End Source File
# Begin Source File
SOURCE="..\strings\ctype-mb.c"
# End Source File
# Begin Source File
......
......@@ -140,10 +140,6 @@ SOURCE=".\ctype-latin1.c"
# End Source File
# Begin Source File
SOURCE=".\ctype-latin1_de.c"
# End Source File
# Begin Source File
SOURCE=".\ctype-mb.c"
# End Source File
# Begin Source File
......
......@@ -566,14 +566,14 @@ my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt);
int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt);
my_bool STDCALL mysql_more_results(MYSQL *mysql);
my_bool STDCALL mysql_next_result(MYSQL *mysql);
MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt,
MYSQL_ROW_OFFSET offset);
MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt);
void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset);
my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt);
/* new status messages */
#define MYSQL_SUCCESS 0
#define MYSQL_STATUS_ERROR 1
/* status return codes */
#define MYSQL_NO_DATA 100
#define MYSQL_NEED_DATA 99
#define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
......
......@@ -3925,9 +3925,9 @@ static my_bool read_prepare_result(MYSQL_STMT *stmt)
DBUG_RETURN(1);
pos= (uchar*) mysql->net.read_pos;
stmt->stmt_id= uint4korr(pos); pos+=4;
field_count= uint2korr(pos); pos+=2;
param_count= uint2korr(pos); pos+=2;
stmt->stmt_id= uint4korr(pos+1); pos+= 5;
field_count= uint2korr(pos); pos+= 2;
param_count= uint2korr(pos); pos+= 2;
if (field_count != 0)
{
......@@ -5418,9 +5418,84 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt)
DBUG_RETURN(0); /* Data buffered, must be fetched with mysql_fetch() */
}
/*
Seek to desired row in the statement result set
*/
MYSQL_ROW_OFFSET STDCALL
mysql_stmt_row_seek(MYSQL_STMT *stmt, MYSQL_ROW_OFFSET row)
{
MYSQL_RES *result;
DBUG_ENTER("mysql_stmt_row_seek");
if ((result= stmt->result))
{
MYSQL_ROW_OFFSET return_value= result->data_cursor;
result->current_row= 0;
result->data_cursor= row;
DBUG_RETURN(return_value);
}
DBUG_PRINT("exit", ("stmt doesn't contain any resultset"));
DBUG_RETURN(0);
}
/*
Return the current statement row cursor position
*/
MYSQL_ROW_OFFSET STDCALL
mysql_stmt_row_tell(MYSQL_STMT *stmt)
{
DBUG_ENTER("mysql_stmt_row_tell");
if (stmt->result)
DBUG_RETURN(stmt->result->data_cursor);
DBUG_PRINT("exit", ("stmt doesn't contain any resultset"));
DBUG_RETURN(0);
}
/*
Move the stmt result set data cursor to specified row
*/
void STDCALL
mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong row)
{
MYSQL_RES *result;
DBUG_ENTER("mysql_stmt_data_seek");
DBUG_PRINT("enter",("row id to seek: %ld",(long) row));
if ((result= stmt->result))
{
MYSQL_ROWS *tmp= 0;
if (result->data)
for (tmp=result->data->data; row-- && tmp ; tmp = tmp->next) ;
result->current_row= 0;
result->data_cursor= tmp;
}
else
DBUG_PRINT("exit", ("stmt doesn't contain any resultset"));
}
/*
Return total rows the current statement result set
*/
my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt)
{
DBUG_ENTER("mysql_stmt_num_rows");
if (stmt->result)
DBUG_RETURN(stmt->result->row_count);
DBUG_PRINT("exit", ("stmt doesn't contain any resultset"));
DBUG_RETURN(0);
}
/********************************************************************
Misc function implementations
statement error handling and close
*********************************************************************/
/*
......@@ -5505,6 +5580,10 @@ const char *STDCALL mysql_stmt_error(MYSQL_STMT * stmt)
DBUG_RETURN(stmt->last_error);
}
/********************************************************************
Transactional APIs
*********************************************************************/
/*
Commit the current transaction
*/
......@@ -5542,7 +5621,7 @@ my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode)
/********************************************************************
Multi query execution related implementations
Multi query execution + SPs APIs
*********************************************************************/
/*
......@@ -5552,9 +5631,14 @@ my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode)
my_bool STDCALL mysql_more_results(MYSQL *mysql)
{
if (mysql->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS)
return 1;
return 0;
my_bool result;
DBUG_ENTER("mysql_more_results");
result= (mysql->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS) ?
1: 0;
DBUG_PRINT("exit",("More results exists ? %d", result));
DBUG_RETURN(result);
}
/*
......@@ -5563,12 +5647,14 @@ my_bool STDCALL mysql_more_results(MYSQL *mysql)
my_bool STDCALL mysql_next_result(MYSQL *mysql)
{
DBUG_ENTER("mysql_next_result");
mysql->net.last_error[0]=0;
mysql->net.last_errno=0;
mysql->net.last_error[0]= 0;
mysql->net.last_errno= 0;
mysql->affected_rows= ~(my_ulonglong) 0;
if (mysql->last_used_con->server_status & SERVER_MORE_RESULTS_EXISTS)
return mysql_read_query_result(mysql);
return 0;
DBUG_RETURN(mysql_read_query_result(mysql));
DBUG_RETURN(0);
}
......@@ -145,8 +145,7 @@ rm -r -f "$BASE/share/Makefile.am"
if [ -d $BASE/SCCS ]
then
find $BASE/ -name SCCS -print | xargs rm -r -f
rm -r -f "$BASE/InstallShield/Script Files/SCCS"
find $BASE/ -type d -name SCCS -printf " \"%p\"" | xargs rm -r -f
fi
mkdir $BASE/Docs $BASE/extra $BASE/include
......@@ -161,7 +160,7 @@ copy_dir_files() {
for arg do
print_debug "Copying files from directory '$arg'"
cd $SOURCE/$arg/
for i in *.c *.h *.ih *.i *.ic *.asm \
for i in *.c *.h *.ih *.i *.ic *.asm *.def \
README INSTALL* LICENSE
do
if [ -f $i ]
......
......@@ -542,6 +542,77 @@ String *Item_param::val_str(String* str)
return (String*) &str_value;
}
}
/*
Return Param item values in string format, for generating the dynamic
query used in update/binary logs
*/
String *Item_param::query_val_str(String* str)
{
switch (item_result_type) {
case INT_RESULT:
case REAL_RESULT:
return val_str(str);
break;
default:
str->set("'", 1, default_charset());
if (!item_is_time)
{
str->append(str_value);
const char *from= str->ptr();
uint32 length= 1;
// Escape misc cases
char *to= (char *)from, *end= (char *)to+str->length();
for (to++; to != end ; length++, to++)
{
switch(*to) {
case '\'':
case '"':
case '\r':
case '\n':
case '\\': // TODO: Add remaining ..
str->replace(length,0,"\\",1);
to++; end++; length++;
break;
default:
break;
}
}
}
else
{
char buff[25];
switch (ltime.time_type) {
case TIMESTAMP_NONE:
break;
case TIMESTAMP_DATE:
sprintf(buff, "%04d-%02d-%02d",
ltime.year,ltime.month,ltime.day);
str->append(buff, 10);
break;
case TIMESTAMP_FULL:
sprintf(buff, "%04d-%02d-%02d %02d:%02d:%02d",
ltime.year,ltime.month,ltime.day,
ltime.hour,ltime.minute,ltime.second);
str->append(buff, 19);
break;
case TIMESTAMP_TIME:
{
sprintf(buff, "%02d:%02d:%02d",
ltime.hour,ltime.minute,ltime.second);
str->append(buff, 8);
break;
}
}
}
str->append("'");
}
return str;
}
/* End of Item_param related */
......
......@@ -239,15 +239,17 @@ class Item_param :public Item
enum Type item_type;
enum enum_field_types buffer_type;
bool item_is_time;
my_bool long_data_supplied;
bool long_data_supplied;
uint pos_in_query;
Item_param(char *name_par=0)
Item_param::Item_param(uint position)
{
name= name_par ? name_par : (char*) "?";
long_data_supplied= false;
name= (char*) "?";
pos_in_query= position;
item_type= STRING_ITEM;
item_result_type = STRING_RESULT;
item_is_time= false;
long_data_supplied= false;
}
enum Type type() const { return item_type; }
double val();
......@@ -268,8 +270,9 @@ class Item_param :public Item
void (*setup_param_func)(Item_param *param, uchar **pos);
enum Item_result result_type () const
{ return item_result_type; }
String *query_val_str(String *str);
enum_field_types field_type() const { return MYSQL_TYPE_STRING; }
Item *new_item() { return new Item_param(name); }
Item *new_item() { return new Item_param(pos_in_query); }
};
class Item_int :public Item
......
......@@ -2920,7 +2920,7 @@ String *Item_func_spatial_collection::val_str(String *str)
}
#ifdef HAVE_COMPRESS
#include <zlib.h>
#include "../zlib/zlib.h"
String *Item_func_compress::val_str(String *str)
{
......
......@@ -283,7 +283,6 @@ void field_str::add()
char buff[MAX_FIELD_WIDTH], *ptr;
String s(buff, sizeof(buff),&my_charset_bin), *res;
ulong length;
TREE_ELEMENT *element;
if (!(res = item->val_str(&s)))
{
......
......@@ -321,11 +321,14 @@ typedef struct st_prep_stmt
Item_param **param;
Item *free_list;
MEM_ROOT mem_root;
String *query;
ulong stmt_id;
uint param_count;
uint last_errno;
char last_error[MYSQL_ERRMSG_SIZE];
bool error_in_prepare, long_data_used;
bool log_full_query;
bool (*setup_params)(st_prep_stmt *stmt, uchar *pos, uchar *read_pos);
} PREP_STMT;
......
......@@ -74,7 +74,10 @@ Long data handling:
#define IS_PARAM_NULL(pos, param_no) pos[param_no/8] & (1 << param_no & 7)
#define STMT_QUERY_LOG_LENGTH 8192
extern int yyparse(void *thd);
static String null_string("NULL", 4, default_charset_info);
/*
Find prepared statement in thd
......@@ -129,6 +132,8 @@ int compare_prep_stmt(void *not_used, PREP_STMT *stmt, ulong *key)
void free_prep_stmt(PREP_STMT *stmt, TREE_FREE mode, void *not_used)
{
my_free((char *)stmt->param, MYF(MY_ALLOW_ZERO_PTR));
if (stmt->query)
stmt->query->free();
free_items(stmt->free_list);
free_root(&stmt->mem_root, MYF(0));
}
......@@ -140,10 +145,11 @@ void free_prep_stmt(PREP_STMT *stmt, TREE_FREE mode, void *not_used)
static bool send_prep_stmt(PREP_STMT *stmt, uint columns)
{
NET *net=&stmt->thd->net;
char buff[8];
int4store(buff, stmt->stmt_id);
int2store(buff+4, columns);
int2store(buff+6, stmt->param_count);
char buff[9];
buff[0]= 0;
int4store(buff+1, stmt->stmt_id);
int2store(buff+5, columns);
int2store(buff+7, stmt->param_count);
#ifndef EMBEDDED_LIBRARY
/* This should be fixed to work with prepared statements
*/
......@@ -374,8 +380,8 @@ static void setup_param_functions(Item_param *param, uchar param_type)
param->setup_param_func= setup_param_date;
param->item_result_type= STRING_RESULT;
break;
case FIELD_TYPE_DATETIME:
case FIELD_TYPE_TIMESTAMP:
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_TIMESTAMP:
param->setup_param_func= setup_param_datetime;
param->item_result_type= STRING_RESULT;
break;
......@@ -386,10 +392,82 @@ static void setup_param_functions(Item_param *param, uchar param_type)
}
/*
Update the parameter markers by reading the data
from client ..
Update the parameter markers by reading data from client packet
and if binary/update log is set, generate the valid query.
*/
static bool insert_params_withlog(PREP_STMT *stmt, uchar *pos, uchar *read_pos)
{
THD *thd= stmt->thd;
List<Item> &params= thd->lex.param_list;
List_iterator<Item> param_iterator(params);
Item_param *param;
DBUG_ENTER("insert_params_withlog");
String str, *res, *query= new String(stmt->query->alloced_length());
query->copy(*stmt->query);
ulong param_no= 0;
uint32 length= 0;
while ((param= (Item_param *)param_iterator++))
{
if (param->long_data_supplied)
res= param->query_val_str(&str);
else
{
if (IS_PARAM_NULL(pos,param_no))
{
param->maybe_null= param->null_value= 1;
res= &null_string;
}
else
{
param->maybe_null= param->null_value= 0;
param->setup_param_func(param,&read_pos);
res= param->query_val_str(&str);
}
}
if (query->replace(param->pos_in_query+length, 1, *res))
DBUG_RETURN(1);
length+= res->length()-1;
param_no++;
}
if (alloc_query(stmt->thd, (char *)query->ptr(), query->length()+1))
DBUG_RETURN(1);
query->free();
DBUG_RETURN(0);
}
static bool insert_params(PREP_STMT *stmt, uchar *pos, uchar *read_pos)
{
THD *thd= stmt->thd;
List<Item> &params= thd->lex.param_list;
List_iterator<Item> param_iterator(params);
Item_param *param;
DBUG_ENTER("insert_params");
ulong param_no= 0;
while ((param= (Item_param *)param_iterator++))
{
if (!param->long_data_supplied)
{
if (IS_PARAM_NULL(pos,param_no))
param->maybe_null= param->null_value= 1;
else
{
param->maybe_null= param->null_value= 0;
param->setup_param_func(param,&read_pos);
}
}
param_no++;
}
DBUG_RETURN(0);
}
static bool setup_params_data(PREP_STMT *stmt)
{
THD *thd= stmt->thd;
......@@ -418,21 +496,7 @@ static bool setup_params_data(PREP_STMT *stmt)
}
param_iterator.rewind();
}
ulong param_no= 0;
while ((param= (Item_param *)param_iterator++))
{
if (!param->long_data_supplied)
{
if (IS_PARAM_NULL(pos,param_no))
param->maybe_null= param->null_value= 1;
else
{
param->maybe_null= param->null_value= 0;
param->setup_param_func(param,&read_pos);
}
}
param_no++;
}
stmt->setup_params(stmt,pos,read_pos);
DBUG_RETURN(0);
}
......@@ -707,10 +771,21 @@ static bool parse_prepare_query(PREP_STMT *stmt,
static bool init_param_items(PREP_STMT *stmt)
{
List<Item> &params= stmt->thd->lex.param_list;
THD *thd= stmt->thd;
List<Item> &params= thd->lex.param_list;
Item_param **to;
uint32 length= thd->query_length;
stmt->lex= thd->lex;
if (mysql_bin_log.is_open() || mysql_update_log.is_open())
{
stmt->log_full_query= 1;
stmt->setup_params= insert_params_withlog;
}
else
stmt->setup_params= insert_params; // not fully qualified query
stmt->lex= stmt->thd->lex;
if (!stmt->param_count)
stmt->param= (Item_param **)0;
else
......@@ -719,9 +794,19 @@ static bool init_param_items(PREP_STMT *stmt)
my_malloc(sizeof(Item_param *)*(stmt->param_count+1),
MYF(MY_WME))))
return 1;
if (stmt->log_full_query)
{
length= thd->query_length+(stmt->param_count*2)+1;
if ( length < STMT_QUERY_LOG_LENGTH )
length= STMT_QUERY_LOG_LENGTH;
}
List_iterator<Item> param_iterator(params);
while ((*(to++)= (Item_param *)param_iterator++));
}
stmt->query= new String(length);
stmt->query->copy(thd->query, thd->query_length, default_charset_info);
return 0;
}
......@@ -741,6 +826,12 @@ static void init_stmt_execute(PREP_STMT *stmt)
*/
for (; tables ; tables= tables->next)
tables->table= 0; //safety - nasty init
if (!(stmt->log_full_query && stmt->param_count))
{
thd->query= stmt->query->c_ptr();
thd->query_length= stmt->query->length();
}
}
/*
......
......@@ -508,14 +508,20 @@ int String::strrstr(const String &s,uint32 offset)
bool String::replace(uint32 offset,uint32 arg_length,const String &to)
{
long diff = (long) to.length()-(long) arg_length;
return replace(offset,arg_length,to.ptr(),to.length());
}
bool String::replace(uint32 offset,uint32 arg_length,
const char *to,uint32 length)
{
long diff = (long) length-(long) arg_length;
if (offset+arg_length <= str_length)
{
if (diff < 0)
{
if (to.length())
memcpy(Ptr+offset,to.ptr(),to.length());
bmove(Ptr+offset+to.length(),Ptr+offset+arg_length,
if (length)
memcpy(Ptr+offset,to,length);
bmove(Ptr+offset+length,Ptr+offset+arg_length,
str_length-offset-arg_length);
}
else
......@@ -527,14 +533,15 @@ bool String::replace(uint32 offset,uint32 arg_length,const String &to)
bmove_upp(Ptr+str_length+diff,Ptr+str_length,
str_length-offset-arg_length);
}
if (to.length())
memcpy(Ptr+offset,to.ptr(),to.length());
if (length)
memcpy(Ptr+offset,to,length);
}
str_length+=(uint32) diff;
}
return FALSE;
}
// added by Holyfoot for "geometry" needs
int String::reserve(uint32 space_needed, uint32 grow_by)
{
......
......@@ -186,6 +186,7 @@ class String
int strstr(const String &search,uint32 offset=0); // Returns offset to substring or -1
int strstr_case(const String &s,uint32 offset=0);
int strrstr(const String &search,uint32 offset=0); // Returns offset to substring or -1
bool replace(uint32 offset,uint32 arg_length,const char *to,uint32 length);
bool replace(uint32 offset,uint32 arg_length,const String &to);
inline bool append(char chr)
{
......
......@@ -3950,7 +3950,7 @@ param_marker:
LEX *lex=Lex;
if (YYTHD->prepare_command)
{
lex->param_list.push_back($$=new Item_param());
lex->param_list.push_back($$=new Item_param((uint)(lex->tok_start-(uchar *)YYTHD->query)));
lex->param_count++;
}
else
......
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