~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/statement_transform.cc

  • Committer: Stewart Smith
  • Date: 2011-03-29 01:30:47 UTC
  • mto: (2257.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2258.
  • Revision ID: stewart@flamingspork.com-20110329013047-5ujzfx6pahmwuko2
have CachedDirectory print out a warning if we can't stat() something in a directory. We should always have access to at least stat() things in directories Drizzle is running in (otherwise there is likely a problem)

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;
806
826
}
807
827
 
808
828
enum TransformSqlError
 
829
transformAlterSchemaStatementToSql(const AlterSchemaStatement &statement,
 
830
                                   string &destination,
 
831
                                   enum TransformSqlVariant sql_variant)
 
832
{
 
833
  const Schema &before= statement.before();
 
834
  const Schema &after= statement.after();
 
835
 
 
836
  /* Make sure we are given the before and after for the same object */
 
837
  if (before.uuid() != after.uuid())
 
838
    return UUID_MISMATCH;
 
839
 
 
840
  char quoted_identifier= '`';
 
841
  if (sql_variant == ANSI)
 
842
    quoted_identifier= '"';
 
843
 
 
844
  destination.append("ALTER SCHEMA ");
 
845
  destination.push_back(quoted_identifier);
 
846
  destination.append(before.name());
 
847
  destination.push_back(quoted_identifier);
 
848
 
 
849
  /*
 
850
   * Diff our schemas. Currently, only collation can change so a
 
851
   * diff of the two structures is not really necessary.
 
852
   */
 
853
  destination.append(" COLLATE = ");
 
854
  destination.append(after.collation());
 
855
 
 
856
  return NONE;
 
857
}
 
858
 
 
859
enum TransformSqlError
809
860
transformDropSchemaStatementToSql(const DropSchemaStatement &statement,
810
861
                                  string &destination,
811
862
                                  enum TransformSqlVariant sql_variant)
833
884
 
834
885
  const Schema &schema= statement.schema();
835
886
 
836
 
  destination.append("CREATE SCHEMA ", 14);
 
887
  destination.append("CREATE SCHEMA ");
837
888
  destination.push_back(quoted_identifier);
838
889
  destination.append(schema.name());
839
890
  destination.push_back(quoted_identifier);
840
891
 
841
892
  if (schema.has_collation())
842
893
  {
843
 
    destination.append(" COLLATE ", 9);
 
894
    destination.append(" COLLATE ");
844
895
    destination.append(schema.collation());
845
896
  }
846
897
 
 
898
  if (not message::is_replicated(schema))
 
899
  {
 
900
    destination.append(" REPLICATE = FALSE");
 
901
  }
 
902
 
847
903
  return NONE;
848
904
}
849
905
 
858
914
 
859
915
  const TableMetadata &table_metadata= statement.table_metadata();
860
916
 
861
 
  destination.append("DROP TABLE ", 11);
 
917
  destination.append("DROP TABLE ");
862
918
 
863
919
  /* Add the IF EXISTS clause if necessary */
864
920
  if (statement.has_if_exists_clause() &&
865
921
      statement.if_exists_clause() == true)
866
922
  {
867
 
    destination.append("IF EXISTS ", 10);
 
923
    destination.append("IF EXISTS ");
868
924
  }
869
925
 
870
926
  destination.push_back(quoted_identifier);
889
945
 
890
946
  const TableMetadata &table_metadata= statement.table_metadata();
891
947
 
892
 
  destination.append("TRUNCATE TABLE ", 15);
 
948
  destination.append("TRUNCATE TABLE ");
893
949
  destination.push_back(quoted_identifier);
894
950
  destination.append(table_metadata.schema_name());
895
951
  destination.push_back(quoted_identifier);
910
966
  const FieldMetadata &variable_metadata= statement.variable_metadata();
911
967
  bool should_quote_field_value= shouldQuoteFieldValue(variable_metadata.type());
912
968
 
913
 
  destination.append("SET GLOBAL ", 11); /* Only global variables are replicated */
 
969
  destination.append("SET GLOBAL "); /* Only global variables are replicated */
