~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/statement_transform.cc

  • Committer: Olaf van der Spek
  • Date: 2011-04-20 09:27:49 UTC
  • mto: This revision was merged to the branch mainline in revision 2285.
  • Revision ID: olafvdspek@gmail.com-20110420092749-hw1q9rfj1pumc2no
Session Cache

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