~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Olaf van der Spek
  • Date: 2011-02-12 18:24:24 UTC
  • mto: (2167.1.2 build) (2172.1.4 build)
  • mto: This revision was merged to the branch mainline in revision 2168.
  • Revision ID: olafvdspek@gmail.com-20110212182424-kgnm9osi7qo97at2
casts

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
 
26
28
#include <string>
 
29
#include <boost/dynamic_bitset.hpp>
27
30
 
28
31
#include "drizzled/order.h"
29
32
#include "drizzled/filesort_info.h"
32
35
#include "drizzled/cursor.h"
33
36
#include "drizzled/lex_string.h"
34
37
#include "drizzled/table_list.h"
35
 
#include "drizzled/table_share.h"
 
38
#include "drizzled/table/instance.h"
36
39
#include "drizzled/atomics.h"
37
40
#include "drizzled/query_id.h"
38
41
 
 
42
#include "drizzled/visibility.h"
 
43
 
39
44
namespace drizzled
40
45
{
41
46
 
46
51
class COND_EQUAL;
47
52
class SecurityContext;
48
53
class TableList;
49
 
class Field_timestamp;
 
54
namespace field {
 
55
class Epoch;
 
56
}
50
57
class Field_blob;
51
58
 
52
59
extern uint64_t refresh_version;
54
61
typedef enum enum_table_category TABLE_CATEGORY;
55
62
typedef struct st_columndef MI_COLUMNDEF;
56
63
 
57
 
bool create_myisam_from_heap(Session *session, Table *table,
58
 
                             MI_COLUMNDEF *start_recinfo,
59
 
                             MI_COLUMNDEF **recinfo,
60
 
                             int error, bool ignore_last_dupp_key_error);
61
 
 
62
64
/**
63
65
 * Class representing a set of records, either in a temporary, 
64
66
 * normal, or derived table.
65
67
 */
66
 
class Table 
 
68
class DRIZZLED_API Table 
67
69
{
68
 
public:
69
 
 
70
 
  TableShare *s; /**< Pointer to the shared metadata about the table */
71
70
  Field **field; /**< Pointer to fields collection */
 
71
public:
 
72
 
 
73
  Field **getFields() const
 
74
  {
 
75
    return field;
 
76
  }
 
77
 
 
78
  Field *getField(uint32_t arg) const
 
79
  {
 
80
    return field[arg];
 
81
  }
 
82
 
 
83
  void setFields(Field **arg)
 
84
  {
 
85
    field= arg;
 
86
  }
 
87
 
 
88
  void setFieldAt(Field *arg, uint32_t arg_pos)
 
89
  {
 
90
    field[arg_pos]= arg;
 
91
  }
72
92
 
73
93
  Cursor *cursor; /**< Pointer to the storage engine's Cursor managing this table */
 
94
 
 
95
private:
74
96
  Table *next;
 
97
 
 
98
public:
 
99
  Table *getNext() const
 
100
  {
 
101
    return next;
 
102
  }
 
103
 
 
104
  Table **getNextPtr()
 
105
  {
 
106
    return &next;
 
107
  }
 
108
 
 
109
  void setNext(Table *arg)
 
110
  {
 
111
    next= arg;
 
112
  }
 
113
 
 
114
  void unlink()
 
115
  {
 
116
    getNext()->setPrev(getPrev());              /* remove from used chain */
 
117
    getPrev()->setNext(getNext());
 
118
  }
 
119
 
 
120
private:
75
121
  Table *prev;
76
 
 
77
 
  MyBitmap *read_set; /* Active column sets */
78
 
  MyBitmap *write_set; /* Active column sets */
 
122
public:
 
123
  Table *getPrev() const
 
124
  {
 
125
    return prev;
 
126
  }
 
127
 
 
128
  Table **getPrevPtr()
 
129
  {
 
130
    return &prev;
 
131
  }
 
132
 
 
133
  void setPrev(Table *arg)
 
134
  {
 
135
    prev= arg;
 
136
  }
 
137
 
 
138
  boost::dynamic_bitset<> *read_set; /* Active column sets */
 
139
  boost::dynamic_bitset<> *write_set; /* Active column sets */
79
140
 
80
141
  uint32_t tablenr;
81
142
  uint32_t db_stat; /**< information about the cursor as in Cursor.h */
82
143
 
83
 
  MyBitmap def_read_set; /**< Default read set of columns */
84
 
  MyBitmap def_write_set; /**< Default write set of columns */
85
 
  MyBitmap tmp_set; /* Not sure about this... */
 
144
  boost::dynamic_bitset<> def_read_set; /**< Default read set of columns */
 
145
  boost::dynamic_bitset<> def_write_set; /**< Default write set of columns */
 
146
  boost::dynamic_bitset<> tmp_set; /* Not sure about this... */
86
147
 
87
148
  Session *in_use; /**< Pointer to the current session using this object */
88
149
  Session *getSession()
90
151
    return in_use;
91
152
  }
92
153
 
 
154
  unsigned char *getInsertRecord()
 
155
  {
 
156
    return record[0];
 
157
  }
 
158
 
 
159
  unsigned char *getUpdateRecord()
 
160
  {
 
161
    return record[1];
 
162
  }
 
163
 
93
164
  unsigned char *record[2]; /**< Pointer to "records" */
94
 
  unsigned char *insert_values; /* used by INSERT ... UPDATE */
95
 
  KEY  *key_info; /**< data of keys in database */
 
165
  std::vector<unsigned char> insert_values; /* used by INSERT ... UPDATE */
 
166
  KeyInfo  *key_info; /**< data of keys in database */
96
167
  Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
97
168
  Field *found_next_number_field; /**< Points to the "next-number" field (autoincrement field) */
98
 
  Field_timestamp *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
 
169
  field::Epoch *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
99
170
 
100
171
  TableList *pos_in_table_list; /* Element referring to this table */
101
 
  order_st *group;
102
 
  const char *alias; /**< alias or table name if no alias */
 
172
  Order *group;
 
173
  
 
174
  const char *getAlias() const
 
175
  {
 
176
    return _alias.c_str();
 
177
  }
 
178
 
 
179
  void clearAlias()
 
180
  {
 
181
    _alias.clear();
 
182
  }
 
183
 
 
184
  void setAlias(const char *arg)
 
185
  {
 
186
    _alias= arg;
 
187
  }
 
188
 
 
189
private:
 
190
  std::string _alias; /**< alias or table name if no alias */
 
191
public:
 
192
 
103
193
  unsigned char *null_flags;
104
194
 
105
195
  uint32_t lock_position; /**< Position in DRIZZLE_LOCK.table */
106
196
  uint32_t lock_data_start; /**< Start pos. in DRIZZLE_LOCK.locks */
107
197
  uint32_t lock_count; /**< Number of locks */
108
198
  uint32_t used_fields;
109
 
  uint32_t status; /* What's in record[0] */
 
199
  uint32_t status; /* What's in getInsertRecord() */
110
200
  /* number of select if it is derived table */
111
201
  uint32_t derived_select_number;
112
202
  int current_lock; /**< Type of lock on table */
126
216
  bool null_row;
127
217
 
128
218
  bool force_index;
129
 
  bool distinct,const_table,no_rows;
 
219
  bool distinct;
 
220
  bool const_table;
 
221
  bool no_rows;
130
222
  bool key_read;
131
223
  bool no_keyread;
132
224
  /*
196
288
    statement then the variable contains TIMESTAMP_NO_AUTO_SET (i.e. 0).
197
289
 
198
290
    Value of this variable is set for each statement in open_table() and
199
 
    if needed cleared later in statement processing code (see mysql_update()
 
291
    if needed cleared later in statement processing code (see update_query()
200
292
    as example).
201
293
  */
202
294
  timestamp_auto_set_type timestamp_field_type;
224
316
    The set is implemented as a bitmap.
225
317
  */
226
318
  key_map keys_in_use_for_query;
 
319
 
227
320
  /* Map of keys that can be used to calculate GROUP BY without sorting */
228
321
  key_map keys_in_use_for_group_by;
 
322
 
229
323
  /* Map of keys that can be used to calculate ORDER BY without sorting */
230
324
  key_map keys_in_use_for_order_by;
231
325
 
241
335
  uint32_t quick_key_parts[MAX_KEY];
242
336
  uint32_t quick_n_ranges[MAX_KEY];
243
337
 
 
338
private:
244
339
  memory::Root mem_root;
245
 
  filesort_info_st sort;
 
340
 
 
341
  void init_mem_root()
 
342
  {
 
343
    init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
 
344
  }
 
345
public:
 
346
  memory::Root *getMemRoot()
 
347
  {
 
348
    if (not mem_root.alloc_root_inited())
 
349
    {
 
350
      init_mem_root();
 
351
    }
 
352
 
 
353
    return &mem_root;
 
354
  }
 
355
 
 
356
  void *alloc_root(size_t arg)
 
357
  {
 
358
    if (not mem_root.alloc_root_inited())
 
359
    {
 
360
      init_mem_root();
 
361
    }
 
362
 
 
363
    return mem_root.alloc_root(arg);
 
364
  }
 
365
 
 
366
  char *strmake_root(const char *str_arg, size_t len_arg)
 
367
  {
 
368
    if (not mem_root.alloc_root_inited())
 
369
    {
 
370
      init_mem_root();
 
371
    }
 
372
 
 
373
    return mem_root.strmake_root(str_arg, len_arg);
 
374
  }
 
375
 
 
376
  filesort_info sort;
246
377
 
247
378
  Table();
 
379
  virtual ~Table();
248
380
 
249
381
  int report_error(int error);
250
382
  /**
251
383
   * Free information allocated by openfrm
252
384
   *
253
385
   * @param If true if we also want to free table_share
 
386
   * @note this should all be the destructor
254
387
   */
255
 
  int closefrm(bool free_share);
 
388
  int delete_table(bool free_share= false);
256
389
 
257
390
  void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg);
