~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 04:19:44 UTC
  • mto: (2192.1.1 drizzle-staging)
  • mto: This revision was merged to the branch mainline in revision 2193.
  • Revision ID: brian@tangent.org-20110222041944-furz1h252ecz7mpd
Merge in modifications such that we check both schema and table for
replication option.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
/* Some general useful functions */
18
18
 
19
 
#include "config.h"
 
19
#include <config.h>
20
20
 
21
21
#include <float.h>
22
22
#include <fcntl.h>
28
28
#include <drizzled/error.h>
29
29
#include <drizzled/gettext.h>
30
30
 
31
 
#include "drizzled/plugin/transactional_storage_engine.h"
32
 
#include "drizzled/plugin/authorization.h"
 
31
#include <drizzled/plugin/transactional_storage_engine.h>
 
32
#include <drizzled/plugin/authorization.h>
33
33
#include <drizzled/nested_join.h>
34
34
#include <drizzled/sql_parse.h>
35
35
#include <drizzled/item/sum.h>
42
42
#include <drizzled/field/double.h>
43
43
#include <drizzled/unireg.h>
44
44
#include <drizzled/message/table.pb.h>
45
 
#include "drizzled/sql_table.h"
46
 
#include "drizzled/charset.h"
47
 
#include "drizzled/internal/m_string.h"
48
 
#include "plugin/myisam/myisam.h"
 
45
#include <drizzled/sql_table.h>
 
46
#include <drizzled/charset.h>
 
47
#include <drizzled/internal/m_string.h>
 
48
#include <plugin/myisam/myisam.h>
 
49
#include <drizzled/plugin/storage_engine.h>
49
50
 
50
51
#include <drizzled/item/string.h>
51
52
#include <drizzled/item/int.h>
54
55
#include <drizzled/item/null.h>
55
56
#include <drizzled/temporal.h>
56
57
 
57
 
#include "drizzled/table/instance.h"
58
 
 
59
 
#include "drizzled/table_proto.h"
 
58
#include <drizzled/refresh_version.h>
 
59
 
 
60
#include <drizzled/table/singular.h>
 
61
 
 
62
#include <drizzled/table_proto.h>
 
63
#include <drizzled/typelib.h>
60
64
 
61
65
using namespace std;
62
66
 
63
67
namespace drizzled
64
68
{
65
69
 
66
 
extern pid_t current_pid;
67
70
extern plugin::StorageEngine *heap_engine;
68
71
extern plugin::StorageEngine *myisam_engine;
69
72
 
70
73
/* Functions defined in this cursor */
71
74
 
72
 
void open_table_error(TableShare *share, int error, int db_errno,
73
 
                      myf errortype, int errarg);
74
 
 
75
75
/*************************************************************************/
76
76
 
77
77
// @note this should all be the destructor
82
82
  if (db_stat)
83
83
    error= cursor->close();
84
84
  _alias.clear();
 
85
 
85
86
  if (field)
86
87
  {
87
88
    for (Field **ptr=field ; *ptr ; ptr++)
90
91
    }
91
92
    field= 0;
92
93
  }
93
 
  delete cursor;
94
 
  cursor= 0;                            /* For easier errorchecking */
 
94
  safe_delete(cursor);
95
95
 
96
96
  if (free_share)
97
97
  {
112
112
                       uint32_t db_stat_arg)
