18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
23
#include <sys/types.h>
24
24
#include <sys/stat.h>
27
#include <drizzled/session.h>
28
#include <plugin/myisam/myisam.h>
29
#include <drizzled/plugin/transactional_storage_engine.h>
30
#include <drizzled/statistics_variables.h>
31
#include <drizzled/table.h>
32
#include <drizzled/create_field.h>
37
Singular::Singular(Session *session, std::list<CreateField>& field_list) :
27
#include "drizzled/session.h"
28
#include "plugin/myisam/myisam.h"
29
#include "drizzled/plugin/transactional_storage_engine.h"
31
#include "drizzled/table.h"
39
Instance::Instance(Session *session, List<CreateField> &field_list) :
38
40
_share(message::Table::INTERNAL),
39
41
_has_variable_width(false)
41
uint32_t field_count= field_list.size();
43
uint32_t field_count= field_list.elements;
42
44
uint32_t blob_count= 0;
46
CreateField *cdef; /* column definition */
43
47
uint32_t record_length= 0;
44
48
uint32_t null_count= 0; /* number of columns which may be null */
45
49
uint32_t null_pack_length; /* NULL representation array length */
47
51
getMutableShare()->setFields(field_count + 1);
48
52
setFields(getMutableShare()->getFields(true));
49
Field** field_arg= getMutableShare()->getFields(true);
53
field_arg= getMutableShare()->getFields(true);
50
54
getMutableShare()->blob_field.resize(field_count+1);
51
getMutableShare()->setFieldSize(field_count);
55
getMutableShare()->fields= field_count;
52
56
getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
53
57
setup_tmp_table_column_bitmaps();
55
59
in_use= session; /* field_arg->reset() may access in_use */
57
61
/* Create all fields and calculate the total length of record */
58
message::Table::Field null_field;
59
BOOST_FOREACH(CreateField& it, field_list)
62
List_iterator_fast<CreateField> it(field_list);
61
*field_arg= getMutableShare()->make_field(null_field,
64
(it.flags & NOT_NULL_FLAG) ? false : true,
65
(unsigned char *) ((it.flags & NOT_NULL_FLAG) ? 0 : ""),
66
(it.flags & NOT_NULL_FLAG) ? 0 : 1,
73
it.flags & UNSIGNED_FLAG ? true : false);
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";
74
81
(*field_arg)->init(this);
75
82
record_length+= (*field_arg)->pack_length();
76
83
if (! ((*field_arg)->flags & NOT_NULL_FLAG))
88
95
null_pack_length= (null_count + 7)/8;
89
96
getMutableShare()->setRecordLength(record_length + null_pack_length);
90
97
getMutableShare()->rec_buff_length= ALIGN_SIZE(getMutableShare()->getRecordLength() + 1);
91
record[0]= session->mem.alloc(getMutableShare()->rec_buff_length);
98
record[0]= (unsigned char*)session->alloc(getMutableShare()->rec_buff_length);
99
if (not getInsertRecord())
101
throw "Memory allocation failure";
93
104
if (null_pack_length)
95
null_flags= getInsertRecord();
106
null_flags= (unsigned char*) getInsertRecord();
96
107
getMutableShare()->null_fields= null_count;
97
108
getMutableShare()->null_bytes= null_pack_length;
127
bool Singular::open_tmp_table()
138
bool Instance::open_tmp_table()
129
identifier::Table identifier(getShare()->getSchemaName(), getShare()->getTableName(), getShare()->getPath());
130
if (int error= cursor->ha_open(identifier, O_RDWR, HA_OPEN_TMP_TABLE | HA_OPEN_INTERNAL_TABLE))
142
TableIdentifier identifier(getShare()->getSchemaName(), getShare()->getTableName(), getShare()->getPath());
143
if ((error=cursor->ha_open(identifier,
145
HA_OPEN_TMP_TABLE | HA_OPEN_INTERNAL_TABLE)))
132
147
print_error(error, MYF(0));
179
194
if (getShare()->sizeKeys())
180
195
{ // Get keys for ni_create
181
196
bool using_unique_constraint= false;
182
HA_KEYSEG *seg= new (mem()) HA_KEYSEG[keyinfo->key_parts];
197
HA_KEYSEG *seg= (HA_KEYSEG*) getMemRoot()->alloc_root(sizeof(*seg) * keyinfo->key_parts);
184
201
memset(seg, 0, sizeof(*seg) * keyinfo->key_parts);
185
202
if (keyinfo->key_length >= cursor->getEngine()->max_key_length() ||
302
cursor->closeMarkForDelete();
304
identifier::Table identifier(getShare()->getSchemaName(), getShare()->getTableName(), getShare()->getTableName());
305
drizzled::error_t ignored;
306
plugin::StorageEngine::dropTable(*in_use, *getShare()->getEngine(), identifier, ignored);
322
cursor->closeMarkForDelete(getShare()->getTableName());
325
TableIdentifier identifier(getShare()->getSchemaName(), getShare()->getTableName(), getShare()->getTableName());
326
getShare()->getEngine()->doDropTable(*in_use, identifier);
311
for (Field **ptr= getFields(); *ptr; ptr++)
332
for (Field **ptr= getFields() ; *ptr ; ptr++)
317
mem().free_root(MYF(0));
338
getMemRoot()->free_root(MYF(0));
318
339
in_use->set_proc_info(save_proc_info);
321
343
} /* namespace table */
322
344
} /* namespace drizzled */