Commit 6897b002 authored by serg@serg.mysql.com's avatar serg@serg.mysql.com

--new option and local variable to optionally turn on

"very new functions" - for now 4.1-compatible TIMESTAMT format
parent 0309191c
...@@ -84,3 +84,23 @@ date date_time time_stamp ...@@ -84,3 +84,23 @@ date date_time time_stamp
2005-01-01 2005-01-01 00:00:00 20050101000000 2005-01-01 2005-01-01 00:00:00 20050101000000
2030-01-01 2030-01-01 00:00:00 20300101000000 2030-01-01 2030-01-01 00:00:00 20300101000000
drop table t1; drop table t1;
show variables like 'new';
Variable_name Value
new OFF
create table t1 (t2 timestamp(2), t4 timestamp(4), t6 timestamp(6),
t8 timestamp(8), t10 timestamp(10), t12 timestamp(12),
t14 timestamp(14));
insert t1 values (0,0,0,0,0,0,0),
("1997-12-31 23:47:59", "1997-12-31 23:47:59", "1997-12-31 23:47:59",
"1997-12-31 23:47:59", "1997-12-31 23:47:59", "1997-12-31 23:47:59",
"1997-12-31 23:47:59");
select * from t1;
t2 t4 t6 t8 t10 t12 t14
00 0000 000000 00000000 0000000000 000000000000 00000000000000
97 9712 971231 19971231 9712312347 971231234759 19971231234759
set new=1;
select * from t1;
t2 t4 t6 t8 t10 t12 t14
00 00-00 00-00-00 0000-00-00 00-00-00 00:00 00-00-00 00:00:00 0000-00-00 00:00:00
97 97-12 97-12-31 1997-12-31 97-12-31 23:47 97-12-31 23:47:59 1997-12-31 23:47:59
drop table t1;
...@@ -55,3 +55,17 @@ INSERT INTO t1 VALUES ("2030-01-01","2030-01-01 00:00:00",20300101000000); ...@@ -55,3 +55,17 @@ INSERT INTO t1 VALUES ("2030-01-01","2030-01-01 00:00:00",20300101000000);
#INSERT INTO t1 VALUES ("2050-01-01","2050-01-01 00:00:00",20500101000000); #INSERT INTO t1 VALUES ("2050-01-01","2050-01-01 00:00:00",20500101000000);
SELECT * FROM t1; SELECT * FROM t1;
drop table t1; drop table t1;
show variables like 'new';
create table t1 (t2 timestamp(2), t4 timestamp(4), t6 timestamp(6),
t8 timestamp(8), t10 timestamp(10), t12 timestamp(12),
t14 timestamp(14));
insert t1 values (0,0,0,0,0,0,0),
("1997-12-31 23:47:59", "1997-12-31 23:47:59", "1997-12-31 23:47:59",
"1997-12-31 23:47:59", "1997-12-31 23:47:59", "1997-12-31 23:47:59",
"1997-12-31 23:47:59");
select * from t1;
set new=1;
select * from t1;
drop table t1;
...@@ -2616,14 +2616,17 @@ String *Field_timestamp::val_str(String *val_buffer, ...@@ -2616,14 +2616,17 @@ String *Field_timestamp::val_str(String *val_buffer,
String *val_ptr __attribute__((unused))) String *val_ptr __attribute__((unused)))
{ {
uint pos; uint pos;
int extra;
int part_time; int part_time;
uint32 temp; uint32 temp;
time_t time_arg; time_t time_arg;
struct tm *l_time; struct tm *l_time;
struct tm tm_tmp; struct tm tm_tmp;
my_bool new_format= (current_thd->variables.new_mode),
full_year=(field_length == 8 || field_length == 14);
static const uint extras[]={0,1,2,2,4,5,5};
val_buffer->alloc(field_length+1); extra= new_format ? extras[field_length/2-1] : 0;
char *to=(char*) val_buffer->ptr(),*end=to+field_length;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first) if (table->db_low_byte_first)
...@@ -2634,17 +2637,24 @@ String *Field_timestamp::val_str(String *val_buffer, ...@@ -2634,17 +2637,24 @@ String *Field_timestamp::val_str(String *val_buffer,
if (temp == 0L) if (temp == 0L)
{ /* Zero time is "000000" */ { /* Zero time is "000000" */
VOID(strfill(to,field_length,'0')); if (new_format)
val_buffer->length(field_length); val_buffer->copy("0000-00-00 00:00:00"+2*(1-full_year),
field_length+extra);
else
val_buffer->copy("00000000000000", field_length);
return val_buffer; return val_buffer;
} }
time_arg=(time_t) temp; time_arg=(time_t) temp;
localtime_r(&time_arg,&tm_tmp); localtime_r(&time_arg,&tm_tmp);
l_time=&tm_tmp; l_time=&tm_tmp;
val_buffer->alloc(field_length+extra+1);
char *to=(char*) val_buffer->ptr(),*end=to+field_length+extra;
for (pos=0; to < end ; pos++) for (pos=0; to < end ; pos++)
{ {
bool year_flag=0; bool year_flag=0;
switch (dayord.pos[pos]) { switch (pos) {
case 0: part_time=l_time->tm_year % 100; year_flag=1; break; case 0: part_time=l_time->tm_year % 100; year_flag=1; break;
case 1: part_time=l_time->tm_mon+1; break; case 1: part_time=l_time->tm_mon+1; break;
case 2: part_time=l_time->tm_mday; break; case 2: part_time=l_time->tm_mday; break;
...@@ -2653,7 +2663,7 @@ String *Field_timestamp::val_str(String *val_buffer, ...@@ -2653,7 +2663,7 @@ String *Field_timestamp::val_str(String *val_buffer,
case 5: part_time=l_time->tm_sec; break; case 5: part_time=l_time->tm_sec; break;
default: part_time=0; break; /* purecov: deadcode */ default: part_time=0; break; /* purecov: deadcode */
} }
if (year_flag && (field_length == 8 || field_length == 14)) if (year_flag && full_year)
{ {
if (part_time < YY_PART_YEAR) if (part_time < YY_PART_YEAR)
{ {
...@@ -2666,7 +2676,14 @@ String *Field_timestamp::val_str(String *val_buffer, ...@@ -2666,7 +2676,14 @@ String *Field_timestamp::val_str(String *val_buffer,
} }
*to++=(char) ('0'+((uint) part_time/10)); *to++=(char) ('0'+((uint) part_time/10));
*to++=(char) ('0'+((uint) part_time % 10)); *to++=(char) ('0'+((uint) part_time % 10));
if (new_format)
{
static const char delim[6]="-- ::";
*to++=delim[pos];
}
} }
if (new_format)
to--;
*to=0; // Safeguard *to=0; // Safeguard
val_buffer->length((uint) (to-val_buffer->ptr())); val_buffer->length((uint) (to-val_buffer->ptr()));
return val_buffer; return val_buffer;
......
...@@ -3423,8 +3423,10 @@ struct my_option my_long_options[] = ...@@ -3423,8 +3423,10 @@ struct my_option my_long_options[] =
{"safemalloc-mem-limit", OPT_SAFEMALLOC_MEM_LIMIT, {"safemalloc-mem-limit", OPT_SAFEMALLOC_MEM_LIMIT,
"Simulate memory shortage when compiled with the --with-debug=full option", "Simulate memory shortage when compiled with the --with-debug=full option",
0, 0, 0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, 0, 0, 0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"new", 'n', "Use very new possible 'unsafe' functions", 0, 0, 0, GET_NO_ARG, {"new", 'n', "Use very new possible 'unsafe' functions",
NO_ARG, 0, 0, 0, 0, 0, 0}, (gptr*) &global_system_variables.new_mode,
(gptr*) &max_system_variables.new_mode,
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
#ifdef NOT_YET #ifdef NOT_YET
{"no-mix-table-types", OPT_NO_MIX_TYPE, "Don't allow commands with uses two different table types", {"no-mix-table-types", OPT_NO_MIX_TYPE, "Don't allow commands with uses two different table types",
(gptr*) &opt_no_mix_types, (gptr*) &opt_no_mix_types, 0, GET_BOOL, NO_ARG, (gptr*) &opt_no_mix_types, (gptr*) &opt_no_mix_types, 0, GET_BOOL, NO_ARG,
...@@ -4222,9 +4224,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), ...@@ -4222,9 +4224,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case 'L': case 'L':
strmake(language, argument, sizeof(language)-1); strmake(language, argument, sizeof(language)-1);
break; break;
case 'n':
opt_specialflag|= SPECIAL_NEW_FUNC;
break;
case 'o': case 'o':
protocol_version=PROTOCOL_VERSION-1; protocol_version=PROTOCOL_VERSION-1;
break; break;
......
...@@ -179,6 +179,7 @@ sys_var_thd_ulong sys_net_write_timeout("net_write_timeout", ...@@ -179,6 +179,7 @@ sys_var_thd_ulong sys_net_write_timeout("net_write_timeout",
sys_var_thd_ulong sys_net_retry_count("net_retry_count", sys_var_thd_ulong sys_net_retry_count("net_retry_count",
&SV::net_retry_count, &SV::net_retry_count,
fix_net_retry_count); fix_net_retry_count);
sys_var_thd_bool sys_new_mode("new", &SV::new_mode);
sys_var_thd_ulong sys_read_buff_size("read_buffer_size", sys_var_thd_ulong sys_read_buff_size("read_buffer_size",
&SV::read_buff_size); &SV::read_buff_size);
sys_var_thd_ulong sys_read_rnd_buff_size("read_rnd_buffer_size", sys_var_thd_ulong sys_read_rnd_buff_size("read_rnd_buffer_size",
...@@ -347,6 +348,7 @@ sys_var *sys_variables[]= ...@@ -347,6 +348,7 @@ sys_var *sys_variables[]=
&sys_net_retry_count, &sys_net_retry_count,
&sys_net_wait_timeout, &sys_net_wait_timeout,
&sys_net_write_timeout, &sys_net_write_timeout,
&sys_new_mode,
&sys_query_cache_size, &sys_query_cache_size,
#ifdef HAVE_QUERY_CACHE #ifdef HAVE_QUERY_CACHE
&sys_query_cache_limit, &sys_query_cache_limit,
...@@ -490,6 +492,7 @@ struct show_var_st init_vars[]= { ...@@ -490,6 +492,7 @@ struct show_var_st init_vars[]= {
{sys_net_read_timeout.name, (char*) &sys_net_read_timeout, SHOW_SYS}, {sys_net_read_timeout.name, (char*) &sys_net_read_timeout, SHOW_SYS},
{sys_net_retry_count.name, (char*) &sys_net_retry_count, SHOW_SYS}, {sys_net_retry_count.name, (char*) &sys_net_retry_count, SHOW_SYS},
{sys_net_write_timeout.name,(char*) &sys_net_write_timeout, SHOW_SYS}, {sys_net_write_timeout.name,(char*) &sys_net_write_timeout, SHOW_SYS},
{sys_new_mode.name, (char*) &sys_new_mode, SHOW_SYS},
{"open_files_limit", (char*) &open_files_limit, SHOW_LONG}, {"open_files_limit", (char*) &open_files_limit, SHOW_LONG},
{"pid_file", (char*) pidfile_name, SHOW_CHAR}, {"pid_file", (char*) pidfile_name, SHOW_CHAR},
{"log_error", (char*) log_error_file, SHOW_CHAR}, {"log_error", (char*) log_error_file, SHOW_CHAR},
......
...@@ -311,6 +311,7 @@ struct system_variables ...@@ -311,6 +311,7 @@ struct system_variables
my_bool log_warnings; my_bool log_warnings;
my_bool low_priority_updates; my_bool low_priority_updates;
my_bool new_mode;
CONVERT *convert_set; CONVERT *convert_set;
}; };
......
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
#define SPECIAL_USE_LOCKS 1 /* Lock used databases */ #define SPECIAL_USE_LOCKS 1 /* Lock used databases */
#define SPECIAL_NO_NEW_FUNC 2 /* Skip new functions */ #define SPECIAL_NO_NEW_FUNC 2 /* Skip new functions */
#define SPECIAL_NEW_FUNC 4 /* New nonstandard functions */ #define SPECIAL_SKIP_SHOW_DB 4 /* Don't allow 'show db' */
#define SPECIAL_WAIT_IF_LOCKED 8 /* Wait if locked database */ #define SPECIAL_WAIT_IF_LOCKED 8 /* Wait if locked database */
#define SPECIAL_SAME_DB_NAME 16 /* form name = file name */ #define SPECIAL_SAME_DB_NAME 16 /* form name = file name */
#define SPECIAL_ENGLISH 32 /* English error messages */ #define SPECIAL_ENGLISH 32 /* English error messages */
...@@ -92,7 +92,6 @@ ...@@ -92,7 +92,6 @@
#define SPECIAL_NO_HOST_CACHE 512 /* Don't cache hosts */ #define SPECIAL_NO_HOST_CACHE 512 /* Don't cache hosts */
#define SPECIAL_LONG_LOG_FORMAT 1024 #define SPECIAL_LONG_LOG_FORMAT 1024
#define SPECIAL_SAFE_MODE 2048 #define SPECIAL_SAFE_MODE 2048
#define SPECIAL_SKIP_SHOW_DB 4096 /* Don't allow 'show db' */
/* Extern defines */ /* Extern defines */
#define store_record(A,B) bmove_allign((A)->record[B],(A)->record[0],(size_t) (A)->reclength) #define store_record(A,B) bmove_allign((A)->record[B],(A)->record[0],(size_t) (A)->reclength)
......
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