~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/statement_transform.cc

  • Committer: Stewart Smith
  • Author(s): Marko Mäkelä, Stewart Smith
  • Date: 2010-12-06 04:20:58 UTC
  • mto: (2021.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1986.
  • Revision ID: stewart@flamingspork.com-20101206042058-kgr10dbz5jut838t
Merge Revision revid:marko.makela@oracle.com-20100909112752-ac5w7zyzbv10nvi1 from MySQL InnoDB

Original revid:marko.makela@oracle.com-20100909112752-ac5w7zyzbv10nvi1

Original Authors: Marko Mkel <marko.makela@oracle.com>
Original commit message:
Remove ut0auxconf.h.
It was needed when InnoDB Plugin was distributed independently of MySQL.
Approved by Vasil Dimov.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems, Inc.
5
 
 *  Copyright (C) 2010 Jay Pipes
 
4
 *  Copyright (C) 2009 Sun Microsystems
 
5
 *  Copyright (c) 2010 Jay Pipes
6
6
 *
7
7
 *  Authors:
8
8
 *
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
 
#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>
 
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>
127
127
 
128
128
  switch (source.type())
129
129
  {
130
 
  case Statement::ROLLBACK_STATEMENT:
131
 
    {
132
 
      break;
133
 
    }
134
130
  case Statement::ROLLBACK:
135
131
    {
136
132
      sql_strings.push_back("ROLLBACK");
152
148
      const InsertHeader &insert_header= source.insert_header();
153
149
      const InsertData &insert_data= source.insert_data();
154
150
      size_t num_keys= insert_data.record_size();
 
151
      size_t x;
155
152
 
156
153
      if (num_keys > 1 && ! already_in_transaction)
157
154
        sql_strings.push_back("START TRANSACTION");
158
155
 
159
 
      for (size_t x= 0; x < num_keys; ++x)
 
156
      for (x= 0; x < num_keys; ++x)
160
157
      {
161
158
        string destination;
162
159
 
317
314
      sql_strings.push_back(destination);
318
315
    }
319
316
    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
317
  case Statement::SET_VARIABLE:
331
318
    {
332
319
      assert(source.has_set_variable_statement());
815
802
}
816
803
 
817
804
enum TransformSqlError
818
 
transformAlterSchemaStatementToSql(const AlterSchemaStatement &statement,
819
 
                                   string &destination,
820
 
                                   enum TransformSqlVariant sql_variant)
821
 
{
822
 
  const Schema &before= statement.before();
823
 
  const Schema &after= statement.after();
824
 
 
825
 
  /* Make sure we are given the before and after for the same object */
826
 
  if (before.uuid() != after.uuid())
827
 
    return UUID_MISMATCH;
828
 
 
829
 
  char quoted_identifier= '`';
830
 
  if (sql_variant == ANSI)
831
 
    quoted_identifier= '"';
832
 
 
833
 
  destination.append("ALTER SCHEMA ");
834
 
  destination.push_back(quoted_identifier);
835
 
  destination.append(before.name());
836
 
  destination.push_back(quoted_identifier);
837
 
 
838
 
  /*
839
 
   * Diff our schemas. Currently, only collation can change so a
840
 
   * diff of the two structures is not really necessary.
841
 
   */
842
 
  destination.append(" COLLATE = ");
843
 
  destination.append(after.collation());
844
 
 
845
 
  return NONE;
846
 
}
847
 
 
848
 
enum TransformSqlError
849
805
transformDropSchemaStatementToSql(const DropSchemaStatement &statement,
850
806
                                  string &destination,
851
807
                                  enum TransformSqlVariant sql_variant)
873
829
 
874
830
  const Schema &schema= statement.schema();
875
831
 
876
 
  destination.append("CREATE SCHEMA ");
 
832
  destination.append("CREATE SCHEMA ", 14);
877
833
  destination.push_back(quoted_identifier);
878
834
  destination.append(schema.name());
879
835
  destination.push_back(quoted_identifier);
880
836
 
881
837
  if (schema.has_collation())
882
838
  {
883
 
    destination.append(" COLLATE ");
 
839
    destination.append(" COLLATE ", 9);
884
840
    destination.append(schema.collation());
885
841
  }
886
842
 
887
 
  if (schema.has_replication_options() and schema.replication_options().has_dont_replicate() and schema.replication_options().dont_replicate())
888
 
  {
889
 
    destination.append(" REPLICATION = FALSE");
890
 
  }
891
 
 
892
843
  return NONE;
893
844
}
894
845
 
903
854
 
904
855
  const TableMetadata &table_metadata= statement.table_metadata();
905
856
 
906
 
  destination.append("DROP TABLE ");
 
857
  destination.append("DROP TABLE ", 11);
907
858
 
908
859
  /* Add the IF EXISTS clause if necessary */
909
860
  if (statement.has_if_exists_clause() &&
910
861
      statement.if_exists_clause() == true)
911
862
  {
912
 
    destination.append("IF EXISTS ");
 
863
    destination.append("IF EXISTS ", 10);
913
864
  }
914
865
 
915
866
  destination.push_back(quoted_identifier);
934
885
 
935
886
  const TableMetadata &table_metadata= statement.table_metadata();
936
887
 
937
 
  destination.append("TRUNCATE TABLE ");
 
888
  destination.append("TRUNCATE TABLE ", 15);
938
889
  destination.push_back(quoted_identifier);
939
890
  destination.append(table_metadata.schema_name());
940
891
  destination.push_back(quoted_identifier);
955
906
  const FieldMetadata &variable_metadata= statement.variable_metadata();
956
907
  bool should_quote_field_value= shouldQuoteFieldValue(variable_metadata.type());
957
908
 
958
 
  destination.append("SET GLOBAL "); /* Only global variables are replicated */
 
909
  destination.append("SET GLOBAL ", 11); /* Only global variables are replicated */
959
910
  destination.append(variable_metadata.name());
960
911
  destination.push_back('=');
961
912
 
987
938
  if (sql_variant == ANSI)
988
939
    quoted_identifier= '"';
989
940
 
990
 
  destination.append("CREATE ");
 
941
  destination.append("CREATE ", 7);
991
942
 
992
943
  if (table.type() == Table::TEMPORARY)
993
 
    destination.append("TEMPORARY ");
 
944
    destination.append("TEMPORARY ", 10);
994
945
  
995
 
  destination.append("TABLE ");
 
946
  destination.append("TABLE ", 6);
996
947
  if (with_schema)
997
948
  {
998
949
    append_escaped_string(&destination, table.schema(), quoted_identifier);
999
950
    destination.push_back('.');
1000
951
  }
1001
952
  append_escaped_string(&destination, table.name(), quoted_identifier);
1002
 
  destination.append(" (\n");
 
953
  destination.append(" (\n", 3);
1003
954
 
1004
955
  enum TransformSqlError result= NONE;
1005
956
  size_t num_fields= table.field_size();
1008
959
    const Table::Field &field= table.field(x);
1009
960
 
1010
961
    if (x != 0)
1011
 
      destination.append(",\n");
 
962
      destination.append(",\n", 2);
1012
963
 
1013
964
    destination.append("  ");
1014
965
 
1021
972
  size_t num_indexes= table.indexes_size();
1022
973
  
1023
974
  if (num_indexes > 0)
1024
 
    destination.append(",\n");
 
975
    destination.append(",\n", 2);
1025
976
 
1026
977
  for (size_t x= 0; x < num_indexes; ++x)
1027
978
  {
1028
979
    const message::Table::Index &index= table.indexes(x);
1029
980
 
1030
981
    if (x != 0)
1031
 
      destination.append(",\n");
 
982
      destination.append(",\n", 2);
1032
983
 
1033
984
    result= transformIndexDefinitionToSql(index, table, destination, sql_variant);
1034
985
    
1039
990
  size_t num_foreign_keys= table.fk_constraint_size();
1040
991
 
1041
992
  if (num_foreign_keys > 0)
1042
 
    destination.append(",\n");
 
993
    destination.append(",\n", 2);
1043
994
 
1044
995
  for (size_t x= 0; x < num_foreign_keys; ++x)
1045
996
  {
1046
997
    const message::Table::ForeignKeyConstraint &fkey= table.fk_constraint(x);
1047
998
 
1048
999
    if (x != 0)
1049
 
      destination.append(",\n");
 
1000
      destination.append(",\n", 2);
1050
1001
 
1051
1002
    result= transformForeignKeyConstraintDefinitionToSql(fkey, table, destination, sql_variant);
1052
1003
 
1054
1005
      return result;
1055
1006
  }
1056
1007
 
1057
 
  destination.append("\n)");
 
1008
  destination.append("\n)", 2);
1058
1009
 
1059
1010
  /* Add ENGINE = " clause */
1060
1011
  if (table.has_engine())
1061
1012
  {
1062
 
    destination.append(" ENGINE=");
 
1013
    destination.append(" ENGINE=", 8);
1063
1014
    destination.append(table.engine().name());
1064
1015
 
1065
1016
    size_t num_engine_options= table.engine().options_size();
1069
1020
    {
1070
1021
      const Engine::Option &option= table.engine().options(x);
1071
1022
      destination.append(option.name());
1072
 
      destination.append("='");
 
1023
      destination.append("='", 2);
1073
1024
      destination.append(option.state());
1074
 
      destination.append("'");
1075
 
      if (x != num_engine_options-1)
1076
 
      {
1077
 
        destination.append(", ");
1078
 
      }
 
1025
      destination.append("'", 1);
 
1026
      if(x != num_engine_options-1)
 
1027
        destination.append(", ", 2);
1079
1028
    }
1080
1029
  }
1081
1030
 
1095
1044
 
1096
1045
  if (options.has_comment())
1097
1046
  {
1098
 
    destination.append(" COMMENT=");
 
1047
    destination.append(" COMMENT=", 9);
1099
1048
    append_escaped_string(&destination, options.comment());
1100
1049
  }
1101
1050
 
1102
1051
  if (options.has_collation())
1103
1052
  {
1104
 
    destination.append(" COLLATE = ");
 
1053
    destination.append(" COLLATE = ", 11);
1105
1054
    destination.append(options.collation());
1106
1055
  }
1107
1056
 
1108
1057
  if (options.has_data_file_name())
1109
1058
  {
1110
 
    destination.append("\nDATA_FILE_NAME = '");
 
1059
    destination.append("\nDATA_FILE_NAME = '", 19);
1111
1060
    destination.append(options.data_file_name());
1112
1061
    destination.push_back('\'');
1113
1062
  }
1114
1063
 
1115
1064
  if (options.has_index_file_name())
1116
1065
  {
1117
 
    destination.append("\nINDEX_FILE_NAME = '");
 
1066
    destination.append("\nINDEX_FILE_NAME = '", 20);
1118
1067
    destination.append(options.index_file_name());
1119
1068
    destination.push_back('\'');
1120
1069
  }
1121
1070
 
1122
1071
  if (options.has_max_rows())
1123
1072
  {
1124
 
    destination.append("\nMAX_ROWS = ");
 
1073
    destination.append("\nMAX_ROWS = ", 12);
1125
1074
    destination.append(boost::lexical_cast<string>(options.max_rows()));
1126
1075
  }
1127
1076
 
1128
1077
  if (options.has_min_rows())
1129
1078
  {
1130
 
    destination.append("\nMIN_ROWS = ");
 
1079
    destination.append("\nMIN_ROWS = ", 12);
1131
1080
    destination.append(boost::lexical_cast<string>(options.min_rows()));
1132
1081
  }
1133
1082
 
1134
1083
  if (options.has_user_set_auto_increment_value()
1135
1084
      && options.has_auto_increment_value())
1136
1085
  {
1137
 
    destination.append(" AUTO_INCREMENT=");
 
1086
    destination.append(" AUTO_INCREMENT=", 16);
1138
1087
    destination.append(boost::lexical_cast<string>(options.auto_increment_value()));
1139
1088
  }
1140
1089
 
1141
1090
  if (options.has_avg_row_length())
1142
1091
  {
1143
 
    destination.append("\nAVG_ROW_LENGTH = ");
 
1092
    destination.append("\nAVG_ROW_LENGTH = ", 18);
1144
1093
    destination.append(boost::lexical_cast<string>(options.avg_row_length()));
1145
1094
  }
1146
1095
 
1147
 
  if (options.has_checksum() && options.checksum())
1148
 
    destination.append("\nCHECKSUM = TRUE");
1149
 
 
1150
 
  if (options.has_page_checksum() && options.page_checksum())
1151
 
    destination.append("\nPAGE_CHECKSUM = TRUE");
1152
 
 
1153
 
  if (options.has_dont_replicate() and options.dont_replicate())
1154
 
  {
1155
 
    destination.append(" REPLICATION = FALSE");
1156
 
  }
 
1096
  if (options.has_checksum() &&
 
1097
      options.checksum())
 
1098
    destination.append("\nCHECKSUM = TRUE", 16);
 
1099
  if (options.has_page_checksum() &&
 
1100
      options.page_checksum())
 
1101
    destination.append("\nPAGE_CHECKSUM = TRUE", 21);
1157
1102
 
1158
1103
  return NONE;
1159
1104
}
1171
1116
  destination.append("  ", 2);
1172
1117
 
1173
1118
  if (index.is_primary())
1174
 
    destination.append("PRIMARY ");
 
1119
    destination.append("PRIMARY ", 8);
1175
1120
  else if (index.is_unique())
1176
 
    destination.append("UNIQUE ");
 
1121
    destination.append("UNIQUE ", 7);
1177
1122
 
1178
1123
  destination.append("KEY ", 4);
1179
1124
  if (! (index.is_primary() && index.name().compare("PRIMARY")==0))
1225
1170
  case Table::Index::UNKNOWN_INDEX:
1226
1171
    break;
1227
1172
  case Table::Index::BTREE:
1228
 
    destination.append(" USING BTREE");
 
1173
    destination.append(" USING BTREE", 12);
1229
1174
    break;
1230
1175
  case Table::Index::RTREE:
1231
 
    destination.append(" USING RTREE");
 
1176
    destination.append(" USING RTREE", 12);
1232
1177
    break;
1233
1178
  case Table::Index::HASH:
1234
 
    destination.append(" USING HASH");
 
1179
    destination.append(" USING HASH", 11);
1235
1180
    break;
1236
1181
  case Table::Index::FULLTEXT:
1237
 
    destination.append(" USING FULLTEXT");
 
1182
    destination.append(" USING FULLTEXT", 15);
1238
1183
    break;
1239
1184
  }
1240
1185
 
1241
1186
  if (index.has_comment())
1242
1187
  {
1243
 
    destination.append(" COMMENT ");
 
1188
    destination.append(" COMMENT ", 9);
1244
1189
    append_escaped_string(&destination, index.comment());
1245
1190
  }
1246
1191
 
1280
1225
  if (sql_variant == ANSI)
1281
1226
    quoted_identifier= '"';
1282
1227
 
1283
 
  destination.append("  ");
 
1228
  destination.append("  ", 2);
1284
1229
 
1285
1230
  if (fkey.has_name())
1286
1231
  {
1287
 
    destination.append("CONSTRAINT ");
 
1232
    destination.append("CONSTRAINT ", 11);
1288
1233
    append_escaped_string(&destination, fkey.name(), quoted_identifier);
1289
1234
    destination.append(" ", 1);
1290
1235
  }
1291
1236
 
1292
 
  destination.append("FOREIGN KEY (");
 
1237
  destination.append("FOREIGN KEY (", 13);
1293
1238
 
1294
1239
  for (ssize_t x= 0; x < fkey.column_names_size(); ++x)
1295
1240
  {
1300
1245
                          quoted_identifier);
1301
1246
  }