914
970
  destination.append(variable_metadata.name());
915
971
  destination.push_back('=');
916
972
 
942
998
  if (sql_variant == ANSI)
943
999
    quoted_identifier= '"';
944
1000
 
945
 
  destination.append("CREATE ", 7);
 
1001
  destination.append("CREATE ");
946
1002
 
947
1003
  if (table.type() == Table::TEMPORARY)
948
 
    destination.append("TEMPORARY ", 10);
 
1004
    destination.append("TEMPORARY ");
949
1005
  
950
 
  destination.append("TABLE ", 6);
 
1006
  destination.append("TABLE ");
951
1007
  if (with_schema)
952
1008
  {
953
1009
    append_escaped_string(&destination, table.schema(), quoted_identifier);
954
1010
    destination.push_back('.');
955
1011
  }
956
1012
  append_escaped_string(&destination, table.name(), quoted_identifier);
957
 
  destination.append(" (\n", 3);
 
1013
  destination.append(" (\n");
958
1014
 
959
1015
  enum TransformSqlError result= NONE;
960
1016
  size_t num_fields= table.field_size();
963
1019
    const Table::Field &field= table.field(x);
964
1020
 
965
1021
    if (x != 0)
966
 
      destination.append(",\n", 2);
 
1022
      destination.append(",\n");
967
1023
 
968
1024
    destination.append("  ");
969
1025
 
976
1032
  size_t num_indexes= table.indexes_size();
977
1033
  
978
1034
  if (num_indexes > 0)
979
 
    destination.append(",\n", 2);
 
1035
    destination.append(",\n");
980
1036
 
981
1037
  for (size_t x= 0; x < num_indexes; ++x)
982
1038
  {
983
1039
    const message::Table::Index &index= table.indexes(x);
984
1040
 
985
1041
    if (x != 0)
986
 
      destination.append(",\n", 2);
 
1042
      destination.append(",\n");
987
1043
 
988
1044
    result= transformIndexDefinitionToSql(index, table, destination, sql_variant);
989
1045
    
994
1050
  size_t num_foreign_keys= table.fk_constraint_size();
995
1051
 
996
1052
  if (num_foreign_keys > 0)
997
 
    destination.append(",\n", 2);
 
1053
    destination.append(",\n");
998
1054
 
999
1055
  for (size_t x= 0; x < num_foreign_keys; ++x)
1000
1056
  {
1001
1057
    const message::Table::ForeignKeyConstraint &fkey= table.fk_constraint(x);
1002
1058
 
1003
1059
    if (x != 0)
1004
 
      destination.append(",\n", 2);
 
1060
      destination.append(",\n");
1005
1061
 
1006
1062
    result= transformForeignKeyConstraintDefinitionToSql(fkey, table, destination, sql_variant);
1007
1063
 
1009
1065
      return result;
1010
1066
  }
1011
1067
 
1012
 
  destination.append("\n)", 2);
 
1068
  destination.append("\n)");
1013
1069
 
1014
1070
  /* Add ENGINE = " clause */
1015
1071
  if (table.has_engine())
1016
1072
  {
1017
 
    destination.append(" ENGINE=", 8);
 
1073
    destination.append(" ENGINE=");
1018
1074
    destination.append(table.engine().name());
1019
1075
 
1020
1076
    size_t num_engine_options= table.engine().options_size();
1024
1080
    {
1025
1081
      const Engine::Option &option= table.engine().options(x);
1026
1082
      destination.append(option.name());
1027
 
      destination.append("='", 2);
 
1083
      destination.append("='");
1028
1084
      destination.append(option.state());
1029
 
      destination.append("'", 1);
1030
 
      if(x != num_engine_options-1)
1031
 
        destination.append(", ", 2);
 
1085
      destination.append("'");
 
1086
      if (x != num_engine_options-1)
 
1087
      {
 
1088
        destination.append(", ");
 
1089
      }
1032
1090
    }
1033
1091
  }
1034
1092
 
1035
1093
  if (table.has_options())
1036
1094
    (void) transformTableOptionsToSql(table.options(), destination, sql_variant);
1037
1095
 
 
1096
  if (not message::is_replicated(table))
 
1097
  {
 
1098
    destination.append(" REPLICATE = FALSE");
 
1099
  }
 
1100
 
1038
1101
  return NONE;
1039
1102
}
1040
1103
 
