Browse Source

Merge branch 'dev' of github.com:sunkaixuan/SqlSugar

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
f51c5f7a10
  1. 2
      Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs
  2. 4
      Src/Asp.Net/SqlSugar/Realization/MySql/MySqlProvider.cs
  3. 11
      Src/Asp.Net/SqlSugar/Realization/Oracle/CodeFirst/OracleCodeFirst.cs
  4. 47
      Src/Asp.Net/SqlSugar/Realization/Oracle/DbBind/OracleDbBind.cs
  5. 11
      Src/Asp.Net/SqlSugar/Realization/Oracle/DbFirst/OracleDbFirst.cs
  6. 205
      Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs
  7. 103
      Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs
  8. 45
      Src/Asp.Net/SqlSugar/Realization/Oracle/Queryable/OracleQueryable.cs
  9. 51
      Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleBuilder.cs
  10. 13
      Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleDeleteBuilder.cs
  11. 25
      Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs
  12. 12
      Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs
  13. 19
      Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleQueryBuilder.cs
  14. 12
      Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs
  15. 4
      Src/Asp.Net/SqlSugar/Realization/Sqlite/SqliteProvider.cs
  16. BIN
      Src/Asp.Net/SqlSugar/References/Oracle.ManagedDataAccess.dll
  17. 19
      Src/Asp.Net/SqlSugar/SqlSugar.csproj

2
Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/IDataReaderEntityBuilder.cs

@ -236,7 +236,7 @@ namespace SqlSugar
method = getString;
if (bindProperyTypeName == "guid")
{
method = getConvertStringGuid;
method =isNullableType? getConvertStringGuid : getStringGuid;
}
break;
case CSharpDataType.DateTime:

4
Src/Asp.Net/SqlSugar/Realization/MySql/MySqlProvider.cs

