~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/statement_transform.cc

Merge Monty - Updates to pandora-build to support features of gcc 4.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 * Statement messages to other formats, including SQL strings.
30
30
 */
31
31
 
32
 
#include <config.h>
 
32
#include "config.h"
33
33
 
34
34
#include <boost/lexical_cast.hpp>
35
 
 
36
 
#include <drizzled/charset.h>
37
 
#include <drizzled/message.h>
38
 
#include <drizzled/message/statement_transform.h>
39
 
#include <drizzled/message/transaction.pb.h>
40
 
#include <drizzled/message/access.h>
 
35
#include "drizzled/message/statement_transform.h"
 
36
#include "drizzled/message/transaction.pb.h"
 
37
#include "drizzled/message/table.pb.h"
 
38
#include "drizzled/charset.h"
 
39
#include "drizzled/charset_info.h"
 
40
#include "drizzled/global_charset_info.h"
41
41
 
42
42
#include <string>
43
43
#include <vector>
152
152
      const InsertHeader &insert_header= source.insert_header();
153
153
      const InsertData &insert_data= source.insert_data();
154
154
      size_t num_keys= insert_data.record_size();
 
155
      size_t x;
155
156
 
156
157
      if (num_keys > 1 && ! already_in_transaction)
157
158
        sql_strings.push_back("START TRANSACTION");
158
159
 
159
 
      for (size_t x= 0; x < num_keys; ++x)
 
160
      for (x= 0; x < num_keys; ++x)
160
161
      {
161
162
        string destination;
162
163
 
317
318
      sql_strings.push_back(destination);
318
319
    }
319
320
    break;
320
 
  case Statement::ALTER_SCHEMA:
321
 
    {
322
 
      assert(source.has_alter_schema_statement());
323
 
      string destination;
324
 
      error= transformAlterSchemaStatementToSql(source.alter_schema_statement(),
325
 
                                                destination,
326
 
                                                sql_variant);
327
 
      sql_strings.push_back(destination);
328
 
    }
329
 
    break;
330
321
  case Statement::SET_VARIABLE:
331
322
    {
332
323
      assert(source.has_set_variable_statement());
338
329
    }
339
330
    break;
340
331
  case Statement::RAW_SQL:
341
 
    {
342
 
      if (source.has_raw_sql_schema())
343
 
      {
344
 
        string destination("USE ");
345
 
        destination.append(source.raw_sql_schema());
346
 
        sql_strings.push_back(destination);
347
 
      }
348
 
      sql_strings.push_back(source.sql());
349
 
    }
350
 
    break;
351
332
  default:
352
333
    sql_strings.push_back(source.sql());
353
334
    break;
402
383
                                                           destination,
403
384
                                                           sql_variant);
404
385
 
 
386
  char quoted_identifier= '`';
 
387
  if (sql_variant == ANSI)
 
388
    quoted_identifier= '"';
 
389
 
405
390
  destination.append(") VALUES (");
406
391
 
407
392
  /* Add insert values */
471
456
                                                           destination,
472
457
                                                           sql_variant);
473
458
 
 
459
  char quoted_identifier= '`';
 
460
  if (sql_variant == ANSI)
 
461
    quoted_identifier= '"';
 
462
 
474
463
  destination.append(") VALUES (", 10);
475
464
 
476
465
  /* Add insert values */
817
806
}
818
807
 
819
808
enum TransformSqlError
820
 
transformAlterSchemaStatementToSql(const AlterSchemaStatement &statement,
821
 
                                   string &destination,
822
 
                                   enum TransformSqlVariant sql_variant)
823
 
{
824
 
  const Schema &before= statement.before();
825
 
  const Schema &after= statement.after();
826
 
 
827
 
  /* Make sure we are given the before and after for the same object */
828
 
  if (before.uuid() != after.uuid())
829
 
    return UUID_MISMATCH;
830
 
 
831
 
  char quoted_identifier= '`';
832
 
  if (sql_variant == ANSI)
833
 
    quoted_identifier= '"';
834
 
 
835
 
  destination.append("ALTER SCHEMA ");
836
 
  destination.push_back(quoted_identifier);
837
 
  destination.append(before.name());
838
 
  destination.push_back(quoted_identifier);
839
 
 
840
 
  /*
841
 
   * Diff our schemas. Currently, only collation can change so a
842
 
   * diff of the two structures is not really necessary.
843
 
   */
844
 
  destination.append(" COLLATE = ");
845
 
  destination.append(after.collation());
846
 
 
847
 
  return NONE;
848
 
}
849
 
 
850
 
