~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/statement_transform.cc

  • Committer: lbieber
  • Date: 2010-10-02 19:48:35 UTC
  • mfrom: (1730.6.19 drizzle-make-lcov)
  • Revision ID: lbieber@orisndriz08-20101002194835-q5zd9qc4lvx1xnfo
Merge Hartmut - clean up lex, now require flex to build, also "make lcov" improvements

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
 *
31
31
 
32
32
#include "config.h"
33
33
 
34
 
#include <boost/lexical_cast.hpp>
35
34
#include "drizzled/message/statement_transform.h"
36
35
#include "drizzled/message/transaction.pb.h"
37
36
#include "drizzled/message/table.pb.h"
127
126
 
128
127
  switch (source.type())
129
128
  {
130
 
  case Statement::ROLLBACK_STATEMENT:
131
 
    {
132
 
      break;
133
 
    }
134
 
  case Statement::ROLLBACK:
135
 
    {
136
 
      sql_strings.push_back("ROLLBACK");
137
 
      break;
138
 
    }
139
129
  case Statement::INSERT:
140
130
    {
141
131
      if (! source.has_insert_header())
318
308
      sql_strings.push_back(destination);
319
309
    }
320
310
    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;
331
311
  case Statement::SET_VARIABLE:
332
312
    {
333
313
      assert(source.has_set_variable_statement());
816
796
}
817
797
 
818
798
enum TransformSqlError
819
 
transformAlterSchemaStatementToSql(const AlterSchemaStatement &statement,
820
 
                                   string &destination,
821
 
                                   enum TransformSqlVariant sql_variant)
822
 
{
823
 
  const Schema &before= statement.before();
824
 
  const Schema &after= statement.after();
825
 
 
826
 
  /* Make sure we are given the before and after for the same object */
827
 
  if (before.uuid() != after.uuid())
828
 
    return UUID_MISMATCH;
829
 
 
830
 
  char quoted_identifier= '`';
831
 
  if (sql_variant == ANSI)
832
 
    quoted_identifier= '"';
833
 
 
834
 
  destination.append("ALTER SCHEMA ");
835
 
  destination.push_back(quoted_identifier);
836
 
  destination.append(before.name());
837
 
  destination.push_back(quoted_identifier);
838
 
 
839
 
  /*
840
 
   * Diff our schemas. Currently, only collation can change so a
841
 
   * diff of the two structures is not really necessary.
842
 
   */
843
 
  destination.append(" COLLATE = ");
844
 
  destination.append(after.collation());
845
 
 
846
 
  return NONE;
847
 
}
848
 
 
849
 
enum TransformSqlError
850
799
transformDropSchemaStatementToSql(const DropSchemaStatement &statement,
851
800
                                  string &destination,
852
801
                                  enum TransformSqlVariant sql_variant)
874
823
 
875
824
  const Schema &schema= statement.schema();
876
825
 
877
 
  destination.append("CREATE SCHEMA ");
 
826
  destination.append("CREATE SCHEMA ", 14);
878
827
  destination.push_back(quoted_identifier);
879
828
  destination.append(schema.name());
880
829
  destination.push_back(quoted_identifier);
881
830
 
882
831
  if (schema.has_collation())
883
832
  {
884
 
    destination.append(" COLLATE ");
 
833
    destination.append(" COLLATE ", 9);
885
834
    destination.append(schema.collation());
886
835
  }
887
836
 
899
848
 
900
849
  const TableMetadata &table_metadata= statement.table_metadata();
901
850
 
902
 
  destination.append("DROP TABLE ");
 
851
  destination.append("DROP TABLE ", 11);
903
852
 
904
853
  /* Add the IF EXISTS clause if necessary */
905
854
  if (statement.has_if_exists_clause() &&
906
855
      statement.if_exists_clause() == true)
907
856
  {
908
 
    destination.append("IF EXISTS ");
 
857
    destination.append("IF EXISTS ", 10);
909
858
  }
910
859
 
911
860
  destination.push_back(quoted_identifier);
930
879
 
931
880
  const TableMetadata &table_metadata= statement.table_metadata();
932
881
 
933
 
  destination.append("TRUNCATE TABLE ");
 
882
  destination.append("TRUNCATE TABLE ", 15);
934
883
  destination.push_back(quoted_identifier);
935
884
  destination.append(table_metadata.schema_name());
936
885
  destination.push_back(quoted_identifier);
951
900
  const FieldMetadata &variable_metadata= statement.variable_metadata();
952
901
  bool should_quote_field_value= shouldQuoteFieldValue(variable_metadata.type());
953
902
 
954
 
  destination.append("SET GLOBAL "); /* Only global variables are replicated */
 
903
  destination.append("SET GLOBAL ", 11); /* Only global variables are replicated */
955
904
  destination.append(variable_metadata.name());
956
905
  destination.push_back('=');
957
906
 
983
932
  if (sql_variant == ANSI)
984
933
    quoted_identifier= '"';
985
934
 
986
 
  destination.append("CREATE ");
 
935
  destination.append("CREATE ", 7);
987
936
 
988
937
  if (table.type() == Table::TEMPORARY)
989
 
    destination.append("TEMPORARY ");
 
938
    destination.append("TEMPORARY ", 10);
990
939
  
991
 
  destination.append("TABLE ");
 
940
  destination.append("TABLE ", 6);
992
941
  if (with_schema)
993
942
  {
994
943
    append_escaped_string(&destination, table.schema(), quoted_identifier);
995
944
    destination.push_back('.');
996
945
  }
997
946
  append_escaped_string(&destination, table.name(), quoted_identifier);
998
 
  destination.append(" (\n");
 
947
  destination.append(" (\n", 3);
999
948
 
1000
949
  enum TransformSqlError result= NONE;
1001
950
  size_t num_fields= table.field_size();
1004
953
    const Table::Field &field= table.field(x);
1005
954
 
1006
955
    if (x != 0)
1007
 
      destination.append(",\n");
 
956
      destination.append(",\n", 2);
1008
957
 
1009
958
    destination.append("  ");
1010
959
 
1017
966
  size_t num_indexes= table.indexes_size();
1018
967
  
1019
968
  if (num_indexes > 0)
1020
 
    destination.append(",\n");
 
969
    destination.append(",\n", 2);
1021
970
 
1022
971
  for (size_t x= 0; x < num_indexes; ++x)
1023
972
  {
1024
973
    const message::Table::Index &index= table.indexes(x);
1025
974
 
1026
975
    if (x != 0)
1027
 
      destination.append(",\n");
 
976
      destination.append(",\n", 2);
1028
977
 
1029
978
    result= transformIndexDefinitionToSql(index, table, destination, sql_variant);
1030
979
    
1035
984
  size_t num_foreign_keys= table.fk_constraint_size();
1036
985
 
1037
986
  if (num_foreign_keys > 0)
1038
 
    destination.append(",\n");
 
987
    destination.append(",\n", 2);
1039
988
 
1040
989
  for (size_t x= 0; x < num_foreign_keys; ++x)
1041
990
  {
1042
991
    const message::Table::ForeignKeyConstraint &fkey= table.fk_constraint(x);
1043
992
 
1044
993
    if (x != 0)
1045
 
      destination.append(",\n");
 
994
      destination.append(",\n", 2);
1046
995
 
1047
996
    result= transformForeignKeyConstraintDefinitionToSql(fkey, table, destination, sql_variant);
1048
997
 
1050
999
      return result;
1051
1000
  }
1052
1001
 
1053
 
  destination.append("\n)");
 
1002
  destination.append("\n)", 2);
1054
1003
 
1055
1004
  /* Add ENGINE = " clause */
1056
1005
  if (table.has_engine())
1057
1006
  {
1058
 
    destination.append(" ENGINE=");
 
1007
    destination.append(" ENGINE=", 8);
1059
1008
    destination.append(table.engine().name());
1060
1009
 
1061
1010
    size_t num_engine_options= table.engine().options_size();
1065
1014
    {
1066
1015
      const Engine::Option &option= table.engine().options(x);
1067
1016
      destination.append(option.name());
1068
 
      destination.append("='");
 
1017
      destination.append("='", 2);
1069
1018
      destination.append(option.state());
1070
 
      destination.append("'");
1071
 
      if (x != num_engine_options-1)
1072
 
      {
1073
 
        destination.append(", ");
1074
 
      }
 
1019
      destination.append("'", 1);
 
1020
      if(x != num_engine_options-1)
 
1021
        destination.append(", ", 2);
1075
1022
    }
1076
1023
  }
1077
1024
 
1089
1036
  if (sql_variant == ANSI)
1090
1037
    return NONE; /* ANSI does not support table options... */
1091
1038
 
 
1039
  stringstream ss;
 
1040
 
1092
1041
  if (options.has_comment())
1093
1042
  {
1094
 
    destination.append(" COMMENT=");
 
1043
    destination.append(" COMMENT=", 9);
1095
1044
    append_escaped_string(&destination, options.comment());
1096
1045
  }
1097
1046
 
1098
1047
  if (options.has_collation())
1099
1048
  {
1100
 
    destination.append(" COLLATE = ");
 
1049
    destination.append(" COLLATE = ", 11);
1101
1050
    destination.append(options.collation());
1102
1051
  }
1103
1052
 
1104
1053
  if (options.has_data_file_name())
1105
1054
  {
1106
 
    destination.append("\nDATA_FILE_NAME = '");
 
1055
    destination.append("\nDATA_FILE_NAME = '", 19);
1107
1056
    destination.append(options.data_file_name());
1108
1057
    destination.push_back('\'');
1109
1058
  }
1110
1059
 
1111
1060
  if (options.has_index_file_name())
1112
1061
  {
1113
 
    destination.append("\nINDEX_FILE_NAME = '");
 
1062
    destination.append("\nINDEX_FILE_NAME = '", 20);
1114
1063
    destination.append(options.index_file_name());
1115
1064
    destination.push_back('\'');
1116
1065
  }
1117
1066
 
1118
1067
  if (options.has_max_rows())
1119
1068
  {
1120
 
    destination.append("\nMAX_ROWS = ");
1121
 
    destination.append(boost::lexical_cast<string>(options.max_rows()));
 
1069
    ss << options.max_rows();
 
1070
    destination.append("\nMAX_ROWS = ", 12);
 
1071
    destination.append(ss.str());
 
1072
    ss.clear();
1122
1073
  }
1123
1074
 
1124
1075
  if (options.has_min_rows())
1125
1076
  {
1126
 
    destination.append("\nMIN_ROWS = ");
1127
 
    destination.append(boost::lexical_cast<string>(options.min_rows()));
 
1077
    ss << options.min_rows();
 
1078
    destination.append("\nMIN_ROWS = ", 12);
 
1079
    destination.append(ss.str());
 
1080
    ss.clear();
1128
1081
  }
1129
1082
 
1130
1083
  if (options.has_user_set_auto_increment_value()
1131
1084
      && options.has_auto_increment_value())
1132
1085
  {
1133
 
    destination.append(" AUTO_INCREMENT=");
1134
 
    destination.append(boost::lexical_cast<string>(options.auto_increment_value()));
 
1086
    ss << options.auto_increment_value();
 
1087
    destination.append(" AUTO_INCREMENT=", 16);
 
1088
    destination.append(ss.str());
 
1089
    ss.clear();
1135
1090
  }
1136
1091
 
1137
1092
  if (options.has_avg_row_length())
1138
1093
  {
1139
 
    destination.append("\nAVG_ROW_LENGTH = ");
1140
 
    destination.append(boost::lexical_cast<string>(options.avg_row_length()));
 
1094
    ss << options.avg_row_length();
 
1095
    destination.append("\nAVG_ROW_LENGTH = ", 18);
 
1096
    destination.append(ss.str());
 
1097
    ss.clear();
1141
1098
  }
1142
1099
 
1143
1100
  if (options.has_checksum() &&
1144
1101
      options.checksum())
1145
 
    destination.append("\nCHECKSUM = TRUE");
 
1102
    destination.append("\nCHECKSUM = TRUE", 16);
1146
1103
  if (options.has_page_checksum() &&
1147
1104
      options.page_checksum())
1148
 
    destination.append("\nPAGE_CHECKSUM = TRUE");
 
1105
    destination.append("\nPAGE_CHECKSUM = TRUE", 21);
1149
1106
 
1150
1107
  return NONE;
1151
1108
}
1163
1120
  destination.append("  ", 2);
1164
1121
 
1165
1122
  if (index.is_primary())
1166
 
    destination.append("PRIMARY ");
 
1123
    destination.append("PRIMARY ", 8);
1167
1124
  else if (index.is_unique())
1168
 
    destination.append("UNIQUE ");
 
1125
    destination.append("UNIQUE ", 7);
1169
1126
 
1170
1127
  destination.append("KEY ", 4);
1171
1128
  if (! (index.is_primary() && index.name().compare("PRIMARY")==0))
1203
1160
      {
1204
1161
        if (part.compare_length() != field.string_options().length())
1205
1162
        {
 
1163
          stringstream ss;
1206
1164
          destination.push_back('(');
1207
 
          destination.append(boost::lexical_cast<string>(part.compare_length()));
 
1165
          ss << part.compare_length();
 
1166
          destination.append(ss.str());
1208
1167
          destination.push_back(')');
1209
1168
        }
1210
1169
      }
1217
1176
  case Table::Index::UNKNOWN_INDEX:
1218
1177
    break;
1219
1178
  case Table::Index::BTREE:
1220
 
    destination.append(" USING BTREE");
 
1179
    destination.append(" USING BTREE", 12);
1221
1180
    break;
1222
1181
  case Table::Index::RTREE:
1223
 
    destination.append(" USING RTREE");
 
1182
    destination.append(" USING RTREE", 12);
1224
1183
    break;
1225
1184
  case Table::Index::HASH:
1226
 
    destination.append(" USING HASH");
 
1185
    destination.append(" USING HASH", 11);
1227
1186
    break;
1228
1187
  case Table::Index::FULLTEXT:
1229
 
    destination.append(" USING FULLTEXT");
 
1188
    destination.append(" USING FULLTEXT", 15);
1230
1189
    break;
1231
1190
  }