258
391
 
259
392
  /* SHARE methods */
260
 
  inline const TableShare *getShare() const { assert(s); return s; } /* Get rid of this long term */
261
 
  inline void setShare(TableShare *new_share) { s= new_share; } /* Get rid of this long term */
262
 
  inline uint32_t sizeKeys() { return s->keys; }
263
 
  inline uint32_t sizeFields() { return s->fields; }
264
 
  inline uint32_t getRecordLength() { return s->reclength; }
265
 
  inline uint32_t sizeBlobFields() { return s->blob_fields; }
266
 
  inline uint32_t *getBlobField() { return s->blob_field; }
267
 
  inline uint32_t getNullBytes() { return s->null_bytes; }
268
 
  inline uint32_t getNullFields() { return s->null_fields; }
269
 
  inline unsigned char *getDefaultValues() { return s->default_values; }
270
 
 
271
 
  inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; } /* Portable row format */
272
 
  inline bool isNameLock() { return s->name_lock; }
273
 
  inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
274
 
  inline bool isWaitingOnCondition() { return s->waiting_on_cond; } /* Protection against free */
 
393
  virtual const TableShare *getShare() const= 0; /* Get rid of this long term */
 
394
  virtual TableShare *getMutableShare()= 0; /* Get rid of this long term */
 
