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>
27
#include "drizzled/session.h"
28
#include "plugin/myisam/myisam.h"
29
#include "drizzled/plugin/transactional_storage_engine.h"
31
#include <drizzled/table.h>
31
#include "drizzled/table.h"
39
Singular::Singular(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()->setFieldSize(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<CreateField>::iterator it(field_list.begin());
63
message::Table::Field null_field;
66
*field_arg= getMutableShare()->make_field(null_field,
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,
78
cdef->flags & UNSIGNED_FLAG ? true : false);
81
throw "Memory allocation failure";
84
(*field_arg)->init(this);
85
record_length+= (*field_arg)->pack_length();
86
if (! ((*field_arg)->flags & NOT_NULL_FLAG))
89
if ((*field_arg)->flags & BLOB_FLAG)
90
getMutableShare()->blob_field[blob_count++]= (uint32_t) (field_arg - getFields());
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;
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())
104
throw "Memory allocation failure";
107
if (null_pack_length)
109
null_flags= (unsigned char*) getInsertRecord();
110
getMutableShare()->null_fields= null_count;
111
getMutableShare()->null_bytes= null_pack_length;
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;
119
for (field_arg= getFields(); *field_arg; ++field_arg)
121
Field *cur_field= *field_arg;
122
if ((cur_field->flags & NOT_NULL_FLAG))
123
cur_field->move_field(field_pos);
126
cur_field->move_field(field_pos, (unsigned char*) null_pos, null_bit);
128
if (null_bit == (1 << 8))
136
field_pos+= cur_field->pack_length();
141
bool Singular::open_tmp_table()
39
bool Instance::open_tmp_table()
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,
148
46
HA_OPEN_TMP_TABLE | HA_OPEN_INTERNAL_TABLE)))
325
223
cursor->closeMarkForDelete(getShare()->getTableName());
328
identifier::Table identifier(getShare()->getSchemaName(), getShare()->getTableName(), getShare()->getTableName());
329
drizzled::error_t ignored;
330
plugin::StorageEngine::dropTable(*in_use,
331
*getShare()->getEngine(),
226
TableIdentifier identifier(getShare()->getSchemaName(), getShare()->getTableName(), getShare()->getTableName());
227
getShare()->getEngine()->doDropTable(*in_use, identifier);