~drizzle-trunk/drizzle/development

1119.2.10 by Monty Taylor
Merged Stewart from lp:~stewart-flamingspork/drizzle/table-proto-text-reader
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
1119.2.10 by Monty Taylor
Merged Stewart from lp:~stewart-flamingspork/drizzle/table-proto-text-reader
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
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
21
#include "config.h"
1122.2.2 by Monty Taylor
Added missing copyright headers. Added drizzled/global.h to a few things that
22
820.1.9 by Stewart Smith
remove the ass that is fstream and use good old open(2) and the protobuf ZeroCopyInputStream
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>
873.2.1 by Monty Taylor
Added missing header for solaris build.
29
#include <unistd.h>
820.1.9 by Stewart Smith
remove the ass that is fstream and use good old open(2) and the protobuf ZeroCopyInputStream
30
323 by Brian Aker
Updated proto file for table (not FRM work).
31
#include <iostream>
32
#include <string>
1308.2.9 by Jay Pipes
Adds CREATE TABLE work to the statement tranform library. Removes it from /drizzle/message/table_reader.cc
33
#include <drizzled/message/statement_transform.h>
820.1.9 by Stewart Smith
remove the ass that is fstream and use good old open(2) and the protobuf ZeroCopyInputStream
34
#include <google/protobuf/io/zero_copy_stream.h>
35
#include <google/protobuf/io/zero_copy_stream_impl.h>
685.1.5 by Monty Taylor
Fixed a few things to make VPATH builds work.
36
323 by Brian Aker
Updated proto file for table (not FRM work).
37
using namespace std;
1101.2.1 by Monty Taylor
Fixed the first set of using namespace
38
using namespace drizzled;
39
using namespace google;
323 by Brian Aker
Updated proto file for table (not FRM work).
40
584.2.3 by Stewart Smith
remove trailing whitespace in serialize/table
41
/*
323 by Brian Aker
Updated proto file for table (not FRM work).
42
  Written from Google proto example
43
*/
44
584.2.3 by Stewart Smith
remove trailing whitespace in serialize/table
45
int main(int argc, char* argv[])
323 by Brian Aker
Updated proto file for table (not FRM work).
46
{
47
  GOOGLE_PROTOBUF_VERIFY_VERSION;
48
49
  if (argc != 2) {
50
    cerr << "Usage:  " << argv[0] << " SCHEMA" << endl;
51
    return -1;
52
  }
53
1101.2.1 by Monty Taylor
Fixed the first set of using namespace
54
  message::Table table;
323 by Brian Aker
Updated proto file for table (not FRM work).
55
56
  {
820.1.9 by Stewart Smith
remove the ass that is fstream and use good old open(2) and the protobuf ZeroCopyInputStream
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
1101.2.1 by Monty Taylor
Fixed the first set of using namespace
65
    protobuf::io::ZeroCopyInputStream* input=
66
      new protobuf::io::FileInputStream(fd);
820.1.9 by Stewart Smith
remove the ass that is fstream and use good old open(2) and the protobuf ZeroCopyInputStream
67
68
    if (!table.ParseFromZeroCopyStream(input))
323 by Brian Aker
Updated proto file for table (not FRM work).
69
    {
70
      cerr << "Failed to parse table." << endl;
869.1.1 by Stewart Smith
closing file descriptors is good.
71
      close(fd);
323 by Brian Aker
Updated proto file for table (not FRM work).
72
      return -1;
73
    }
869.1.1 by Stewart Smith
closing file descriptors is good.
74
75
    close(fd);
323 by Brian Aker
Updated proto file for table (not FRM work).
76
  }
77
1308.2.9 by Jay Pipes
Adds CREATE TABLE work to the statement tranform library. Removes it from /drizzle/message/table_reader.cc
78
  string output;
1389 by Brian Aker
Large reord in ALTER TABLE for RENAME.
79
  (void) message::transformTableDefinitionToSql(table, output, message::DRIZZLE, true);
1308.2.9 by Jay Pipes
Adds CREATE TABLE work to the statement tranform library. Removes it from /drizzle/message/table_reader.cc
80
81
  cout << output << endl;
323 by Brian Aker
Updated proto file for table (not FRM work).
82
83
  return 0;
84
}