113
113
{
114
114
  setShare(share);
 
115
  in_use= session;
 
116
 
115
117
  field= NULL;
116
118
 
117
119
  cursor= NULL;
124
126
  tablenr= 0;
125
127
  db_stat= db_stat_arg;
126
128
 
127
 
  in_use= session;
128
129
  record[0]= (unsigned char *) NULL;
129
130
  record[1]= (unsigned char *) NULL;
130
131
 
222
223
    
223
224
  result->type_lengths= (uint*) (result->type_names + result->count + 1);
224
225
 
225
 
  List_iterator<String> it(strings);
 
226
  List<String>::iterator it(strings);
226
227
  String *tmp;
227
228
  for (uint32_t i= 0; (tmp= it++); i++)
228
229
  {
322
323
}
323
324
 
324
325
/*
325
 
  Check if database name is valid
326
 
 
327
 
  SYNPOSIS
328
 
    check_db_name()
329
 
    org_name            Name of database and length
330
 
 
331
 
  RETURN
332
 
    false error
333
 
    true ok
334
 
*/
335
 
 
336
 
bool check_db_name(Session *session, SchemaIdentifier &schema_identifier)
337
 
{
338
 
  if (not plugin::Authorization::isAuthorized(session->getSecurityContext(), schema_identifier))
339
 
  {
340
 
    return false;
341
 
  }
342
 
 
343
 
  return schema_identifier.isValid();
344
 
}
345
 
 
346
 
/*
347
326
  Allow anything as a table name, as long as it doesn't contain an
348
327
  ' ' at the end
349
328
  returns 1 on error
838
817
    copy_func_count+= param->sum_func_count;
839
818
  }
840
819
 
841
 
  table::Instance *table;
 
820
  table::Singular *table;
842
821
  table= session->getInstanceTable(); // This will not go into the tableshare cache, so no key is used.
843
822
 
844
823
  if (not table->getMemRoot()->multi_alloc_root(0,
884
863
 
885
864
  table->getMutableShare()->blob_field.resize(field_count+1);
886
865
  uint32_t *blob_field= &table->getMutableShare()->blob_field[0];
887
 
  table->getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
888
866
  table->getMutableShare()->db_low_byte_first=1;                // True for HEAP and MyISAM
889
867
  table->getMutableShare()->table_charset= param->table_charset;
890
868
  table->getMutableShare()->keys_for_keyread.reset();
896
874
  blob_count= string_count= null_count= hidden_null_count= group_null_items= 0;
897
875
  param->using_indirect_summary_function= 0;
898
876
 
899
 
  List_iterator_fast<Item> li(fields);
 
877
  List<Item>::iterator li(fields);
900
878
  Item *item;
901
879
  Field **tmp_from_field=from_field;
902
880
  while ((item=li++))
1035
1013
  field_count= fieldnr;
1036
1014
  *reg_field= 0;
1037
1015
  *blob_field= 0;                               // End marker
1038
 
  table->getMutableShare()->fields= field_count;
 
1016
  table->getMutableShare()->setFieldSize(field_count);
1039
1017
 
1040
1018
  /* If result table is small; use a heap */
1041
1019
  /* future: storage engine selection can be made dynamic? */
1647
1625
  query_id(0),
1648
1626
  quick_condition_rows(0),
1649
1627
  timestamp_field_type(TIMESTAMP_NO_AUTO_SET),
1650
 
  map(0)
 
1628
  map(0),
 
1629
  quick_rows(),
 
1630
  const_key_parts(),
 
1631
  quick_key_parts(),
 
1632
  quick_n_ranges()
1651
1633
{
1652
1634
  record[0]= (unsigned char *) 0;
1653
1635
  record[1]= (unsigned char *) 0;
1654
 
 
1655
 
  reginfo.reset();
1656
 
  covering_keys.reset();
1657
 
  quick_keys.reset();
1658
 
  merge_keys.reset();
1659
 
 
1660
 
  keys_in_use_for_query.reset();
1661
 
  keys_in_use_for_group_by.reset();
1662
 
  keys_in_use_for_order_by.reset();
1663
 
 
1664
 
  memset(quick_rows, 0, sizeof(ha_rows) * MAX_KEY);
1665
 
  memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
1666
 
 
1667
 
  memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
1668
 
  memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
1669
1636
}
1670
1637
 
1671
1638
/*****************************************************************************
1687
1654
    print them to the .err log
1688
1655
  */
1689
1656
  if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT)
1690
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Got error %d when reading table '%s'"),
 
1657
    errmsg_printf(error::ERROR, _("Got error %d when reading table '%s'"),
1691
1658
                  error, getShare()->getPath());
1692
1659
  print_error(error, MYF(0));
1693
1660
 
1765
1732
  }
1766
1733
}
1767
1734
 
 
1735
/*
 
1736
  Is this instance of the table should be reopen or represents a name-lock?
 
1737
*/
 
1738
bool Table::needs_reopen_or_name_lock() const
 
1739
 
1740
  return getShare()->getVersion() != refresh_version;
 
1741
}
 
1742
 
 
1743
uint32_t Table::index_flags(uint32_t idx) const
 
1744
{
 
1745
  return getShare()->getEngine()->index_flags(getShare()->getKeyInfo(idx).algorithm);
 
1746
}
 
1747
 
 
1748
void Table::print_error(int error, myf errflag) const
 
1749
{
 
1750
  getShare()->getEngine()->print_error(error, errflag, *this);
 
1751
}
 
1752
 
1768
1753
} /* namespace drizzled */