1048
1111
 
1049
1112
  if (options.has_comment())
1050
1113
  {
1051
 
    destination.append(" COMMENT=", 9);
 
1114
    destination.append(" COMMENT=");
1052
1115
    append_escaped_string(&destination, options.comment());
1053
1116
  }
1054
1117
 
1055
1118
  if (options.has_collation())
1056
1119
  {
1057
 
    destination.append(" COLLATE = ", 11);
 
1120
    destination.append(" COLLATE = ");
1058
1121
    destination.append(options.collation());
1059
1122
  }
1060
1123
 
1061
1124
  if (options.has_data_file_name())
1062
1125
  {
1063
 
    destination.append("\nDATA_FILE_NAME = '", 19);
 
1126
    destination.append("\nDATA_FILE_NAME = '");
1064
1127
    destination.append(options.data_file_name());
1065
1128
    destination.push_back('\'');
1066
1129
  }
1067
1130
 
1068
1131
  if (options.has_index_file_name())
1069
1132
  {
1070
 
    destination.append("\nINDEX_FILE_NAME = '", 20);
 
1133
    destination.append("\nINDEX_FILE_NAME = '");
1071
1134
    destination.append(options.index_file_name());
1072
1135
    destination.push_back('\'');
1073
1136
  }
1074
1137
 
1075
1138
  if (options.has_max_rows())
1076
1139
  {
1077
 
    destination.append("\nMAX_ROWS = ", 12);
 
1140
    destination.append("\nMAX_ROWS = ");
1078
1141
    destination.append(boost::lexical_cast<string>(options.max_rows()));
1079
1142
  }
1080
1143
 
1081
1144
  if (options.has_min_rows())
1082
1145
  {
1083
 
    destination.append("\nMIN_ROWS = ", 12);
 
1146
    destination.append("\nMIN_ROWS = ");
1084
1147
    destination.append(boost::lexical_cast<string>(options.min_rows()));
1085
1148
  }
1086
1149
 
1087
1150
  if (options.has_user_set_auto_increment_value()
1088
1151
      && options.has_auto_increment_value())
1089
1152
  {
1090
 
    destination.append(" AUTO_INCREMENT=", 16);
 
1153
    destination.append(" AUTO_INCREMENT=");
1091
1154
    destination.append(boost::lexical_cast<string>(options.auto_increment_value()));
1092
1155
  }
1093
1156
 
1094
1157
  if (options.has_avg_row_length())
1095
1158
  {
1096
 
    destination.append("\nAVG_ROW_LENGTH = ", 18);
 
1159
    destination.append("\nAVG_ROW_LENGTH = ");
1097
1160
    destination.append(boost::lexical_cast<string>(options.avg_row_length()));
1098
1161
  }
1099
1162
 
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);
 
1163
  if (options.has_checksum() && options.checksum())
 
1164
    destination.append("\nCHECKSUM = TRUE");
 
1165
 
 
1166
  if (options.has_page_checksum() && options.page_checksum())
 
1167
    destination.append("\nPAGE_CHECKSUM = TRUE");
1106
1168
 
1107
1169
  return NONE;
1108
1170
}
1120
1182
  destination.append("  ", 2);
1121
1183
 
1122
1184
  if (index.is_primary())
1123
 
    destination.append("PRIMARY ", 8);
 
1185
    destination.append("PRIMARY ");
1124
1186
  else if (index.is_unique())
1125
 
    destination.append("UNIQUE ", 7);
 
1187
    destination.append("UNIQUE ");
1126
1188
 
1127
1189
  destination.append("KEY ", 4);
1128
1190
  if (! (index.is_primary() && index.name().compare("PRIMARY")==0))
1174
1236
  case Table::Index::UNKNOWN_INDEX:
1175
1237
    break;
1176
1238
  case Table::Index::BTREE:
