2012-12-20 11:36:20 -01:00
|
|
|
|
using System;
|
2013-01-25 15:05:42 -01:00
|
|
|
|
using System.Collections.Generic;
|
2012-12-20 11:36:20 -01:00
|
|
|
|
using System.Linq;
|
2016-04-12 15:11:07 +02:00
|
|
|
|
using NPoco;
|
2015-01-09 12:04:33 +11:00
|
|
|
|
using Umbraco.Core.Logging;
|
2012-10-19 19:07:17 -02:00
|
|
|
|
using Umbraco.Core.Persistence.DatabaseAnnotations;
|
2012-12-07 13:48:38 -01:00
|
|
|
|
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
2012-10-19 13:20:57 -02:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Persistence.SqlSyntax
|
|
|
|
|
|
{
|
2012-10-23 08:09:01 -02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents an SqlSyntaxProvider for MySql
|
|
|
|
|
|
/// </summary>
|
2016-05-18 10:55:19 +02:00
|
|
|
|
[SqlSyntaxProvider(Constants.DbProviderNames.MySql)]
|
2013-03-09 10:43:34 -01:00
|
|
|
|
public class MySqlSyntaxProvider : SqlSyntaxProviderBase<MySqlSyntaxProvider>
|
2012-10-19 13:20:57 -02:00
|
|
|
|
{
|
2015-01-09 12:04:33 +11:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
|
|
public MySqlSyntaxProvider(ILogger logger)
|
2012-10-19 13:20:57 -02:00
|
|
|
|
{
|
2015-01-09 12:04:33 +11:00
|
|
|
|
_logger = logger;
|
2016-02-26 14:30:32 +00:00
|
|
|
|
|
2012-10-19 13:20:57 -02:00
|
|
|
|
AutoIncrementDefinition = "AUTO_INCREMENT";
|
|
|
|
|
|
IntColumnDefinition = "int(11)";
|
|
|
|
|
|
BoolColumnDefinition = "tinyint(1)";
|
2012-12-27 18:52:47 -01:00
|
|
|
|
DateTimeColumnDefinition = "TIMESTAMP";
|
2012-10-19 13:20:57 -02:00
|
|
|
|
TimeColumnDefinition = "time";
|
|
|
|
|
|
DecimalColumnDefinition = "decimal(38,6)";
|
2012-12-27 18:52:47 -01:00
|
|
|
|
GuidColumnDefinition = "char(36)";
|
2016-02-26 14:30:32 +00:00
|
|
|
|
|
2015-09-11 17:49:47 +02:00
|
|
|
|
DefaultValueFormat = "DEFAULT {0}";
|
2016-02-19 13:33:11 +01:00
|
|
|
|
|
|
|
|
|
|
InitColumnTypeMap();
|
2012-12-27 18:52:47 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-01-25 15:05:42 -01:00
|
|
|
|
public override IEnumerable<string> GetTablesInSchema(Database db)
|
|
|
|
|
|
{
|
2013-01-28 14:01:38 -01:00
|
|
|
|
List<string> list;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2014-03-13 20:42:57 +11:00
|
|
|
|
//needs to be open to read the schema name
|
2013-01-28 14:01:38 -01:00
|
|
|
|
db.OpenSharedConnection();
|
2014-03-13 20:42:57 +11:00
|
|
|
|
|
2013-01-28 14:01:38 -01:00
|
|
|
|
var items =
|
|
|
|
|
|
db.Fetch<dynamic>(
|
|
|
|
|
|
"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = @TableSchema",
|
2013-12-06 10:26:32 +11:00
|
|
|
|
new { TableSchema = db.Connection.Database });
|
2013-01-28 14:01:38 -01:00
|
|
|
|
list = items.Select(x => x.TABLE_NAME).Cast<string>().ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
db.CloseSharedConnection();
|
|
|
|
|
|
}
|
|
|
|
|
|
return list;
|
2013-01-25 15:05:42 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<ColumnInfo> GetColumnsInSchema(Database db)
|
|
|
|
|
|
{
|
2013-01-28 14:01:38 -01:00
|
|
|
|
List<ColumnInfo> list;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2014-03-13 20:42:57 +11:00
|
|
|
|
//needs to be open to read the schema name
|
2013-01-28 14:01:38 -01:00
|
|
|
|
db.OpenSharedConnection();
|
2014-03-13 20:42:57 +11:00
|
|
|
|
|
2013-01-28 14:01:38 -01:00
|
|
|
|
var items =
|
|
|
|
|
|
db.Fetch<dynamic>(
|
|
|
|
|
|
"SELECT TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION, COLUMN_DEFAULT, IS_NULLABLE, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = @TableSchema",
|
2013-12-06 10:26:32 +11:00
|
|
|
|
new { TableSchema = db.Connection.Database });
|
2013-01-28 14:01:38 -01:00
|
|
|
|
list =
|
|
|
|
|
|
items.Select(
|
|
|
|
|
|
item =>
|
2013-01-29 12:55:55 -01:00
|
|
|
|
new ColumnInfo(item.TABLE_NAME, item.COLUMN_NAME, int.Parse(item.ORDINAL_POSITION.ToString()), item.COLUMN_DEFAULT ?? "",
|
2013-01-28 14:01:38 -01:00
|
|
|
|
item.IS_NULLABLE, item.DATA_TYPE)).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
db.CloseSharedConnection();
|
|
|
|
|
|
}
|
|
|
|
|
|
return list;
|
2013-01-25 15:05:42 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<Tuple<string, string>> GetConstraintsPerTable(Database db)
|
|
|
|
|
|
{
|
2013-01-28 14:01:38 -01:00
|
|
|
|
List<Tuple<string, string>> list;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2014-03-13 20:42:57 +11:00
|
|
|
|
//needs to be open to read the schema name
|
|
|
|
|
|
db.OpenSharedConnection();
|
|
|
|
|
|
|
2013-01-28 14:01:38 -01:00
|
|
|
|
//Does not include indexes and constraints are named differently
|
|
|
|
|
|
var items =
|
|
|
|
|
|
db.Fetch<dynamic>(
|
|
|
|
|
|
"SELECT TABLE_NAME, CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_SCHEMA = @TableSchema",
|
2013-12-06 10:26:32 +11:00
|
|
|
|
new { TableSchema = db.Connection.Database });
|
2013-01-28 14:01:38 -01:00
|
|
|
|
list = items.Select(item => new Tuple<string, string>(item.TABLE_NAME, item.CONSTRAINT_NAME)).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
db.CloseSharedConnection();
|
|
|
|
|
|
}
|
|
|
|
|
|
return list;
|
2013-01-25 15:05:42 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<Tuple<string, string, string>> GetConstraintsPerColumn(Database db)
|
|
|
|
|
|
{
|
2013-01-28 14:01:38 -01:00
|
|
|
|
List<Tuple<string, string, string>> list;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2014-03-13 20:42:57 +11:00
|
|
|
|
//needs to be open to read the schema name
|
|
|
|
|
|
db.OpenSharedConnection();
|
|
|
|
|
|
|
2013-01-28 14:01:38 -01:00
|
|
|
|
//Does not include indexes and constraints are named differently
|
|
|
|
|
|
var items =
|
|
|
|
|
|
db.Fetch<dynamic>(
|
|
|
|
|
|
"SELECT TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = @TableSchema",
|
2013-12-06 10:26:32 +11:00
|
|
|
|
new { TableSchema = db.Connection.Database });
|
2013-01-28 14:01:38 -01:00
|
|
|
|
list =
|
|
|
|
|
|
items.Select(
|
|
|
|
|
|
item =>
|
|
|
|
|
|
new Tuple<string, string, string>(item.TABLE_NAME, item.COLUMN_NAME, item.CONSTRAINT_NAME))
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
db.CloseSharedConnection();
|
|
|
|
|
|
}
|
|
|
|
|
|
return list;
|
2013-01-25 15:05:42 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-03-12 17:17:52 +11:00
|
|
|
|
public override IEnumerable<Tuple<string, string, string, bool>> GetDefinedIndexes(Database db)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<Tuple<string, string, string, bool>> list;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2014-03-13 20:42:57 +11:00
|
|
|
|
//needs to be open to read the schema name
|
|
|
|
|
|
db.OpenSharedConnection();
|
|
|
|
|
|
|
2014-03-12 17:17:52 +11:00
|
|
|
|
var indexes =
|
2014-03-14 13:04:20 +11:00
|
|
|
|
db.Fetch<dynamic>(@"SELECT DISTINCT
|
|
|
|
|
|
TABLE_NAME, INDEX_NAME, COLUMN_NAME, CASE NON_UNIQUE WHEN 1 THEN 0 ELSE 1 END AS `UNIQUE`
|
|
|
|
|
|
FROM INFORMATION_SCHEMA.STATISTICS
|
2014-03-12 17:17:52 +11:00
|
|
|
|
WHERE TABLE_SCHEMA = @TableSchema
|
2014-03-14 13:04:20 +11:00
|
|
|
|
AND INDEX_NAME <> COLUMN_NAME AND INDEX_NAME <> 'PRIMARY'
|
2014-03-12 17:17:52 +11:00
|
|
|
|
ORDER BY TABLE_NAME, INDEX_NAME",
|
|
|
|
|
|
new { TableSchema = db.Connection.Database });
|
|
|
|
|
|
list =
|
|
|
|
|
|
indexes.Select(
|
|
|
|
|
|
item =>
|
2014-03-12 18:37:22 +11:00
|
|
|
|
new Tuple<string, string, string, bool>(item.TABLE_NAME, item.INDEX_NAME, item.COLUMN_NAME, item.UNIQUE == 1))
|
2014-03-12 17:17:52 +11:00
|
|
|
|
.ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
db.CloseSharedConnection();
|
|
|
|
|
|
}
|
|
|
|
|
|
return list;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-12-27 18:52:47 -01:00
|
|
|
|
public override bool DoesTableExist(Database db, string tableName)
|
|
|
|
|
|
{
|
2013-01-18 09:00:18 -01:00
|
|
|
|
long result;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2014-03-13 20:42:57 +11:00
|
|
|
|
//needs to be open to read the schema name
|
2013-01-18 09:00:18 -01:00
|
|
|
|
db.OpenSharedConnection();
|
2014-03-13 20:42:57 +11:00
|
|
|
|
|
2013-01-18 09:00:18 -01:00
|
|
|
|
result =
|
|
|
|
|
|
db.ExecuteScalar<long>("SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES " +
|
|
|
|
|
|
"WHERE TABLE_NAME = @TableName AND " +
|
|
|
|
|
|
"TABLE_SCHEMA = @TableSchema",
|
2013-12-06 10:26:32 +11:00
|
|
|
|
new { TableName = tableName, TableSchema = db.Connection.Database });
|
2013-01-18 09:00:18 -01:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
db.CloseSharedConnection();
|
|
|
|
|
|
}
|
2012-12-27 18:52:47 -01:00
|
|
|
|
|
|
|
|
|
|
return result > 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override bool SupportsClustered()
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override bool SupportsIdentityInsert()
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
2012-10-19 13:20:57 -02:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-09-11 11:49:37 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This is used ONLY if we need to format datetime without using SQL parameters (i.e. during migrations)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="date"></param>
|
|
|
|
|
|
/// <param name="includeTime"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// MySQL has a DateTime standard that is unambiguous and works on all servers:
|
|
|
|
|
|
/// YYYYMMDDHHMMSS
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public override string FormatDateTime(DateTime date, bool includeTime = true)
|
|
|
|
|
|
{
|
2015-09-11 13:55:13 +02:00
|
|
|
|
return includeTime ? date.ToString("yyyyMMddHHmmss") : date.ToString("yyyyMMdd");
|
2015-09-11 11:49:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-10-19 13:20:57 -02:00
|
|
|
|
public override string GetQuotedTableName(string tableName)
|
|
|
|
|
|
{
|
|
|
|
|
|
return string.Format("`{0}`", tableName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override string GetQuotedColumnName(string columnName)
|
|
|
|
|
|
{
|
|
|
|
|
|
return string.Format("`{0}`", columnName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override string GetQuotedName(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return string.Format("`{0}`", name);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-10-19 19:07:17 -02:00
|
|
|
|
public override string GetSpecialDbType(SpecialDbTypes dbTypes)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (dbTypes == SpecialDbTypes.NCHAR)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "CHAR";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (dbTypes == SpecialDbTypes.NTEXT)
|
|
|
|
|
|
return "LONGTEXT";
|
|
|
|
|
|
|
|
|
|
|
|
return "NVARCHAR";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-12-27 18:52:47 -01:00
|
|
|
|
public override string Format(TableDefinition table)
|
|
|
|
|
|
{
|
|
|
|
|
|
string primaryKey = string.Empty;
|
|
|
|
|
|
var columnDefinition = table.Columns.FirstOrDefault(x => x.IsPrimaryKey);
|
2014-03-14 17:11:21 +11:00
|
|
|
|
if (columnDefinition != null)
|
2012-12-27 18:52:47 -01:00
|
|
|
|
{
|
|
|
|
|
|
string columns = string.IsNullOrEmpty(columnDefinition.PrimaryKeyColumns)
|
|
|
|
|
|
? GetQuotedColumnName(columnDefinition.Name)
|
2012-12-27 19:53:01 -01:00
|
|
|
|
: string.Join(", ", columnDefinition.PrimaryKeyColumns
|
|
|
|
|
|
.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
|
|
|
|
|
|
.Select(GetQuotedColumnName));
|
2012-12-27 18:52:47 -01:00
|
|
|
|
|
|
|
|
|
|
primaryKey = string.Format(", \nPRIMARY KEY {0} ({1})", columnDefinition.IsIndexed ? "CLUSTERED" : "NONCLUSTERED", columns);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var statement = string.Format(CreateTable, GetQuotedTableName(table.Name), Format(table.Columns), primaryKey);
|
|
|
|
|
|
|
|
|
|
|
|
return statement;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-12-19 15:23:05 -01:00
|
|
|
|
public override string Format(IndexDefinition index)
|
2012-10-19 19:07:17 -02:00
|
|
|
|
{
|
2012-12-19 15:23:05 -01:00
|
|
|
|
string name = string.IsNullOrEmpty(index.Name)
|
|
|
|
|
|
? string.Format("IX_{0}_{1}", index.TableName, index.ColumnName)
|
|
|
|
|
|
: index.Name;
|
|
|
|
|
|
|
|
|
|
|
|
string columns = index.Columns.Any()
|
|
|
|
|
|
? string.Join(",", index.Columns.Select(x => GetQuotedColumnName(x.Name)))
|
|
|
|
|
|
: GetQuotedColumnName(index.ColumnName);
|
|
|
|
|
|
|
|
|
|
|
|
return string.Format(CreateIndex,
|
|
|
|
|
|
GetQuotedName(name),
|
2013-12-06 10:26:32 +11:00
|
|
|
|
GetQuotedTableName(index.TableName),
|
2012-12-19 15:23:05 -01:00
|
|
|
|
columns);
|
2012-10-19 19:07:17 -02:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-12-27 18:52:47 -01:00
|
|
|
|
public override string Format(ForeignKeyDefinition foreignKey)
|
2012-10-19 19:07:17 -02:00
|
|
|
|
{
|
2012-12-27 18:52:47 -01:00
|
|
|
|
return string.Format(CreateForeignKeyConstraint,
|
|
|
|
|
|
GetQuotedTableName(foreignKey.ForeignTable),
|
|
|
|
|
|
GetQuotedColumnName(foreignKey.ForeignColumns.First()),
|
|
|
|
|
|
GetQuotedTableName(foreignKey.PrimaryTable),
|
|
|
|
|
|
GetQuotedColumnName(foreignKey.PrimaryColumns.First()),
|
|
|
|
|
|
FormatCascade("DELETE", foreignKey.OnDelete),
|
|
|
|
|
|
FormatCascade("UPDATE", foreignKey.OnUpdate));
|
|
|
|
|
|
}
|
2012-10-19 19:07:17 -02:00
|
|
|
|
|
2012-12-27 18:52:47 -01:00
|
|
|
|
public override string FormatPrimaryKey(TableDefinition table)
|
|
|
|
|
|
{
|
|
|
|
|
|
return string.Empty;
|
2012-10-19 19:07:17 -02:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-12-27 18:52:47 -01:00
|
|
|
|
protected override string FormatConstraint(ColumnDefinition column)
|
2012-12-26 14:44:42 -01:00
|
|
|
|
{
|
2012-12-27 18:52:47 -01:00
|
|
|
|
return string.Empty;
|
2012-12-26 14:44:42 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-12-19 15:23:05 -01:00
|
|
|
|
protected override string FormatIdentity(ColumnDefinition column)
|
2012-10-19 19:07:17 -02:00
|
|
|
|
{
|
2012-12-19 15:23:05 -01:00
|
|
|
|
return column.IsIdentity ? AutoIncrementDefinition : string.Empty;
|
2012-10-19 19:07:17 -02:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-12-19 15:23:05 -01:00
|
|
|
|
protected override string FormatDefaultValue(ColumnDefinition column)
|
2012-10-19 19:07:17 -02:00
|
|
|
|
{
|
2012-12-19 15:23:05 -01:00
|
|
|
|
if (column.DefaultValue == null)
|
|
|
|
|
|
return string.Empty;
|
2012-10-19 19:07:17 -02:00
|
|
|
|
|
2015-09-11 17:49:47 +02:00
|
|
|
|
//hack - probably not needed with latest changes
|
|
|
|
|
|
if (column.DefaultValue.ToString().ToLower().Equals("getdate()".ToLower()))
|
|
|
|
|
|
column.DefaultValue = SystemMethods.CurrentDateTime;
|
|
|
|
|
|
|
2012-12-19 15:23:05 -01:00
|
|
|
|
// see if this is for a system method
|
|
|
|
|
|
if (column.DefaultValue is SystemMethods)
|
2012-10-19 19:07:17 -02:00
|
|
|
|
{
|
2012-12-19 15:23:05 -01:00
|
|
|
|
string method = FormatSystemMethods((SystemMethods)column.DefaultValue);
|
|
|
|
|
|
if (string.IsNullOrEmpty(method))
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
return string.Format(DefaultValueFormat, method);
|
2012-10-19 19:07:17 -02:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-09-11 17:49:47 +02:00
|
|
|
|
//needs quote
|
|
|
|
|
|
return string.Format(DefaultValueFormat, string.Format("'{0}'", column.DefaultValue));
|
2012-10-19 13:20:57 -02:00
|
|
|
|
}
|
2012-11-30 15:01:52 -01:00
|
|
|
|
|
2012-12-19 15:23:05 -01:00
|
|
|
|
protected override string FormatPrimaryKey(ColumnDefinition column)
|
2012-11-30 15:01:52 -01:00
|
|
|
|
{
|
2012-12-19 15:23:05 -01:00
|
|
|
|
return string.Empty;
|
2012-11-30 15:01:52 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override string FormatSystemMethods(SystemMethods systemMethod)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (systemMethod)
|
|
|
|
|
|
{
|
|
|
|
|
|
case SystemMethods.NewGuid:
|
2015-09-11 17:49:47 +02:00
|
|
|
|
return null; // NOT SUPPORTED!
|
2016-02-26 14:30:32 +00:00
|
|
|
|
//return "NEWID()";
|
2012-11-30 15:01:52 -01:00
|
|
|
|
case SystemMethods.CurrentDateTime:
|
2015-09-11 17:49:47 +02:00
|
|
|
|
return "CURRENT_TIMESTAMP";
|
2016-02-26 14:30:32 +00:00
|
|
|
|
//case SystemMethods.NewSequentialId:
|
|
|
|
|
|
// return "NEWSEQUENTIALID()";
|
|
|
|
|
|
//case SystemMethods.CurrentUTCDateTime:
|
|
|
|
|
|
// return "GETUTCDATE()";
|
2012-11-30 15:01:52 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-12-20 11:36:20 -01:00
|
|
|
|
public override string DeleteDefaultConstraint
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2013-12-06 10:26:32 +11:00
|
|
|
|
return "ALTER TABLE {0} ALTER COLUMN {1} DROP DEFAULT";
|
2012-12-20 11:36:20 -01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-30 15:01:52 -01:00
|
|
|
|
public override string AlterColumn { get { return "ALTER TABLE {0} MODIFY COLUMN {1}"; } }
|
|
|
|
|
|
|
2012-12-27 18:52:47 -01:00
|
|
|
|
//CREATE TABLE {0} ({1}) ENGINE = INNODB versus CREATE TABLE {0} ({1}) ENGINE = MYISAM ?
|
|
|
|
|
|
public override string CreateTable { get { return "CREATE TABLE {0} ({1}{2})"; } }
|
|
|
|
|
|
|
|
|
|
|
|
public override string CreateIndex { get { return "CREATE INDEX {0} ON {1} ({2})"; } }
|
|
|
|
|
|
|
|
|
|
|
|
public override string CreateForeignKeyConstraint { get { return "ALTER TABLE {0} ADD FOREIGN KEY ({1}) REFERENCES {2} ({3}){4}{5}"; } }
|
|
|
|
|
|
|
2013-12-06 10:26:32 +11:00
|
|
|
|
public override string DeleteConstraint { get { return "ALTER TABLE {0} DROP {1} {2}"; } }
|
2012-11-30 15:01:52 -01:00
|
|
|
|
|
2012-12-20 11:36:20 -01:00
|
|
|
|
public override string DropIndex { get { return "DROP INDEX {0} ON {1}"; } }
|
|
|
|
|
|
|
2012-12-27 18:52:47 -01:00
|
|
|
|
public override string RenameColumn { get { return "ALTER TABLE {0} CHANGE {1} {2}"; } }
|
2016-04-20 12:50:52 +02:00
|
|
|
|
public override string ConvertIntegerToOrderableString { get { return "LPAD(FORMAT({0}, 0), 8, '0')"; } }
|
2016-02-26 14:30:32 +00:00
|
|
|
|
public override string ConvertDateToOrderableString { get { return "DATE_FORMAT({0}, '%Y%m%d')"; } }
|
2016-04-20 12:50:52 +02:00
|
|
|
|
public override string ConvertDecimalToOrderableString { get { return "LPAD(FORMAT({0}, 9), 20, '0')"; } }
|
2013-02-25 13:14:26 -01:00
|
|
|
|
|
|
|
|
|
|
public override bool? SupportsCaseInsensitiveQueries(Database db)
|
|
|
|
|
|
{
|
2013-02-25 14:42:07 -01:00
|
|
|
|
bool? supportsCaseInsensitiveQueries = null;
|
2013-02-25 13:14:26 -01:00
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
db.OpenSharedConnection();
|
2013-02-25 14:42:07 -01:00
|
|
|
|
// Need 4 @ signs as it is regarded as a parameter, @@ escapes it once, @@@@ escapes it twice
|
|
|
|
|
|
var lowerCaseTableNames = db.Fetch<int>("SELECT @@@@Global.lower_case_table_names");
|
2013-12-06 10:26:32 +11:00
|
|
|
|
|
|
|
|
|
|
if (lowerCaseTableNames.Any())
|
2013-07-23 15:38:26 +02:00
|
|
|
|
supportsCaseInsensitiveQueries = lowerCaseTableNames.First() == 1;
|
2013-02-25 14:42:07 -01:00
|
|
|
|
}
|
2013-12-06 10:26:32 +11:00
|
|
|
|
catch (Exception ex)
|
2013-02-25 14:42:07 -01:00
|
|
|
|
{
|
2015-01-09 12:04:33 +11:00
|
|
|
|
_logger.Error<MySqlSyntaxProvider>("Error querying for lower_case support", ex);
|
2013-02-25 13:14:26 -01:00
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
db.CloseSharedConnection();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Could return null, which means testing failed,
|
|
|
|
|
|
// add message to check with their hosting provider
|
|
|
|
|
|
return supportsCaseInsensitiveQueries;
|
|
|
|
|
|
}
|
2014-02-17 21:38:13 +11:00
|
|
|
|
|
|
|
|
|
|
public override string EscapeString(string val)
|
|
|
|
|
|
{
|
2016-04-12 15:11:07 +02:00
|
|
|
|
return NPocoDatabaseExtensions.EscapeAtSymbols(MySql.Data.MySqlClient.MySqlHelper.EscapeString(val));
|
2014-02-17 21:38:13 +11:00
|
|
|
|
}
|
2012-10-19 13:20:57 -02:00
|
|
|
|
}
|
|
|
|
|
|
}
|