395
  virtual bool hasShare() const= 0; /* Get rid of this long term */
 
396
  virtual void setShare(TableShare *new_share)= 0; /* Get rid of this long term */
 
397
 
 
398
  virtual void release(void)= 0;
 
399
 
 
400
  uint32_t sizeKeys() { return getMutableShare()->sizeKeys(); }
 
401
  uint32_t sizeFields() { return getMutableShare()->sizeFields(); }
 
402
  uint32_t getRecordLength() const { return getShare()->getRecordLength(); }
 
403
  uint32_t sizeBlobFields() { return getMutableShare()->blob_fields; }
 
404
  uint32_t *getBlobField() { return &getMutableShare()->blob_field[0]; }
 
405
 
 
406
public:
 
407
  virtual bool hasVariableWidth() const
 
408
  {
 
409
    return getShare()->hasVariableWidth(); // We should calculate this.
 
410
  }
 
411
 
 
412
  virtual void setVariableWidth(void);
 
413
 
 
414
  Field_blob *getBlobFieldAt(uint32_t arg) const
 
415
  {
 
416
    if (arg < getShare()->blob_fields)
 
417
      return (Field_blob*) field[getShare()->blob_field[arg]]; /*NOTE: Using 'Table.field' NOT SharedTable.field. */
 
418
 
 
419
    return NULL;
 
420
  }
 
