25
25
#include <drizzled/message/table.pb.h>
26
26
#include <google/protobuf/io/zero_copy_stream.h>
27
27
#include <google/protobuf/io/zero_copy_stream_impl.h>
29
#include <drizzled/table_proto.h>
30
28
using namespace std;
32
int fill_table_proto(drizzled::message::Table *table_proto,
33
const char *table_name,
34
List<CreateField> &create_fields,
35
HA_CREATE_INFO *create_info,
30
int drizzle_read_table_proto(const char* path, drizzled::message::Table* table)
32
int fd= open(path, O_RDONLY);
37
google::protobuf::io::ZeroCopyInputStream* input=
38
new google::protobuf::io::FileInputStream(fd);
40
if (!table->ParseFromZeroCopyStream(input))
52
static int fill_table_proto(drizzled::message::Table *table_proto,
53
const char *table_name,
54
List<CreateField> &create_fields,
55
HA_CREATE_INFO *create_info,
39
59
CreateField *field_arg;
40
60
List_iterator<CreateField> it(create_fields);
535
int copy_table_proto_file(const char *from, const char* to)
539
string file_ext = ".dfe";
541
dfesrc.append(file_ext);
542
dfedst.append(file_ext);
544
return my_copy(dfesrc.c_str(), dfedst.c_str(),
545
MYF(MY_DONT_OVERWRITE_FILE));
515
548
int rename_table_proto_file(const char *from, const char* to)
517
550
string from_path(from);
533
566
return my_delete(new_path.c_str(), MYF(0));
536
int drizzle_write_proto_file(const std::string file_name,
537
drizzled::message::Table *table_proto)
539
int fd= open(file_name.c_str(), O_RDWR|O_CREAT|O_TRUNC, my_umask);
569
int table_proto_exists(const char *path)
571
string proto_path(path);
572
string file_ext(".dfe");
573
proto_path.append(file_ext);
575
int error= access(proto_path.c_str(), F_OK);
583
static int create_table_proto_file(const char *file_name,
585
const char *table_name,
586
drizzled::message::Table *table_proto,
587
HA_CREATE_INFO *create_info,
588
List<CreateField> &create_fields,
592
string new_path(file_name);
593
string file_ext = ".dfe";
595
if(fill_table_proto(table_proto, table_name, create_fields, create_info,
599
new_path.append(file_ext);
601
int fd= open(new_path.c_str(), O_RDWR|O_CREAT|O_TRUNC, my_umask);
606
my_error(ER_BAD_DB_ERROR,MYF(0),db);
608
my_error(ER_CANT_CREATE_TABLE,MYF(0),table_name,errno);
544
612
google::protobuf::io::ZeroCopyOutputStream* output=
545
613
new google::protobuf::io::FileOutputStream(fd);
547
if (table_proto->SerializeToZeroCopyStream(output) == false)
615
if (!table_proto->SerializeToZeroCopyStream(output))
582
650
drizzled::message::Table *table_proto,
583
651
HA_CREATE_INFO *create_info,
584
652
List<CreateField> &create_fields,
585
uint32_t keys, KEY *key_info)
653
uint32_t keys, KEY *key_info,
587
656
/* Proto will blow up unless we give a name */
588
657
assert(table_name);
590
if (fill_table_proto(table_proto, table_name, create_fields, create_info,
594
string new_path(path);
595
string file_ext = ".dfe";
597
new_path.append(file_ext);
601
StorageEngine* engine= ha_resolve_by_name(session,
602
table_proto->engine().name());
603
if (engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY) == false)
604
err= drizzle_write_proto_file(new_path, table_proto);
609
my_error(ER_BAD_DB_ERROR,MYF(0),db);
611
my_error(ER_CANT_CREATE_TABLE,MYF(0),table_name,err);
659
/* For is_like we return once the file has been created */
662
if (create_table_proto_file(path, db, table_name, table_proto,
664
create_fields, keys, key_info)!=0)
669
/* Here we need to build the full frm from the path */
672
if (create_table_proto_file(path, db, table_name, table_proto,
674
create_fields, keys, key_info))
616
678
if (ha_create_table(session, path, db, table_name,
617
create_info,0, table_proto))
618
680
goto err_handler;
622
if (engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY) == false)
623
delete_table_proto_file(path);
684
delete_table_proto_file(path);
626
687
} /* rea_create_table */