sunkaixuan
7 years ago
17 changed files with 577 additions and 6 deletions
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
namespace SqlSugar |
|||
{ |
|||
public class OracleCodeFirst : CodeFirstProvider |
|||
{ |
|||
} |
|||
} |
@ -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)}; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
namespace SqlSugar |
|||
{ |
|||
public class OracleDbFirst : DbFirstProvider |
|||
{ |
|||
} |
|||
} |
@ -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
|
|||
} |
|||
} |
@ -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; |
|||
} |
|||
} |
|||
} |
@ -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> |
|||
{ |
|||
|
|||
} |
|||
} |
@ -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; |
|||
} |
|||
} |
|||
} |
@ -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 |
|||
{ |
|||
|
|||
} |
|||
} |
@ -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 |
|||
{ |
|||
|
|||
} |
|||
} |
@ -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 |
|||
{ |
|||
} |
|||
} |
@ -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}"; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -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 |
|||
{ |
|||
} |
|||
} |
Binary file not shown.
Loading…
Reference in new issue