421
  inline uint8_t getBlobPtrSize() const { return getShare()->sizeBlobPtr(); }
 
422
  inline uint32_t getNullBytes() const { return getShare()->null_bytes; }
 
423
  inline uint32_t getNullFields() const { return getShare()->null_fields; }
 
424
  inline unsigned char *getDefaultValues() { return  getMutableShare()->getDefaultValues(); }
 
425
  inline const char *getSchemaName()  const { return getShare()->getSchemaName(); }
 
426
  inline const char *getTableName()  const { return getShare()->getTableName(); }
 
427
 
 
428
  inline bool isDatabaseLowByteFirst() const { return getShare()->db_low_byte_first; } /* Portable row format */
 
429
  inline bool isNameLock() const { return open_placeholder; }
275
430
 
276
431
  uint32_t index_flags(uint32_t idx) const
277
432
  {
278
 
    return s->storage_engine->index_flags(s->key_info[idx].algorithm);
 
433
    return getShare()->storage_engine->index_flags(getShare()->getKeyInfo(idx).algorithm);
279
434
  }
280
435
 
281
 
  inline plugin::StorageEngine *getEngine() const       /* table_type for handler */
 
436
  inline plugin::StorageEngine *getEngine() const   /* table_type for handler */
282
437
  {
283
 
    return s->storage_engine;
 
438
    return getShare()->storage_engine;
284
439
  }
285
440
 
286
 
  Cursor &getCursor() const     /* table_type for handler */
 
441
  Cursor &getCursor() const /* table_type for handler */
287
442
  {
288
443
    assert(cursor);
289
444
    return *cursor;
290
445
  }
291
446
 
292
 
  /* For TMP tables, should be pulled out as a class */
293
 
  void updateCreateInfo(message::Table *table_proto);
294
 
  void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
295
 
  bool create_myisam_tmp_table(KEY *keyinfo,
296
 
                               MI_COLUMNDEF *start_recinfo,
297
 
                               MI_COLUMNDEF **recinfo,
298
 
                               uint64_t options);
299
 
  void free_tmp_table(Session *session);
300
 
  bool open_tmp_table();
301
447
  size_t max_row_length(const unsigned char *data);
302
448
  uint32_t find_shortest_key(const key_map *usable_keys);
303
449
  bool compare_record(Field **ptr);
304
 
  bool compare_record();
 
450
  bool records_are_comparable();
 
451
  bool compare_records();
305
452
  /* TODO: the (re)storeRecord's may be able to be further condensed */
306
453
  void storeRecord();
307
454
  void storeRecordAsInsert();
310
457
  void restoreRecordAsDefault();
311
458
  void emptyRecord();
312
459
 
 
460
 
313
461
  /* See if this can be blown away */
314
462
  inline uint32_t getDBStat () { return db_stat; }
315
463
  inline uint32_t setDBStat () { return db_stat; }
332
480
  bool fill_item_list(List<Item> *item_list) const;
333
481
  void clear_column_bitmaps(void);
334
482
  void prepare_for_position(void);
335
 
  void mark_columns_used_by_index_no_reset(uint32_t index, MyBitmap *map);
 
483
  void mark_columns_used_by_index_no_reset(uint32_t index, boost::dynamic_bitset<>& bitmap);
336
484
  void mark_columns_used_by_index_no_reset(uint32_t index);
