Drizzled Public API Documentation

schema_reader.cc

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2009 Sun Microsystems, Inc.
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; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include <iostream>
00021 #include <fstream>
00022 #include <string>
00023 #include <drizzled/message/schema.pb.h>
00024 
00025 using namespace std;
00026 using namespace drizzled;
00027 
00028 
00029 /*
00030   Written from Google proto example
00031 */
00032 
00033 static void printSchema(const message::Schema *schema)
00034 {
00035   cout << "CREATE SCHEMA `" << schema->name() << "` ";
00036   if (schema->has_collation())
00037     cout << "COLLATE `" << schema->collation() << "` ";
00038 
00039   for (int option_nr=0; option_nr < schema->engine().options_size(); option_nr++)
00040   {
00041     cout << " " << schema->engine().options(option_nr).name() << " = "
00042          << "'" << schema->engine().options(option_nr).state() << "'";
00043   }
00044 
00045   cout << ";" << endl;
00046 }
00047 
00048 int main(int argc, char* argv[])
00049 {
00050   GOOGLE_PROTOBUF_VERIFY_VERSION;
00051 
00052   if (argc != 2) {
00053     cerr << "Usage:  " << argv[0] << " SCHEMA" << endl;
00054     return -1;
00055   }
00056 
00057   message::Schema schema;
00058 
00059   {
00060     // Read the existing address book.
00061     fstream input(argv[1], ios::in | ios::binary);
00062     if (!schema.ParseFromIstream(&input))
00063     {
00064       cerr << "Failed to parse schema." << endl;
00065       return -1;
00066     }
00067   }
00068 
00069   printSchema(&schema);
00070 
00071   return 0;
00072 }