~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/collation_dictionary/collations.cc

Monty's fixes, my rewrite of collations dictionary.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
 
28
28
CollationsTool::CollationsTool() :
29
 
  plugin::TableFunction("DATA_DICTIONARY", "COLLATIONS")
 
29
  CharacterSetsTool("COLLATIONS")
30
30
{
31
31
  add_field("CHARACTER_SET_NAME");
32
32
  add_field("COLLATION_NAME");
38
38
}
39
39
 
40
40
CollationsTool::Generator::Generator(Field **arg) :
41
 
  plugin::TableFunction::Generator(arg)
42
 
{
43
 
  cs= all_charsets;
44
 
  cl= all_charsets;
 
41
  CharacterSetsTool::Generator(arg),
 
42
  is_collation_primed(false)
 
43
{
 
44
}
 
45
 
 
46
 
 
47
bool CollationsTool::Generator::end()
 
48
{
 
49
  return collation_iter == all_charsets+255;
 
50
}
 
51
 
 
52
 
 
53
bool CollationsTool::Generator::check()
 
54
{
 
55
  const CHARSET_INFO *tmp_cs= character_set();
 
56
  const CHARSET_INFO *tmp_cl= collation();
 
57
 
 
58
  if (not tmp_cl || 
 
59
      not (tmp_cl->state & MY_CS_AVAILABLE) ||
 
60
      not my_charset_same(tmp_cs, tmp_cl))
 
61
    return true;
 
62
 
 
63
  return false;
 
64
}
 
65
 
 
66
bool CollationsTool::Generator::nextCollationCore()
 
67
{
 
68
  if (isPrimed())
 
69
  {
 
70
    collation_iter++;
 
71
  }
 
72
  else
 
73
  {
 
74
    if (not isCharacterSetPrimed())
 
75
     return false;
 
76
 
 
77
    collation_iter= all_charsets;
 
78
    prime();
 
79
  }
 
80
 
 
81
  if (end())
 
82
    return false;
 
83
 
 
84
  if (check())
 
85
      return false;
 
86
 
 
87
  return true;
 
88
}
 
89
 
 
90
 
 
91
bool CollationsTool::Generator::next()
 
92
{
 
93
  while (not nextCollationCore())
 
94
  {
 
95
 
 
96
    if (isPrimed() && not end())
 
97
      continue;
 
98
 
 
99
    if (not nextCharacterSet())
 
100
      return false;
 
101
 
 
102
    prime(false);
 
103
  }
 
104
 
 
105
  return true;
45
106
}
46
107
 
47
108
bool CollationsTool::Generator::populate()
48
109
{
49
 
  for (; cs < all_charsets+255 ; cs++)
50
 
  {
51
 
    const CHARSET_INFO *tmp_cs= cs[0];
52
 
 
53
 
    if (! tmp_cs || ! (tmp_cs->state & MY_CS_AVAILABLE) ||
54
 
        (tmp_cs->state & MY_CS_HIDDEN) ||
55
 
        !(tmp_cs->state & MY_CS_PRIMARY))
56
 
      continue;
57
 
 
58
 
    for (; cl < all_charsets+255 ;cl ++)
59
 
    {
60
 
      const CHARSET_INFO *tmp_cl= cl[0];
61
 
 
62
 
      if (! tmp_cl || ! (tmp_cl->state & MY_CS_AVAILABLE) ||
63
 
          !my_charset_same(tmp_cs, tmp_cl))
64
 
        continue;
65
 
 
66
 
      {
67
 
        /* CHARACTER_SET_NAME */
68
 
        push(tmp_cs->name);
69
 
 
70
 
        /* "COLLATION_NAME" */
71
 
        push(tmp_cl->name);
72
 
 
73
 
        /* "DESCRIPTION" */
74
 
        push(tmp_cl->csname);
75
 
 
76
 
        /* COLLATION_ID */
77
 
        push((int64_t) tmp_cl->number);
78
 
         
79
 
        /* IS_DEFAULT */
80
 
        push((bool)(tmp_cl->state & MY_CS_PRIMARY));
81
 
 
82
 
        /* IS_COMPILED */
83
 
        push((bool)(tmp_cl->state & MY_CS_COMPILED));
84
 
 
85
 
        /* SORTLEN */
86
 
        push((int64_t) tmp_cl->strxfrm_multiply);
87
 
 
88
 
        cl++;
89
 
 
90
 
        return true;
91
 
      }
92
 
      cs++;
93
 
    }
94
 
 
95
 
    cl= all_charsets;
96
 
  }
97
 
 
98
 
  return false;
 
110
  if (not next())
 
111
    return false;
 
112
 
 
113
  fill();
 
114
 
 
115
  return true;
 
116
}
 
117
 
 
118
void CollationsTool::Generator::fill()
 
119
{
 
120
  const CHARSET_INFO *tmp_cs= character_set();
 
121
  const CHARSET_INFO *tmp_cl= collation_iter[0];
 
122
 
 
123
  assert(tmp_cs);
 
124
  assert(tmp_cl);
 
125
 
 
126
  fprintf(stderr, "CHAR %s\n", tmp_cs->name);
 
127
  assert(tmp_cs->name);
 
128
  /* CHARACTER_SET_NAME */
 
129
  push(tmp_cs->name);
 
130
 
 
131
  /* "COLLATION_NAME" */
 
132
  assert(tmp_cl->name);
 
133
  push(tmp_cl->name);
 
134
 
 
135
  /* "DESCRIPTION" */
 
136
  push(tmp_cl->csname);
 
137
 
 
138
  /* COLLATION_ID */
 
139
  push((int64_t) tmp_cl->number);
 
140
 
 
141
  /* IS_DEFAULT */
 
142
  push((bool)(tmp_cl->state & MY_CS_PRIMARY));
 
143
 
 
144
  /* IS_COMPILED */
 
145
  push((bool)(tmp_cl->state & MY_CS_COMPILED));
 
146
 
 
147
  /* SORTLEN */
 
148
  push((int64_t) tmp_cl->strxfrm_multiply);
99
149
}