00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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 }