1302
1247
 
1303
 
  destination.append(") REFERENCES ");
 
1248
  destination.append(") REFERENCES ", 13);
1304
1249
 
1305
1250
  append_escaped_string(&destination, fkey.references_table_name(),
1306
1251
                        quoted_identifier);
1307
 
  destination.append(" (");
 
1252
  destination.append(" (", 2);
1308
1253
 
1309
1254
  for (ssize_t x= 0; x < fkey.references_columns_size(); ++x)
1310
1255
  {
1319
1264
 
1320
1265
  if (fkey.has_update_option() and fkey.update_option() != Table::ForeignKeyConstraint::OPTION_UNDEF)
1321
1266
  {
1322
 
    destination.append(" ON UPDATE ");
 
1267
    destination.append(" ON UPDATE ", 11);
1323
1268
    transformForeignKeyOptionToSql(fkey.update_option(), destination);
1324
1269
  }
1325
1270
 
1326
1271
  if (fkey.has_delete_option() and fkey.delete_option() != Table::ForeignKeyConstraint::OPTION_UNDEF)
1327
1272
  {
1328
 
    destination.append(" ON DELETE ");
 
1273
    destination.append(" ON DELETE ", 11);
1329
1274
    transformForeignKeyOptionToSql(fkey.delete_option(), destination);
1330
1275
  }
1331
1276
 
1355
1300
  switch (field_type)
1356
1301
  {
1357
1302
    case Table::Field::DOUBLE:
1358
 
    destination.append(" DOUBLE");
 
1303
    destination.append(" DOUBLE", 7);
1359
1304
    if (field.has_numeric_options()
1360
1305
        && field.numeric_options().has_precision())
1361
1306
    {
1369
1314
    {
1370
1315
      if (field.string_options().has_collation()
1371
1316
          && field.string_options().collation().compare("binary") == 0)
1372
 
        destination.append(" VARBINARY(");
 
1317
        destination.append(" VARBINARY(", 11);
1373
1318
      else
1374
 
        destination.append(" VARCHAR(");
 
1319
        destination.append(" VARCHAR(", 9);
1375
1320
 
1376
1321
      destination.append(boost::lexical_cast<string>(field.string_options().length()));
1377
1322
      destination.append(")");
1381
1326
    {
1382
1327
      if (field.string_options().has_collation()
1383
1328
          && field.string_options().collation().compare("binary") == 0)
1384
 
        destination.append(" BLOB");
 
1329
        destination.append(" BLOB", 5);
1385
1330
      else
1386
 
        destination.append(" TEXT");
 
1331
        destination.append(" TEXT", 5);
1387
1332
    }
1388
1333
    break;
1389
1334
  case Table::Field::ENUM:
1390
1335
    {
1391
1336
      size_t num_field_values= field.enumeration_values().field_value_size();
1392
 
      destination.append(" ENUM(");
 
1337
      destination.append(" ENUM(", 6);
1393
1338
      for (size_t x= 0; x < num_field_values; ++x)
1394
1339
      {
1395
1340
        const string &type= field.enumeration_values().field_value(x);
1404
1349
      destination.push_back(')');
1405
1350
      break;
1406
1351
    }
1407
 
  case Table::Field::UUID:
1408
 
    destination.append(" UUID");
1409
 
    break;
1410
 
  case Table::Field::BOOLEAN:
1411
 
    destination.append(" BOOLEAN");
1412
 
    break;
1413
1352
  case Table::Field::INTEGER:
1414
 
    destination.append(" INT");
 
1353
    destination.append(" INT", 4);
1415
1354
    break;
1416
1355
  case Table::Field::BIGINT:
1417
 
    if (field.has_constraints() and
1418
 
        field.constraints().is_unsigned())
1419
 
    {
1420
 
      destination.append(" BIGINT UNSIGNED");
1421
 
    }
1422
 
    else
1423
 
    {
1424
 
      destination.append(" BIGINT");
1425
 
    }
 
1356
    destination.append(" BIGINT", 7);
1426
1357
    break;
1427
1358
  case Table::Field::DECIMAL:
1428
1359
    {
1429
 
      destination.append(" DECIMAL(");
 
1360
      destination.append(" DECIMAL(", 9);
1430
1361
      stringstream ss;
1431
1362
      ss << field.numeric_options().precision() << ",";
1432
1363
      ss << field.numeric_options().scale() << ")";
1434
1365
    }
1435
1366
    break;
1436
1367
  case Table::Field::DATE:
1437
 
    destination.append(" DATE");
1438
 
    break;
1439
 
 
1440
 
  case Table::Field::EPOCH:
1441
 
    if (field.time_options().microseconds())
1442
 
    {
1443
 
      destination.append(" TIMESTAMP(6)");
1444
 
    }
1445
 
    else
1446
 
    {
1447
 
      destination.append(" TIMESTAMP");
1448
 
    }
1449
 
    break;
1450
 
 
 
1368
    destination.append(" DATE", 5);
 
1369
    break;
 
1370
  case Table::Field::TIMESTAMP:
 
1371
    destination.append(" TIMESTAMP",  10);
 
1372
    break;
1451
1373
  case Table::Field::DATETIME:
1452
 
    destination.append(" DATETIME");
1453
 
    break;
1454
 
  case Table::Field::TIME:
1455
 
    destination.append(" TIME");
1456
 
    break;
 
1374
    destination.append(" DATETIME",  9);
 
1375
    break;
 
1376
  }
 
1377
 
 
1378
  if (field.type() == Table::Field::INTEGER || 
 
1379
      field.type() == Table::Field::BIGINT)
 
1380
  {
 
1381
    if (field.has_constraints() &&
 
1382
        field.constraints().has_is_unsigned() &&
 
1383
        field.constraints().is_unsigned())
 
1384
    {
 
1385
      destination.append(" UNSIGNED", 9);
 
1386
    }
1457
1387
  }
1458
1388
 
1459
1389
  if (field.type() == Table::Field::BLOB ||
1462
1392
    if (field.string_options().has_collation()
1463
1393
        && field.string_options().collation().compare("binary"))
1464
1394
    {
1465
 
      destination.append(" COLLATE ");
 
1395
      destination.append(" COLLATE ", 9);
1466
1396
      destination.append(field.string_options().collation());
1467
1397
    }
1468
1398
  }
1469
1399
 
1470
 
  if (field.has_constraints() and field.constraints().is_unique())
1471
 
  {
1472
 
    destination.append(" UNIQUE");
1473
 
  }
1474
 
 
1475
 
  if (field.has_constraints() && field.constraints().is_notnull())
1476
 
  {
1477
 
    destination.append(" NOT NULL");
1478
 
  }
1479
 
  else if (field.type() == Table::Field::EPOCH)
1480
 
  {
1481
 
    destination.append(" NULL");
1482
 
  }
 
1400
  if (field.has_constraints() &&
 
1401
      ! field.constraints().is_nullable())
 
1402
  {
 
1403
    destination.append(" NOT NULL", 9);
 
1404
  }
 
1405
  else if (field.type() == Table::Field::TIMESTAMP)
 
1406
    destination.append(" NULL", 5);
1483
1407
 
1484
1408
  if (field.type() == Table::Field::INTEGER || 
1485
1409
      field.type() == Table::Field::BIGINT)
1488
1412
    if (field.has_numeric_options() &&
1489
1413
        field.numeric_options().is_autoincrement())
1490
1414
    {
1491
 
      destination.append(" AUTO_INCREMENT");
 
1415
      destination.append(" AUTO_INCREMENT", 15);
1492
1416
    }
1493
1417
  }
1494
1418
 
1495
1419
  if (field.options().has_default_value())
1496
1420
  {
1497
 
    destination.append(" DEFAULT ");
 
1421
    destination.append(" DEFAULT ", 9);
1498
1422
    append_escaped_string(&destination, field.options().default_value());
1499
1423
  }
1500
1424
  else if (field.options().has_default_expression())
1501
1425
  {
1502
 
    destination.append(" DEFAULT ");
 
1426
    destination.append(" DEFAULT ", 9);
1503
1427
    destination.append(field.options().default_expression());
1504
1428
  }
1505
1429
  else if (field.options().has_default_bin_value())
1506
1430
  {
1507
1431
    const string &v= field.options().default_bin_value();
1508
1432
    if (v.length() == 0)
1509
 
    {
1510
 
      destination.append(" DEFAULT ''");
1511
 
    }
 
1433
      destination.append(" DEFAULT ''", 11);
1512
1434
    else
1513
1435
    {
1514
 
      destination.append(" DEFAULT 0x");
 
1436
      destination.append(" DEFAULT 0x", 11);
1515
1437
      for (size_t x= 0; x < v.length(); x++)
1516
1438
      {
1517
1439
        char hex[3];
1524
1446
           && field.options().default_null()
1525
1447
           && field.type() != Table::Field::BLOB)
1526
1448
  {
1527
 
    destination.append(" DEFAULT NULL");
 
1449
    destination.append(" DEFAULT NULL", 13);
1528
1450
  }
1529
1451
 
1530
1452
  if (field.has_options() && field.options().has_update_expression())
1531
1453
  {
1532
 
    destination.append(" ON UPDATE ");
 
1454
    destination.append(" ON UPDATE ", 11);
1533
1455
    destination.append(field.options().update_expression());
1534
1456
  }
1535
1457
 
1536
1458
  if (field.has_comment())
1537
1459
  {
1538
 
    destination.append(" COMMENT ");
 
1460
    destination.append(" COMMENT ", 9);
1539
1461
    append_escaped_string(&destination, field.comment(), quoted_default);
1540
1462
  }
1541
1463
  return NONE;
1565
1487
  case DRIZZLE_TYPE_NULL:
1566
1488
    assert(false); /* Not a user definable type */
1567
1489
    return Table::Field::INTEGER; /* unreachable */
1568
 
  case DRIZZLE_TYPE_MICROTIME:
1569
1490
  case DRIZZLE_TYPE_TIMESTAMP:
1570
 
    return Table::Field::EPOCH;
 
1491
    return Table::Field::TIMESTAMP;
1571
1492
  case DRIZZLE_TYPE_LONGLONG:
1572
1493
    return Table::Field::BIGINT;
1573
1494
  case DRIZZLE_TYPE_DATETIME:
1574
1495
    return Table::Field::DATETIME;
1575
 
  case DRIZZLE_TYPE_TIME:
1576
 
    return Table::Field::TIME;
1577
1496
  case DRIZZLE_TYPE_DATE:
1578
1497
    return Table::Field::DATE;
1579
1498
  case DRIZZLE_TYPE_VARCHAR:
1584
1503
    return Table::Field::ENUM;
1585
1504
  case DRIZZLE_TYPE_BLOB:
1586
1505
    return Table::Field::BLOB;
1587
 
  case DRIZZLE_TYPE_UUID:
1588
 
    return Table::Field::UUID;
1589
 
  case DRIZZLE_TYPE_BOOLEAN:
1590
 
    return Table::Field::BOOLEAN;
1591
1506
  }
1592
1507
 
1593
1508
  assert(false);