Drizzled Public API Documentation

catalogs.cc
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Brian Aker
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <plugin/catalog/module.h>
00024 
00025 namespace plugin {
00026 namespace catalog {
00027 namespace tables {
00028 
00029 Catalogs::Catalogs() :
00030   drizzled::plugin::TableFunction("DATA_DICTIONARY", "CATALOGS")
00031 {
00032   add_field("CATALOG_NAME", drizzled::plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
00033   add_field("CATALOG_CREATION_TIME");
00034   add_field("CATALOG_UPDATE_TIME");
00035   add_field("CATALOG_UUID", drizzled::plugin::TableFunction::STRING, 36, true);
00036   add_field("CATALOG_VERSION", drizzled::plugin::TableFunction::NUMBER, 0, true);
00037 }
00038 
00039 Catalogs::Generator::Generator(drizzled::Field **arg) :
00040   drizzled::plugin::TableFunction::Generator(arg)
00041 {
00042 }
00043 
00044 bool Catalogs::Generator::populate()
00045 {
00046   drizzled::message::catalog::shared_ptr tmp;
00047 
00048   while ((tmp= catalog_generator))
00049   {
00050     // CATALOG_NAME
00051     push(tmp->name());
00052 
00053     /* SCHEMA_CREATION_TIME */
00054     time_t time_arg= tmp->creation_timestamp();
00055     char buffer[40];
00056     struct tm tm_buffer;
00057 
00058     localtime_r(&time_arg, &tm_buffer);
00059     strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
00060     push(buffer);
00061 
00062     /* SCHEMA_UPDATE_TIME */
00063     time_arg= tmp->update_timestamp();
00064     localtime_r(&time_arg, &tm_buffer);
00065     strftime(buffer, sizeof(buffer), "%a %b %d %H:%M:%S %Y", &tm_buffer);
00066     push(buffer);
00067 
00068     /* SCHEMA_UUID */
00069     push(tmp->uuid());
00070 
00071     /* SCHEMA_VERSION */
00072     push(tmp->version());
00073 
00074     return true;
00075   }
00076 
00077   return false;
00078 }
00079 
00080 } /* namespace tables */
00081 } /* namespace catalog */
00082 } /* namespace plugin */