324
324
sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
325
325
&SV::engine_condition_pushdown);
327
/* Time/date/datetime formats */
329
static sys_var_session_date_time_format sys_time_format(&vars, "time_format",
331
DRIZZLE_TIMESTAMP_TIME);
332
static sys_var_session_date_time_format sys_date_format(&vars, "date_format",
334
DRIZZLE_TIMESTAMP_DATE);
335
static sys_var_session_date_time_format sys_datetime_format(&vars, "datetime_format",
336
&SV::datetime_format,
337
DRIZZLE_TIMESTAMP_DATETIME);
339
327
/* Variables that are bits in Session */
341
329
sys_var_session_bit sys_autocommit(&vars, "autocommit", 0,
1373
/** Update a date_time format variable based on given value. */
1375
void sys_var_session_date_time_format::update2(Session *session, enum_var_type type,
1376
DATE_TIME_FORMAT *new_value)
1378
DATE_TIME_FORMAT *old;
1380
if (type == OPT_GLOBAL)
1382
pthread_mutex_lock(&LOCK_global_system_variables);
1383
old= (global_system_variables.*offset);
1384
(global_system_variables.*offset)= new_value;
1385
pthread_mutex_unlock(&LOCK_global_system_variables);
1389
old= (session->variables.*offset);
1390
(session->variables.*offset)= new_value;
1397
bool sys_var_session_date_time_format::update(Session *session, set_var *var)
1399
DATE_TIME_FORMAT *new_value;
1400
/* We must make a copy of the last value to get it into normal memory */
1401
new_value= date_time_format_copy((Session*) 0,
1402
var->save_result.date_time_format);
1404
return 1; // Out of memory
1405
update2(session, var->type, new_value); // Can't fail
1410
bool sys_var_session_date_time_format::check(Session *session, set_var *var)
1412
char buff[STRING_BUFFER_USUAL_SIZE];
1413
String str(buff,sizeof(buff), system_charset_info), *res;
1414
DATE_TIME_FORMAT *format;
1416
if (!(res=var->value->val_str(&str)))
1417
res= &my_empty_string;
1419
if (!(format= date_time_format_make(date_time_type,
1420
res->ptr(), res->length())))
1422
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, res->c_ptr());
1427
We must copy result to thread space to not get a memory leak if
1430
var->save_result.date_time_format= date_time_format_copy(session, format);
1431
free((char*) format);
1432
return var->save_result.date_time_format == 0;
1436
void sys_var_session_date_time_format::set_default(Session *session, enum_var_type type)
1438
DATE_TIME_FORMAT *res= 0;
1440
if (type == OPT_GLOBAL)
1443
if ((format= opt_date_time_formats[date_time_type]))
1444
res= date_time_format_make(date_time_type, format, strlen(format));
1448
/* Make copy with malloc */
1449
res= date_time_format_copy((Session *) 0, global_system_variables.*offset);
1452
if (res) // Should always be true
1453
update2(session, type, res);
1457
unsigned char *sys_var_session_date_time_format::value_ptr(Session *session,
1461
if (type == OPT_GLOBAL)
1465
We do a copy here just to be sure things will work even if someone
1466
is modifying the original string while the copy is accessed
1467
(Can't happen now in SQL SHOW, but this is a good safety for the future)
1469
res= session->strmake((global_system_variables.*offset)->format.str,
1470
(global_system_variables.*offset)->format.length);
1471
return (unsigned char*) res;
1473
return (unsigned char*) (session->variables.*offset)->format.str;
1477
1361
typedef struct old_names_map_st
1479
1363
const char *old_name;