~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table/singular.cc

  • Committer: Lee Bieber
  • Date: 2011-02-23 23:22:48 UTC
  • mfrom: (2183.2.20 list2)
  • mto: This revision was merged to the branch mainline in revision 2197.
  • Revision ID: kalebral@gmail.com-20110223232248-ev4y8pyt16b806o0
Merge Olaf - Use List::size()

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
 
Instance::Instance(Session *session, List<CreateField> &field_list) :
 
39
Singular::Singular(Session *session, List<CreateField> &field_list) :
40
40
  _share(message::Table::INTERNAL),
41
41
  _has_variable_width(false)
42
42
{
43
 
  uint32_t field_count= field_list.elements;
 
43
  uint32_t field_count= field_list.size();
44
44
  uint32_t blob_count= 0;
45
45
  Field **field_arg;
46
46
  CreateField *cdef;                           /* column definition */
52
52
  setFields(getMutableShare()->getFields(true));
53
53
  field_arg= getMutableShare()->getFields(true);
54
54
  getMutableShare()->blob_field.resize(field_count+1);
55
 
  getMutableShare()->fields= field_count;
 
55
  getMutableShare()->setFieldSize(field_count);
56
56
  getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
57
57
  setup_tmp_table_column_bitmaps();
58
58
 
59
59
  in_use= session;           /* field_arg->reset() may access in_use */
60
60
 
61
61
  /* Create all fields and calculate the total length of record */
62
 
  List_iterator_fast<CreateField> it(field_list);
 
62
  List<CreateField>::iterator it(field_list.begin());
 
63
  message::Table::Field null_field;
63
64
  while ((cdef= it++))
64
65
  {
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);
 
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);
76
79
    if (!*field_arg)
77
80
    {
78
81
      throw "Memory allocation failure";
95
98
  null_pack_length= (null_count + 7)/8;
96
99
  getMutableShare()->setRecordLength(record_length + null_pack_length);
97
100
  getMutableShare()->rec_buff_length= ALIGN_SIZE(getMutableShare()->getRecordLength() + 1);
98
 
  record[0]= (unsigned char*)session->alloc(getMutableShare()->rec_buff_length);
 
101
  record[0]= (unsigned char*)session->getMemRoot()->allocate(getMutableShare()->rec_buff_length);
99
102
  if (not getInsertRecord())
100
103
  {
101
104
    throw "Memory allocation failure";
135
138
  }
136
139
}
137
140
 
138
 
bool Instance::open_tmp_table()
 
141
bool Singular::open_tmp_table()
139
142
{
140
143
  int error;
141
144
  
142
 
  TableIdentifier identifier(getShare()->getSchemaName(), getShare()->getTableName(), getShare()->getPath());
 
145
  identifier::Table identifier(getShare()->getSchemaName(), getShare()->getTableName(), getShare()->getPath());
143
146
  if ((error=cursor->ha_open(identifier,
144
147
                             O_RDWR,
145
148
                             HA_OPEN_TMP_TABLE | HA_OPEN_INTERNAL_TABLE)))
182
185
     true  - Error
183
186
*/
184
187
 
185
 
bool Instance::create_myisam_tmp_table(KeyInfo *keyinfo,
 
188
bool Singular::create_myisam_tmp_table(KeyInfo *keyinfo,
186
189
                                                 MI_COLUMNDEF *start_recinfo,
187
190
                                                 MI_COLUMNDEF **recinfo,
188
191
                                                 uint64_t options)
291
294
    a tmp_set bitmap to be used by things like filesort.
292
295
*/
293
296
 
294
 
void Instance::setup_tmp_table_column_bitmaps()
 
297
void Singular::setup_tmp_table_column_bitmaps()
295
298
{
296
299
  uint32_t field_count= getShare()->sizeFields();
297
300
 
305
308
  default_column_bitmaps();
306
309
}
307
310
 
308
 
Instance::~Instance()
 
311
Singular::~Singular()
309
312
{
310
313
  const char *save_proc_info;
311
314
 
322
325
      cursor->closeMarkForDelete(getShare()->getTableName());
323
326
    }
324
327
 
325
 
    TableIdentifier identifier(getShare()->getSchemaName(), getShare()->getTableName(), getShare()->getTableName());
326
 
    getShare()->getEngine()->doDropTable(*in_use, identifier);
 
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);
327
334
 
328
335
    delete cursor;
329
336
  }