~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/schema_dictionary/schemas.cc

  • Committer: Brian Aker
  • Date: 2010-08-17 01:34:55 UTC
  • mto: (1711.1.23 build)
  • mto: This revision was merged to the branch mainline in revision 1714.
  • Revision ID: brian@tangent.org-20100817013455-zx3nm7qilxvpwrgb
Style on structure cleanup

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) 2010 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2010 Sun Microsystems
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
25
25
using namespace drizzled;
26
26
 
27
27
SchemasTool::SchemasTool() :
28
 
  DataDictionary("SCHEMAS")
 
28
  plugin::TableFunction("DATA_DICTIONARY", "SCHEMAS")
29
29
{
30
30
  add_field("SCHEMA_NAME");
31
31
  add_field("DEFAULT_COLLATION_NAME");
32
32
  add_field("SCHEMA_CREATION_TIME");
33
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
34
}
38
35
 
39
 
SchemasTool::Generator::Generator(drizzled::Field **arg) :
40
 
  DataDictionary::Generator(arg),
 
36
SchemasTool::Generator::Generator(Field **arg) :
 
37
  plugin::TableFunction::Generator(arg),
41
38
  schema_generator(getSession())
42
39
{
43
40
}
 
41
  
 
42
bool SchemasTool::Generator::nextSchema()
 
43
{
 
44
  const drizzled::message::Schema *schema_ptr;
 
45
  while ((schema_ptr= schema_generator))
 
46
  {
 
47
    schema.CopyFrom(*schema_ptr);
 
48
    return true;
 
49
  }
 
50
 
 
51
  return false;
 
52
}
 
53
 
44
54
 
45
55
bool SchemasTool::Generator::populate()
46
56
{
47
 
  drizzled::message::schema::shared_ptr schema_ptr;
48
 
  while ((schema_ptr= schema_generator))
 
57
  if (nextSchema())
49
58
  {
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());
 
59
    fill();
79
60
    return true;
80
61
  }
81
62
 
82
63
  return false;
83
64
}
 
65
 
 
66
/**
 
67
  A lack of a parsed schema file means we are using defaults.
 
68
*/
 
69
void SchemasTool::Generator::fill()
 
70
{
 
71
  /* SCHEMA_NAME */
 
72
  push(schema.name());
 
73
 
 
74
  /* DEFAULT_COLLATION_NAME */
 
75
  push(schema.collation());
 
76
 
 
77
  /* SCHEMA_CREATION_TIME */
 
78
  time_t time_arg= schema.creation_timestamp();
 
79
  char buffer[40];
 
80
  struct tm tm_buffer;
 
81
 
 
82
  localtime_r(&time_arg, &tm_buffer);
 
83
  strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
 
84
  push(buffer);
 
85
 
 
86
  /* SCHEMA_UPDATE_TIME */
 
87
  time_arg= schema.update_timestamp();
 
88
  localtime_r(&time_arg, &tm_buffer);
 
89
  strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
 
90
  push(buffer);
 
91
}