enum TransformSqlError
851
809
transformDropSchemaStatementToSql(const DropSchemaStatement &statement,
852
810
                                  string &destination,
853
811
                                  enum TransformSqlVariant sql_variant)
875
833
 
876
834
  const Schema &schema= statement.schema();
877
835
 
878
 
  destination.append("CREATE SCHEMA ");
 
836
  destination.append("CREATE SCHEMA ", 14);
879
837
  destination.push_back(quoted_identifier);
880
838
  destination.append(schema.name());
881
839
  destination.push_back(quoted_identifier);
882
840
 
883
841
  if (schema.has_collation())
884
842
  {
885
 
    destination.append(" COLLATE ");
 
843
    destination.append(" COLLATE ", 9);
886
844
    destination.append(schema.collation());
887
845
  }
888
846
 
889
 
  if (not message::is_replicated(schema))
890
 
  {
891
 
    destination.append(" REPLICATE = FALSE");
892
 
  }
893
 
 
894
 
  if (message::has_definer(schema))
895
 
  {
896
 
    destination.append(" DEFINER ");
897
 
    destination.push_back('\'');
898
 
    destination.append(message::definer(schema));
899
 
    destination.push_back('\'');
900
 
  }
901
 
 
902
847
  return NONE;
903
848
}
904
849
 
913
858
 
914
859
  const TableMetadata &table_metadata= statement.table_metadata();
915
860
 
916
 
  destination.append("DROP TABLE ");
 
861
  destination.append("DROP TABLE ", 11);
917
862
 
918
863
  /* Add the IF EXISTS clause if necessary */
919
864
  if (statement.has_if_exists_clause() &&
920
865
      statement.if_exists_clause() == true)
921
866
  {
922
 
    destination.append("IF EXISTS ");
 
867
    destination.append("IF EXISTS ", 10);
923
868
  }
924
869
 
925
870
  destination.push_back(quoted_identifier);
944
889
 
945
890
  const TableMetadata &table_metadata= statement.table_metadata();
946
891
 
947
 
  destination.append("TRUNCATE TABLE ");
 
892
  destination.append("TRUNCATE TABLE ", 15);
948
893
  destination.push_back(quoted_identifier);
949
894
  destination.append(table_metadata.schema_name());
950
895
  destination.push_back(quoted_identifier);
965
910
  const FieldMetadata &variable_metadata= statement.variable_metadata();
966
911
  bool should_quote_field_value= shouldQuoteFieldValue(variable_metadata.type());
967
912
 
968
 
  destination.append("SET GLOBAL "); /* Only global variables are replicated */
 
913
  destination.append("SET GLOBAL ", 11); /* Only global variables are replicated */
969
914
  destination.append(variable_metadata.name());
970
915
  destination.push_back('=');
971
916
 
997
942
  if (sql_variant == ANSI)
998
943
    quoted_identifier= '"';
999
944
 
1000
 
  destination.append("CREATE ");
 
945
  destination.append("CREATE ", 7);
1001
946
 
1002
947
  if (table.type() == Table::TEMPORARY)
1003
 
    destination.append("TEMPORARY ");
 
948
    destination.append("TEMPORARY ", 10);
1004
949
  
1005
 
  destination.append("TABLE ");
 
950
  destination.append("TABLE ", 6);
1006
951
  if (with_schema)
1007
952
  {
1008
953
    append_escaped_string(&destination, table.schema(), quoted_identifier);
1009
954
    destination.push_back('.');
1010
955
  }
1011
956
  append_escaped_string(&destination, table.name(), quoted_identifier);
1012
 
  destination.append(" (\n");
 
957
  destination.append(" (\n", 3);
1013
958
 
1014
959
  enum TransformSqlError result= NONE;
1015
960
  size_t num_fields= table.field_size();
1018
963
    const Table::Field &field= table.field(x);
