1
- /* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
1
+ /* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
2
2
3
3
This program is free software; you can redistribute it and/or modify
4
4
it under the terms of the GNU General Public License as published by
32
32
#include " sql_lex.h"
33
33
#include " sql_string.h"
34
34
#include " system_variables.h"
35
- #include " transaction.h" // trans_commit
36
35
#include " tztime.h" // Time_zone
37
36
38
37
@@ -258,29 +257,6 @@ static Event::enum_interval_field get_enum_interval_field(
258
257
}
259
258
260
259
261
- bool
262
- event_exists (dd::cache::Dictionary_client *dd_client,
263
- const String_type &schema_name,
264
- const String_type &event_name,
265
- bool *exists)
266
- {
267
- DBUG_ENTER (" dd::event_exists" );
268
- DBUG_ASSERT (exists);
269
-
270
- const dd::Event *event_ptr= nullptr ;
271
- dd::cache::Dictionary_client::Auto_releaser releaser (dd_client);
272
- if (dd_client->acquire (schema_name, event_name, &event_ptr))
273
- {
274
- // Error is reported by the dictionary subsystem.
275
- DBUG_RETURN (true );
276
- }
277
-
278
- *exists= event_ptr != nullptr ;
279
-
280
- DBUG_RETURN (false );
281
- }
282
-
283
-
284
260
/* *
285
261
Set Event attributes.
286
262
@@ -387,7 +363,7 @@ static void set_event_attributes(THD *thd, Event *event,
387
363
388
364
389
365
bool create_event (THD *thd,
390
- const String_type &schema_name ,
366
+ const Schema &schema ,
391
367
const String_type &event_name,
392
368
const String_type &event_body,
393
369
const String_type &event_body_utf8,
@@ -396,143 +372,55 @@ bool create_event(THD *thd,
396
372
{
397
373
DBUG_ENTER (" dd::create_event" );
398
374
399
- dd::cache::Dictionary_client *client= thd->dd_client ();
400
- dd::cache::Dictionary_client::Auto_releaser releaser (client);
401
- const dd::Schema *sch_obj= nullptr ;
402
-
403
- // Acquire schema object.
404
- if (client->acquire (schema_name, &sch_obj))
405
- {
406
- // Error is reported by the dictionary subsystem.
407
- DBUG_RETURN (true );
408
- }
409
- if (sch_obj == nullptr )
410
- {
411
- my_error (ER_BAD_DB_ERROR, MYF (0 ), schema_name.c_str ());
412
- DBUG_RETURN (true );
413
- }
414
-
415
- std::unique_ptr<dd::Event> event (sch_obj->create_event (thd));
375
+ std::unique_ptr<dd::Event> event (schema.create_event (thd));
416
376
417
377
// Set Event attributes.
418
378
set_event_attributes (thd, event.get (), event_name, event_body,
419
379
event_body_utf8, definer, event_data, false );
420
380
421
- if (client->store (event.get ()))
422
- {
423
- trans_rollback_stmt (thd);
424
- // Full rollback we have THD::transaction_rollback_request.
425
- trans_rollback (thd);
426
- DBUG_RETURN (true );
427
- }
428
-
429
- DBUG_RETURN (trans_commit_stmt (thd) || trans_commit (thd));
381
+ DBUG_RETURN (thd->dd_client ()->store (event.get ()));
430
382
}
431
383
432
384
433
- bool update_event (THD *thd, const Event *event,
434
- const String_type &new_db_name ,
385
+ bool update_event (THD *thd, Event *event,
386
+ const dd::Schema *new_schema ,
435
387
const String_type &new_event_name,
436
388
const String_type &new_event_body,
437
389
const String_type &new_event_body_utf8,
438
390
const LEX_USER *definer,
439
391
Event_parse_data *event_data)
440
392
{
441
393
DBUG_ENTER (" dd::update_event" );
442
- DBUG_ASSERT (event != nullptr );
443
-
444
- dd::cache::Dictionary_client *client= thd->dd_client ();
445
- dd::cache::Dictionary_client::Auto_releaser releaser (client);
446
-
447
- Event *new_event= nullptr ;
448
- if (client->acquire_for_modification (event->id (), &new_event))
449
- DBUG_RETURN (true );
450
394
451
395
// Check whether alter event was given dates that are in the past.
452
- if (event_data->check_dates (thd, static_cast <int >(new_event ->on_completion ())))
396
+ if (event_data->check_dates (thd, static_cast <int >(event ->on_completion ())))
453
397
DBUG_RETURN (true );
454
398
455
399
// Update Schema Id if there is a dbname change.
456
- if (new_db_name != " " )
457
- {
458
- const dd::Schema *to_sch_ptr;
459
- if (client->acquire (new_db_name, &to_sch_ptr))
460
- DBUG_RETURN (true );
461
-
462
- if (to_sch_ptr == nullptr )
463
- {
464
- my_error (ER_BAD_DB_ERROR, MYF (0 ), new_db_name.c_str ());
465
- DBUG_RETURN (true );
466
- }
467
-
468
- new_event->set_schema_id (to_sch_ptr->id ());
469
- }
400
+ if (new_schema != nullptr )
401
+ event->set_schema_id (new_schema->id ());
470
402
471
403
// Set the altered event attributes.
472
- set_event_attributes (thd, new_event ,
404
+ set_event_attributes (thd, event ,
473
405
new_event_name != " " ? new_event_name : event->name (),
474
406
new_event_body, new_event_body_utf8, definer,
475
407
event_data, true );
476
408
477
- if (client->update (new_event))
478
- {
479
- trans_rollback_stmt (thd);
480
- // Full rollback we have THD::transaction_rollback_request.
481
- trans_rollback (thd);
482
- DBUG_RETURN (true );
483
- }
484
-
485
- DBUG_RETURN (trans_commit_stmt (thd) || trans_commit (thd));
409
+ DBUG_RETURN (thd->dd_client ()->update (event));
486
410
}
487
411
488
- bool update_event_time_and_status (THD *thd, const Event *event,
489
- my_time_t last_executed, ulonglong status)
490
- {
491
- DBUG_ENTER (" dd::update_event_time_fields" );
492
-
493
- DBUG_ASSERT (event != nullptr );
494
-
495
- dd::cache::Dictionary_client *client= thd->dd_client ();
496
- dd::cache::Dictionary_client::Auto_releaser releaser (client);
497
-
498
- Event *new_event= nullptr ;
499
- if (client->acquire_for_modification (event->id (), &new_event))
500
- DBUG_RETURN (true );
501
-
502
- new_event->set_event_status_null (false );
503
- new_event->set_event_status (get_enum_event_status (status));
504
- new_event->set_last_executed_null (false );
505
- new_event->set_last_executed (last_executed);
506
412
507
- if (client->update (new_event))
508
- {
509
- trans_rollback_stmt (thd);
510
- // Full rollback in case we have THD::transaction_rollback_request.
511
- trans_rollback (thd);
512
- DBUG_RETURN (true );
513
- }
514
-
515
- DBUG_RETURN (trans_commit_stmt (thd) || trans_commit (thd));
516
- }
517
-
518
-
519
- bool drop_event (THD *thd, const Event *event)
413
+ bool update_event_time_and_status (THD *thd, Event *event,
414
+ my_time_t last_executed, ulonglong status)
520
415
{
521
- DBUG_ENTER (" dd::drop_event" );
522
-
523
- DBUG_ASSERT (event != nullptr );
524
-
525
- Disable_gtid_state_update_guard disabler (thd);
416
+ DBUG_ENTER (" dd::update_event_time_and_status" );
526
417
527
- if (thd->dd_client ()->drop (event))
528
- {
529
- trans_rollback_stmt (thd);
530
- // Full rollback in case we have THD::transaction_rollback_request.
531
- trans_rollback (thd);
532
- DBUG_RETURN (true );
533
- }
418
+ event->set_event_status_null (false );
419
+ event->set_event_status (get_enum_event_status (status));
420
+ event->set_last_executed_null (false );
421
+ event->set_last_executed (last_executed);
534
422
535
- DBUG_RETURN (trans_commit_stmt ( thd) || trans_commit (thd ));
423
+ DBUG_RETURN (thd-> dd_client ()-> update (event ));
536
424
}
537
425
538
426
} // namespace dd
0 commit comments