30 #include <boost/unordered_map.hpp>
31 #include <boost/thread/condition_variable.hpp>
32 #include <boost/dynamic_bitset.hpp>
33 #include <boost/shared_ptr.hpp>
34 #include <boost/scoped_ptr.hpp>
37 #include <drizzled/message.h>
38 #include <drizzled/util/string.h>
39 #include <drizzled/key_map.h>
40 #include <drizzled/field.h>
41 #include <drizzled/util/find_ptr.h>
45 const static std::string NO_PROTOBUFFER_AVAILABLE(
"NO PROTOBUFFER AVAILABLE");
49 typedef std::vector<std::string> StringVector;
52 typedef boost::shared_ptr<TableShare> shared_ptr;
53 typedef std::vector <shared_ptr> vector;
55 TableShare(
const identifier::Table::Type type_arg);
61 TableShare(
const identifier::Table::Type type_arg,
63 const char *path_arg= NULL, uint32_t path_length_arg= 0);
72 bool isTemporaryCategory()
const
83 typedef std::vector<Field *> Fields;
89 const Fields getFields()
const
99 Field ** getFields(
bool)
104 void setFields(uint32_t arg)
109 uint32_t positionFields(Field **arg)
const
111 return (arg - (Field **)&_fields[0]);
114 void pushField(Field *arg)
117 _fields.push_back(arg);
120 Field **found_next_number_field;
123 Field *timestamp_field;
127 Field *getTimestampField() const
129 return timestamp_field;
132 void setTimestampField(Field *arg)
134 timestamp_field= arg;
142 KeyInfo &getKeyInfo(uint32_t arg)
const
144 return key_info[arg];
146 std::vector<uint> blob_field;
150 typedef boost::unordered_map<std::string, Field**, util::insensitive_hash, util::insensitive_equal_to> FieldMap;
154 size_t getNamedFieldSize()
const
156 return name_hash.size();
159 Field **getNamedField(
const std::string &arg)
161 return find_ptr2(name_hash, arg);
165 memory::Root mem_root;
167 unsigned char* alloc(
size_t arg)
169 return mem_root.
alloc(arg);
177 typedef std::vector<std::string> keynames_t;
179 keynames_t _keynames;
181 void addKeyName(
const std::string& arg)
183 _keynames.push_back(boost::to_upper_copy(arg));
187 uint32_t doesKeyNameExist(
const std::string& arg)
const
189 keynames_t::const_iterator it= find(_keynames.begin(), _keynames.end(), boost::to_upper_copy(arg));
190 return it == _keynames.end() ? UINT32_MAX : it - _keynames.begin();
194 std::vector<TYPELIB> intervals;
200 virtual void unlock()
204 std::vector<unsigned char> default_values;
208 unsigned char *getDefaultValues()
210 return &default_values[0];
212 void resizeDefaultValues(
size_t arg)
214 default_values.resize(arg);
217 const charset_info_st *table_charset;
219 boost::dynamic_bitset<> all_set;
232 identifier::Table::Key private_key_for_cache;
233 std::vector<char> private_normalized_path;
240 const char *getNormalizedPath()
const
242 return normalized_path.data();
245 const char *getPath()
const
250 const identifier::Table::Key& getCacheKey() const
252 assert(private_key_for_cache.size());
253 return private_key_for_cache;
256 size_t getCacheKeySize()
const
258 return private_key_for_cache.size();
261 str_ref getTableNameRef()
const
263 return str_ref(table_identifier->getTableName());
266 const char *getTableName()
const
268 return table_identifier->getTableName().c_str();
271 str_ref getSchemaNameRef()
const
273 return str_ref(table_identifier->getSchemaName());
276 const char *getSchemaName()
const
278 return table_identifier->getSchemaName().c_str();
283 return *table_identifier;
292 uint64_t getVersion()
const
297 void refreshVersion();
305 uint32_t timestamp_offset;
308 uint32_t stored_rec_length;
311 uint32_t sizeStoredRecord()
const
313 return stored_rec_length;
316 uint32_t getRecordLength()
const
321 void setRecordLength(uint32_t arg)
326 const Field_blob *getBlobFieldAt(uint32_t arg)
const
328 if (arg < blob_fields)
329 return (Field_blob*) _fields[blob_field[arg]];
338 boost::scoped_ptr<message::Table> _table_message;
345 message::Table::TableType getTableType()
const
347 return getTableMessage() ? getTableMessage()->type() : message::Table::STANDARD;
350 const std::string &getTableTypeAsString()
const
352 if (getTableMessage())
353 return message::type(getTableMessage()->type());
355 return NO_PROTOBUFFER_AVAILABLE;
359 inline message::Table *getTableMessage()
const
361 return _table_message.get();
364 void setTableMessage(
const message::Table &arg)
366 assert(not getTableMessage());
367 _table_message.reset(
new message::Table(arg));
370 const message::Table::Field &field(int32_t field_position)
const
372 assert(getTableMessage());
373 return getTableMessage()->field(field_position);
376 inline bool hasComment()
const
378 return getTableMessage() ? getTableMessage()->options().has_comment() :
false;
381 inline const char *getComment()
383 return (getTableMessage() && getTableMessage()->has_options()) ? getTableMessage()->options().comment().c_str() : NULL;
386 inline uint32_t getCommentLength()
const
388 return (getTableMessage()) ? getTableMessage()->options().comment().length() : 0;
391 inline uint64_t getMaxRows()
const
396 inline void setMaxRows(uint64_t arg)
407 plugin::StorageEngine *storage_engine;
408 inline plugin::StorageEngine *db_type() const
410 return storage_engine;
412 inline plugin::StorageEngine *getEngine() const
414 return storage_engine;
418 identifier::Table::Type tmp_table;
421 identifier::Table::Type getType()
const
430 uint32_t getTableCount()
const
435 void incrementTableCount()
442 uint32_t decrementTableCount()
448 uint32_t last_null_bit_pos;
450 uint32_t _field_size;
453 void setFieldSize(uint32_t arg)
458 uint32_t sizeFields()
const
463 uint32_t rec_buff_length;
466 uint32_t sizeKeys()
const
471 uint32_t max_key_length, max_unique_length, total_key_length;
473 uint32_t null_fields;
474 uint32_t blob_fields;
476 bool has_variable_width;
479 bool hasVariableWidth()
const
481 return has_variable_width;
483 void setVariableWidth()
485 has_variable_width=
true;
487 uint32_t db_create_options;
488 uint32_t db_options_in_use;
489 uint32_t db_record_offset;
490 uint32_t rowid_field_offset;
504 uint32_t getPrimaryKey()
const
509 bool hasPrimaryKey()
const
515 uint32_t next_number_index;
516 uint32_t next_number_key_offset;
517 uint32_t next_number_keypart;
518 uint32_t error, open_errno, errarg;
521 uint8_t blob_ptr_size;
524 uint8_t sizeBlobPtr()
const
526 return blob_ptr_size;
529 bool db_low_byte_first;
536 key_map keys_for_keyread;
542 virtual plugin::EventObserverList *getTableObservers()
547 virtual void setTableObservers(plugin::EventObserverList *)
559 void setIdentifier(
const identifier::Table &identifier_arg);
578 void init(
const char *new_table_name,
579 const char *new_path);
582 void open_table_error(
int pass_error,
int db_errno,
int pass_errarg);
586 static TableShare::shared_ptr getShareCreate(Session*,
const identifier::Table&,
int &error);
588 friend std::ostream& operator<<(std::ostream& output,
const TableShare &share)
590 return output <<
"TableShare:(" << share.getSchemaNameRef() <<
", " << share.getTableName() <<
", " << share.getTableTypeAsString() <<
", " << share.getPath() <<
")";
596 Field *make_field(
const message::Table::Field &pfield,
598 uint32_t field_length,
600 unsigned char *null_pos,
601 unsigned char null_bit,
603 enum_field_types field_type,
604 const charset_info_st * field_charset,
605 Field::utype unireg_check,
607 const char *field_name);
609 Field *make_field(
const message::Table::Field &pfield,
611 uint32_t field_length,
613 unsigned char *null_pos,
614 unsigned char null_bit,
616 enum_field_types field_type,
617 const charset_info_st * field_charset,
618 Field::utype unireg_check,
620 const char *field_name,
624 int open_table_def(Session& session,
const identifier::Table &identifier);
626 int open_table_from_share(Session *session,
627 const identifier::Table &identifier,
629 uint32_t
db_stat, uint32_t ha_open_flags,
632 int open_table_from_share_inner(Session *session,
636 int open_table_cursor_inner(
const identifier::Table &identifier,
637 uint32_t
db_stat, uint32_t ha_open_flags,
639 bool &error_reported);
641 bool parse_table_proto(Session& session,
const message::Table &table);
643 virtual bool is_replicated()
const
bool fieldInPrimaryKey(Field *field) const
unsigned char * alloc(size_t Size)
Allocate a chunk of memory from the Root structure provided, obtaining more memory from the heap if n...
Memory root declarations.
enum_table_category table_category