~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table/instance.cc

  • Committer: Brian Aker
  • Date: 2010-10-27 23:31:42 UTC
  • mto: (1887.2.1 merge)
  • mto: This revision was merged to the branch mainline in revision 1888.
  • Revision ID: brian@tangent.org-20101027233142-lmo86qafuoz1xmk2
Move table_share over into definition and fix header.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
 
21
#include "config.h"
22
22
 
23
23
#include <sys/types.h>
24
24
#include <sys/stat.h>
25
25
#include <fcntl.h>
26
26
 
27
 
#include <drizzled/session.h>
28
 
#include <plugin/myisam/myisam.h>
29
 
#include <drizzled/plugin/transactional_storage_engine.h>
 
27
#include "drizzled/session.h"
 
28
#include "plugin/myisam/myisam.h"
 
29
#include "drizzled/plugin/transactional_storage_engine.h"
30
30
 
31
 
#include <drizzled/table.h>
 
31
#include "drizzled/table.h"
32
32
 
33
33
namespace drizzled
34
34
{
36
36
namespace table
37
37
{
38
38
 
39
 
Singular::Singular(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()->setFieldSize(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<CreateField>::iterator it(field_list.begin());
63
 
  message::Table::Field null_field;
64
 
  while ((cdef= it++))
65
 
  {
66
 
    *field_arg= getMutableShare()->make_field(null_field,
67
 
                                              NULL,
68
 
                                              cdef->length,
69
 
                                              (cdef->flags & NOT_NULL_FLAG) ? false : true,
70
 
                                              (unsigned char *) ((cdef->flags & NOT_NULL_FLAG) ? 0 : ""),
71
 
                                              (cdef->flags & NOT_NULL_FLAG) ? 0 : 1,
72
 
                                              cdef->decimals,
73
 
                                              cdef->sql_type,
74
 
                                              cdef->charset,
75
 
                                              cdef->unireg_check,
76
 
                                              cdef->interval,
77
 
                                              cdef->field_name,
78
 
                                              cdef->flags & UNSIGNED_FLAG ? true : false);
79
 
    if (!*field_arg)
80
 
    {
81
 
      throw "Memory allocation failure";
82
 
    }
83
 
 
84
 
    (*field_arg)->init(this);
85
 
    record_length+= (*field_arg)->pack_length();
86
 
    if (! ((*field_arg)->flags & NOT_NULL_FLAG))
87
 
      null_count++;
88
 
 
89
 
    if ((*field_arg)->flags & BLOB_FLAG)
90
 
      getMutableShare()->blob_field[blob_count++]= (uint32_t) (field_arg - getFields());
91
 
 
92
 
    field_arg++;
93
 
  }
94
 
  *field_arg= NULL;                             /* mark the end of the list */
95
 
  getMutableShare()->blob_field[blob_count]= 0;            /* mark the end of the list */
96
 
  getMutableShare()->blob_fields= blob_count;
97
 
 
98
 
  null_pack_length= (null_count + 7)/8;
99
 
  getMutableShare()->setRecordLength(record_length + null_pack_length);
100
 
  getMutableShare()->rec_buff_length= ALIGN_SIZE(getMutableShare()->getRecordLength() + 1);
101
 
  record[0]= (unsigned char*)session->getMemRoot()->allocate(getMutableShare()->rec_buff_length);
102
 
  if (not getInsertRecord())
103
 
  {
104
 
    throw "Memory allocation failure";
105
 
  }
106
 
 
107
 
  if (null_pack_length)
108
 
  {
109
 
    null_flags= (unsigned char*) getInsertRecord();
110
 
    getMutableShare()->null_fields= null_count;
111
 
    getMutableShare()->null_bytes= null_pack_length;
112
 
  }
113
 
  {
114
 
    /* Set up field pointers */
115
 
    unsigned char *null_pos= getInsertRecord();
116
 
    unsigned char *field_pos= null_pos + getMutableShare()->null_bytes;
117
 
    uint32_t null_bit= 1;
118
 
 
119
 
    for (field_arg= getFields(); *field_arg; ++field_arg)
120
 
    {
121
 
      Field *cur_field= *field_arg;
122
 
      if ((cur_field->flags & NOT_NULL_FLAG))
123
 
        cur_field->move_field(field_pos);
124
 
      else
125
 
      {
126
 
        cur_field->move_field(field_pos, (unsigned char*) null_pos, null_bit);
127
 
        null_bit<<= 1;
128
 
        if (null_bit == (1 << 8))
129
 
        {
130
 
          ++null_pos;
131
 
          null_bit= 1;
132
 
        }
133
 
      }
134
 
      cur_field->reset();
135
 
 
136
 
      field_pos+= cur_field->pack_length();
137
 
    }
138
 
  }
139
 
}
140
 
 
141
 
bool Singular::open_tmp_table()
 
39
bool Instance::open_tmp_table()
142
40
{
143
41
  int error;
144
42
  
145
 
  identifier::Table identifier(getShare()->getSchemaName(), getShare()->getTableName(), getShare()->getPath());
 
43
  TableIdentifier identifier(getShare()->getSchemaName(), getShare()->getTableName(), getShare()->getPath());
146
44
  if ((error=cursor->ha_open(identifier,
147
45
                             O_RDWR,
148
46
                             HA_OPEN_TMP_TABLE | HA_OPEN_INTERNAL_TABLE)))
185
83
     true  - Error
186
84
*/
187
85
 
188
 
bool Singular::create_myisam_tmp_table(KeyInfo *keyinfo,
 
86
bool Instance::create_myisam_tmp_table(KeyInfo *keyinfo,
189
87
                                                 MI_COLUMNDEF *start_recinfo,
190
88
                                                 MI_COLUMNDEF **recinfo,
191
89
                                                 uint64_t options)
294
192
    a tmp_set bitmap to be used by things like filesort.
295
193
*/
296
194
 
297
 
void Singular::setup_tmp_table_column_bitmaps()
 
195
void Instance::setup_tmp_table_column_bitmaps()
298
196
{
299
197
  uint32_t field_count= getShare()->sizeFields();
300
198
 
308
206
  default_column_bitmaps();
309
207
}
310
208
 
311
 
Singular::~Singular()
 
209
Instance::~Instance()
312
210
{
313
211
  const char *save_proc_info;
314
212
 
325
223
      cursor->closeMarkForDelete(getShare()->getTableName());
326
224
    }
327
225
 
328
 
    identifier::Table identifier(getShare()->getSchemaName(), getShare()->getTableName(), getShare()->getTableName());
329
 
    drizzled::error_t ignored;
330
 
    plugin::StorageEngine::dropTable(*in_use,
331
 
                                     *getShare()->getEngine(),
332
 
                                     identifier,
333
 
                                     ignored);
 
226
    TableIdentifier identifier(getShare()->getSchemaName(), getShare()->getTableName(), getShare()->getTableName());
 
227
    getShare()->getEngine()->doDropTable(*in_use, identifier);
334
228
 
335
229
    delete cursor;
336
230
  }