39
Instance::Instance(Session *session, List<CreateField> &field_list) :
40
_share(message::Table::INTERNAL),
41
_has_variable_width(false)
43
uint32_t field_count= field_list.elements;
44
uint32_t blob_count= 0;
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 */
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();
59
in_use= session; /* field_arg->reset() may access in_use */
61
/* Create all fields and calculate the total length of record */
62
List_iterator_fast<CreateField> it(field_list);
65
*field_arg= getMutableShare()->make_field(NULL,
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,
78
throw "Memory allocation failure";
81
(*field_arg)->init(this);
82
record_length+= (*field_arg)->pack_length();
83
if (! ((*field_arg)->flags & NOT_NULL_FLAG))
86
if ((*field_arg)->flags & BLOB_FLAG)
87
getMutableShare()->blob_field[blob_count++]= (uint32_t) (field_arg - getFields());
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;
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())
101
throw "Memory allocation failure";
104
if (null_pack_length)
106
null_flags= (unsigned char*) getInsertRecord();
107
getMutableShare()->null_fields= null_count;
108
getMutableShare()->null_bytes= null_pack_length;
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;
116
for (field_arg= getFields(); *field_arg; ++field_arg)
118
Field *cur_field= *field_arg;
119
if ((cur_field->flags & NOT_NULL_FLAG))
120
cur_field->move_field(field_pos);
123
cur_field->move_field(field_pos, (unsigned char*) null_pos, null_bit);
125
if (null_bit == (1 << 8))
133
field_pos+= cur_field->pack_length();
138
39
bool Instance::open_tmp_table()
142
43
TableIdentifier identifier(getShare()->getSchemaName(), getShare()->getTableName(), getShare()->getPath());
143
44
if ((error=cursor->ha_open(identifier,
145
47
HA_OPEN_TMP_TABLE | HA_OPEN_INTERNAL_TABLE)))