1177
 
    destination.append(" USING BTREE", 12);
 
1239
    destination.append(" USING BTREE");
1178
1240
    break;
1179
1241
  case Table::Index::RTREE:
1180
 
    destination.append(" USING RTREE", 12);
 
1242
    destination.append(" USING RTREE");
1181
1243
    break;
1182
1244
  case Table::Index::HASH:
1183
 
    destination.append(" USING HASH", 11);
 
1245
    destination.append(" USING HASH");
1184
1246
    break;
1185
1247
  case Table::Index::FULLTEXT:
1186
 
    destination.append(" USING FULLTEXT", 15);
 
1248
    destination.append(" USING FULLTEXT");
1187
1249
    break;
1188
1250
  }
1189
1251
 
1190
1252
  if (index.has_comment())
1191
1253
  {
1192
 
    destination.append(" COMMENT ", 9);
 
1254
    destination.append(" COMMENT ");
1193
1255
    append_escaped_string(&destination, index.comment());
1194
1256
  }
1195
1257
 
1229
1291
  if (sql_variant == ANSI)
1230
1292
    quoted_identifier= '"';
1231
1293
 
1232
 
  destination.append("  ", 2);
 
1294
  destination.append("  ");
1233
1295
 
1234
1296
  if (fkey.has_name())
1235
1297
  {
1236
 
    destination.append("CONSTRAINT ", 11);
 
1298
    destination.append("CONSTRAINT ");
1237
1299
    append_escaped_string(&destination, fkey.name(), quoted_identifier);
1238
1300
    destination.append(" ", 1);
1239
1301
  }
1240
1302
 
1241
 
  destination.append("FOREIGN KEY (", 13);
 
1303
  destination.append("FOREIGN KEY (");
1242
1304
 
1243
1305
  for (ssize_t x= 0; x < fkey.column_names_size(); ++x)
1244
1306
  {
1249
1311
                          quoted_identifier);
1250
1312
  }
1251
1313
 
1252
 
  destination.append(") REFERENCES ", 13);
 
1314
  destination.append(") REFERENCES ");
1253
1315
 
1254
1316
  append_escaped_string(&destination, fkey.references_table_name(),
1255
1317
                        quoted_identifier);
1256
 
  destination.append(" (", 2);
 
1318
  destination.append(" (");
1257
1319
 
1258
1320
  for (ssize_t x= 0; x < fkey.references_columns_size(); ++x)
