mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 10:08:19 +08:00
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectView>ShowAllFiles</ProjectView>
|
||||
<ProjectView>ProjectFiles</ProjectView>
|
||||
</PropertyGroup>
|
||||
</Project>
|
@@ -17,10 +17,10 @@ namespace SqlSugar
|
||||
}
|
||||
|
||||
#region Private Fileds
|
||||
private List<JoinQueryInfo> _JoinQueryInfos;
|
||||
protected List<JoinQueryInfo> _JoinQueryInfos;
|
||||
private List<string> _WhereInfos;
|
||||
private string _HavingInfos;
|
||||
private string _TableNameString;
|
||||
protected string _TableNameString;
|
||||
#endregion
|
||||
|
||||
#region Service object
|
||||
|
95
SqlSugar/Realization/MySql/Core/DbBind/MySqlDbBind.cs
Normal file
95
SqlSugar/Realization/MySql/Core/DbBind/MySqlDbBind.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class MySqlDbBind : DbBindProvider
|
||||
{
|
||||
public override string ChangeDBTypeToCSharpType(string typeName)
|
||||
{
|
||||
string reval;
|
||||
switch (typeName.ToLower())
|
||||
{
|
||||
case "int":
|
||||
reval = "int";
|
||||
break;
|
||||
case "text":
|
||||
reval = "string";
|
||||
break;
|
||||
case "bigint":
|
||||
reval = "long";
|
||||
break;
|
||||
case "binary":
|
||||
reval = "object";
|
||||
break;
|
||||
case "bit":
|
||||
reval = "bool";
|
||||
break;
|
||||
case "char":
|
||||
reval = "string";
|
||||
break;
|
||||
case "datetime":
|
||||
case "date":
|
||||
case "datetime2":
|
||||
reval = "dateTime";
|
||||
break;
|
||||
case "single":
|
||||
case "decimal":
|
||||
reval = "decimal";
|
||||
break;
|
||||
case "float":
|
||||
reval = "double";
|
||||
break;
|
||||
case "image":
|
||||
reval = "byte[]";
|
||||
break;
|
||||
case "money":
|
||||
reval = "decimal";
|
||||
break;
|
||||
case "nchar":
|
||||
reval = "string";
|
||||
break;
|
||||
case "ntext":
|
||||
reval = "string";
|
||||
break;
|
||||
case "numeric":
|
||||
reval = "decimal";
|
||||
break;
|
||||
case "nvarchar":
|
||||
reval = "string";
|
||||
break;
|
||||
case "real":
|
||||
reval = "float";
|
||||
break;
|
||||
case "smalldatetime":
|
||||
reval = "dateTime";
|
||||
break;
|
||||
case "smallint":
|
||||
reval = "short";
|
||||
break;
|
||||
case "smallmoney":
|
||||
reval = "decimal";
|
||||
break;
|
||||
case "timestamp":
|
||||
reval = "dateTime";
|
||||
break;
|
||||
case "tinyint":
|
||||
reval = "byte";
|
||||
break;
|
||||
case "uniqueidentifier":
|
||||
reval = "guid";
|
||||
break;
|
||||
case "varbinary":
|
||||
reval = "byte[]";
|
||||
break;
|
||||
case "varchar":
|
||||
reval = "string";
|
||||
break;
|
||||
case "Variant":
|
||||
reval = "object";
|
||||
break;
|
||||
default:
|
||||
reval = "other";
|
||||
break;
|
||||
}
|
||||
return reval;
|
||||
}
|
||||
}
|
||||
}
|
42
SqlSugar/Realization/MySql/Core/SqlBuilder/MySqlBuilder.cs
Normal file
42
SqlSugar/Realization/MySql/Core/SqlBuilder/MySqlBuilder.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class MySqlBuilder : SqlBuilderProvider
|
||||
{
|
||||
|
||||
public override string GetTranslationTableName(string name)
|
||||
{
|
||||
Check.ArgumentNullException(name, string.Format(ErrorMessage.ObjNotExist, "Table Name"));
|
||||
var context = this.Context;
|
||||
var mappingInfo = context
|
||||
.MappingTables
|
||||
.FirstOrDefault(it => it.EntityName.Equals(name, StringComparison.CurrentCultureIgnoreCase));
|
||||
return "`" + (mappingInfo == null ? name : mappingInfo.DbTableName) + "`";
|
||||
}
|
||||
public override string GetTranslationColumnName(string entityName, string propertyName)
|
||||
{
|
||||
Check.ArgumentNullException(entityName, string.Format(ErrorMessage.ObjNotExist, "Table Name"));
|
||||
Check.ArgumentNullException(propertyName, string.Format(ErrorMessage.ObjNotExist, "Column Name"));
|
||||
var context = this.Context;
|
||||
var mappingInfo = context
|
||||
.MappingColumns
|
||||
.FirstOrDefault(it =>
|
||||
it.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase) &&
|
||||
it.PropertyName.Equals(propertyName, StringComparison.CurrentCultureIgnoreCase));
|
||||
return (mappingInfo == null ? "`" + propertyName + "`" : "`" + mappingInfo.DbColumnName + "`");
|
||||
}
|
||||
|
||||
public override string GetTranslationColumnName(string propertyName)
|
||||
{
|
||||
return "`" + propertyName + "`";
|
||||
}
|
||||
|
||||
public override string GetNoTranslationColumnName(string name)
|
||||
{
|
||||
return name == null ? string.Empty : Regex.Match(name, @"\`(.*?)\`").Groups[1].Value;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class MySqlDeleteBuilder : DeleteBuilder
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class MySqlExpressionContext : ExpressionContext, ILambdaExpressions
|
||||
{
|
||||
public SqlSugarClient Context { get; set; }
|
||||
public MySqlExpressionContext()
|
||||
{
|
||||
base.DbMehtods = new MySqlMethod();
|
||||
}
|
||||
|
||||
}
|
||||
public class MySqlMethod : DefaultDbMethod, IDbMethods
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class MySqlInsertBuilder : InsertBuilder
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,86 @@
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public partial class MySqlQueryBuilder : QueryBuilder
|
||||
{
|
||||
#region Sql Template
|
||||
public override string PageTempalte
|
||||
{
|
||||
get
|
||||
{
|
||||
/*
|
||||
SELECT * FROM TABLE WHERE CONDITION ORDER BY ID DESC LIMIT 0,10
|
||||
*/
|
||||
var template = "SELECT {0} FROM {1} {2} {3} {4} LIMIT {5},{6}";
|
||||
return template;
|
||||
}
|
||||
}
|
||||
public override string DefaultOrderByTemplate
|
||||
{
|
||||
get
|
||||
{
|
||||
return "ORDER BY NOW() ";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Common Methods
|
||||
|
||||
public override string ToSqlString()
|
||||
{
|
||||
sql = new StringBuilder();
|
||||
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, (Skip != null || Take != null) ? null : GetOrderByString);
|
||||
if (IsCount) { return sql.ToString(); }
|
||||
if (Skip != null && Take == null)
|
||||
{
|
||||
if (this.OrderByValue == "ORDER BY ") this.OrderByValue += GetSelectValue.Split(',')[0];
|
||||
return string.Format(PageTempalte, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, (Skip != null || Take != null) ? null : GetOrderByString, Skip.ObjToInt() + 1, long.MaxValue);
|
||||
}
|
||||
else if (Skip == null && Take != null)
|
||||
{
|
||||
if (this.OrderByValue == "ORDER BY ") this.OrderByValue += GetSelectValue.Split(',')[0];
|
||||
return string.Format(PageTempalte, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, GetOrderByString, 1, Take.ObjToInt());
|
||||
}
|
||||
else if (Skip != null && Take != null)
|
||||
{
|
||||
if (this.OrderByValue == "ORDER BY ") this.OrderByValue += GetSelectValue.Split(',')[0];
|
||||
return string.Format(PageTempalte, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, GetOrderByString, Skip.ObjToInt() > 0 ? Skip.ObjToInt() + 1 : 0, Take);
|
||||
}
|
||||
else
|
||||
{
|
||||
return sql.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Get SQL Partial
|
||||
public override string GetSelectValue
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.IsCount) return "COUNT(1) AS `Count` ";
|
||||
string reval = string.Empty;
|
||||
if (this.SelectValue == null || this.SelectValue is string)
|
||||
{
|
||||
reval = GetSelectValueByString();
|
||||
}
|
||||
else
|
||||
{
|
||||
reval = GetSelectValueByExpression();
|
||||
}
|
||||
if (this.SelectType == ResolveExpressType.SelectMultiple)
|
||||
{
|
||||
this.SelectCacheKey = this.SelectCacheKey + string.Join("-", this._JoinQueryInfos.Select(it => it.TableName));
|
||||
}
|
||||
return reval;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class MySqlUpdateBuilder : UpdateBuilder
|
||||
{
|
||||
}
|
||||
}
|
19
SqlSugar/Realization/MySql/Queryable/MySqlQueryable.cs
Normal file
19
SqlSugar/Realization/MySql/Queryable/MySqlQueryable.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class MySqlQueryable<T>:QueryableProvider<T>
|
||||
{
|
||||
|
||||
}
|
||||
public class MySqlQueryable<T,T2> : QueryableProvider<T,T2>
|
||||
{
|
||||
|
||||
}
|
||||
public class MySqlQueryable<T, T2,T3> : QueryableProvider<T, T2,T3>
|
||||
{
|
||||
|
||||
}
|
||||
public class MySqlQueryable<T, T2,T3,T4> : QueryableProvider<T, T2,T3,T4>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -1,12 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
namespace SqlSugar
|
||||
{
|
||||
public partial class DbType
|
||||
{
|
||||
public const string SqlServer = "SqlServer";
|
||||
public const string MySql = "MySql";
|
||||
}
|
||||
}
|
||||
|
94
SqlSugar/Realization/SqlServer/MySqlProvider.cs
Normal file
94
SqlSugar/Realization/SqlServer/MySqlProvider.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class MySqlProvider : AdoProvider
|
||||
{
|
||||
public MySqlProvider() {}
|
||||
public override IDbConnection Connection
|
||||
{
|
||||
get
|
||||
{
|
||||
if (base._DbConnection == null)
|
||||
{
|
||||
base._DbConnection = new MySqlConnection(base.Context.CurrentConnectionConfig.ConnectionString);
|
||||
}
|
||||
return base._DbConnection;
|
||||
}
|
||||
set
|
||||
{
|
||||
base._DbConnection = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Only SqlServer
|
||||
/// </summary>
|
||||
/// <param name="transactionName"></param>
|
||||
public override void BeginTran(string transactionName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// Only SqlServer
|
||||
/// </summary>
|
||||
/// <param name="iso"></param>
|
||||
/// <param name="transactionName"></param>
|
||||
public override void BeginTran(IsolationLevel iso, string transactionName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public override IDataAdapter GetAdapter()
|
||||
{
|
||||
return new MySqlDataAdapter();
|
||||
}
|
||||
public override IDbCommand GetCommand(string sql, SugarParameter[] pars)
|
||||
{
|
||||
MySqlCommand sqlCommand = new MySqlCommand(sql, (MySqlConnection)this.Connection);
|
||||
sqlCommand.CommandType = this.CommandType;
|
||||
sqlCommand.CommandTimeout = this.CommandTimeOut;
|
||||
if (this.Transaction != null)
|
||||
{
|
||||
sqlCommand.Transaction = (MySqlTransaction)this.Transaction;
|
||||
}
|
||||
if (pars.IsValuable())
|
||||
{
|
||||
IDataParameter[] ipars= ToIDbDataParameter(pars);
|
||||
sqlCommand.Parameters.AddRange((SqlParameter[])ipars);
|
||||
}
|
||||
CheckConnection();
|
||||
return sqlCommand;
|
||||
}
|
||||
public override void SetCommandToAdapter(IDataAdapter dataAdapter, IDbCommand command)
|
||||
{
|
||||
((MySqlDataAdapter)dataAdapter).SelectCommand = (MySqlCommand)command;
|
||||
}
|
||||
/// <summary>
|
||||
/// if mysql return MySqlParameter[] pars
|
||||
/// if sqlerver return SqlParameter[] pars ...
|
||||
/// </summary>
|
||||
/// <param name="pars"></param>
|
||||
/// <returns></returns>
|
||||
public override IDataParameter[] ToIDbDataParameter(params SugarParameter[] pars)
|
||||
{
|
||||
if (pars == null || pars.Length == 0) return null;
|
||||
SqlParameter[] reval = new SqlParameter[pars.Length];
|
||||
int i = 0;
|
||||
foreach (var par in pars)
|
||||
{
|
||||
if (par.Value == null) par.Value = DBNull.Value;
|
||||
var p = new SqlParameter();
|
||||
p.ParameterName = par.ParameterName;
|
||||
p.UdtTypeName = par.UdtTypeName;
|
||||
p.Size = par.Size;
|
||||
p.Value = par.Value;
|
||||
p.DbType = par.DbType;
|
||||
reval[i] =p;
|
||||
++i;
|
||||
}
|
||||
return reval;
|
||||
}
|
||||
}
|
||||
}
|
@@ -31,6 +31,9 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MySql.Data.6.9.9\lib\net40\MySql.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>Lib\Newtonsoft.Json.dll</HintPath>
|
||||
@@ -60,6 +63,14 @@
|
||||
<Compile Include="Abstract\UpdateProvider\UpdateableProvider.cs" />
|
||||
<Compile Include="Entities\SugarMessageResult.cs" />
|
||||
<Compile Include="Interface\IConnectionConfig.cs" />
|
||||
<Compile Include="Realization\MySql\Core\DbBind\MySqlDbBind.cs" />
|
||||
<Compile Include="Realization\MySql\Core\SqlBuilder\MySqlBuilder.cs" />
|
||||
<Compile Include="Realization\MySql\Core\SqlBuilder\MySqlDeleteBuilder.cs" />
|
||||
<Compile Include="Realization\MySql\Core\SqlBuilder\MySqlExpressionContext.cs" />
|
||||
<Compile Include="Realization\MySql\Core\SqlBuilder\MySqlInsertBuilder.cs" />
|
||||
<Compile Include="Realization\MySql\Core\SqlBuilder\MySqlQueryBuilder.cs" />
|
||||
<Compile Include="Realization\MySql\Core\SqlBuilder\MySqlUpdateBuilder.cs" />
|
||||
<Compile Include="Realization\MySql\Queryable\MySqlQueryable.cs" />
|
||||
<Compile Include="Realization\SqlServer\Core\SqlBuilder\SqlServerDeleteBuilder.cs" />
|
||||
<Compile Include="Realization\SqlServer\Core\SqlBuilder\SqlServerInsertBuilder.cs" />
|
||||
<Compile Include="Entities\EntityColumnInfo.cs" />
|
||||
@@ -93,6 +104,7 @@
|
||||
<Compile Include="Realization\SqlServer\Core\SqlBuilder\SqlServerBuilder.cs" />
|
||||
<Compile Include="Realization\SqlServer\DbMaintenance\SqlServerDbMaintenance.cs" />
|
||||
<Compile Include="Realization\SqlServer\Core\SqlBuilder\SqlServerQueryBuilder.cs" />
|
||||
<Compile Include="Realization\SqlServer\MySqlProvider.cs" />
|
||||
<Compile Include="Realization\SqlServer\SqlServerProvider.cs" />
|
||||
<Compile Include="Realization\SqlServer\Queryable\SqlServerQueryable.cs" />
|
||||
<Compile Include="Entities\SugarDynamic.cs" />
|
||||
@@ -166,10 +178,13 @@
|
||||
<Content Include="Lib\Newtonsoft.Json.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Realization\MySql\" />
|
||||
<Folder Include="Realization\Oracle\" />
|
||||
<Folder Include="Realization\Sqlite\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
9
SqlSugar/app.config
Normal file
9
SqlSugar/app.config
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<system.data>
|
||||
<DbProviderFactories>
|
||||
<remove invariant="MySql.Data.MySqlClient" />
|
||||
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
|
||||
</DbProviderFactories>
|
||||
</system.data>
|
||||
</configuration>
|
4
SqlSugar/packages.config
Normal file
4
SqlSugar/packages.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="MySql.Data" version="6.9.9" targetFramework="net40" />
|
||||
</packages>
|
Reference in New Issue
Block a user