337
485
  void mark_columns_used_by_index(uint32_t index);
338
486
  void restore_column_maps_after_mark_index();
340
488
  void mark_columns_needed_for_update(void);
341
489
  void mark_columns_needed_for_delete(void);
342
490
  void mark_columns_needed_for_insert(void);
343
 
  inline void column_bitmaps_set(MyBitmap *read_set_arg,
344
 
                                 MyBitmap *write_set_arg)
345
 
  {
346
 
    read_set= read_set_arg;
347
 
    write_set= write_set_arg;
348
 
  }
349
 
 
350
 
  void restore_column_map(my_bitmap_map *old);
351
 
 
352
 
  my_bitmap_map *use_all_columns(MyBitmap *bitmap);
 
491
  void column_bitmaps_set(boost::dynamic_bitset<>& read_set_arg,
 
492
                          boost::dynamic_bitset<>& write_set_arg);
 
493
 
 
494
  void restore_column_map(const boost::dynamic_bitset<>& old);
 
495
 
 
496
  const boost::dynamic_bitset<> use_all_columns(boost::dynamic_bitset<>& map);
353
497
  inline void use_all_columns()
354
498
  {
355
 
    column_bitmaps_set(&s->all_set, &s->all_set);
 
499
    column_bitmaps_set(getMutableShare()->all_set, getMutableShare()->all_set);
356
500
  }
357
501
 
358
502
  inline void default_column_bitmaps()
364
508
  /* Both of the below should go away once we can move this bit to the field objects */
365
509
  inline bool isReadSet(uint32_t index)
366
510
  {
367
 
    return read_set->isBitSet(index);
 
511
    return read_set->test(index);
368
512
  }
369
513
 
370
514
  inline void setReadSet(uint32_t index)
371
515
  {
372
 
    read_set->setBit(index);
 
516
    read_set->set(index);
373
517
  }
374
518
 
375
519
  inline void setReadSet()
376
520
  {
377
 
    read_set->setAll();
 
521
    read_set->set();
378
522
  }
379
523
 
380
524
  inline void clearReadSet(uint32_t index)
381
525
  {
382
 
    read_set->clearBit(index);
 
526
    read_set->reset(index);
383
527
  }
384
528
 
385
529
  inline void clearReadSet()
386
530
  {
387
 
    read_set->clearAll();
 
531
    read_set->reset();
388
532
  }
389
533
 
390
534
  inline bool isWriteSet(uint32_t index)
391
535
  {
392
 
    return write_set->isBitSet(index);
 
536
    return write_set->test(index);
393
537
  }
394
538
 
395
539
  inline void setWriteSet(uint32_t index)
396
540
  {
397
 
    write_set->setBit(index);
 
541
    write_set->set(index);
398
542
  }
399
543
 
400
544
  inline void setWriteSet()
401
545
  {
402
 
    write_set->setAll();
 
546
    write_set->set();
403
547
  }
404
548
 
405
549
  inline void clearWriteSet(uint32_t index)
406
550
  {
407
 
    write_set->clearBit(index);
 
551
    write_set->reset(index);
408
552
  }
409
553
 
410
554
  inline void clearWriteSet()
411
555
  {
412
 
    write_set->clearAll();
 
556
    write_set->reset();
413
557
  }
414
558
 
415
559
  /* Is table open or should be treated as such by name-locking? */
422
566
  */
423
567
  inline bool needs_reopen_or_name_lock()
424
568
  { 
425
 
    return s->version != refresh_version;
 
569
    return getShare()->getVersion() != refresh_version;
426
570
  }
427
571
 
428
572
  /**
437
581
  {
438
582
    null_row= 1;
439
583
    status|= STATUS_NULL_ROW;
440
 
    memset(null_flags, 255, s->null_bytes);
 
584
    memset(null_flags, 255, getShare()->null_bytes);
441
585
  }
442
586
 
443
 
  bool renameAlterTemporaryTable(TableIdentifier &identifier);
444
587
  void free_io_cache();
445
588
  void filesort_free_buffers(bool full= false);
446
589
  void intern_close_table();
447
590
 
448
591
  void print_error(int error, myf errflag)
449
592
  {
450
 
    s->storage_engine->print_error(error, errflag, *this);
 
593
    getShare()->storage_engine->print_error(error, errflag, *this);
451
594
  }
452
595
 
453
596
  /**
470
613
  */
