~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Jay Pipes
  • Date: 2009-02-28 17:49:22 UTC
  • mto: (910.2.6 mordred-noatomics)
  • mto: This revision was merged to the branch mainline in revision 908.
  • Revision ID: jpipes@serialcoder-20090228174922-jczgt4d0662fqmnf
Merging in old r902 temporal changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
324
324
sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
325
325
                              &SV::engine_condition_pushdown);
326
326
 
327
 
/* Time/date/datetime formats */
328
 
 
329
 
static sys_var_session_date_time_format sys_time_format(&vars, "time_format",
330
 
                                             &SV::time_format,
331
 
                                             DRIZZLE_TIMESTAMP_TIME);
332
 
static sys_var_session_date_time_format sys_date_format(&vars, "date_format",
333
 
                                             &SV::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);
338
 
 
339
327
/* Variables that are bits in Session */
340
328
 
341
329
sys_var_session_bit sys_autocommit(&vars, "autocommit", 0,
1370
1358
}
1371
1359
 
1372
1360
 
1373
 
/** Update a date_time format variable based on given value. */
1374
 
 
1375
 
void sys_var_session_date_time_format::update2(Session *session, enum_var_type type,
1376
 
                                           DATE_TIME_FORMAT *new_value)
1377
 
{
1378
 
  DATE_TIME_FORMAT *old;
1379
 
 
1380
 
  if (type == OPT_GLOBAL)
1381
 
  {
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);
1386
 
  }
1387
 
  else
1388
 
  {
1389
 
    old= (session->variables.*offset);
1390
 
    (session->variables.*offset)= new_value;
1391
 
  }
1392
 
  free((char*) old);
1393
 
  return;
1394
 
}
1395
 
 
1396
 
 
1397
 
bool sys_var_session_date_time_format::update(Session *session, set_var *var)
1398
 
{
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);
1403
 
  if (!new_value)
1404
 
    return 1;                                   // Out of memory
1405
 
  update2(session, var->type, new_value);               // Can't fail
1406
 
  return 0;
1407
 
}
1408
 
 
1409
 
 
1410
 
bool sys_var_session_date_time_format::check(Session *session, set_var *var)
1411
 
{
1412
 
  char buff[STRING_BUFFER_USUAL_SIZE];
1413
 
  String str(buff,sizeof(buff), system_charset_info), *res;
1414
 
  DATE_TIME_FORMAT *format;
1415
 
 
1416
 
  if (!(res=var->value->val_str(&str)))
1417
 
    res= &my_empty_string;
1418
 
 
1419
 
  if (!(format= date_time_format_make(date_time_type,
1420
 
                                      res->ptr(), res->length())))
1421
 
  {
1422
 
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, res->c_ptr());
1423
 
    return 1;
1424
 
  }
1425
 
 
1426
 
  /*
1427
 
    We must copy result to thread space to not get a memory leak if
1428
 
    update is aborted
1429
 
  */
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;
1433
 
}
1434
 
 
1435
 
 
1436
 
void sys_var_session_date_time_format::set_default(Session *session, enum_var_type type)
1437
 
{
1438
 
  DATE_TIME_FORMAT *res= 0;
1439
 
 
1440
 
  if (type == OPT_GLOBAL)
1441
 
  {
1442
 
    const char *format;
1443
 
    if ((format= opt_date_time_formats[date_time_type]))
1444
 
      res= date_time_format_make(date_time_type, format, strlen(format));
1445
 
  }
1446
 
  else
1447
 
  {
1448
 
    /* Make copy with malloc */
1449
 
    res= date_time_format_copy((Session *) 0, global_system_variables.*offset);
1450
 
  }
1451
 
 
1452
 
  if (res)                                      // Should always be true
1453
 
    update2(session, type, res);
1454
 
}
1455
 
 
1456
 
 
1457
 
unsigned char *sys_var_session_date_time_format::value_ptr(Session *session,
1458
 
                                                           enum_var_type type,
1459
 
                                                           const LEX_STRING *)
1460
 
{
1461
 
  if (type == OPT_GLOBAL)
1462
 
  {
1463
 
    char *res;
1464
 
    /*
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)
1468
 
    */
1469
 
    res= session->strmake((global_system_variables.*offset)->format.str,
1470
 
                      (global_system_variables.*offset)->format.length);
1471
 
    return (unsigned char*) res;
1472
 
  }
1473
 
  return (unsigned char*) (session->variables.*offset)->format.str;
1474
 
}
1475
 
 
1476
 
 
1477
1361
typedef struct old_names_map_st
1478
1362
{
1479
1363
  const char *old_name;