1232
1191
 
1233
1192
  if (index.has_comment())
1234
1193
  {
1235
 
    destination.append(" COMMENT ");
 
1194
    destination.append(" COMMENT ", 9);
1236
1195
    append_escaped_string(&destination, index.comment());
1237
1196
  }
1238
1197
 
1243
1202
{
1244
1203
  switch (opt)
1245
1204
  {
 
1205
  case Table::ForeignKeyConstraint::OPTION_UNDEF:
 
1206
    break;
1246
1207
  case Table::ForeignKeyConstraint::OPTION_RESTRICT:
1247
1208
    destination.append("RESTRICT");
1248
1209
    break;
1252
1213
  case Table::ForeignKeyConstraint::OPTION_SET_NULL:
1253
1214
    destination.append("SET NULL");
1254
1215
    break;
1255
 
  case Table::ForeignKeyConstraint::OPTION_UNDEF:
1256
1216
  case Table::ForeignKeyConstraint::OPTION_NO_ACTION:
1257
1217
    destination.append("NO ACTION");
1258
1218
    break;
1259
 
  case Table::ForeignKeyConstraint::OPTION_SET_DEFAULT:
 
1219
  case Table::ForeignKeyConstraint::OPTION_DEFAULT:
1260
1220
    destination.append("SET DEFAULT");
1261
1221
    break;
1262
1222
  }
1272
1232
  if (sql_variant == ANSI)
1273
1233
    quoted_identifier= '"';
1274
1234
 
1275
 
  destination.append("  ");
 
1235
  destination.append("  ", 2);
1276
1236
 
1277
1237
  if (fkey.has_name())
1278
1238
  {
1279
 
    destination.append("CONSTRAINT ");
 
1239
    destination.append("CONSTRAINT ", 11);
1280
1240
    append_escaped_string(&destination, fkey.name(), quoted_identifier);
1281
1241
    destination.append(" ", 1);
1282
1242
  }
1283
1243
 
1284
 
  destination.append("FOREIGN KEY (");
 
1244
  destination.append("FOREIGN KEY (", 13);
1285
1245
 
1286
1246
  for (ssize_t x= 0; x < fkey.column_names_size(); ++x)
1287
1247
  {
1292
1252
                          quoted_identifier);
1293
1253
  }