471
614
  bool operator<(const Table &right) const
472
615
  {
473
 
    int result= strcasecmp(this->getShare()->getSchemaName(), right.getShare()->getSchemaName());
474
 
 
475
 
    if (result <  0)
476
 
      return true;
477
 
 
478
 
    if (result >  0)
479
 
      return false;
480
 
 
481
 
    result= strcasecmp(this->getShare()->getTableName(), right.getShare()->getTableName());
482
 
 
483
 
    if (result <  0)
484
 
      return true;
485
 
 
486
 
    if (result >  0)
487
 
      return false;
488
 
 
489
 
    if (this->getShare()->getTableProto()->type()  < right.getShare()->getTableProto()->type())
490
 
      return true;
491
 
 
492
 
    return false;
 
616
    return getShare()->getCacheKey() < right.getShare()->getCacheKey();
493
617
  }
494
618
 
495
619
  static bool compare(const Table *a, const Table *b)
499
623
 
500
624
  friend std::ostream& operator<<(std::ostream& output, const Table &table)
501
625
  {
502
 
    output << "Table:(";
503
 
    output << table.getShare()->getSchemaName();
504
 
    output << ", ";
505
 
    output <<  table.getShare()->getTableName();
506
 
    output << ", ";
507
 
    output <<  table.getShare()->getTableTypeAsString();
508
 
    output << ")";
 
626
    if (table.getShare())
 
627
    {
 
628
      output << "Table:(";
 
629
      output << table.getShare()->getSchemaName();
 
630
      output << ", ";
 
631
      output <<  table.getShare()->getTableName();
 
632
      output << ", ";
 
633
      output <<  table.getShare()->getTableTypeAsString();
 
634
      output << ")";
 
635
    }
 
636
    else
 
637
    {
 
638
      output << "Table:(has no share)";
 
639
    }
509
640
 
510
641
    return output;  // for multiple << operators.
511
642
  }
512
643
 
 
644
public:
 
645
  virtual bool isPlaceHolder(void) const
 
646
  {
 
647
    return false;
 
648
  }
513
649
};
514
650
 
515
 
Table *create_virtual_tmp_table(Session *session, List<CreateField> &field_list);
516
 
 
517
 
typedef struct st_foreign_key_info
 
651
/**
 
652
 * @class
 
653
 *  ForeignKeyInfo
 
654
 *
 
655
 * @brief
 
656
 *  This class defines the information for foreign keys.
 
657
 */
 
658
class ForeignKeyInfo
518
659
{
519
 
  LEX_STRING *forein_id;
520
 
  LEX_STRING *referenced_db;
521
 
  LEX_STRING *referenced_table;
522
 
  LEX_STRING *update_method;
523
 
  LEX_STRING *delete_method;
524
 
  LEX_STRING *referenced_key_name;
525
 
  List<LEX_STRING> foreign_fields;
526
 
  List<LEX_STRING> referenced_fields;
527
 
} FOREIGN_KEY_INFO;
528
 
 
529
 
 
 
660
public:
 
661
    /**
 
662
     * @brief
 
663
     *  This is the constructor with all properties set.
 
664
     *
 
665
     * @param[in] in_foreign_id The id of the foreign key
 
666
     * @param[in] in_referenced_db The referenced database name of the foreign key
 
667
     * @param[in] in_referenced_table The referenced table name of the foreign key
 
668
     * @param[in] in_update_method The update method of the foreign key.
 
669
     * @param[in] in_delete_method The delete method of the foreign key.
 
670
     * @param[in] in_referenced_key_name The name of referenced key
 
671
     * @param[in] in_foreign_fields The foreign fields
 
672
     * @param[in] in_referenced_fields The referenced fields
 
673
     */
 