@ -34,7 +34,7 @@ namespace SqlSugar
public override void BeginTran(string transactionName)
{
((MySqlConnection)this.Connection).BeginTransaction();
base.BeginTran();
}
/// <summary>
/// Only SqlServer
@ -43,7 +43,7 @@ namespace SqlSugar
/// <param name="transactionName"></param>
public override void BeginTran(IsolationLevel iso, string transactionName)
{
((MySqlConnection)this.Connection).BeginTransaction(iso);
base.BeginTran(iso);
}
public override IDataAdapter GetAdapter()
{

11
Src/Asp.Net/SqlSugar/Realization/Oracle/CodeFirst/OracleCodeFirst.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SqlSugar
{
public class OracleCodeFirst : CodeFirstProvider
{
}
}

47
Src/Asp.Net/SqlSugar/Realization/Oracle/DbBind/OracleDbBind.cs

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SqlSugar
{
public class OracleDbBind : DbBindProvider
{
public override List<KeyValuePair<string, CSharpDataType>> MappingTypes
{
get
{
return new List<KeyValuePair<string, CSharpDataType>>()
{
new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int),
new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.@string),
new KeyValuePair<string, CSharpDataType>("nvarchar",CSharpDataType.@string),
new KeyValuePair<string, CSharpDataType>("sql_variant",CSharpDataType.@string),
new KeyValuePair<string, CSharpDataType>("text",CSharpDataType.@string),
new KeyValuePair<string, CSharpDataType>("char",CSharpDataType.@string),
new KeyValuePair<string, CSharpDataType>("ntext",CSharpDataType.@string),
new KeyValuePair<string, CSharpDataType>("nchar",CSharpDataType.@string),
new KeyValuePair<string, CSharpDataType>("bigint",CSharpDataType.@long),
new KeyValuePair<string, CSharpDataType>("bit",CSharpDataType.@bool),
new KeyValuePair<string, CSharpDataType>("datetime",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("time",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("smalldatetime",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("timestamp",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("datetime2",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("date",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("decimal",CSharpDataType.@decimal),
new KeyValuePair<string, CSharpDataType>("single",CSharpDataType.@decimal),
new KeyValuePair<string, CSharpDataType>("money",CSharpDataType.@decimal),
new KeyValuePair<string, CSharpDataType>("numeric",CSharpDataType.@decimal),
new KeyValuePair<string, CSharpDataType>("smallmoney",CSharpDataType.@decimal),
new KeyValuePair<string, CSharpDataType>("float",CSharpDataType.@double),
new KeyValuePair<string, CSharpDataType>("real",CSharpDataType.@float),
new KeyValuePair<string, CSharpDataType>("smallint",CSharpDataType.@short),
new KeyValuePair<string, CSharpDataType>("tinyint",CSharpDataType.@byte),
new KeyValuePair<string, CSharpDataType>("uniqueidentifier",CSharpDataType.Guid),
new KeyValuePair<string, CSharpDataType>("binary",CSharpDataType.byteArray),
new KeyValuePair<string, CSharpDataType>("image",CSharpDataType.byteArray),
new KeyValuePair<string, CSharpDataType>("varbinary",CSharpDataType.byteArray)};
}
}
}
}

11
Src/Asp.Net/SqlSugar/Realization/Oracle/DbFirst/OracleDbFirst.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SqlSugar
{
public class OracleDbFirst : DbFirstProvider
{
}
}

205
Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs

@ -0,0 +1,205 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SqlSugar
{
public class OracleDbMaintenance : DbMaintenanceProvider
{
#region DML
protected override string GetColumnInfosByTableNameSql
{
get
{
string sql = @"SELECT Sysobjects.name AS TableName,
syscolumns.Id AS TableId,
syscolumns.name AS DbColumnName,
systypes.name AS DataType,
syscolumns.length AS [Length],
sys.extended_properties.[value] AS [ColumnDescription],
syscomments.text AS DefaultValue,
syscolumns.isnullable AS IsNullable,
columnproperty(syscolumns.id,syscolumns.name,'IsIdentity')as IsIdentity,
(CASE
WHEN EXISTS
(
select 1
from sysindexes i
join sysindexkeys k on i.id = k.id and i.indid = k.indid
join sysobjects o on i.id = o.id
join syscolumns c on i.id=c.id and k.colid = c.colid
where o.xtype = 'U'
and exists(select 1 from sysobjects where xtype = 'PK' and name = i.name)
and o.name=sysobjects.name and c.name=syscolumns.name
) THEN 1
ELSE 0
END) AS IsPrimaryKey
FROM syscolumns
INNER JOIN systypes ON syscolumns.xtype = systypes.xtype
LEFT JOIN sysobjects ON syscolumns.id = sysobjects.id
LEFT OUTER JOIN sys.extended_properties ON (sys.extended_properties.minor_id = syscolumns.colid
AND sys.extended_properties.major_id = syscolumns.id)
LEFT OUTER JOIN syscomments ON syscolumns.cdefault = syscomments.id
WHERE syscolumns.id IN
(SELECT id
FROM sysobjects
WHERE xtype IN('u',
'v') )
AND (systypes.name <> 'sysname')
AND sysobjects.name='{0}'
AND systypes.name<>'geometry'
AND systypes.name<>'geography'
ORDER BY syscolumns.colid";
return sql;
}
}
protected override string GetTableInfoListSql
{
get
{
return @"SELECT s.Name,Convert(varchar(max),tbp.value) as Description
FROM sysobjects s
LEFT JOIN sys.extended_properties as tbp ON s.id=tbp.major_id and tbp.minor_id=0 WHERE s.xtype IN('U') AND (tbp.Name='MS_Description' OR tbp.Name is null)";
}
}
protected override string GetViewInfoListSql
{
get
{
return @"SELECT s.Name,Convert(varchar(max),tbp.value) as Description
FROM sysobjects s
LEFT JOIN sys.extended_properties as tbp ON s.id=tbp.major_id and tbp.minor_id=0 WHERE s.xtype IN('V') AND (tbp.Name='MS_Description' OR tbp.Name is null)";
}
}
#endregion
#region DDL
protected override string AddPrimaryKeySql
{
get
{
return "ALTER TABLE {0} ADD CONSTRAINT {1} PRIMARY KEY({2})";
}
}
protected override string AddColumnToTableSql
{
get
{
return "ALTER TABLE {0} ADD {1} {2}{3} {4} {5} {6}";
}
}
protected override string AlterColumnToTableSql
{
get
{
return "ALTER TABLE {0} ALTER COLUMN {1} {2}{3} {4} {5} {6}";
}
}
protected override string BackupDataBaseSql
{
get
{
return @"USE master;BACKUP DATABASE {0} TO disk = '{1}'";
}
}
protected override string CreateTableSql
{
get
{
return "CREATE TABLE {0}(\r\n{1})";
}
}
protected override string CreateTableColumn
{
get
{
return "{0} {1}{2} {3} {4} {5}";
}
}
protected override string TruncateTableSql
{
get
{
return "TRUNCATE TABLE {0}";
}
}
protected override string BackupTableSql
{
get
{
return "SELECT TOP {0} * INTO {1} FROM {2}";
}
}
protected override string DropTableSql
{
get
{
return "DROP TABLE {0}";
}
}
protected override string DropColumnToTableSql
{
get
{
return "ALTER TABLE {0} DROP COLUMN {1}";
}
}
protected override string DropConstraintSql
{
get
{
return "ALTER TABLE {0} DROP CONSTRAINT {1}";
}
}
protected override string RenameColumnSql
{
get
{
return "exec sp_rename '{0}.{1}','{2}','column';";
}
}
#endregion
#region Check
protected override string CheckSystemTablePermissionsSql
{
get
{
return "select top 1 id from sysobjects";
}
}
#endregion
#region Scattered
protected override string CreateTableNull
{
get
{
return "NULL";
}
}
protected override string CreateTableNotNull
{
get
{
return "NOT NULL";
}
}
protected override string CreateTablePirmaryKey
{
get
{
return "PRIMARY KEY";
}
}
protected override string CreateTableIdentity
{
get
{
return "IDENTITY(1,1)";
}
}
#endregion
}
}

103
Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs

@ -0,0 +1,103 @@
using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public class OracleProvider : AdoProvider
{
public OracleProvider() { }
public override IDbConnection Connection
{
get
{
if (base._DbConnection == null)
{
base._DbConnection = new OracleConnection(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)
{
((OracleConnection)this.Connection).BeginTransaction();
}
/// <summary>
/// Only SqlServer
/// </summary>
/// <param name="iso"></param>
/// <param name="transactionName"></param>
public override void BeginTran(IsolationLevel iso, string transactionName)
{
((OracleConnection)this.Connection).BeginTransaction(iso);
}
public override IDataAdapter GetAdapter()
{
return new SqlDataAdapter();
}
public override IDbCommand GetCommand(string sql, SugarParameter[] parameters)
{
OracleCommand sqlCommand = new OracleCommand(sql, (OracleConnection)this.Connection);
sqlCommand.CommandType = this.CommandType;
sqlCommand.CommandTimeout = this.CommandTimeOut;
if (this.Transaction != null)
{
sqlCommand.Transaction = (OracleTransaction)this.Transaction;
}
if (parameters.IsValuable())
{
IDataParameter[] ipars = ToIDbDataParameter(parameters);
sqlCommand.Parameters.AddRange((OracleParameter[])ipars);
}
CheckConnection();
return sqlCommand;
}
public override void SetCommandToAdapter(IDataAdapter dataAdapter, IDbCommand command)
{
((OracleDataAdapter)dataAdapter).SelectCommand = (OracleCommand)command;
}
/// <summary>
/// if mysql return MySqlParameter[] pars
/// if sqlerver return SqlParameter[] pars ...
/// </summary>
/// <param name="parameters"></param>
/// <returns></returns>
public override IDataParameter[] ToIDbDataParameter(params SugarParameter[] parameters)
{
if (parameters == null || parameters.Length == 0) return null;
OracleParameter[] result = new OracleParameter[parameters.Length];
int index = 0;
foreach (var parameter in parameters)
{
if (parameter.Value == null) parameter.Value = DBNull.Value;
var sqlParameter = new OracleParameter();
sqlParameter.ParameterName = parameter.ParameterName;
sqlParameter.UdtTypeName = parameter.UdtTypeName;
sqlParameter.Size = parameter.Size;
sqlParameter.Value = parameter.Value;
sqlParameter.DbType = parameter.DbType;
sqlParameter.Direction = parameter.Direction;
result[index] = sqlParameter;
if (sqlParameter.Direction == ParameterDirection.Output) {
if (this.OutputParameters == null) this.OutputParameters = new List<IDataParameter>();
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName);
this.OutputParameters.Add(sqlParameter);
}
++index;
}
return result;
}
}
}

45
Src/Asp.Net/SqlSugar/Realization/Oracle/Queryable/OracleQueryable.cs

@ -0,0 +1,45 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace SqlSugar
{
public class OracleQueryable<T> : QueryableProvider<T>
{
public override ISugarQueryable<T> With(string withString)
{
return this;
}
}
public class OracleQueryable<T, T2> : QueryableProvider<T, T2>
{
}
public class OracleQueryable<T, T2, T3> : QueryableProvider<T, T2, T3>
{
}
public class OracleQueryable<T, T2, T3, T4> : QueryableProvider<T, T2, T3, T4>
{
}
public class OracleQueryable<T, T2, T3, T4, T5> : QueryableProvider<T, T2, T3, T4, T5>
{
}
public class OracleQueryable<T, T2, T3, T4, T5, T6> : QueryableProvider<T, T2, T3, T4, T5, T6>
{
}
public class OracleQueryable<T, T2, T3, T4, T5, T6, T7> : QueryableProvider<T, T2, T3, T4, T5, T6, T7>
{
}
public class OracleQueryable<T, T2, T3, T4, T5, T6, T7, T8> : QueryableProvider<T, T2, T3, T4, T5, T6, T7, T8>
{
}
}

51
Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleBuilder.cs

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace SqlSugar
{
public class OracleBuilder : 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));
name = (mappingInfo == null ? name : mappingInfo.DbTableName);
if (name.Contains("["))
return name;
else
return "[" + name + "]";
}
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)
{
if (propertyName.Contains("[")) return propertyName;
else
return "[" + propertyName + "]";
}
public override string GetNoTranslationColumnName(string name)
{
if (!name.Contains("[")) return name;
return name == null ? string.Empty : Regex.Match(name, @".*\[(.*?)\]").Groups[1].Value;
}
}
}

13
Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleDeleteBuilder.cs

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public class OracleDeleteBuilder : DeleteBuilder
{
}
}