1294
1254
 
1295
 
  destination.append(") REFERENCES ");
 
1255
  destination.append(") REFERENCES ", 13);
1296
1256
 
1297
1257
  append_escaped_string(&destination, fkey.references_table_name(),
1298
1258
                        quoted_identifier);
1299
 
  destination.append(" (");
 
1259
  destination.append(" (", 2);
1300
1260
 
1301
1261
  for (ssize_t x= 0; x < fkey.references_columns_size(); ++x)
1302
1262
  {
1309
1269
 
1310
1270
  destination.push_back(')');
1311
1271
 
1312
 
  if (fkey.has_update_option() and fkey.update_option() != Table::ForeignKeyConstraint::OPTION_UNDEF)
 
1272
  if (fkey.update_option() != Table::ForeignKeyConstraint::OPTION_UNDEF)
1313
1273
  {
1314
 
    destination.append(" ON UPDATE ");
 
1274
    destination.append(" ON UPDATE ", 11);
1315
1275
    transformForeignKeyOptionToSql(fkey.update_option(), destination);
1316
1276
  }
1317
1277
 
1318
 
  if (fkey.has_delete_option() and fkey.delete_option() != Table::ForeignKeyConstraint::OPTION_UNDEF)
 
1278
  if (fkey.delete_option() != Table::ForeignKeyConstraint::OPTION_UNDEF)
1319
1279
  {
1320
 
    destination.append(" ON DELETE ");
 
1280
    destination.append(" ON DELETE ", 11);
1321
1281
    transformForeignKeyOptionToSql(fkey.delete_option(), destination);
1322
1282
  }
1323
1283
 
1347
1307
  switch (field_type)
1348
1308
  {
1349
1309
    case Table::Field::DOUBLE:
1350
 
    destination.append(" DOUBLE");
 
1310
    destination.append(" DOUBLE", 7);
1351
1311
    if (field.has_numeric_options()
1352
1312
        && field.numeric_options().has_precision())
1353
1313
    {
1361
1321
    {
1362
1322
      if (field.string_options().has_collation()
1363
1323
          && field.string_options().collation().compare("binary") == 0)
1364
 
        destination.append(" VARBINARY(");
 
1324
        destination.append(" VARBINARY(", 11);
1365
1325
      else
1366
 
        destination.append(" VARCHAR(");
 
1326
        destination.append(" VARCHAR(", 9);
1367
1327
 
1368
 
      destination.append(boost::lexical_cast<string>(field.string_options().length()));
1369
 
      destination.append(")");
 
1328
      stringstream ss;
 
1329
      ss << field.string_options().length() << ")";
 
1330
      destination.append(ss.str());
1370
1331
    }
1371
1332
    break;
1372
1333
  case Table::Field::BLOB:
1373
1334
    {
1374
1335
      if (field.string_options().has_collation()
1375
1336
          && field.string_options().collation().compare("binary") == 0)
1376
 
        destination.append(" BLOB");
 
1337
        destination.append(" BLOB", 5);
1377
1338
      else
1378
 
        destination.append(" TEXT");
 
1339
        destination.append(" TEXT", 5);
1379
1340
    }
1380
1341
    break;
1381
1342
  case Table::Field::ENUM:
1382
1343
    {
1383
1344
      size_t num_field_values= field.enumeration_values().field_value_size();
1384
 
      destination.append(" ENUM(");
 
1345
      destination.append(" ENUM(", 6);
1385
1346
      for (size_t x= 0; x < num_field_values; ++x)
1386
1347
      {
1387
1348
        const string &type= field.enumeration_values().field_value(x);
1396
1357
      destination.push_back(')');
1397
1358
      break;
1398
1359
    }
1399
 
  case Table::Field::UUID:
1400
 
    destination.append(" UUID");
1401
 
    break;
1402
 
  case Table::Field::BOOLEAN:
1403
 
    destination.append(" BOOLEAN");
1404
 
    break;
1405
1360
  case Table::Field::INTEGER:
1406
 
    destination.append(" INT");
 
1361
    destination.append(" INT", 4);
1407
1362
    break;
1408
1363
  case Table::Field::BIGINT:
1409
 
    if (field.has_constraints() and
1410
 
        field.constraints().is_unsigned())
1411
 
    {
1412
 
      destination.append(" BIGINT UNSIGNED");
1413
 
    }
1414
 
    else
1415
 
    {
1416
 
      destination.append(" BIGINT");
1417
 
    }
 
1364
    destination.append(" BIGINT", 7);
1418
1365
    break;
1419
1366
  case Table::Field::DECIMAL:
1420
1367
    {
1421
 
      destination.append(" DECIMAL(");
 
1368
      destination.append(" DECIMAL(", 9);
1422
1369
      stringstream ss;
1423
1370
      ss << field.numeric_options().precision() << ",";
1424
1371
      ss << field.numeric_options().scale() << ")";
1426
1373
    }
1427
1374
    break;
1428
1375
  case Table::Field::DATE:
1429
 
    destination.append(" DATE");
1430
 
    break;
1431
 
 
1432
 
  case Table::Field::EPOCH:
1433
 
    if (field.time_options().microseconds())
1434
 
    {
1435
 
      destination.append(" TIMESTAMP(6)");
1436
 
    }
1437
 
    else
1438
 
    {
1439
 
      destination.append(" TIMESTAMP");
1440
 
    }
1441
 
    break;
1442
 
 
 
1376
    destination.append(" DATE", 5);
 
1377
    break;
 
1378
  case Table::Field::TIMESTAMP:
 
1379
    destination.append(" TIMESTAMP",  10);
 
1380
    break;
1443
1381
  case Table::Field::DATETIME:
1444
 
    destination.append(" DATETIME");
1445
 
    break;
1446
 
  case Table::Field::TIME:
1447
 
    destination.append(" TIME");
1448
 
    break;
 
1382
    destination.append(" DATETIME",  9);
 
1383
    break;
 
1384
  }
 
1385
 
 
1386
  if (field.type() == Table::Field::INTEGER || 
 
1387
      field.type() == Table::Field::BIGINT)
 
1388
  {
 
1389
    if (field.has_constraints() &&
 
1390
        field.constraints().has_is_unsigned() &&
 
1391
        field.constraints().is_unsigned())
 
1392
    {
 
1393
      destination.append(" UNSIGNED", 9);
 
1394
    }
1449
1395
  }
1450
1396
 
1451
1397
  if (field.type() == Table::Field::BLOB ||
1454
1400
    if (field.string_options().has_collation()
1455
1401
        && field.string_options().collation().compare("binary"))
1456
1402
    {
1457
 
      destination.append(" COLLATE ");
 
1403
      destination.append(" COLLATE ", 9);
1458
1404
      destination.append(field.string_options().collation());
1459
1405
    }
1460
1406
  }
1461
1407
 
1462
 
  if (field.has_constraints() and field.constraints().is_unique())
1463
 
  {
1464
 
    destination.append(" UNIQUE");
1465
 
  }
1466
 
 
1467
 
  if (field.has_constraints() && field.constraints().is_notnull())
1468
 
  {
1469
 
    destination.append(" NOT NULL");
1470
 
  }
1471
 
  else if (field.type() == Table::Field::EPOCH)
1472
 
  {
1473
 
    destination.append(" NULL");
1474
 
  }
 
1408
  if (field.has_constraints() &&
 
1409
      ! field.constraints().is_nullable())
 
1410
  {
 
1411
    destination.append(" NOT NULL", 9);
 
1412
  }
 
1413
  else if (field.type() == Table::Field::TIMESTAMP)
 
1414
    destination.append(" NULL", 5);
1475
1415
 
1476
1416
  if (field.type() == Table::Field::INTEGER || 
1477
1417
      field.type() == Table::Field::BIGINT)
1480
1420
    if (field.has_numeric_options() &&
1481
1421
        field.numeric_options().is_autoincrement())
1482
1422
    {
1483
 
      destination.append(" AUTO_INCREMENT");
 
1423
      destination.append(" AUTO_INCREMENT", 15);
1484
1424
    }
1485
1425
  }
1486
1426
 
1487
1427
  if (field.options().has_default_value())
1488
1428
  {
1489
 
    destination.append(" DEFAULT ");
 
1429
    destination.append(" DEFAULT ", 9);
1490
1430
    append_escaped_string(&destination, field.options().default_value());
1491
1431
  }
1492
1432
  else if (field.options().has_default_expression())
1493
1433
  {
1494
 
    destination.append(" DEFAULT ");
 
1434
    destination.append(" DEFAULT ", 9);
1495
1435
    destination.append(field.options().default_expression());
1496
1436
  }
1497
1437
  else if (field.options().has_default_bin_value())
1498
1438
  {
1499
1439
    const string &v= field.options().default_bin_value();
1500
1440
    if (v.length() == 0)
1501
 
    {
1502
 
      destination.append(" DEFAULT ''");
1503
 
    }
 
1441
      destination.append(" DEFAULT ''", 11);
1504
1442
    else
1505
1443
    {
1506
 
      destination.append(" DEFAULT 0x");
 
1444
      destination.append(" DEFAULT 0x", 11);
1507
1445
      for (size_t x= 0; x < v.length(); x++)
1508
1446
      {
1509
1447
        char hex[3];
1516
1454
           && field.options().default_null()
1517
1455
           && field.type() != Table::Field::BLOB)
1518
1456
  {
1519
 
    destination.append(" DEFAULT NULL");
 
1457
    destination.append(" DEFAULT NULL", 13);
1520
1458
  }
1521
1459
 
1522
1460
  if (field.has_options() && field.options().has_update_expression())
1523
1461
  {
1524
 
    destination.append(" ON UPDATE ");
 
1462
    destination.append(" ON UPDATE ", 11);
1525
1463
    destination.append(field.options().update_expression());
1526
1464
  }
1527
1465
 
1528
1466
  if (field.has_comment())
1529
1467
  {
1530
 
    destination.append(" COMMENT ");
 
1468
    destination.append(" COMMENT ", 9);
1531
1469
    append_escaped_string(&destination, field.comment(), quoted_default);
1532
1470
  }
1533
1471
  return NONE;
1557
1495
  case DRIZZLE_TYPE_NULL:
1558
1496
    assert(false); /* Not a user definable type */
1559
1497
    return Table::Field::INTEGER; /* unreachable */
1560
 
  case DRIZZLE_TYPE_MICROTIME:
1561
1498
  case DRIZZLE_TYPE_TIMESTAMP:
1562
 
    return Table::Field::EPOCH;
 
1499
    return Table::Field::TIMESTAMP;
1563
1500
  case DRIZZLE_TYPE_LONGLONG:
1564
1501
    return Table::Field::BIGINT;
1565
1502
  case DRIZZLE_TYPE_DATETIME:
1566
1503
    return Table::Field::DATETIME;
1567
 
  case DRIZZLE_TYPE_TIME:
1568
 
    return Table::Field::TIME;
1569
1504
  case DRIZZLE_TYPE_DATE:
1570
1505
    return Table::Field::DATE;
1571
1506
  case DRIZZLE_TYPE_VARCHAR:
1576
1511
    return Table::Field::ENUM;
1577
1512
  case DRIZZLE_TYPE_BLOB:
1578
1513
    return Table::Field::BLOB;
1579
 
  case DRIZZLE_TYPE_UUID:
1580
 
    return Table::Field::UUID;
1581
 
  case DRIZZLE_TYPE_BOOLEAN:
1582
 
    return Table::Field::BOOLEAN;
1583
1514
  }
1584
1515
 
1585
1516
  assert(false);