674
    ForeignKeyInfo(LEX_STRING *in_foreign_id,
 
675
                   LEX_STRING *in_referenced_db,
 
676
                   LEX_STRING *in_referenced_table,
 
677
                   LEX_STRING *in_update_method,
 
678
                   LEX_STRING *in_delete_method,
 
679
                   LEX_STRING *in_referenced_key_name,
 
680
                   List<LEX_STRING> in_foreign_fields,
 
681
                   List<LEX_STRING> in_referenced_fields)
 
682
    :
 
683
      foreign_id(in_foreign_id),
 
684
      referenced_db(in_referenced_db),
 
685
      referenced_table(in_referenced_table),
 
686
      update_method(in_update_method),
 
687
      delete_method(in_delete_method),
 
688
      referenced_key_name(in_referenced_key_name),
 
689
      foreign_fields(in_foreign_fields),
 
690
      referenced_fields(in_referenced_fields)
 
691
    {}
 
692
 
 
693
    /**
 
694
     * @brief
 
695
     *  This is the default constructor. All properties are set to default values for their types.
 
696
     */
 
697
    ForeignKeyInfo()
 
698
    : foreign_id(NULL), referenced_db(NULL), referenced_table(NULL),
 
699
      update_method(NULL), delete_method(NULL), referenced_key_name(NULL)
 
700
    {}
 
701
 
 
702
    /**
 
703
     * @brief
 
704
     *  Gets the foreign id.
 
705
     *
 
706
     * @ retval  the foreign id
 
707
     */
 
708
    const LEX_STRING *getForeignId() const
 
709
    {
 
710
        return foreign_id;
 
711
    }
 
712
 
 
713
    /**
 
714
     * @brief
 
715
     *  Gets the name of the referenced database.
 
716
     *
 
717
     * @ retval  the name of the referenced database
 
718
     */
 
719
    const LEX_STRING *getReferencedDb() const
 
720
    {
 
721
        return referenced_db;
 
722
    }
 
723
 
 
724
    /**
 
725
     * @brief
 
726
     *  Gets the name of the referenced table.
 
727
     *
 
728
     * @ retval  the name of the referenced table
 
729
     */
 
730
    const LEX_STRING *getReferencedTable() const
 
731
    {
 
732
        return referenced_table;
 
733
    }
 
734
 
 
735
    /**
 
736
     * @brief
 
737
     *  Gets the update method.
 
738
     *
 
739
     * @ retval  the update method
 
740
     */
 
741
    const LEX_STRING *getUpdateMethod() const
 
742
    {
 
743
        return update_method;
 
744
    }
 
745
 
 
746
    /**
 
747
     * @brief
 
748
     *  Gets the delete method.
 
749
     *
 
750
     * @ retval  the delete method
 
751
     */
 
752
    const LEX_STRING *getDeleteMethod() const
 
753
    {
 
754
        return delete_method;
 
755
    }
 
756
 
 
757
    /**
 
758
     * @brief
 
759
     *  Gets the name of the referenced key.
 
760
     *
 
761
     * @ retval  the name of the referenced key
 
762
     */
 
763
    const LEX_STRING *getReferencedKeyName() const
 
764
    {
 
765
        return referenced_key_name;
 
766
    }
 
767
 
 
768
    /**
 
769
     * @brief
 
770
     *  Gets the foreign fields.
 
771
     *
 
772
     * @ retval  the foreign fields
 
773
     */
 
774
    const List<LEX_STRING> &getForeignFields() const
 
775
    {
 
776
        return foreign_fields;
 
777
    }
 
778
 
 
779
    /**
 
780
     * @brief
 
781
     *  Gets the referenced fields.
 
782
     *
 
783
     * @ retval  the referenced fields
 
784
     */
 
785
    const List<LEX_STRING> &getReferencedFields() const
 
786
    {
 
787
        return referenced_fields;
 
788
    }
 
789
private:
 
790
    /**
 
791
     * The foreign id.
 
792
     */
 
