~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cursor.cc

Merge Monty - Added inter-plugin dependencies for controlling plugin load order

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
  Handler-calling-functions
24
24
*/
25
25
 
26
 
#include <config.h>
 
26
#include "config.h"
 
27
 
27
28
#include <fcntl.h>
28
 
#include <drizzled/error.h>
29
 
#include <drizzled/field/epoch.h>
30
 
#include <drizzled/gettext.h>
31
 
#include <drizzled/internal/my_sys.h>
32
 
#include <drizzled/item/empty_string.h>
33
 
#include <drizzled/item/int.h>
34
 
#include <drizzled/lock.h>
35
 
#include <drizzled/message/table.h>
36
 
#include <drizzled/optimizer/cost_vector.h>
37
 
#include <drizzled/plugin/client.h>
38
 
#include <drizzled/plugin/event_observer.h>
39
 
#include <drizzled/plugin/storage_engine.h>
40
 
#include <drizzled/probes.h>
41
 
#include <drizzled/session.h>
42
 
#include <drizzled/sql_base.h>
43
 
#include <drizzled/sql_parse.h>
44
 
#include <drizzled/transaction_services.h>
45
 
#include <drizzled/key.h>
46
 
#include <drizzled/sql_lex.h>
47
 
#include <drizzled/resource_context.h>
48
 
#include <drizzled/statistics_variables.h>
49
 
#include <drizzled/system_variables.h>
 
29
 
 
30
#include "drizzled/my_hash.h"
 
31
#include "drizzled/error.h"
 
32
#include "drizzled/gettext.h"
 
33
#include "drizzled/probes.h"
 
34
#include "drizzled/sql_parse.h"
 
35
#include "drizzled/optimizer/cost_vector.h"
 
36
#include "drizzled/session.h"
 
37
#include "drizzled/sql_base.h"
 
38
#include "drizzled/transaction_services.h"
 
39
#include "drizzled/lock.h"
 
40
#include "drizzled/item/int.h"
 
41
#include "drizzled/item/empty_string.h"
 
42
#include "drizzled/field/epoch.h"
 
43
#include "drizzled/message/table.pb.h"
 
44
#include "drizzled/plugin/client.h"
 
45
#include "drizzled/internal/my_sys.h"
 
46
#include "drizzled/plugin/event_observer.h"
50
47
 
51
48
using namespace std;
52
49
 
53
 
namespace drizzled {
 
50
namespace drizzled
 
51
{
54
52
 
55
53
/****************************************************************************
56
54
** General Cursor functions
268
266
*/
269
267
int Cursor::read_first_row(unsigned char * buf, uint32_t primary_key)
270
268
{
271
 
  int error;
 
269
  register int error;
272
270
 
273
271
  ha_statistic_increment(&system_status_var::ha_read_first_count);
274
272
 
275
273
  /*
276
274
    If there is very few deleted rows in the table, find the first row by
277
275
    scanning the table.
278
 
    @todo remove the test for HA_READ_ORDER
 
276
    TODO remove the test for HA_READ_ORDER
279
277
  */
280
278
  if (stats.deleted < 10 || primary_key >= MAX_KEY ||
281
279
      !(getTable()->index_flags(primary_key) & HA_READ_ORDER))
479
477
 
480
478
  if ((nr= next_insert_id) >= auto_inc_interval_for_cur_row.maximum())
481
479
  {
 
480
    /* next_insert_id is beyond what is reserved, so we reserve more. */
 
481
    const Discrete_interval *forced=
 
482
      session->auto_inc_intervals_forced.get_next();
 
483
    if (forced != NULL)
 
484
    {
 
485
      nr= forced->minimum();
 
486
      nb_reserved_values= forced->values();
 
487
    }
 
488
    else
482
489
    {
483
490
      /*
484
491
        Cursor::estimation_rows_to_insert was set by
485
492
        Cursor::ha_start_bulk_insert(); if 0 it means "unknown".
486
493
      */
487
 
      uint32_t nb_already_reserved_intervals= 0;
 
494
      uint32_t nb_already_reserved_intervals=
 
495
        session->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements();
488
496
      uint64_t nb_desired_values;
489
497
      /*
490
498
        If an estimation was given to the engine:
559
567
      nr= getTable()->next_number_field->val_int();
560
568
  }
561
569
  if (append)
562
 
    auto_inc_interval_for_cur_row.replace(nr, nb_reserved_values, variables->auto_increment_increment);
 
570
  {
 
571
    auto_inc_interval_for_cur_row.replace(nr, nb_reserved_values,
 
572
                                          variables->auto_increment_increment);
 
573
  }
563
574
 
564
575
  /*
565
576
    Record this autogenerated value. If the caller then
600
611
  release_auto_increment();
601
612
  insert_id_for_cur_row= 0;
602
613
  auto_inc_interval_for_cur_row.replace(0, 0, 0);
603
 
  next_insert_id= 0;
 
614
  if (next_insert_id > 0)
 
615
  {
 
616
    next_insert_id= 0;
 
617
    /*
 
618
      this statement used forced auto_increment values if there were some,
 
619
      wipe them away for other statements.
 
620
    */
 
621
    getTable()->in_use->auto_inc_intervals_forced.empty();
 
622
  }
604
623
}
605
624
 
606
625
void Cursor::drop_table(const char *)
638
657
void
639
658
Cursor::setTransactionReadWrite()
640
659
{
 
660
  ResourceContext *resource_context;
 
661
 
641
662
  /*
642
663
   * If the cursor has not context for execution then there should be no
643
664
   * possible resource to gain (and if there is... then there is a bug such
646
667
  if (not getTable()->in_use)
647
668
    return;
648
669
 
 
670
  resource_context= getTable()->in_use->getResourceContext(getEngine());
649
671
  /*
650
672
    When a storage engine method is called, the transaction must
651
673
    have been started, unless it's a DDL call, for which the
654
676
    Unfortunately here we can't know know for sure if the engine
655
677
    has registered the transaction or not, so we must check.
656
678
  */
657
 
  ResourceContext& resource_context= getTable()->in_use->getResourceContext(*getEngine());
658
 
  if (resource_context.isStarted())
659
 
    resource_context.markModifiedData();
 
679
  if (resource_context->isStarted())
 
680
  {
 
681
    resource_context->markModifiedData();
 
682
  }
660
683
}
661
684
 
662
685
 
1276
1299
 
1277
1300
  bool result= false;
1278
1301
 
1279
 
  switch (session->lex().sql_command)
 
1302
  switch (session->lex->sql_command)
1280
1303
  {
1281
1304
  case SQLCOM_CREATE_TABLE:
1282
1305
    /*