~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

Merge with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
20
20
 
21
21
/* Structs that defines the Table */
22
22
 
 
23
 
 
24
 
23
25
#ifndef DRIZZLED_TABLE_H
24
26
#define DRIZZLED_TABLE_H
25
27
 
32
34
#include "drizzled/field_iterator.h"
33
35
#include "drizzled/cursor.h"
34
36
#include "drizzled/lex_string.h"
35
 
#include "drizzled/table_list.h"
36
 
#include "drizzled/definition/table.h"
 
37
#include "drizzled/table/instance.h"
37
38
#include "drizzled/atomics.h"
38
39
#include "drizzled/query_id.h"
39
40
 
 
41
#include "drizzled/visibility.h"
 
42
 
40
43
namespace drizzled
41
44
{
42
45
 
 
46
class COND_EQUAL;
 
47
class Field_blob;
43
48
class Item;
44
49
class Item_subselect;
 
50
class SecurityContext;
 
51
class Select_Lex;
45
52
class Select_Lex_Unit;
46
 
class Select_Lex;
47
 
class COND_EQUAL;
48
 
class SecurityContext;
49
53
class TableList;
50
 
class Field_timestamp;
51
 
class Field_blob;
52
 
 
53
 
extern uint64_t refresh_version;
 
54
namespace field { class Epoch; }
 
55
namespace plugin { class StorageEngine; }
54
56
 
55
57
typedef enum enum_table_category TABLE_CATEGORY;
56
58
typedef struct st_columndef MI_COLUMNDEF;
59
61
 * Class representing a set of records, either in a temporary, 
60
62
 * normal, or derived table.
61
63
 */
62
 
class Table 
 
64
class DRIZZLED_API Table 
63
65
{
64
66
  Field **field; /**< Pointer to fields collection */
 
67
 
65
68
public:
66
 
 
67
69
  Field **getFields() const
68
70
  {
69
71
    return field;
85
87
  }
86
88
 
87
89
  Cursor *cursor; /**< Pointer to the storage engine's Cursor managing this table */
 
90
 
88
91
private:
89
92
  Table *next;
 
93
 
90
94
public:
91
95
  Table *getNext() const
92
96
  {
143
147
    return in_use;
144
148
  }
145
149
 
146
 
  unsigned char *getInsertRecord()
 
150
  unsigned char *getInsertRecord() const
147
151
  {
148
152
    return record[0];
149
153
  }
158
162
  KeyInfo  *key_info; /**< data of keys in database */
159
163
  Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
160
164
  Field *found_next_number_field; /**< Points to the "next-number" field (autoincrement field) */
161
 
  Field_timestamp *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
 
165
  field::Epoch *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
162
166
 
163
167
  TableList *pos_in_table_list; /* Element referring to this table */
164
168
  Order *group;
280
284
    statement then the variable contains TIMESTAMP_NO_AUTO_SET (i.e. 0).
281
285
 
282
286
    Value of this variable is set for each statement in open_table() and
283
 
    if needed cleared later in statement processing code (see mysql_update()
 
287
    if needed cleared later in statement processing code (see update_query()
284
288
    as example).
285
289
  */
286
290
  timestamp_auto_set_type timestamp_field_type;
308
312
    The set is implemented as a bitmap.
309
313
  */
310
314
  key_map keys_in_use_for_query;
 
315
 
311
316
  /* Map of keys that can be used to calculate GROUP BY without sorting */
312
317
  key_map keys_in_use_for_group_by;
 
318
 
313
319
  /* Map of keys that can be used to calculate ORDER BY without sorting */
314
320
  key_map keys_in_use_for_order_by;
315
321
 
408
414
 
409
415
    return NULL;
410
416
  }
411
 
  inline uint8_t getBlobPtrSize() { return getShare()->blob_ptr_size; }
412
 
  inline uint32_t getNullBytes() { return getShare()->null_bytes; }
413
 
  inline uint32_t getNullFields() { return getShare()->null_fields; }
 
417
  inline uint8_t getBlobPtrSize() const { return getShare()->sizeBlobPtr(); }
 
418
  inline uint32_t getNullBytes() const { return getShare()->null_bytes; }
 
419
  inline uint32_t getNullFields() const { return getShare()->null_fields; }
414
420
  inline unsigned char *getDefaultValues() { return  getMutableShare()->getDefaultValues(); }
415
421
  inline const char *getSchemaName()  const { return getShare()->getSchemaName(); }
416
422
  inline const char *getTableName()  const { return getShare()->getTableName(); }
417
423
 
418
 
  inline bool isDatabaseLowByteFirst() { return getShare()->db_low_byte_first; } /* Portable row format */
 
424
  inline bool isDatabaseLowByteFirst() const { return getShare()->db_low_byte_first; } /* Portable row format */
419
425
  inline bool isNameLock() const { return open_placeholder; }
420
426
 
421
 
  uint32_t index_flags(uint32_t idx) const
422
 
  {
423
 
    return getShare()->storage_engine->index_flags(getShare()->getKeyInfo(idx).algorithm);
424
 
  }
 
427
  uint32_t index_flags(uint32_t idx) const;
425
428
 
426
429
  inline plugin::StorageEngine *getEngine() const   /* table_type for handler */
427
430
  {
428
 
    return getShare()->storage_engine;
 
431
    return getShare()->getEngine();
429
432
  }
430
433
 
431
434
  Cursor &getCursor() const /* table_type for handler */
551
554
  {
552
555
    return db_stat || open_placeholder;
553
556
  }
 
557
 
554
558
  /*
555
559
    Is this instance of the table should be reopen or represents a name-lock?
556
560
  */
557
 
  inline bool needs_reopen_or_name_lock()
558
 
  { 
559
 
    return getShare()->getVersion() != refresh_version;
560
 
  }
 
561
  bool needs_reopen_or_name_lock() const;
561
562
 
562
563
  /**
563
564
    clean/setup table fields and map.
578
579
  void filesort_free_buffers(bool full= false);
579
580
  void intern_close_table();
580
581
 
581
 
  void print_error(int error, myf errflag)
582
 
  {
583
 
    getShare()->storage_engine->print_error(error, errflag, *this);
584
 
  }
 
582
  void print_error(int error, myf errflag) const;
585
583
 
586
584
  /**
587
585
    @return
588
586
    key if error because of duplicated keys
589
587
  */
590
 
  uint32_t get_dup_key(int error)
 
588
  uint32_t get_dup_key(int error) const
591
589
  {
592
590
    cursor->errkey  = (uint32_t) -1;
593
591
    if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
831
829
namespace optimizer { class SqlSelect; }
832
830
 
833
831
void change_double_for_sort(double nr,unsigned char *to);
834
 
double my_double_round(double value, int64_t dec, bool dec_unsigned,
835
 
                       bool truncate);
836
832
int get_quick_record(optimizer::SqlSelect *select);
837
833
 
838
834
void find_date(char *pos,uint32_t *vek,uint32_t flag);
841
837
ulong get_form_pos(int file, unsigned char *head, TYPELIB *save_names);
842
838
void append_unescaped(String *res, const char *pos, uint32_t length);
843
839
 
844
 
int rename_file_ext(const char * from,const char * to,const char * ext);
 
840
DRIZZLED_API int rename_file_ext(const char * from,const char * to,const char * ext);
845
841
bool check_column_name(const char *name);
846
 
bool check_db_name(Session *session, SchemaIdentifier &schema);
847
842
bool check_table_name(const char *name, uint32_t length);
848
843
 
849
844
} /* namespace drizzled */
850
845
 
851
 
#include "drizzled/table/instance.h"
 
846
#include "drizzled/table/singular.h"
852
847
#include "drizzled/table/concurrent.h"
853
848
 
854
849
#endif /* DRIZZLED_TABLE_H */