Drizzled Public API Documentation

table_reader.cc
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2009 Sun Microsystems, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <config.h>
22 
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26 #include <string.h>
27 #include <stdio.h>
28 #include <errno.h>
29 #include <unistd.h>
30 
31 #include <iostream>
32 #include <string>
34 #include <google/protobuf/io/zero_copy_stream.h>
35 #include <google/protobuf/io/zero_copy_stream_impl.h>
36 
37 using namespace std;
38 using namespace drizzled;
39 using namespace google;
40 
41 /*
42  Written from Google proto example
43 */
44 
45 int main(int argc, char* argv[])
46 {
47  GOOGLE_PROTOBUF_VERIFY_VERSION;
48 
49  if (argc != 2) {
50  cerr << "Usage: " << argv[0] << " SCHEMA" << endl;
51  return -1;
52  }
53 
54  message::Table table;
55 
56  {
57  int fd= open(argv[1], O_RDONLY);
58 
59  if(fd==-1)
60  {
61  perror("Failed to open table definition file");
62  return -1;
63  }
64 
65  protobuf::io::ZeroCopyInputStream* input=
66  new protobuf::io::FileInputStream(fd);
67 
68  if (!table.ParseFromZeroCopyStream(input))
69  {
70  cerr << "Failed to parse table." << endl;
71  close(fd);
72  return -1;
73  }
74 
75  close(fd);
76  }
77 
78  string output;
79  (void) message::transformTableDefinitionToSql(table, output, message::DRIZZLE, true);
80 
81  cout << output << endl;
82 
83  return 0;
84 }
TODO: Rename this file - func.h is stupid.