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
2005-01-01 2005-01-01 00:00:00 20050101000000
2030-01-01 2030-01-01 00:00:00 20300101000000
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);
#INSERT INTO t1 VALUES ("2050-01-01","2050-01-01 00:00:00",20500101000000);
SELECT * FROM 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,
String *val_ptr __attribute__((unused)))
{
uint pos;
int extra;
int part_time;
uint32 temp;
time_t time_arg;
struct tm *l_time;
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);
char *to=(char*) val_buffer->ptr(),*end=to+field_length;
extra= new_format ? extras[field_length/2-1] : 0;
#ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first)
......@@ -2634,17 +2637,24 @@ String *Field_timestamp::val_str(String *val_buffer,
if (temp == 0L)
{ /* Zero time is "000000" */
VOID(strfill(to,field_length,'0'));
val_buffer->length(field_length);
if (new_format)
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;
}
time_arg=(time_t) temp;
localtime_r(&time_arg,&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++)
{
bool year_flag=0;
switch (dayord.pos[pos]) {
switch (pos) {
case 0: part_time=l_time->tm_year % 100; year_flag=1; break;
case 1: part_time=l_time->tm_mon+1; break;
case 2: part_time=l_time->tm_mday; break;
......@@ -2653,7 +2663,7 @@ String *Field_timestamp::val_str(String *val_buffer,
case 5: part_time=l_time->tm_sec; break;
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)
{
......@@ -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));
if (new_format)
{
static const char delim[6]="-- ::";
*to++=delim[pos];
}
}
if (new_format)
to--;
*to=0; // Safeguard
val_buffer->length((uint) (to-val_buffer->ptr()));
return val_buffer;
......
......@@ -3340,7 +3340,7 @@ struct my_option my_long_options[] =
{"log-long-format", OPT_LONG_FORMAT,
"Log some extra information to update log", 0, 0, 0, GET_NO_ARG, NO_ARG,
0, 0, 0, 0, 0, 0},
{"log-slave-updates", OPT_LOG_SLAVE_UPDATES,
{"log-slave-updates", OPT_LOG_SLAVE_UPDATES,
"Tells the slave to log the updates from the slave thread to the binary log. You will need to turn it on if you plan to daisy-chain the slaves.",
(gptr*) &opt_log_slave_updates, (gptr*) &opt_log_slave_updates, 0, GET_BOOL,
NO_ARG, 0, 0, 0, 0, 0, 0},
......@@ -3349,7 +3349,7 @@ struct my_option my_long_options[] =
(gptr*) &global_system_variables.low_priority_updates,
(gptr*) &max_system_variables.low_priority_updates,
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"master-host", OPT_MASTER_HOST,
{"master-host", OPT_MASTER_HOST,
"Master hostname or IP address for replication. If not set, the slave thread will not be started. Note that the setting of master-host will be ignored if there exists a valid master.info file.",
(gptr*) &master_host, (gptr*) &master_host, 0, GET_STR, REQUIRED_ARG, 0, 0,
0, 0, 0, 0},
......@@ -3423,8 +3423,10 @@ struct my_option my_long_options[] =
{"safemalloc-mem-limit", OPT_SAFEMALLOC_MEM_LIMIT,
"Simulate memory shortage when compiled with the --with-debug=full option",
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,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"new", 'n', "Use very new possible 'unsafe' functions",
(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
{"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,
......@@ -4222,9 +4224,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case 'L':
strmake(language, argument, sizeof(language)-1);
break;
case 'n':
opt_specialflag|= SPECIAL_NEW_FUNC;
break;
case 'o':
protocol_version=PROTOCOL_VERSION-1;
break;
......@@ -4232,9 +4231,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
init_slave_skip_errors(argument);
break;
case OPT_SAFEMALLOC_MEM_LIMIT:
#if !defined(DBUG_OFF) && defined(SAFEMALLOC)
#if !defined(DBUG_OFF) && defined(SAFEMALLOC)
safemalloc_mem_limit = atoi(argument);
#endif
#endif
break;
#ifdef EMBEDDED_LIBRARY
case OPT_MAX_ALLOWED_PACKET:
......
......@@ -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",
&SV::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",
&SV::read_buff_size);
sys_var_thd_ulong sys_read_rnd_buff_size("read_rnd_buffer_size",
......@@ -347,6 +348,7 @@ sys_var *sys_variables[]=
&sys_net_retry_count,
&sys_net_wait_timeout,
&sys_net_write_timeout,
&sys_new_mode,
&sys_query_cache_size,
#ifdef HAVE_QUERY_CACHE
&sys_query_cache_limit,
......@@ -490,6 +492,7 @@ struct show_var_st init_vars[]= {
{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_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},
{"pid_file", (char*) pidfile_name, SHOW_CHAR},
{"log_error", (char*) log_error_file, SHOW_CHAR},
......
......@@ -310,7 +310,8 @@ struct system_variables
ulong table_type;
my_bool log_warnings;
my_bool low_priority_updates;
my_bool low_priority_updates;
my_bool new_mode;
CONVERT *convert_set;
};
......
......@@ -82,7 +82,7 @@
#define SPECIAL_USE_LOCKS 1 /* Lock used databases */
#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_SAME_DB_NAME 16 /* form name = file name */
#define SPECIAL_ENGLISH 32 /* English error messages */
......@@ -92,7 +92,6 @@
#define SPECIAL_NO_HOST_CACHE 512 /* Don't cache hosts */
#define SPECIAL_LONG_LOG_FORMAT 1024
#define SPECIAL_SAFE_MODE 2048
#define SPECIAL_SKIP_SHOW_DB 4096 /* Don't allow 'show db' */
/* Extern defines */
#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