1019
964
 
1020
965
    if (x != 0)
1021
 
      destination.append(",\n");
 
966
      destination.append(",\n", 2);
1022
967
 
1023
968
    destination.append("  ");
1024
969
 
1031
976
  size_t num_indexes= table.indexes_size();
1032
977
  
1033
978
  if (num_indexes > 0)
1034
 
    destination.append(",\n");
 
979
    destination.append(",\n", 2);
1035
980
 
1036
981
  for (size_t x= 0; x < num_indexes; ++x)
1037
982
  {
1038
983
    const message::Table::Index &index= table.indexes(x);
1039
984
 
1040
985
    if (x != 0)
1041
 
      destination.append(",\n");
 
986
      destination.append(",\n", 2);
1042
987
 
1043
988
    result= transformIndexDefinitionToSql(index, table, destination, sql_variant);
1044
989
    
1049
994
  size_t num_foreign_keys= table.fk_constraint_size();
1050
995
 
1051
996
  if (num_foreign_keys > 0)
1052
 
    destination.append(",\n");
 
997
    destination.append(",\n", 2);
1053
998
 
1054
999
  for (size_t x= 0; x < num_foreign_keys; ++x)
1055
1000
  {
1056
1001
    const message::Table::ForeignKeyConstraint &fkey= table.fk_constraint(x);
1057
1002
 
1058
1003
    if (x != 0)
1059
 
      destination.append(",\n");
 
1004
      destination.append(",\n", 2);
1060
1005
 
1061
1006
    result= transformForeignKeyConstraintDefinitionToSql(fkey, table, destination, sql_variant);
1062
1007
 
1064
1009
      return result;
1065
1010
  }
1066
1011
 
1067
 
  destination.append("\n)");
 
1012
  destination.append("\n)", 2);
1068
1013
 
1069
1014
  /* Add ENGINE = " clause */
1070
1015
  if (table.has_engine())
1071
1016
  {
1072
 
    destination.append(" ENGINE=");
 
1017
    destination.append(" ENGINE=", 8);
1073
1018
    destination.append(table.engine().name());
1074
1019
 
1075
1020
    size_t num_engine_options= table.engine().options_size();
1079
1024
    {
1080
1025
      const Engine::Option &option= table.engine().options(x);
1081
1026
      destination.append(option.name());
1082
 
      destination.append("='");
 
1027
      destination.append("='", 2);
1083
1028
      destination.append(option.state());
1084
 
      destination.append("'");
1085
 
      if (x != num_engine_options-1)
1086
 
      {
1087
 
        destination.append(", ");
1088
 
      }
 
1029
      destination.append("'", 1);
 
1030
      if(x != num_engine_options-1)
 
1031
        destination.append(", ", 2);
1089
1032
    }
1090
1033
  }
1091
1034
 
1092
1035
  if (table.has_options())
1093
1036
    (void) transformTableOptionsToSql(table.options(), destination, sql_variant);
1094
1037
 
1095
 
  if (not message::is_replicated(table))
1096
 
  {
1097
 
    destination.append(" REPLICATE = FALSE");
1098
 
  }
1099
 
 
1100
 
  if (message::has_definer(table))
1101
 
  {
1102
 
    destination.append(" DEFINER ");
1103
 
    destination.push_back('\'');
1104
 
    destination.append(message::definer(table));
1105
 
    destination.push_back('\'');
1106
 
  }
1107
 
 
1108
1038
  return NONE;
1109
1039
}
1110
1040
 
1118
1048
 
1119
1049
  if (options.has_comment())
1120
1050
  {
1121
 
    destination.append(" COMMENT=");
 
1051
    destination.append(" COMMENT=", 9);
1122
1052
    append_escaped_string(&destination, options.comment());
1123
1053
  }
1124
1054
 
1125
1055
  if (options.has_collation())
1126
1056
  {
1127
 
    destination.append(" COLLATE = ");
 
1057
    destination.append(" COLLATE = ", 11);
1128
1058
    destination.append(options.collation());
1129
1059
  }
1130
1060
 
1131
1061
  if (options.has_data_file_name())
