~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/foreign_key.cc

  • Committer: Brian Aker
  • Date: 2009-10-15 00:22:33 UTC
  • mto: (1183.1.11 merge)
  • mto: This revision was merged to the branch mainline in revision 1198.
  • Revision ID: brian@gaz-20091015002233-fa4ao2mbc67wls91
First pass of information engine. OMG, ponies... is it so much easier to
deal with creating and engine.

The list table iterator though... its ass, needs to go. We should also
abstract out share. Very few engines need a custom one. Just say'in

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
22
 
#include <string>
23
 
 
 
20
#include "drizzled/global.h"
 
21
#include "drizzled/server_includes.h" /* @TODO remove this when header include is refactored more... */
24
22
#include "drizzled/foreign_key.h"
25
23
#include "drizzled/error.h"
26
 
#include "drizzled/create_field.h"
27
 
#include "drizzled/internal/my_sys.h"
28
 
#include "drizzled/table_ident.h"
29
 
 
30
 
namespace drizzled
31
 
{
32
 
 
33
 
extern const CHARSET_INFO *system_charset_info;
34
 
 
35
 
void add_foreign_key_to_table_message(
36
 
    message::Table *table_message,
37
 
    const char* fkey_name,
38
 
    List<Key_part_spec> &cols,
39
 
    Table_ident *table,
40
 
    List<Key_part_spec> &ref_cols,
41
 
    message::Table::ForeignKeyConstraint::ForeignKeyOption delete_opt_arg,
42
 
    message::Table::ForeignKeyConstraint::ForeignKeyOption update_opt_arg,
43
 
    message::Table::ForeignKeyConstraint::ForeignKeyMatchOption match_opt_arg)
44
 
{
45
 
  message::Table::ForeignKeyConstraint *pfkey= table_message->add_fk_constraint();
46
 
  if (fkey_name)
47
 
    pfkey->set_name(fkey_name);
48
 
  else if (table_message->has_name())
49
 
  {
50
 
    std::string name(table_message->name());
51
 
    char number[20];
52
 
 
53
 
    name.append("_ibfk_");
54
 
    snprintf(number, sizeof(number), "%d", table_message->fk_constraint_size());
55
 
    name.append(number);
56
 
 
57
 
    pfkey->set_name(name);
58
 
  }
59
 
 
60
 
  pfkey->set_match(match_opt_arg);
61
 
  pfkey->set_update_option(update_opt_arg);
62
 
  pfkey->set_delete_option(delete_opt_arg);
63
 
 
64
 
  pfkey->set_references_table_name(table->table.str);
65
 
 
66
 
  Key_part_spec *keypart;
67
 
  List_iterator<Key_part_spec> col_it(cols);
68
 
  while ((keypart= col_it++))
69
 
  {
70
 
    pfkey->add_column_names(keypart->field_name.str);
71
 
  }
72
 
 
73
 
  List_iterator<Key_part_spec> ref_it(ref_cols);
74
 
  while ((keypart= ref_it++))
75
 
  {
76
 
    pfkey->add_references_columns(keypart->field_name.str);
77
 
  }
78
 
 
79
 
}
80
 
 
81
 
Foreign_key::Foreign_key(const Foreign_key &rhs, memory::Root *mem_root)
 
24
 
 
25
Foreign_key::Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root)
82
26
  :Key(rhs),
83
27
  ref_table(rhs.ref_table),
84
28
  ref_columns(rhs.ref_columns),
184
128
  return false;
185
129
}
186
130
 
187
 
} /* namespace drizzled */
 
131
 
 
132