~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table/instance.cc

  • Committer: Brian Aker
  • Date: 2010-10-22 17:44:34 UTC
  • mto: This revision was merged to the branch mainline in revision 1873.
  • Revision ID: brian@tangent.org-20101022174434-q8fjovcpclzqer7n
TableShare is no longer in the house (i.e. we no longer directly have a copy
of it in cursor).

One more bit of the knot now gone.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
namespace table
37
37
{
38
38
 
39
 
Instance::Instance(Session *session, List<CreateField> &field_list) :
40
 
  _share(message::Table::INTERNAL),
41
 
  _has_variable_width(false)
42
 
{
43
 
  uint32_t field_count= field_list.elements;
44
 
  uint32_t blob_count= 0;
45
 
  Field **field_arg;
46
 
  CreateField *cdef;                           /* column definition */
47
 
  uint32_t record_length= 0;
48
 
  uint32_t null_count= 0;                 /* number of columns which may be null */
49
 
  uint32_t null_pack_length;              /* NULL representation array length */
50
 
 
51
 
  getMutableShare()->setFields(field_count + 1);
52
 
  setFields(getMutableShare()->getFields(true));
53
 
  field_arg= getMutableShare()->getFields(true);
54
 
  getMutableShare()->blob_field.resize(field_count+1);
55
 
  getMutableShare()->fields= field_count;
56
 
  getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
57
 
  setup_tmp_table_column_bitmaps();
58
 
 
59
 
  in_use= session;           /* field_arg->reset() may access in_use */
60
 
 
61
 
  /* Create all fields and calculate the total length of record */
62
 
  List_iterator_fast<CreateField> it(field_list);
63
 
  while ((cdef= it++))
64
 
  {
65
 
    *field_arg= getMutableShare()->make_field(NULL,
66
 
                                                 cdef->length,
67
 
                                                 (cdef->flags & NOT_NULL_FLAG) ? false : true,
68
 
                                                 (unsigned char *) ((cdef->flags & NOT_NULL_FLAG) ? 0 : ""),
69
 
                                                 (cdef->flags & NOT_NULL_FLAG) ? 0 : 1,
70
 
                                                 cdef->decimals,
71
 
                                                 cdef->sql_type,
72
 
                                                 cdef->charset,
73
 
                                                 cdef->unireg_check,
74
 
                                                 cdef->interval,
75
 
                                                 cdef->field_name);
76
 
    if (!*field_arg)
77
 
    {
78
 
      throw "Memory allocation failure";
79
 
    }
80
 
 
81
 
    (*field_arg)->init(this);
82
 
    record_length+= (*field_arg)->pack_length();
83
 
    if (! ((*field_arg)->flags & NOT_NULL_FLAG))
84
 
      null_count++;
85
 
 
86
 
    if ((*field_arg)->flags & BLOB_FLAG)
87
 
      getMutableShare()->blob_field[blob_count++]= (uint32_t) (field_arg - getFields());
88
 
 
89
 
    field_arg++;
90
 
  }
91
 
  *field_arg= NULL;                             /* mark the end of the list */
92
 
  getMutableShare()->blob_field[blob_count]= 0;            /* mark the end of the list */
93
 
  getMutableShare()->blob_fields= blob_count;
94
 
 
95
 
  null_pack_length= (null_count + 7)/8;
96
 
  getMutableShare()->setRecordLength(record_length + null_pack_length);
97
 
  getMutableShare()->rec_buff_length= ALIGN_SIZE(getMutableShare()->getRecordLength() + 1);
98
 
  record[0]= (unsigned char*)session->alloc(getMutableShare()->rec_buff_length);
99
 
  if (not getInsertRecord())
100
 
  {
101
 
    throw "Memory allocation failure";
102
 
  }
103
 
 
104
 
  if (null_pack_length)
105
 
  {
106
 
    null_flags= (unsigned char*) getInsertRecord();
107
 
    getMutableShare()->null_fields= null_count;
108
 
    getMutableShare()->null_bytes= null_pack_length;
109
 
  }
110
 
  {
111
 
    /* Set up field pointers */
112
 
    unsigned char *null_pos= getInsertRecord();
113
 
    unsigned char *field_pos= null_pos + getMutableShare()->null_bytes;
114
 
    uint32_t null_bit= 1;
115
 
 
116
 
    for (field_arg= getFields(); *field_arg; ++field_arg)
117
 
    {
118
 
      Field *cur_field= *field_arg;
119
 
      if ((cur_field->flags & NOT_NULL_FLAG))
120
 
        cur_field->move_field(field_pos);
121
 
      else
122
 
      {
123
 
        cur_field->move_field(field_pos, (unsigned char*) null_pos, null_bit);
124
 
        null_bit<<= 1;
125
 
        if (null_bit == (1 << 8))
126
 
        {
127
 
          ++null_pos;
128
 
          null_bit= 1;
129
 
        }
130
 
      }
131
 
      cur_field->reset();
132
 
 
133
 
      field_pos+= cur_field->pack_length();
134
 
    }
135
 
  }
136
 
}
137
 
 
138
39
bool Instance::open_tmp_table()
139
40
{
140
41
  int error;
141
42
  
142
43
  TableIdentifier identifier(getShare()->getSchemaName(), getShare()->getTableName(), getShare()->getPath());
143
44
  if ((error=cursor->ha_open(identifier,
 
45
                             this,
144
46
                             O_RDWR,
145
47
                             HA_OPEN_TMP_TABLE | HA_OPEN_INTERNAL_TABLE)))
146
48
  {