1132
1062
  {
1133
 
    destination.append("\nDATA_FILE_NAME = '");
 
1063
    destination.append("\nDATA_FILE_NAME = '", 19);
1134
1064
    destination.append(options.data_file_name());
1135
1065
    destination.push_back('\'');
1136
1066
  }
1137
1067
 
1138
1068
  if (options.has_index_file_name())
1139
1069
  {
1140
 
    destination.append("\nINDEX_FILE_NAME = '");
 
1070
    destination.append("\nINDEX_FILE_NAME = '", 20);
1141
1071
    destination.append(options.index_file_name());
1142
1072
    destination.push_back('\'');
1143
1073
  }
1144
1074
 
1145
1075
  if (options.has_max_rows())
1146
1076
  {
1147
 
    destination.append("\nMAX_ROWS = ");
 
1077
    destination.append("\nMAX_ROWS = ", 12);
1148
1078
    destination.append(boost::lexical_cast<string>(options.max_rows()));
1149
1079
  }
1150
1080
 
1151
1081
  if (options.has_min_rows())
1152
1082
  {
1153
 
    destination.append("\nMIN_ROWS = ");
 
1083
    destination.append("\nMIN_ROWS = ", 12);
1154
1084
    destination.append(boost::lexical_cast<string>(options.min_rows()));
1155
1085
  }
1156
1086
 
1157
1087
  if (options.has_user_set_auto_increment_value()
1158
1088
      && options.has_auto_increment_value())
1159
1089
  {
1160
 
    destination.append(" AUTO_INCREMENT=");
 
1090
    destination.append(" AUTO_INCREMENT=", 16);
1161
1091
    destination.append(boost::lexical_cast<string>(options.auto_increment_value()));
1162
1092
  }
1163
1093
 
1164
1094
  if (options.has_avg_row_length())
1165
1095
  {
1166
 
    destination.append("\nAVG_ROW_LENGTH = ");
 
1096
    destination.append("\nAVG_ROW_LENGTH = ", 18);
1167
1097
    destination.append(boost::lexical_cast<string>(options.avg_row_length()));
1168
1098
  }
1169
1099
 
1170
 
  if (options.has_checksum() && options.checksum())
1171
 
    destination.append("\nCHECKSUM = TRUE");
1172
 
 
1173
 
  if (options.has_page_checksum() && options.page_checksum())
1174
 
    destination.append("\nPAGE_CHECKSUM = TRUE");
 
1100
  if (options.has_checksum() &&
 
1101
      options.checksum())
 
1102
    destination.append("\nCHECKSUM = TRUE", 16);
 
1103
  if (options.has_page_checksum() &&
 
1104
      options.page_checksum())
 
1105
    destination.append("\nPAGE_CHECKSUM = TRUE", 21);
1175
1106
 
1176
1107
  return NONE;
1177
1108
}
1189
1120
  destination.append("  ", 2);
1190
1121
 
1191
1122
  if (index.is_primary())
1192
 
    destination.append("PRIMARY ");
 
1123
    destination.append("PRIMARY ", 8);
1193
1124
  else if (index.is_unique())
1194
 
    destination.append("UNIQUE ");
 
1125
    destination.append("UNIQUE ", 7);
1195
1126
 
1196
1127
  destination.append("KEY ", 4);
1197
1128
  if (! (index.is_primary() && index.name().compare("PRIMARY")==0))
1243
1174
  case Table::Index::UNKNOWN_INDEX:
1244
1175
    break;
1245
1176
  case Table::Index::BTREE:
1246
 
    destination.append(" USING BTREE");
 
1177
    destination.append(" USING BTREE", 12);
1247
1178
    break;
1248
1179
  case Table::Index::RTREE:
1249
 
    destination.append(" USING RTREE");
 
1180
    destination.append(" USING RTREE", 12);
1250
1181
    break;
1251
1182
  case Table::Index::HASH:
1252
 
    destination.append(" USING HASH");
 
1183
    destination.append(" USING HASH", 11);
1253
1184
    break;
1254
1185
  case Table::Index::FULLTEXT:
1255
 
    destination.append(" USING FULLTEXT");
 
1186
    destination.append(" USING FULLTEXT", 15);
1256
1187
    break;
1257
1188
  }
1258
1189
 
