~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/data_engine/schemas.cc

  • Committer: Monty Taylor
  • Date: 2010-02-05 08:11:15 UTC
  • mfrom: (1283 build)
  • mto: (1273.13.43 fix_is)
  • mto: This revision was merged to the branch mainline in revision 1300.
  • Revision ID: mordred@inaugust.com-20100205081115-dr82nvrwv4lvw7sd
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
#include "config.h"
22
 
#include "plugin/schema_dictionary/dictionary.h"
 
22
 
 
23
#include <plugin/data_engine/schemas.h>
23
24
 
24
25
using namespace std;
25
26
using namespace drizzled;
26
27
 
27
28
SchemasTool::SchemasTool() :
28
 
  DataDictionary("SCHEMAS")
 
29
  plugin::TableFunction("DATA_DICTIONARY", "SCHEMAS")
29
30
{
30
31
  add_field("SCHEMA_NAME");
31
32
  add_field("DEFAULT_COLLATION_NAME");
32
 
  add_field("SCHEMA_CREATION_TIME");
33
 
  add_field("SCHEMA_UPDATE_TIME");
34
 
  add_field("SCHEMA_UUID", plugin::TableFunction::STRING, 36, true);
35
 
  add_field("SCHEMA_VERSION", plugin::TableFunction::NUMBER, 0, true);
36
 
  add_field("SCHEMA_USE_COUNT", plugin::TableFunction::NUMBER, 0, true);
37
 
}
38
 
 
39
 
SchemasTool::Generator::Generator(drizzled::Field **arg) :
40
 
  DataDictionary::Generator(arg),
41
 
  schema_generator(getSession())
42
 
{
43
 
}
 
33
}
 
34
 
 
35
SchemasTool::Generator::Generator(Field **arg) :
 
36
  plugin::TableFunction::Generator(arg),
 
37
  is_schema_primed(false),
 
38
  is_schema_parsed(false)
 
39
{
 
40
}
 
41
 
 
42
/**
 
43
  @note return true if a match occurs.
 
44
*/
 
45
bool SchemasTool::Generator::checkSchema()
 
46
{
 
47
  return isWild(schema_name());
 
48
}
 
49
 
 
50
bool SchemasTool::Generator::nextSchemaCore()
 
51
{
 
52
  if (is_schema_primed)
 
53
  {
 
54
    schema_iterator++;
 
55
  }
 
56
  else
 
57
  {
 
58
    plugin::StorageEngine::getSchemaNames(schema_names);
 
59
    schema_iterator= schema_names.begin();
 
60
    is_schema_primed= true;
 
61
  }
 
62
 
 
63
  if (schema_iterator == schema_names.end())
 
64
    return false;
 
65
 
 
66
  schema.Clear();
 
67
  is_schema_parsed= plugin::StorageEngine::getSchemaDefinition(*schema_iterator, schema);
 
68
 
 
69
  if (checkSchema())
 
70
      return false;
 
71
 
 
72
  return true;
 
73
}
 
74
  
 
75
bool SchemasTool::Generator::nextSchema()
 
76
{
 
77
  while (not nextSchemaCore())
 
78
  {
 
79
    if (schema_iterator == schema_names.end())
 
80
      return false;
 
81
  }
 
82
 
 
83
  return true;
 
84
}
 
85
 
44
86
 
45
87
bool SchemasTool::Generator::populate()
46
88
{
47
 
  drizzled::message::schema::shared_ptr schema_ptr;
48
 
  while ((schema_ptr= schema_generator))
 
89
  if (nextSchema())
49
90
  {
50
 
    /* SCHEMA_NAME */
51
 
    push(schema_ptr->name());
52
 
 
53
 
    /* DEFAULT_COLLATION_NAME */
54
 
    push(schema_ptr->collation());
55
 
 
56
 
    /* SCHEMA_CREATION_TIME */
57
 
    time_t time_arg= schema_ptr->creation_timestamp();
58
 
    char buffer[40];
59
 
    struct tm tm_buffer;
60
 
 
61
 
    localtime_r(&time_arg, &tm_buffer);
62
 
    strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
63
 
    push(buffer);
64
 
 
65
 
    /* SCHEMA_UPDATE_TIME */
66
 
    time_arg= schema_ptr->update_timestamp();
67
 
    localtime_r(&time_arg, &tm_buffer);
68
 
    strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
69
 
    push(buffer);
70
 
 
71
 
    /* SCHEMA_UUID */
72
 
    push(schema_ptr->uuid());
73
 
 
74
 
    /* SCHEMA_VERSION */
75
 
    push(schema_ptr->version());
76
 
 
77
 
    /* SCHEMA_USE_COUNT */
78
 
    push(schema_ptr->version());
 
91
    fill();
79
92
    return true;
80
93
  }
81
94
 
82
95
  return false;
83
96
}
 
97
 
 
98
/**
 
99
  A lack of a parsed schema file means we are using defaults.
 
100
*/
 
101
void SchemasTool::Generator::fill()
 
102
{
 
103
  /* SCHEMA_NAME */
 
104
  push(schema.name());
 
105
 
 
106
  /* DEFAULT_COLLATION_NAME */
 
107
  if (is_schema_parsed)
 
108
    push(schema.collation());
 
109
  else
 
110
    push(scs->name);
 
111
}