1
0
mirror of https://github.com/MariaDB/server.git synced 2025-06-12 01:53:02 +03:00

Fix for Bug#4030 "Client side conversion string -> date type doesn't

work (prepared statements)" and after-review fixes:
- str_to_TIME renamed to str_to_datetime to pair with str_to_time
- functions str_to_time and str_to_TIME moved to sql-common
- send_data_str now supports MYSQL_TYPE_TIME, MYSQL_TIME_DATE,
  MYSQL_TIME_DATETIME types of user input buffers.
- few more comments in the client library
- a test case added.


VC++Files/libmysql/libmysql.dsp:
  new file: my_time.c
VC++Files/libmysqld/libmysqld.dsp:
  new file: my_time.c
VC++Files/sql/mysqld.dsp:
  new file: my_time.c
include/Makefile.am:
  - mysql_time.h added to the list of installed client library headers
include/mysql.h:
  - declarations for MYSQL_TIME and enum_mysql_timestamp_type moved to 
  mysql_time.h, which is in shared use of client library and mysys.
libmysql/Makefile.shared:
  - my_time.lo added to the list of libmysql objects
libmysql/libmysql.c:
  Fix for bug#4030 "Client side conversion string -> date type doesn't work
   (prepared statements)" and cleanup.
  - added case labels for TIME/DATE/DATETIME types to send_data_str
  - comments for read_binary_{date,time,datetime}, fetch_result_*, fetch_results.
libmysqld/Makefile.am:
  - my_time.c added
sql-common/Makefile.am:
  - my_time.c added to the list of files included into source distribution.
sql/Makefile.am:
  my_time.c added to the list of mysqld sources.
sql/field.cc:
  - TIMESTAMP_{TIME,DATE,DATETIME,...} renamed to 
    MYSQL_TIMESTAMP_{TIME,DATETIME,DATE,...}
sql/item.cc:
  - TIMESTAMP_{TIME,DATE,DATETIME,...} renamed to 
    MYSQL_TIMESTAMP_{TIME,DATETIME,DATE,...}
sql/item_timefunc.cc:
  - TIMESTAMP_{TIME,DATE,DATETIME,...} renamed to 
    MYSQL_TIMESTAMP_{TIME,DATETIME,DATE,...}
sql/mysql_priv.h:
  - added typedefs for TIME and timestamp_type
  - removed declarations for str_to_time and str_to_TIME (now this functions
    reside in mysys)