1259
1190
  if (index.has_comment())
1260
1191
  {
1261
 
    destination.append(" COMMENT ");
 
1192
    destination.append(" COMMENT ", 9);
1262
1193
    append_escaped_string(&destination, index.comment());
1263
1194
  }
1264
1195
 
1298
1229
  if (sql_variant == ANSI)
1299
1230
    quoted_identifier= '"';
1300
1231
 
1301
 
  destination.append("  ");
 
1232
  destination.append("  ", 2);
1302
1233
 
1303
1234
  if (fkey.has_name())
1304
1235
  {
1305
 
    destination.append("CONSTRAINT ");
 
1236
    destination.append("CONSTRAINT ", 11);
1306
1237
    append_escaped_string(&destination, fkey.name(), quoted_identifier);
1307
1238
    destination.append(" ", 1);
1308
1239
  }
1309
1240
 
1310
 
  destination.append("FOREIGN KEY (");
 
1241
  destination.append("FOREIGN KEY (", 13);
1311
1242
 
1312
1243
  for (ssize_t x= 0; x < fkey.column_names_size(); ++x)
1313
1244
  {
1318
1249
                          quoted_identifier);
1319
1250
  }
1320
1251
 
1321
 
  destination.append(") REFERENCES ");
 
1252
  destination.append(") REFERENCES ", 13);
1322
1253
 
1323
1254
  append_escaped_string(&destination, fkey.references_table_name(),
1324
1255
                        quoted_identifier);
1325
 
  destination.append(" (");
 
1256
  destination.append(" (", 2);
1326
1257
 
1327
1258
  for (ssize_t x= 0; x < fkey.references_columns_size(); ++x)
