sunkaixuan
1 year ago
29 changed files with 3703 additions and 1 deletions
@ -0,0 +1,157 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data; |
|||
using System.Data.Odbc; |
|||
using System.Text; |
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
/// <summary>
|
|||
/// 数据填充器
|
|||
/// </summary>
|
|||
public class OceanBaseForOracleDataAdapter : IDataAdapter |
|||
{ |
|||
private OdbcCommand command; |
|||
private string sql; |
|||
private OdbcConnection _sqlConnection; |
|||
|
|||
/// <summary>
|
|||
/// SqlDataAdapter
|
|||
/// </summary>
|
|||
/// <param name="command"></param>
|
|||
public OceanBaseForOracleDataAdapter(OdbcCommand command) |
|||
{ |
|||
this.command = command; |
|||
} |
|||
|
|||
public OceanBaseForOracleDataAdapter() |
|||
{ |
|||
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// SqlDataAdapter
|
|||
/// </summary>
|
|||
/// <param name="sql"></param>
|
|||
/// <param name="_sqlConnection"></param>
|
|||
public OceanBaseForOracleDataAdapter(string sql, OdbcConnection _sqlConnection) |
|||
{ |
|||
this.sql = sql; |
|||
this._sqlConnection = _sqlConnection; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// SelectCommand
|
|||
/// </summary>
|
|||
public OdbcCommand SelectCommand |
|||
{ |
|||
get |
|||
{ |
|||
if (this.command == null) |
|||
{ |
|||
var conn = (OdbcConnection)this._sqlConnection; |
|||
this.command = conn.CreateCommand(); |
|||
this.command.CommandText = sql; |
|||
} |
|||
return this.command; |
|||
} |
|||
set |
|||
{ |
|||
this.command = value; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Fill
|
|||
/// </summary>
|
|||
/// <param name="dt"></param>
|
|||
public void Fill(DataTable dt) |
|||
{ |
|||
if (dt == null) |
|||
{ |
|||
dt = new DataTable(); |
|||
} |
|||
var columns = dt.Columns; |
|||
var rows = dt.Rows; |
|||
using (var dr = command.ExecuteReader()) |
|||
{ |
|||
for (int i = 0; i < dr.FieldCount; i++) |
|||
{ |
|||
string name = dr.GetName(i).Trim(); |
|||
if (!columns.Contains(name)) |
|||
columns.Add(new DataColumn(name, dr.GetFieldType(i))); |
|||
else |
|||
{ |
|||
columns.Add(new DataColumn(name + i, dr.GetFieldType(i))); |
|||
} |
|||
} |
|||
|
|||
while (dr.Read()) |
|||
{ |
|||
DataRow daRow = dt.NewRow(); |
|||
for (int i = 0; i < columns.Count; i++) |
|||
{ |
|||
daRow[columns[i].ColumnName] = dr.GetValue(i); |
|||
} |
|||
dt.Rows.Add(daRow); |
|||
} |
|||
} |
|||
dt.AcceptChanges(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Fill
|
|||
/// </summary>
|
|||
/// <param name="ds"></param>
|
|||
public void Fill(DataSet ds) |
|||
{ |
|||
if (ds == null) |
|||
{ |
|||
ds = new DataSet(); |
|||
} |
|||
using (var dr = command.ExecuteReader()) |
|||
{ |
|||
do |
|||
{ |
|||
var dt = new DataTable(); |
|||
var columns = dt.Columns; |
|||
var rows = dt.Rows; |
|||
for (int i = 0; i < dr.FieldCount; i++) |
|||
{ |
|||
string name = dr.GetName(i).Trim(); |
|||
if (dr.GetFieldType(i).Name == "DateTime") |
|||
{ |
|||
if (!columns.Contains(name)) |
|||
columns.Add(new DataColumn(name, UtilConstants.DateType)); |
|||
else |
|||
{ |
|||
columns.Add(new DataColumn(name + i, UtilConstants.DateType)); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
if (!columns.Contains(name)) |
|||
columns.Add(new DataColumn(name, dr.GetFieldType(i))); |
|||
else |
|||
{ |
|||
columns.Add(new DataColumn(name + i, dr.GetFieldType(i))); |
|||
} |
|||
} |
|||
} |
|||
|
|||
while (dr.Read()) |
|||
{ |
|||
DataRow daRow = dt.NewRow(); |
|||
for (int i = 0; i < columns.Count; i++) |
|||
{ |
|||
daRow[columns[i].ColumnName] = dr.GetValue(i); |
|||
} |
|||
dt.Rows.Add(daRow); |
|||
} |
|||
dt.AcceptChanges(); |
|||
ds.Tables.Add(dt); |
|||
} while (dr.NextResult()); |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
Binary file not shown.
@ -0,0 +1,51 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
public class OceanBaseForOracleCodeFirst : CodeFirstProvider |
|||
{ |
|||
public OceanBaseForOracleCodeFirst() |
|||
{ |
|||
if (DefultLength == 0) |
|||
DefultLength = 40; |
|||
} |
|||
protected override int DefultLength { get; set; } |
|||
|
|||
protected override void GetDbType(EntityColumnInfo item, Type propertyType, DbColumnInfo result) |
|||
{ |
|||
if (!string.IsNullOrEmpty(item.DataType)) |
|||
{ |
|||
result.DataType = item.DataType; |
|||
} |
|||
else if (propertyType.IsEnum()) |
|||
{ |
|||
result.DataType = this.Context.Ado.DbBind.GetDbTypeName(item.Length > 9 ? UtilConstants.LongType.Name : UtilConstants.IntType.Name); |
|||
} |
|||
else |
|||
{ |
|||
if (propertyType.Name.Equals("Guid", StringComparison.CurrentCultureIgnoreCase)) |
|||
{ |
|||
result.DataType = this.Context.Ado.DbBind.GetDbTypeName(UtilConstants.StringType.Name); |
|||
if (result.Length <= 1) |
|||
{ |
|||
result.Length = 36; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
result.DataType = this.Context.Ado.DbBind.GetDbTypeName(propertyType.Name); |
|||
} |
|||
} |
|||
} |
|||
|
|||
protected override void KeyAction(EntityColumnInfo item, DbColumnInfo dbColumn, out bool pkDiff, out bool idEntityDiff) |
|||
{ |
|||
pkDiff = item.IsPrimarykey != dbColumn.IsPrimarykey; |
|||
idEntityDiff = false; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,139 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
public class OceanBaseForOracleDbBind : DbBindProvider |
|||
{ |
|||
public override string GetDbTypeName(string csharpTypeName) |
|||
{ |
|||
if (csharpTypeName == UtilConstants.ByteArrayType.Name) |
|||
return "blob"; |
|||
if (csharpTypeName.ToLower() == "int32") |
|||
csharpTypeName = "int"; |
|||
if (csharpTypeName.ToLower() == "int16") |
|||
csharpTypeName = "short"; |
|||
if (csharpTypeName.ToLower() == "int64") |
|||
csharpTypeName = "long"; |
|||
if (csharpTypeName.ToLower().IsIn("boolean", "bool")) |
|||
csharpTypeName = "bool"; |
|||
if (csharpTypeName == "Guid") |
|||
csharpTypeName = "string"; |
|||
if (csharpTypeName == "DateTimeOffset") |
|||
csharpTypeName = "DateTime"; |
|||
var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase)); |
|||
return mappings.HasValue() ? mappings.First().Key : "varchar"; |
|||
} |
|||
public override string GetPropertyTypeName(string dbTypeName) |
|||
{ |
|||
dbTypeName = dbTypeName.ToLower(); |
|||
var propertyTypes = MappingTypes.Where(it => it.Value.ToString().ToLower() == dbTypeName || it.Key.ToLower() == dbTypeName); |
|||
if (dbTypeName == "int32") |
|||
{ |
|||
return "int"; |
|||
} |
|||
else if (dbTypeName == "int64") |
|||
{ |
|||
return "long"; |
|||
} |
|||
else if (dbTypeName == "int16") |
|||
{ |
|||
return "short"; |
|||
} |
|||
else if (propertyTypes == null) |
|||
{ |
|||
return "other"; |
|||
} |
|||
else if (dbTypeName == "xml" || dbTypeName == "string") |
|||
{ |
|||
return "string"; |
|||
} |
|||
if (dbTypeName == "byte[]") |
|||
{ |
|||
return "byte[]"; |
|||
} |
|||
else if (propertyTypes == null || propertyTypes.Count() == 0) |
|||
{ |
|||
Check.ThrowNotSupportedException(string.Format(" \"{0}\" Type NotSupported, DbBindProvider.GetPropertyTypeName error.", dbTypeName)); |
|||
return null; |
|||
} |
|||
else if (propertyTypes.First().Value == CSharpDataType.byteArray) |
|||
{ |
|||
return "byte[]"; |
|||
} |
|||
else |
|||
{ |
|||
return propertyTypes.First().Value.ToString(); |
|||
} |
|||
} |
|||
public override List<KeyValuePair<string, CSharpDataType>> MappingTypes |
|||
{ |
|||
get |
|||
{ |
|||
var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices; |
|||
if (extService != null && extService.AppendDataReaderTypeMappings.HasValue()) |
|||
{ |
|||
return extService.AppendDataReaderTypeMappings.Union(MappingTypesConst).ToList(); |
|||
} |
|||
else |
|||
{ |
|||
return MappingTypesConst; |
|||
} |
|||
} |
|||
} |
|||
public static List<KeyValuePair<string, CSharpDataType>> MappingTypesConst = new List<KeyValuePair<string, CSharpDataType>>() |
|||
{ |
|||
new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int), |
|||
new KeyValuePair<string, CSharpDataType>("integer",CSharpDataType.@int), |
|||
new KeyValuePair<string, CSharpDataType>("interval year to month",CSharpDataType.@int), |
|||
new KeyValuePair<string, CSharpDataType>("interval day to second",CSharpDataType.@int), |
|||
|
|||
new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@int), |
|||
new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@float), |
|||
new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@short), |
|||
new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@byte), |
|||
new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@double), |
|||
new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@long), |
|||
new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@bool), |
|||
new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@decimal), |
|||
new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.Single), |
|||
new KeyValuePair<string, CSharpDataType>("decimal",CSharpDataType.@decimal), |
|||
new KeyValuePair<string, CSharpDataType>("decimal",CSharpDataType.Single), |
|||
|
|||
new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.@string), |
|||
new KeyValuePair<string, CSharpDataType>("varchar2",CSharpDataType.@string), |
|||
new KeyValuePair<string, CSharpDataType>("nvarchar2",CSharpDataType.@string), |
|||
new KeyValuePair<string, CSharpDataType>("xmltype",CSharpDataType.@string), |
|||
new KeyValuePair<string, CSharpDataType>("char",CSharpDataType.@string), |
|||
new KeyValuePair<string, CSharpDataType>("nchar",CSharpDataType.@string), |
|||
new KeyValuePair<string, CSharpDataType>("clob",CSharpDataType.@string), |
|||
new KeyValuePair<string, CSharpDataType>("long",CSharpDataType.@string), |
|||
new KeyValuePair<string, CSharpDataType>("nclob",CSharpDataType.@string), |
|||
new KeyValuePair<string, CSharpDataType>("rowid",CSharpDataType.@string), |
|||
|
|||
new KeyValuePair<string, CSharpDataType>("date",CSharpDataType.DateTime), |
|||
new KeyValuePair<string, CSharpDataType>("timestamptz",CSharpDataType.DateTime), |
|||
new KeyValuePair<string, CSharpDataType>("timestamp",CSharpDataType.DateTime), |
|||
new KeyValuePair<string, CSharpDataType>("timestamp with local time zone",CSharpDataType.DateTime), |
|||
new KeyValuePair<string, CSharpDataType>("timestamp with time zone",CSharpDataType.DateTime), |
|||
|
|||
new KeyValuePair<string, CSharpDataType>("float",CSharpDataType.@decimal), |
|||
|
|||
new KeyValuePair<string, CSharpDataType>("blob",CSharpDataType.byteArray), |
|||
new KeyValuePair<string, CSharpDataType>("long raw",CSharpDataType.byteArray), |
|||
new KeyValuePair<string, CSharpDataType>("longraw",CSharpDataType.byteArray), |
|||
new KeyValuePair<string, CSharpDataType>("raw",CSharpDataType.byteArray), |
|||