~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/statement_transform.cc

  • Committer: Lee Bieber
  • Date: 2011-03-29 22:31:41 UTC
  • mfrom: (2257.1.3 build)
  • Revision ID: kalebral@gmail.com-20110329223141-yxc22h3l2he58sk0
Merge Andrew - 743842: Build failure using GCC 4.6
Merge Stewart - 738022: CachedDirectory silently fails to add entries if stat() fails
Merge Olaf - Common fwd: add copyright, add more declaration

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