1328
1259
  {
1337
1268
 
1338
1269
  if (fkey.has_update_option() and fkey.update_option() != Table::ForeignKeyConstraint::OPTION_UNDEF)
1339
1270
  {
1340
 
    destination.append(" ON UPDATE ");
 
1271
    destination.append(" ON UPDATE ", 11);
1341
1272
    transformForeignKeyOptionToSql(fkey.update_option(), destination);
1342
1273
  }
1343
1274
 
1344
1275
  if (fkey.has_delete_option() and fkey.delete_option() != Table::ForeignKeyConstraint::OPTION_UNDEF)
1345
1276
  {
1346
 
    destination.append(" ON DELETE ");
 
1277
    destination.append(" ON DELETE ", 11);
1347
1278
    transformForeignKeyOptionToSql(fkey.delete_option(), destination);
1348
1279
  }
1349
1280
 
1373
1304
  switch (field_type)
1374
1305
  {
1375
1306
    case Table::Field::DOUBLE:
1376
 
    destination.append(" DOUBLE");
 
1307
    destination.append(" DOUBLE", 7);
1377
1308
    if (field.has_numeric_options()
1378
1309
        && field.numeric_options().has_precision())
1379
1310
    {
1387
1318
    {
1388
1319
      if (field.string_options().has_collation()
1389
1320
          && field.string_options().collation().compare("binary") == 0)
1390
 
        destination.append(" VARBINARY(");
 
1321
        destination.append(" VARBINARY(", 11);
1391
1322
      else
1392
 
        destination.append(" VARCHAR(");
 
1323
        destination.append(" VARCHAR(", 9);
1393
1324
 
1394
1325
      destination.append(boost::lexical_cast<string>(field.string_options().length()));
1395
1326
      destination.append(")");
1399
1330
    {
1400
1331
      if (field.string_options().has_collation()
1401
1332
          && field.string_options().collation().compare("binary") == 0)
1402
 
        destination.append(" BLOB");
 
1333
        destination.append(" BLOB", 5);
1403
1334
      else
1404
 
        destination.append(" TEXT");
 
1335
        destination.append(" TEXT", 5);
1405
1336
    }
1406
1337
    break;
1407
1338
  case Table::Field::ENUM:
1408
1339
    {
1409
1340
      size_t num_field_values= field.enumeration_values().field_value_size();
1410
 
      destination.append(" ENUM(");
 
1341
      destination.append(" ENUM(", 6);
1411
1342
      for (size_t x= 0; x < num_field_values; ++x)
1412
1343
      {
1413
1344
        const string &type= field.enumeration_values().field_value(x);
1423
1354
      break;
1424
1355
    }
1425
1356
  case Table::Field::UUID:
1426
 
    destination.append(" UUID");
1427
 
    break;
1428
 
  case Table::Field::IPV6:
1429
 
    destination.append(" IPV6");
1430
 
    break;
1431
 
  case Table::Field::BOOLEAN:
1432
 
    destination.append(" BOOLEAN");
 
1357
    destination.append(" UUID", 5);
1433
1358
    break;
1434
1359
  case Table::Field::INTEGER:
1435
 
    destination.append(" INT");
 
1360
    destination.append(" INT", 4);
1436
1361
    break;
1437
1362
  case Table::Field::BIGINT:
1438
 
    if (field.has_constraints() and
1439
 
        field.constraints().is_unsigned())
1440
 
    {
1441
 
      destination.append(" BIGINT UNSIGNED");
1442
 
    }
1443
 
    else
1444
 
    {
1445
 
      destination.append(" BIGINT");
1446
 
    }
 
1363
    destination.append(" BIGINT", 7);
1447
1364
    break;
1448
1365
  case Table::Field::DECIMAL:
1449
1366
    {
1450
 
      destination.append(" DECIMAL(");
 
1367
      destination.append(" DECIMAL(", 9);
1451
1368
      stringstream ss;
1452
1369
      ss << field.numeric_options().precision() << ",";
1453
1370
      ss << field.numeric_options().scale() << ")";
1455
1372
    }
1456
1373
    break;
1457
1374
  case Table::Field::DATE:
1458
 
    destination.append(" DATE");
1459
 
    break;
1460
 
 
1461
 
  case Table::Field::EPOCH:
1462
 
    if (field.time_options().microseconds())
1463
 
    {
1464
 
      destination.append(" TIMESTAMP(6)");
1465
 
    }
1466
 
    else
1467
 
    {
1468
 
      destination.append(" TIMESTAMP");
1469
 
    }
1470
 
    break;
1471
 
 
 
1375
    destination.append(" DATE", 5);
 
1376
    break;
 
1377
  case Table::Field::TIMESTAMP:
 
1378
    destination.append(" TIMESTAMP",  10);
 
1379
    break;
1472
1380
  case Table::Field::DATETIME:
1473
 
    destination.append(" DATETIME");
1474
 
    break;
1475
 
  case Table::Field::TIME:
1476
 
    destination.append(" TIME");
1477
 
    break;
 
1381
    destination.append(" DATETIME",  9);
 
1382
    break;
 
1383
  }
 
1384
 
 
1385
  if (field.type() == Table::Field::INTEGER || 
 
1386
      field.type() == Table::Field::BIGINT)
 
1387
  {
 
1388
    if (field.has_constraints() &&
 
1389
        field.constraints().has_is_unsigned() &&
 
1390
        field.constraints().is_unsigned())
 
1391
    {
 
1392
      destination.append(" UNSIGNED", 9);
 
1393
    }
1478
1394
  }
1479
1395
 
1480
1396
  if (field.type() == Table::Field::BLOB ||
1483
1399
    if (field.string_options().has_collation()
1484
1400
        && field.string_options().collation().compare("binary"))
1485
1401
    {
1486
 
      destination.append(" COLLATE ");
 
1402
      destination.append(" COLLATE ", 9);
1487
1403
      destination.append(field.string_options().collation());
1488
1404
    }
1489
1405
  }
1490
1406
 
1491
 
  if (field.has_constraints() and field.constraints().is_unique())
1492
 
  {
1493
 
    destination.append(" UNIQUE");
1494
 
  }
1495
 
 
1496
 
  if (field.has_constraints() && field.constraints().is_notnull())
1497
 
  {
1498
 
    destination.append(" NOT NULL");
1499
 
  }
1500
 
  else if (field.type() == Table::Field::EPOCH)
1501
 
  {
1502
 
    destination.append(" NULL");
1503
 
  }
 
1407
  if (field.has_constraints() &&
 
1408
      ! field.constraints().is_nullable())
 
1409
  {
 
1410
    destination.append(" NOT NULL", 9);
 
1411
  }
 
1412
  else if (field.type() == Table::Field::TIMESTAMP)
 
1413
    destination.append(" NULL", 5);
1504
1414
 
1505
1415
  if (field.type() == Table::Field::INTEGER || 
1506
1416
      field.type() == Table::Field::BIGINT)
1509
1419
    if (field.has_numeric_options() &&
1510
1420
        field.numeric_options().is_autoincrement())
1511
1421
    {
1512
 
      destination.append(" AUTO_INCREMENT");
 
1422
      destination.append(" AUTO_INCREMENT", 15);
1513
1423
    }
1514
1424
  }
1515
1425
 
1516
1426
  if (field.options().has_default_value())
1517
1427
  {
1518
 
    destination.append(" DEFAULT ");
 
1428
    destination.append(" DEFAULT ", 9);
1519
1429
    append_escaped_string(&destination, field.options().default_value());
1520
1430
  }
1521
1431
  else if (field.options().has_default_expression())
1522
1432
  {
1523
 
    destination.append(" DEFAULT ");
 
1433
    destination.append(" DEFAULT ", 9);
1524
1434
    destination.append(field.options().default_expression());
1525
1435
  }
1526
1436
  else if (field.options().has_default_bin_value())
1527
1437
  {
1528
1438
    const string &v= field.options().default_bin_value();
1529
1439
    if (v.length() == 0)
1530
 
    {
1531
 
      destination.append(" DEFAULT ''");
1532
 
    }
 
1440
      destination.append(" DEFAULT ''", 11);
1533
1441
    else
1534
1442
    {
1535
 
      destination.append(" DEFAULT 0x");
 
1443
      destination.append(" DEFAULT 0x", 11);
1536
1444
      for (size_t x= 0; x < v.length(); x++)
1537
1445
      {
1538
1446
        char hex[3];
1545
1453
           && field.options().default_null()
1546
1454
           && field.type() != Table::Field::BLOB)
1547
1455
  {
1548
 
    destination.append(" DEFAULT NULL");
 
1456
    destination.append(" DEFAULT NULL", 13);
1549
1457
  }
1550
1458
 
1551
1459
  if (field.has_options() && field.options().has_update_expression())
1552
1460
  {
1553
 
    destination.append(" ON UPDATE ");
 
1461
    destination.append(" ON UPDATE ", 11);
1554
1462
    destination.append(field.options().update_expression());
1555
1463
  }
1556
1464
 
1557
1465
  if (field.has_comment())
1558
1466
  {
1559
 
    destination.append(" COMMENT ");
 
1467
    destination.append(" COMMENT ", 9);
1560
1468
    append_escaped_string(&destination, field.comment(), quoted_default);
1561
1469
  }
1562
1470
  return NONE;
1586
1494
  case DRIZZLE_TYPE_NULL:
1587
1495
    assert(false); /* Not a user definable type */
1588
1496
    return Table::Field::INTEGER; /* unreachable */
1589
 
  case DRIZZLE_TYPE_MICROTIME:
1590
1497
  case DRIZZLE_TYPE_TIMESTAMP:
1591
 
    return Table::Field::EPOCH;
 
1498
    return Table::Field::TIMESTAMP;
1592
1499
  case DRIZZLE_TYPE_LONGLONG:
1593
1500
    return Table::Field::BIGINT;
1594
1501
  case DRIZZLE_TYPE_DATETIME:
1595
1502
    return Table::Field::DATETIME;
1596
 
  case DRIZZLE_TYPE_TIME:
1597
 
    return Table::Field::TIME;
1598
1503
  case DRIZZLE_TYPE_DATE:
1599
1504
    return Table::Field::DATE;
1600
1505
  case DRIZZLE_TYPE_VARCHAR:
1607
1512
    return Table::Field::BLOB;
1608
1513
  case DRIZZLE_TYPE_UUID:
1609
1514
    return Table::Field::UUID;
1610
 
  case DRIZZLE_TYPE_BOOLEAN:
1611
 
    return Table::Field::BOOLEAN;
1612
 
  case DRIZZLE_TYPE_IPV6:
1613
 
    return Table::Field::IPV6;
1614
1515
  }
1615
1516
 
1616
1517
  assert(false);