1259
1321
  {
1268
1330
 
1269
1331
  if (fkey.has_update_option() and fkey.update_option() != Table::ForeignKeyConstraint::OPTION_UNDEF)
1270
1332
  {
1271
 
    destination.append(" ON UPDATE ", 11);
 
1333
    destination.append(" ON UPDATE ");
1272
1334
    transformForeignKeyOptionToSql(fkey.update_option(), destination);
1273
1335
  }
1274
1336
 
1275
1337
  if (fkey.has_delete_option() and fkey.delete_option() != Table::ForeignKeyConstraint::OPTION_UNDEF)
1276
1338
  {
1277
 
    destination.append(" ON DELETE ", 11);
 
1339
    destination.append(" ON DELETE ");
1278
1340
    transformForeignKeyOptionToSql(fkey.delete_option(), destination);
1279
1341
  }
1280
1342
 
1304
1366
  switch (field_type)
1305
1367
  {
1306
1368
    case Table::Field::DOUBLE:
1307
 
    destination.append(" DOUBLE", 7);
 
1369
    destination.append(" DOUBLE");
1308
1370
    if (field.has_numeric_options()
1309
1371
        && field.numeric_options().has_precision())
1310
1372
    {
1318
1380
    {
1319
1381
      if (field.string_options().has_collation()
1320
1382
          && field.string_options().collation().compare("binary") == 0)
1321
 
        destination.append(" VARBINARY(", 11);
 
1383
        destination.append(" VARBINARY(");
1322
1384
      else
1323
 
        destination.append(" VARCHAR(", 9);
 
1385
        destination.append(" VARCHAR(");
1324
1386
 
1325
1387
      destination.append(boost::lexical_cast<string>(field.string_options().length()));
1326
1388
      destination.append(")");
1330
1392
    {
1331
1393
      if (field.string_options().has_collation()
1332
1394
          && field.string_options().collation().compare("binary") == 0)
1333
 
        destination.append(" BLOB", 5);
 
1395
        destination.append(" BLOB");
1334
1396
      else
1335
 
        destination.append(" TEXT", 5);
 
1397
        destination.append(" TEXT");
1336
1398
    }
1337
1399
    break;
1338
1400
  case Table::Field::ENUM:
1339
1401
    {
1340
1402
      size_t num_field_values= field.enumeration_values().field_value_size();
1341
 
      destination.append(" ENUM(", 6);
 
1403
      destination.append(" ENUM(");
1342
1404
      for (size_t x= 0; x < num_field_values; ++x)
1343
1405
      {
1344
1406
        const string &type= field.enumeration_values().field_value(x);
1354
1416
      break;
1355
1417
    }
1356
1418
  case Table::Field::UUID:
1357
 
    destination.append(" UUID", 5);
 
1419
    destination.append(" UUID");
 
1420
    break;
 
1421
  case Table::Field::BOOLEAN:
 
1422
    destination.append(" BOOLEAN");
1358
1423
    break;
1359
1424
  case Table::Field::INTEGER:
1360
 
    destination.append(" INT", 4);
 
1425
    destination.append(" INT");
1361
1426
    break;
1362
1427
  case Table::Field::BIGINT:
1363
 
    destination.append(" BIGINT", 7);
 
1428
    if (field.has_constraints() and
 
1429
        field.constraints().is_unsigned())
 
1430
    {
 
1431
      destination.append(" BIGINT UNSIGNED");
 
1432
    }
 
1433
    else
 
1434
    {
 
1435
      destination.append(" BIGINT");
 
1436
    }
1364
1437
    break;
1365
1438
  case Table::Field::DECIMAL:
1366
1439
    {
1367
 
      destination.append(" DECIMAL(", 9);
 
1440
      destination.append(" DECIMAL(");
1368
1441
      stringstream ss;
1369
1442
      ss << field.numeric_options().precision() << ",";
1370
1443
      ss << field.numeric_options().scale() << ")";
1372
1445
    }
1373
1446
    break;
1374
1447
  case Table::Field::DATE:
1375
 
    destination.append(" DATE", 5);
1376
 
    break;
1377
 
  case Table::Field::TIMESTAMP:
1378
 
    destination.append(" TIMESTAMP",  10);
1379
 
    break;
 
1448
    destination.append(" DATE");
 
1449
    break;
 
1450
 
 
1451
  case Table::Field::EPOCH:
 
1452
    if (field.time_options().microseconds())
 
1453
    {
 
1454
      destination.append(" TIMESTAMP(6)");
 
1455
    }
 
1456
    else
 
1457
    {
 
1458
      destination.append(" TIMESTAMP");
 
1459
    }
 
1460
    break;
 
1461
 
1380
1462
  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
 
    }
 
1463
    destination.append(" DATETIME");
 
1464
    break;
 
1465
  case Table::Field::TIME:
 
1466
    destination.append(" TIME");
 
1467
    break;
1394
1468
  }
1395
1469
 
1396
1470
  if (field.type() == Table::Field::BLOB ||
1399
1473
    if (field.string_options().has_collation()
1400
1474
        && field.string_options().collation().compare("binary"))
1401
1475
    {
1402
 
      destination.append(" COLLATE ", 9);
 
1476
      destination.append(" COLLATE ");
1403
1477
      destination.append(field.string_options().collation());
1404
1478
    }
1405
1479
  }
1406
1480
 
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);
 
1481
  if (field.has_constraints() and field.constraints().is_unique())
 
1482
  {
 
1483
    destination.append(" UNIQUE");
 
1484
  }
 
1485
 
 
1486
  if (field.has_constraints() && field.constraints().is_notnull())
 
1487
  {
 
1488
    destination.append(" NOT NULL");
 
1489
  }
 
1490
  else if (field.type() == Table::Field::EPOCH)
 
1491
  {
 
1492
    destination.append(" NULL");
 
1493
  }
1414
1494
 
1415
1495
  if (field.type() == Table::Field::INTEGER || 
1416
1496
      field.type() == Table::Field::BIGINT)
1419
1499
    if (field.has_numeric_options() &&
1420
1500
        field.numeric_options().is_autoincrement())
1421
1501
    {
1422
 
      destination.append(" AUTO_INCREMENT", 15);
 
1502
      destination.append(" AUTO_INCREMENT");
1423
1503
    }
1424
1504
  }
1425
1505
 
1426
1506
  if (field.options().has_default_value())
1427
1507
  {
1428
 
    destination.append(" DEFAULT ", 9);
 
1508
    destination.append(" DEFAULT ");
1429
1509
    append_escaped_string(&destination, field.options().default_value());
1430
1510
  }
1431
1511
  else if (field.options().has_default_expression())
1432
1512
  {
1433
 
    destination.append(" DEFAULT ", 9);
 
1513
    destination.append(" DEFAULT ");
1434
1514
    destination.append(field.options().default_expression());
1435
1515
  }
1436
1516
  else if (field.options().has_default_bin_value())
1437
1517
  {
1438
1518
    const string &v= field.options().default_bin_value();
1439
1519
    if (v.length() == 0)
1440
 
      destination.append(" DEFAULT ''", 11);
 
1520
    {
 
1521
      destination.append(" DEFAULT ''");
 
1522
    }
1441
1523
    else
1442
1524
    {
1443
 
      destination.append(" DEFAULT 0x", 11);
 
1525
      destination.append(" DEFAULT 0x");
1444
1526
      for (size_t x= 0; x < v.length(); x++)
1445
1527
      {
1446
1528
        char hex[3];
1453
1535
           && field.options().default_null()
1454
1536
           && field.type() != Table::Field::BLOB)
1455
1537
  {
1456
 
    destination.append(" DEFAULT NULL", 13);
 
1538
    destination.append(" DEFAULT NULL");
1457
1539
  }
1458
1540
 
1459
1541
  if (field.has_options() && field.options().has_update_expression())
1460
1542
  {
1461
 
    destination.append(" ON UPDATE ", 11);
 
1543
    destination.append(" ON UPDATE ");
1462
1544
    destination.append(field.options().update_expression());
1463
1545
  }
1464
1546
 
1465
1547
  if (field.has_comment())
1466
1548
  {
1467
 
    destination.append(" COMMENT ", 9);
 
1549
    destination.append(" COMMENT ");
1468
1550
    append_escaped_string(&destination, field.comment(), quoted_default);
1469
1551
  }
1470
1552
  return NONE;
1494
1576
  case DRIZZLE_TYPE_NULL:
1495
1577
    assert(false); /* Not a user definable type */
1496
1578
    return Table::Field::INTEGER; /* unreachable */
 
1579
  case DRIZZLE_TYPE_MICROTIME:
1497
1580
  case DRIZZLE_TYPE_TIMESTAMP:
1498
 
    return Table::Field::TIMESTAMP;
 
1581
    return Table::Field::EPOCH;
1499
1582
  case DRIZZLE_TYPE_LONGLONG:
1500
1583
    return Table::Field::BIGINT;
1501
1584
  case DRIZZLE_TYPE_DATETIME:
1502
1585
    return Table::Field::DATETIME;
 
1586
  case DRIZZLE_TYPE_TIME:
 
1587
    return Table::Field::TIME;
1503
1588
  case DRIZZLE_TYPE_DATE:
1504
1589
    return Table::Field::DATE;
1505
1590
  case DRIZZLE_TYPE_VARCHAR:
1512
1597
    return Table::Field::BLOB;
1513
1598
  case DRIZZLE_TYPE_UUID:
1514
1599
    return Table::Field::UUID;
 
1600
  case DRIZZLE_TYPE_BOOLEAN:
 
1601
    return Table::Field::BOOLEAN;
1515
1602
  }
1516
1603
 
1517
1604
  assert(false);