793
    LEX_STRING *foreign_id;
 
794
    /**
 
795
     * The name of the reference database.
 
796
     */
 
797
    LEX_STRING *referenced_db;
 
798
    /**
 
799
     * The name of the reference table.
 
800
     */
 
801
    LEX_STRING *referenced_table;
 
802
    /**
 
803
     * The update method.
 
804
     */
 
805
    LEX_STRING *update_method;
 
806
    /**
 
807
     * The delete method.
 
808
     */
 
809
    LEX_STRING *delete_method;
 
810
    /**
 
811
     * The name of the referenced key.
 
812
     */
 
813
    LEX_STRING *referenced_key_name;
 
814
    /**
 
815
     * The foreign fields.
 
816
     */
 
817
    List<LEX_STRING> foreign_fields;
 
818
    /**
 
819
     * The referenced fields.
 
820
     */
 
821
    List<LEX_STRING> referenced_fields;
 
822
};
530
823
 
531
824
class TableList;
532
825
 
533
 
#define JOIN_TYPE_LEFT  1
534
 
#define JOIN_TYPE_RIGHT 2
 
826
#define JOIN_TYPE_LEFT  1
 
827
#define JOIN_TYPE_RIGHT 2
535
828
 
536
829
struct st_lex;
537
830
class select_union;
538
831
class Tmp_Table_Param;
539
832
 
540
 
struct open_table_list_st
541
 
{
542
 
  std::string   db;
543
 
  std::string   table;
544
 
  uint32_t in_use;
545
 
  uint32_t locked;
546
 
 
547
 
  open_table_list_st() :
548
 
    in_use(0),
549
 
    locked(0)
550
 
  { }
551
 
 
552
 
};
553
 
 
554
 
TableShare *alloc_table_share(TableList *table_list, char *key,
555
 
                               uint32_t key_length);
556
 
int open_table_def(Session& session, TableIdentifier &identifier, TableShare *share);
557
 
void open_table_error(TableShare *share, int error, int db_errno, int errarg);
558
 
int open_table_from_share(Session *session, TableShare *share, const char *alias,
559
 
                          uint32_t db_stat, uint32_t ha_open_flags,
560
 
                          Table *outparam);
561
833
void free_blobs(Table *table);
562
834
int set_zone(int nr,int min_zone,int max_zone);
563
835
uint32_t convert_period_to_month(uint32_t period);
568
840
 
569
841
namespace optimizer { class SqlSelect; }
570
842
 
571
 
ha_rows filesort(Session *session,
572
 
                 Table *form,
573
 
                 st_sort_field *sortorder,
574
 
                 uint32_t s_length,
575
 
                 optimizer::SqlSelect *select,
576
 
                 ha_rows max_rows,
577
 
                 bool sort_positions,
578
 
                 ha_rows *examined_rows);
579
 
 
580
 
void filesort_free_buffers(Table *table, bool full);
581
843
void change_double_for_sort(double nr,unsigned char *to);
582
844
double my_double_round(double value, int64_t dec, bool dec_unsigned,
583
845
                       bool truncate);
587
849
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
588
850
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings);
589
851
ulong get_form_pos(int file, unsigned char *head, TYPELIB *save_names);
590
 
ulong next_io_size(ulong pos);
591
852
void append_unescaped(String *res, const char *pos, uint32_t length);
592
853
 
593
 
int rename_file_ext(const char * from,const char * to,const char * ext);
 
854
DRIZZLED_API int rename_file_ext(const char * from,const char * to,const char * ext);
594
855
bool check_column_name(const char *name);
595
 
bool check_db_name(SchemaIdentifier &schema);
 
856
bool check_db_name(Session *session, identifier::Schema &schema);
596
857
bool check_table_name(const char *name, uint32_t length);
597
858
 
598
859
} /* namespace drizzled */
599
860
 
 
861
#include "drizzled/table/singular.h"
 
862
#include "drizzled/table/concurrent.h"
 
863
 
600
864
#endif /* DRIZZLED_TABLE_H */