sql/mysqld.cc:
  - log_10_int moved to mysys (it's used by str_to_TIME and str_to_time)
  - enum values TIMESTAMP_{TIME,DATE,DATETIME} were renamed to
    MYSQL_TIMESTAMP_{TIME,DATE,DATETIME}
sql/set_var.cc:
  - TIMESTAMP_{TIME,DATE,DATETIME,...} renamed to 
    MYSQL_TIMESTAMP_{TIME,DATETIME,DATE,...}
sql/set_var.h:
  - fixed timestamp_type usage to be compatible with typedef.
sql/sql_prepare.cc:
  - TIMESTAMP_{TIME,DATE,DATETIME} were renamed to
    MYSQL_TIMESTAMP_{TIME,DATE,DATETIME}
  - embedded library implementation of set_param_{time,date,datetime} is
  much simplier now, as MYSQL_TIME is the same as TIME.
sql/sql_yacc.yy:
  - s/\<TIMESTAMP_/MYSQL_TIMESTAMP/gc
sql/structs.h:
  - declarations for TIME and timestamp_type replaced with typedefs
  - str_to_datetime arguments moved to mysys headers
sql/time.cc:
  - str_to_time and str_to_TIME moved to mysys
  - TIMESTAMP_{TIME,DATE,DATETIME,...} renamed to 
    MYSQL_TIMESTAMP_{TIME,DATETIME,DATE,...} as these names are now
    exported to client.
  - str_to_TIME renamed to str_to_datetime to pair with str_to_time
  - str_to_TIME_with_warn renamed accordingly
sql/tztime.cc:
  - TIMESTAMP_{TIME,DATE,DATETIME,...} renamed to 
    MYSQL_TIMESTAMP_{TIME,DATETIME,DATE,...}
tests/client_test.c:
  - a test case for Bug#4030 "Client side conversion string -> date type 
  doesn't work (prepared statements)"
This commit is contained in:
unknown
2004-06-24 19:08:36 +04:00
parent 85e9258b05
commit 9dde418895
25 changed files with 386 additions and 770 deletions

View File

@ -16,6 +16,7 @@
#include <my_global.h>
#include <my_sys.h>
#include <my_time.h>
#include <mysys_err.h>
#include <m_string.h>
#include <m_ctype.h>
@ -3008,33 +3009,33 @@ mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number,
/********************************************************************
Fetch-bind related implementations
Fetch and conversion of result set rows (binary protocol).
*********************************************************************/
/****************************************************************************
Functions to fetch data to application buffers
All functions have the following characteristics:
SYNOPSIS
fetch_result_xxx()
param MySQL bind param
row Row value
RETURN VALUES
0 ok
1 Error (Can't alloc net->buffer)
****************************************************************************/
static void set_zero_time(MYSQL_TIME *tm)
{
tm->year= tm->month= tm->day= 0;
tm->hour= tm->minute= tm->second= 0;
tm->second_part= 0;
tm->neg= (bool)0;
bzero((void *)tm, sizeof(*tm));
}
/* Read TIME from binary packet and return it to MYSQL_TIME */
/*
Read date, (time, datetime) value from network buffer and store it
in MYSQL_TIME structure.
SYNOPSIS
read_binary_{date,time,datetime}()
tm MYSQL_TIME structure to fill
pos pointer to current position in network buffer.
These functions increase pos to point to the beginning of this
field (this is just due to implementation of net_field_length
which is used to get length of binary representation of
time value).
Auxiliary functions to read time (date, datetime) values from network
buffer and store in MYSQL_TIME structure. Jointly used by conversion
and no-conversion fetching.
*/
static uint read_binary_time(MYSQL_TIME *tm, uchar **pos)
{
uchar *to;
@ -3060,7 +3061,6 @@ static uint read_binary_time(MYSQL_TIME *tm, uchar **pos)
return length;
}
/* Read DATETIME from binary packet and return it to MYSQL_TIME */
static uint read_binary_datetime(MYSQL_TIME *tm, uchar **pos)
{
uchar *to;
@ -3091,7 +3091,6 @@ static uint read_binary_datetime(MYSQL_TIME *tm, uchar **pos)
return length;
}
/* Read DATE from binary packet and return it to MYSQL_TIME */
static uint read_binary_date(MYSQL_TIME *tm, uchar **pos)
{
uchar *to;
@ -3115,7 +3114,8 @@ static uint read_binary_date(MYSQL_TIME *tm, uchar **pos)
}
/* Convert Numeric to buffer types */
/* Convert integer value to client buffer type. */
static void send_data_long(MYSQL_BIND *param, MYSQL_FIELD *field,
longlong value)
{
@ -3273,6 +3273,21 @@ static void send_data_str(MYSQL_BIND *param, char *value, uint length)
doublestore(buffer, data);
break;
}
case MYSQL_TYPE_TIME:
{
int dummy;
MYSQL_TIME *tm= (MYSQL_TIME *)buffer;
str_to_time(value, length, tm, &dummy);
break;
}
case MYSQL_TYPE_DATE:
case MYSQL_TYPE_DATETIME:
{
int dummy;
MYSQL_TIME *tm= (MYSQL_TIME *)buffer;
str_to_datetime(value, length, tm, 0, &dummy);
break;
}
case MYSQL_TYPE_TINY_BLOB:
case MYSQL_TYPE_MEDIUM_BLOB:
case MYSQL_TYPE_LONG_BLOB:
@ -3332,7 +3347,7 @@ static void send_data_time(MYSQL_BIND *param, MYSQL_TIME ltime,
length= my_sprintf(buff,(buff, "%04d-%02d-%02d", ltime.year,
ltime.month,ltime.day));
break;
case MYSQL_TIMESTAMP_FULL:
case MYSQL_TIMESTAMP_DATETIME:
length= my_sprintf(buff,(buff, "%04d-%02d-%02d %02d:%02d:%02d",
ltime.year,ltime.month,ltime.day,
ltime.hour,ltime.minute,ltime.second));
@ -3351,7 +3366,7 @@ static void send_data_time(MYSQL_BIND *param, MYSQL_TIME ltime,
}
/* Fetch data to buffers */
/* Fetch data to client buffers with conversion. */
static void fetch_results(MYSQL_BIND *param, MYSQL_FIELD *field, uchar **row)
{
@ -3437,7 +3452,7 @@ static void fetch_results(MYSQL_BIND *param, MYSQL_FIELD *field, uchar **row)
MYSQL_TIME tm;
length= read_binary_datetime(&tm, row);
tm.time_type= MYSQL_TIMESTAMP_FULL;
tm.time_type= MYSQL_TIMESTAMP_DATETIME;
send_data_time(param, tm, length);
break;
}
@ -3450,6 +3465,25 @@ static void fetch_results(MYSQL_BIND *param, MYSQL_FIELD *field, uchar **row)
}
/*
Functions to fetch data to application buffers without conversion.
All functions have the following characteristics:
SYNOPSIS
fetch_result_xxx()
param MySQL bind param
pos Row value
DESCRIPTION
These are no-conversion functions, used in binary protocol to store
rows in application buffers. A function used only if type of binary data
is compatible with type of application buffer.
RETURN
none
*/
static void fetch_result_tinyint(MYSQL_BIND *param, uchar **row)
{
*param->buffer= **row;