Add float/double data types
This commit is contained in:
parent
234e203eb3
commit
8b7e8772da
1 changed files with 28 additions and 24 deletions
|
|
@ -45,8 +45,8 @@ namespace TShockAPI.DB
|
|||
table.Columns.Select(
|
||||
c =>
|
||||
"'{0}' {1} {2} {3} {4} {5}".SFormat(c.Name, DbTypeToString(c.Type, c.Length), c.Primary ? "PRIMARY KEY" : "",
|
||||
c.AutoIncrement ? "AUTOINCREMENT" : "", c.NotNull ? "NOT NULL" : "",
|
||||
c.Unique ? "UNIQUE" : ""));
|
||||
c.AutoIncrement ? "AUTOINCREMENT" : "", c.NotNull ? "NOT NULL" : "",
|
||||
c.Unique ? "UNIQUE" : ""));
|
||||
return "CREATE TABLE {0} ({1})".SFormat(EscapeTableName(table.Name), string.Join(", ", columns));
|
||||
}
|
||||
|
||||
|
|
@ -57,14 +57,16 @@ namespace TShockAPI.DB
|
|||
|
||||
private static readonly Dictionary<MySqlDbType, string> TypesAsStrings = new Dictionary<MySqlDbType, string>
|
||||
{
|
||||
{MySqlDbType.VarChar, "TEXT"},
|
||||
{MySqlDbType.String, "TEXT"},
|
||||
{MySqlDbType.Text, "TEXT"},
|
||||
{MySqlDbType.TinyText, "TEXT"},
|
||||
{MySqlDbType.MediumText, "TEXT"},
|
||||
{MySqlDbType.LongText, "TEXT"},
|
||||
{MySqlDbType.Int32, "INTEGER"},
|
||||
{MySqlDbType.Blob, "BLOB"},
|
||||
{ MySqlDbType.VarChar, "TEXT" },
|
||||
{ MySqlDbType.String, "TEXT" },
|
||||
{ MySqlDbType.Text, "TEXT" },
|
||||
{ MySqlDbType.TinyText, "TEXT" },
|
||||
{ MySqlDbType.MediumText, "TEXT" },
|
||||
{ MySqlDbType.LongText, "TEXT" },
|
||||
{ MySqlDbType.Float, "REAL" },
|
||||
{ MySqlDbType.Double, "REAL" },
|
||||
{ MySqlDbType.Int32, "INTEGER" },
|
||||
{ MySqlDbType.Blob, "BLOB" },
|
||||
};
|
||||
|
||||
public string DbTypeToString(MySqlDbType type, int? length)
|
||||
|
|
@ -72,7 +74,7 @@ namespace TShockAPI.DB
|
|||
string ret;
|
||||
if (TypesAsStrings.TryGetValue(type, out ret))
|
||||
return ret;
|
||||
throw new NotImplementedException(Enum.GetName(typeof (MySqlDbType), type));
|
||||
throw new NotImplementedException(Enum.GetName(typeof(MySqlDbType), type));
|
||||
}
|
||||
|
||||
protected override string EscapeTableName(string table)
|
||||
|
|
@ -89,12 +91,12 @@ namespace TShockAPI.DB
|
|||
table.Columns.Select(
|
||||
c =>
|
||||
"{0} {1} {2} {3} {4}".SFormat(c.Name, DbTypeToString(c.Type, c.Length), c.Primary ? "PRIMARY KEY" : "",
|
||||
c.AutoIncrement ? "AUTO_INCREMENT" : "", c.NotNull ? "NOT NULL" : ""));
|
||||
c.AutoIncrement ? "AUTO_INCREMENT" : "", c.NotNull ? "NOT NULL" : ""));
|
||||
var uniques = table.Columns.Where(c => c.Unique).Select(c => c.Name);
|
||||
return "CREATE TABLE {0} ({1} {2})".SFormat(EscapeTableName(table.Name), string.Join(", ", columns),
|
||||
uniques.Count() > 0
|
||||
? ", UNIQUE({0})".SFormat(string.Join(", ", uniques))
|
||||
: "");
|
||||
uniques.Count() > 0
|
||||
? ", UNIQUE({0})".SFormat(string.Join(", ", uniques))
|
||||
: "");
|
||||
}
|
||||
|
||||
public override string RenameTable(string from, string to)
|
||||
|
|
@ -104,21 +106,23 @@ namespace TShockAPI.DB
|
|||
|
||||
private static readonly Dictionary<MySqlDbType, string> TypesAsStrings = new Dictionary<MySqlDbType, string>
|
||||
{
|
||||
{MySqlDbType.VarChar, "VARCHAR"},
|
||||
{MySqlDbType.String, "CHAR"},
|
||||
{MySqlDbType.Text, "TEXT"},
|
||||
{MySqlDbType.TinyText, "TINYTEXT"},
|
||||
{MySqlDbType.MediumText, "MEDIUMTEXT"},
|
||||
{MySqlDbType.LongText, "LONGTEXT"},
|
||||
{MySqlDbType.Int32, "INT"},
|
||||
{ MySqlDbType.VarChar, "VARCHAR" },
|
||||
{ MySqlDbType.String, "CHAR" },
|
||||
{ MySqlDbType.Text, "TEXT" },
|
||||
{ MySqlDbType.TinyText, "TINYTEXT" },
|
||||
{ MySqlDbType.MediumText, "MEDIUMTEXT" },
|
||||
{ MySqlDbType.LongText, "LONGTEXT" },
|
||||
{ MySqlDbType.Float, "FLOAT" },
|
||||
{ MySqlDbType.Double, "DOUBLE" },
|
||||
{ MySqlDbType.Int32, "INT" },
|
||||
};
|
||||
|
||||
public string DbTypeToString(MySqlDbType type, int? length)
|
||||
{
|
||||
string ret;
|
||||
if (TypesAsStrings.TryGetValue(type, out ret))
|
||||
return ret + (length != null ? "({0})".SFormat((int) length) : "");
|
||||
throw new NotImplementedException(Enum.GetName(typeof (MySqlDbType), type));
|
||||
return ret + (length != null ? "({0})".SFormat((int)length) : "");
|
||||
throw new NotImplementedException(Enum.GetName(typeof(MySqlDbType), type));
|
||||
}
|
||||
|
||||
protected override string EscapeTableName(string table)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue