854
868
if (result != NONE)
857
destination.append("\n)\n", 2);
871
destination.append("\n)", 2);
859
873
/* Add ENGINE = " clause */
860
874
if (table.has_engine())
862
876
const Table::StorageEngine &engine= table.engine();
863
destination.append("ENGINE = ", 9);
877
destination.append("\nENGINE = ", 10);
864
878
destination.append(engine.name());
865
destination.push_back('\n');
867
880
size_t num_engine_options= engine.option_size();
868
881
for (size_t x= 0; x < num_engine_options; ++x)
870
883
const Table::StorageEngine::EngineOption &option= engine.option(x);
871
destination.push_back('\t');
884
destination.push_back('\n');
872
885
destination.append(option.option_name());
873
886
destination.append(" = ", 3);
874
887
destination.append(option.option_value());
895
908
if (options.has_comment())
897
destination.append(" COMMENT = '", 12);
910
destination.append("\nCOMMENT = '", 12);
898
911
destination.append(options.comment());
899
destination.append("'\n", 2);
912
destination.push_back('\'');
902
915
if (options.has_collation())
904
destination.append(" COLLATE = '", 12);
917
destination.append("\nCOLLATE = ", 11);
905
918
destination.append(options.collation());
906
destination.append("'\n", 2);
909
921
if (options.has_auto_increment())
911
923
ss << options.auto_increment();
912
destination.append(" AUTOINCREMENT_OFFSET = ", 24);
924
destination.append("\nAUTOINCREMENT_OFFSET = ", 24);
913
925
destination.append(ss.str());
914
destination.push_back('\n');
918
929
if (options.has_row_type())
920
931
ss << options.row_type();
921
destination.append(" ROW_TYPE = ", 12);
932
destination.append("\nROW_TYPE = ", 12);
922
933
destination.append(ss.str());
923
destination.push_back('\n');
927
937
if (options.has_data_file_name())
929
destination.append(" DATA_FILE_NAME = '", 19);
939
destination.append("\nDATA_FILE_NAME = '", 19);
930
940
destination.append(options.data_file_name());
931
destination.append("'\n", 2);
941
destination.push_back('\'');
934
944
if (options.has_index_file_name())
936
destination.append(" INDEX_FILE_NAME = '", 20);
946
destination.append("\nINDEX_FILE_NAME = '", 20);
937
947
destination.append(options.index_file_name());
938
destination.append("'\n", 2);
948
destination.push_back('\'');
941
951
if (options.has_max_rows())
943
953
ss << options.max_rows();
944
destination.append(" MAX_ROWS = ", 12);
954
destination.append("\nMAX_ROWS = ", 12);
945
955
destination.append(ss.str());
946
destination.push_back('\n');
950
959
if (options.has_min_rows())
952
961
ss << options.min_rows();
953
destination.append(" MIN_ROWS = ", 12);
962
destination.append("\nMIN_ROWS = ", 12);
954
963
destination.append(ss.str());
955
destination.push_back('\n');
959
967
if (options.has_auto_increment_value())
961
969
ss << options.auto_increment_value();
962
destination.append(" AUTO_INCREMENT = ", 18);
970
destination.append("\nAUTO_INCREMENT = ", 18);
963
971
destination.append(ss.str());
964
destination.push_back('\n');
968
975
if (options.has_avg_row_length())
970
977
ss << options.avg_row_length();
971
destination.append(" AVG_ROW_LENGTH = ", 18);
978
destination.append("\nAVG_ROW_LENGTH = ", 18);
972
979
destination.append(ss.str());
973
destination.push_back('\n');
977
983
if (options.has_key_block_size())
979
985
ss << options.key_block_size();
980
destination.append(" KEY_BLOCK_SIZE = ", 18);
986
destination.append("\nKEY_BLOCK_SIZE = ", 18);
981
987
destination.append(ss.str());
982
destination.push_back('\n');
986
991
if (options.has_block_size())
988
993
ss << options.block_size();
989
destination.append(" BLOCK_SIZE = ", 14);
994
destination.append("\nBLOCK_SIZE = ", 14);
990
995
destination.append(ss.str());
991
destination.push_back('\n');
995
999
if (options.has_pack_keys() &&
996
1000
options.pack_keys())
997
destination.append(" PACK_KEYS = TRUE\n", 18);
1001
destination.append("\nPACK_KEYS = TRUE", 17);
998
1002
if (options.has_pack_record() &&
999
1003
options.pack_record())
1000
destination.append(" PACK_RECORD = TRUE\n", 20);
1004
destination.append("\nPACK_RECORD = TRUE", 19);
1001
1005
if (options.has_checksum() &&
1002
1006
options.checksum())
1003
destination.append(" CHECKSUM = TRUE\n", 17);
1007
destination.append("\nCHECKSUM = TRUE", 16);
1004
1008
if (options.has_page_checksum() &&
1005
1009
options.page_checksum())
1006
destination.append(" PAGE_CHECKSUM = TRUE\n", 22);
1010
destination.append("\nPAGE_CHECKSUM = TRUE", 21);
1033
1037
for (size_t x= 0; x < num_parts; ++x)
1035
1039
const Table::Index::IndexPart &part= index.index_part(x);
1040
const Table::Field &field= table.field(part.fieldnr());
1038
1043
destination.push_back(',');
1040
1045
destination.push_back(quoted_identifier);
1041
destination.append(table.field(part.fieldnr()).name());
1046
destination.append(field.name());
1042
1047
destination.push_back(quoted_identifier);
1044
if (part.has_compare_length())
1050
* If the index part's field type is VARCHAR or TEXT
1051
* then check for a prefix length
1053
if (field.type() == Table::Field::VARCHAR ||
1054
field.type() == Table::Field::BLOB)
1047
destination.push_back('(');
1048
ss << part.compare_length();
1049
destination.append(ss.str());
1050
destination.push_back(')');
1056
if (part.has_compare_length() &&
1057
part.compare_length() != field.string_options().length())
1060
destination.push_back('(');
1061
ss << part.compare_length();
1062
destination.append(ss.str());
1063
destination.push_back(')');
1053
1067
destination.push_back(')');
1108
1116
destination.push_back('\'');
1110
1118
destination.push_back(')');
1111
destination.push_back(' ');
1114
1121
case Table::Field::INTEGER:
1115
destination.append(" INT ", 5);
1122
destination.append(" INT", 4);
1117
1124
case Table::Field::BIGINT:
1118
destination.append(" BIGINT ", 8);
1125
destination.append(" BIGINT", 7);
1120
1127
case Table::Field::DECIMAL:
1122
1129
destination.append(" DECIMAL(", 9);
1123
1130
stringstream ss;
1124
1131
ss << field.numeric_options().precision() << ",";
1125
ss << field.numeric_options().scale() << ") ";
1132
ss << field.numeric_options().scale() << ")";
1126
1133
destination.append(ss.str());
1129
1136
case Table::Field::DATE:
1130
destination.append(" DATE ", 6);
1137
destination.append(" DATE", 5);
1132
1139
case Table::Field::TIMESTAMP:
1133
destination.append(" TIMESTAMP ", 11);
1140
destination.append(" TIMESTAMP", 10);
1135
1142
case Table::Field::DATETIME:
1136
destination.append(" DATETIME ", 10);
1143
destination.append(" DATETIME", 9);
1147
1154
destination.append(" UNSIGNED", 9);
1159
if (! (field.has_constraints() &&
1160
field.constraints().is_nullable()))
1162
destination.append(" NOT", 4);
1164
destination.append(" NULL", 5);
1166
if (field.type() == Table::Field::INTEGER ||
1167
field.type() == Table::Field::BIGINT)
1169
/* AUTO_INCREMENT must be after NOT NULL */
1150
1170
if (field.has_numeric_options() &&
1151
1171
field.numeric_options().is_autoincrement())
1153
destination.append(" AUTOINCREMENT ", 15);
1173
destination.append(" AUTO_INCREMENT", 15);
1158
if (! (field.has_constraints() &&
1159
field.constraints().is_nullable()))
1161
destination.append(" NOT NULL ", 10);
1164
1177
if (field.type() == Table::Field::BLOB ||
1165
1178
field.type() == Table::Field::VARCHAR)