Drizzled Public API Documentation

table_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; 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 <sys/types.h>
00024 #include <sys/stat.h>
00025 #include <fcntl.h>
00026 #include <string.h>
00027 #include <stdio.h>
00028 #include <errno.h>
00029 #include <unistd.h>
00030 
00031 #include <iostream>
00032 #include <string>
00033 #include <drizzled/message/statement_transform.h>
00034 #include <google/protobuf/io/zero_copy_stream.h>
00035 #include <google/protobuf/io/zero_copy_stream_impl.h>
00036 
00037 using namespace std;
00038 using namespace drizzled;
00039 using namespace google;
00040 
00041 /*
00042   Written from Google proto example
00043 */
00044 
00045 int main(int argc, char* argv[])
00046 {
00047   GOOGLE_PROTOBUF_VERIFY_VERSION;
00048 
00049   if (argc != 2) {
00050     cerr << "Usage:  " << argv[0] << " SCHEMA" << endl;
00051     return -1;
00052   }
00053 
00054   message::Table table;
00055 
00056   {
00057     int fd= open(argv[1], O_RDONLY);
00058 
00059     if(fd==-1)
00060     {
00061       perror("Failed to open table definition file");
00062       return -1;
00063     }
00064 
00065     protobuf::io::ZeroCopyInputStream* input=
00066       new protobuf::io::FileInputStream(fd);
00067 
00068     if (!table.ParseFromZeroCopyStream(input))
00069     {
00070       cerr << "Failed to parse table." << endl;
00071       close(fd);
00072       return -1;
00073     }
00074 
00075     close(fd);
00076   }
00077 
00078   string output;
00079   (void) message::transformTableDefinitionToSql(table, output, message::DRIZZLE, true);
00080 
00081   cout << output << endl;
00082 
00083   return 0;
00084 }