25
Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public partial class OracleExpressionContext : ExpressionContext, ILambdaExpressions
{
public SqlSugarClient Context { get; set; }
public OracleExpressionContext()
{
base.DbMehtods = new SqlServerMethod();
}
}
public partial class SqlServerMethod : DefaultDbMethod, IDbMethods
{
}
}

12
Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public class OracleInsertBuilder : InsertBuilder
{
}
}

19
Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleQueryBuilder.cs

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public class OracleQueryBuilder : QueryBuilder
{
public override string SqlTemplate
{
get
{
return "SELECT {0}{{$:OrderByString:$}} FROM {1}{2}{3}{4}";
}
}
}
}

12
Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public class OracleUpdateBuilder : UpdateBuilder
{
}
}

4
Src/Asp.Net/SqlSugar/Realization/Sqlite/SqliteProvider.cs

@ -30,7 +30,7 @@ namespace SqlSugar
public override void BeginTran(string transactionName)
{
((SQLiteConnection)this.Connection).BeginTransaction();
base.BeginTran();
}
/// <summary>
/// Only SqlServer
@ -39,7 +39,7 @@ namespace SqlSugar
/// <param name="transactionName"></param>
public override void BeginTran(IsolationLevel iso, string transactionName)
{
((SQLiteConnection)this.Connection).BeginTransaction(iso);
base.BeginTran(iso);
}
public override IDataAdapter GetAdapter()
{

BIN
Src/Asp.Net/SqlSugar/References/Oracle.ManagedDataAccess.dll

Binary file not shown.

19
Src/Asp.Net/SqlSugar/SqlSugar.csproj

@ -39,6 +39,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>Lib\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>References\Oracle.ManagedDataAccess.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data.SQLite, Version=1.0.102.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
@ -71,6 +75,18 @@
<Compile Include="Realization\MySql\CodeFirst\MySqlCodeFirst.cs" />
<Compile Include="Realization\MySql\DbFirst\MySqlDbFirst.cs" />
<Compile Include="Realization\MySql\DbMaintenance\MySqlDbMaintenance.cs" />
<Compile Include="Realization\Oracle\CodeFirst\OracleCodeFirst.cs" />
<Compile Include="Realization\Oracle\DbBind\OracleDbBind.cs" />
<Compile Include="Realization\Oracle\DbFirst\OracleDbFirst.cs" />
<Compile Include="Realization\Oracle\DbMaintenance\OracleDbMaintenance.cs" />
<Compile Include="Realization\Oracle\OracleProvider.cs" />
<Compile Include="Realization\Oracle\Queryable\OracleQueryable.cs" />
<Compile Include="Realization\Oracle\SqlBuilder\OracleBuilder.cs" />
<Compile Include="Realization\Oracle\SqlBuilder\OracleDeleteBuilder.cs" />
<Compile Include="Realization\Oracle\SqlBuilder\OracleExpressionContext.cs" />
<Compile Include="Realization\Oracle\SqlBuilder\OracleInsertBuilder.cs" />
<Compile Include="Realization\Oracle\SqlBuilder\OracleQueryBuilder.cs" />
<Compile Include="Realization\Oracle\SqlBuilder\OracleUpdateBuilder.cs" />
<Compile Include="Realization\Sqlite\CodeFirst\SqliteCodeFirst.cs" />
<Compile Include="Realization\Sqlite\DbBind\SqliteDbBind.cs" />
<Compile Include="Realization\Sqlite\DbFirst\SqliteDbFirst.cs" />
@ -207,10 +223,11 @@
<ItemGroup>
<Content Include="References\MySql.Data.dll" />
<Content Include="References\Newtonsoft.Json.dll" />
<Content Include="References\Oracle.ManagedDataAccess.dll" />
<Content Include="References\System.Data.SQLite.dll" />
</ItemGroup>
<ItemGroup>
<Folder Include="Realization\Oracle\" />
<None Include="SqlSugar.nuspec" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

Loading…
Cancel
Save