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;
241 const char *getNormalizedPath()
const
243 return normalized_path.data();
246 const char *getPath()
const
251 const identifier::Table::Key& getCacheKey() const
253 assert(private_key_for_cache.size());
254 return private_key_for_cache;
257 size_t getCacheKeySize()
const
259 return private_key_for_cache.size();
262 str_ref getTableNameRef()
const
267 const char *getTableName()
const
269 return table_name.data();
272 str_ref getSchemaNameRef()
const
277 const char *getSchemaName()
const
288 uint64_t getVersion()
const
293 void refreshVersion();
301 uint32_t timestamp_offset;
304 uint32_t stored_rec_length;
307 uint32_t sizeStoredRecord()
const
309 return stored_rec_length;
312 uint32_t getRecordLength()
const
317 void setRecordLength(uint32_t arg)
322 const Field_blob *getBlobFieldAt(uint32_t arg)
const
324 if (arg < blob_fields)
325 return (Field_blob*) _fields[blob_field[arg]];
334 boost::scoped_ptr<message::Table> _table_message;
341 message::Table::TableType getTableType()
const
343 return getTableMessage() ? getTableMessage()->type() : message::Table::STANDARD;
346 const std::string &getTableTypeAsString()
const
348 if (getTableMessage())
349 return message::type(getTableMessage()->type());
351 return NO_PROTOBUFFER_AVAILABLE;
355 inline message::Table *getTableMessage()
const
357 return _table_message.get();
360 void setTableMessage(
const message::Table &arg)
362 assert(not getTableMessage());
363 _table_message.reset(
new message::Table(arg));
366 const message::Table::Field &field(int32_t field_position)
const
368 assert(getTableMessage());
369 return getTableMessage()->field(field_position);
372 inline bool hasComment()
const
374 return getTableMessage() ? getTableMessage()->options().has_comment() :
false;
377 inline const char *getComment()
379 return (getTableMessage() && getTableMessage()->has_options()) ? getTableMessage()->options().comment().c_str() : NULL;
382 inline uint32_t getCommentLength()
const
384 return (getTableMessage()) ? getTableMessage()->options().comment().length() : 0;
387 inline uint64_t getMaxRows()
const
392 inline void setMaxRows(uint64_t arg)
403 plugin::StorageEngine *storage_engine;
404 inline plugin::StorageEngine *db_type() const
406 return storage_engine;
408 inline plugin::StorageEngine *getEngine() const
410 return storage_engine;
414 identifier::Table::Type tmp_table;
417 identifier::Table::Type getType()
const
426 uint32_t getTableCount()
const
431 void incrementTableCount()
438 uint32_t decrementTableCount()
444 uint32_t last_null_bit_pos;
446 uint32_t _field_size;
449 void setFieldSize(uint32_t arg)
454 uint32_t sizeFields()
const
459 uint32_t rec_buff_length;
462 uint32_t sizeKeys()
const
467 uint32_t max_key_length, max_unique_length, total_key_length;
469 uint32_t null_fields;
470 uint32_t blob_fields;
472 bool has_variable_width;
475 bool hasVariableWidth()
const
477 return has_variable_width;
479 void setVariableWidth()
481 has_variable_width=
true;
483 uint32_t db_create_options;
484 uint32_t db_options_in_use;
485 uint32_t db_record_offset;
486 uint32_t rowid_field_offset;
500 uint32_t getPrimaryKey()
const
505 bool hasPrimaryKey()
const
511 uint32_t next_number_index;
512 uint32_t next_number_key_offset;
513 uint32_t next_number_keypart;
514 uint32_t error, open_errno, errarg;
517 uint8_t blob_ptr_size;
520 uint8_t sizeBlobPtr()
const
522 return blob_ptr_size;
525 bool db_low_byte_first;
532 key_map keys_for_keyread;
538 virtual plugin::EventObserverList *getTableObservers()
543 virtual void setTableObservers(plugin::EventObserverList *)
555 void setIdentifier(
const identifier::Table &identifier_arg);
574 void init(
const char *new_table_name,
575 const char *new_path);
578 void open_table_error(
int pass_error,
int db_errno,
int pass_errarg);
582 static TableShare::shared_ptr getShareCreate(Session*,
const identifier::Table&,
int &error);
584 friend std::ostream& operator<<(std::ostream& output,
const TableShare &share)
586 return output <<
"TableShare:(" << share.getSchemaNameRef() <<
", " << share.getTableName() <<
", " << share.getTableTypeAsString() <<
", " << share.getPath() <<
")";
592 Field *make_field(
const message::Table::Field &pfield,
594 uint32_t field_length,
596 unsigned char *null_pos,
597 unsigned char null_bit,
599 enum_field_types field_type,
600 const charset_info_st * field_charset,
601 Field::utype unireg_check,
603 const char *field_name);
605 Field *make_field(
const message::Table::Field &pfield,
607 uint32_t field_length,
609 unsigned char *null_pos,
610 unsigned char null_bit,
612 enum_field_types field_type,
613 const charset_info_st * field_charset,
614 Field::utype unireg_check,
616 const char *field_name,
620 int open_table_def(Session& session,
const identifier::Table &identifier);
622 int open_table_from_share(Session *session,
623 const identifier::Table &identifier,
625 uint32_t
db_stat, uint32_t ha_open_flags,
628 int open_table_from_share_inner(Session *session,
632 int open_table_cursor_inner(
const identifier::Table &identifier,
633 uint32_t
db_stat, uint32_t ha_open_flags,
635 bool &error_reported);
637 bool parse_table_proto(Session& session,
const message::Table &table);
639 virtual bool is_replicated()
const