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), |
|||
new KeyValuePair<string, CSharpDataType>("bfile",CSharpDataType.byteArray), |
|||
new KeyValuePair<string, CSharpDataType>("varbinary",CSharpDataType.byteArray) }; |
|||
public override List<string> StringThrow |
|||
{ |
|||
get |
|||
{ |
|||
return new List<string>() { "int32", "datetime", "decimal", "double", "byte" }; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,12 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
public class OceanBaseForOracleDbFirst : DbFirstProvider |
|||
{ |
|||
} |
|||
} |
@ -0,0 +1,582 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data.Common; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
public class OceanBaseForOracleDbMaintenance : DbMaintenanceProvider |
|||
{ |
|||
#region DML
|
|||
protected override string GetDataBaseSql |
|||
{ |
|||
get |
|||
{ |
|||
throw new NotSupportedException(); |
|||
} |
|||
} |
|||
protected override string GetColumnInfosByTableNameSql |
|||
{ |
|||
get |
|||
{ |
|||
throw new NotSupportedException(); |
|||
} |
|||
} |
|||
protected override string GetTableInfoListSql |
|||
{ |
|||
get |
|||
{ |
|||
return @"SELECT table_name name ,
|
|||
(select COMMENTS from user_tab_comments where t.table_name=table_name ) as Description |
|||
|
|||
from user_tables t where |
|||
table_name!='HELP' |
|||
AND table_name NOT LIKE '%$%' |
|||
AND table_name NOT LIKE 'LOGMNRC_%' |
|||
AND table_name!='LOGMNRP_CTAS_PART_MAP' |
|||
AND table_name!='LOGMNR_LOGMNR_BUILDLOG' |
|||
AND table_name!='SQLPLUS_PRODUCT_PROFILE' |
|||
";
|
|||
} |
|||
} |
|||
protected override string GetViewInfoListSql |
|||
{ |
|||
get |
|||
{ |
|||
return @"select view_name name from user_views
|
|||
WHERE VIEW_name NOT LIKE '%$%' |
|||
AND VIEW_NAME !='PRODUCT_PRIVS' |
|||
AND VIEW_NAME NOT LIKE 'MVIEW_%' ";
|
|||
} |
|||
} |
|||
#endregion
|
|||
|
|||
#region DDL
|
|||
protected override string IsAnyIndexSql |
|||
{ |
|||
get |
|||
{ |
|||
return "select count(1) from user_ind_columns where index_name=('{0}')"; |
|||
} |
|||
} |
|||
protected override string CreateIndexSql |
|||
{ |
|||
get |
|||
{ |
|||
return "CREATE {3} INDEX Index_{0}_{2} ON {0}({1})"; |
|||
} |
|||
} |
|||
protected override string AddDefaultValueSql |
|||
{ |
|||
get |
|||
{ |
|||
return "ALTER TABLE {0} MODIFY({1} DEFAULT '{2}')"; |
|||
} |
|||
} |
|||
protected override string CreateDataBaseSql |
|||
{ |
|||
get |
|||
{ |
|||
return "CREATE DATABASE {0}"; |
|||
} |
|||
} |
|||
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} modify ({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 "create table {1} as select * from {2} where ROWNUM<={0}"; |
|||
} |
|||
} |
|||
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 "ALTER TABLE {0} rename column {1} to {2}"; |
|||
} |
|||
} |
|||
protected override string AddColumnRemarkSql |
|||
{ |
|||
get |
|||
{ |
|||
return "comment on column {1}.{0} is '{2}'"; |
|||
} |
|||
} |
|||
|
|||
protected override string DeleteColumnRemarkSql |
|||
{ |
|||
get |
|||
{ |
|||
return "comment on column {1}.{0} is ''"; |
|||
} |
|||
} |
|||
|
|||
protected override string IsAnyColumnRemarkSql |
|||
{ |
|||
get |
|||
{ |
|||
return "select * from user_col_comments where Table_Name='{1}' AND COLUMN_NAME='{0}' order by column_name"; |
|||
} |
|||
} |
|||
|
|||
protected override string AddTableRemarkSql |
|||
{ |
|||
get |
|||
{ |
|||
return "comment on table {0} is '{1}'"; |
|||
} |
|||
} |
|||
|
|||
protected override string DeleteTableRemarkSql |
|||
{ |
|||
get |
|||
{ |
|||
return "comment on table {0} is ''"; |
|||
} |
|||
} |
|||
|
|||
protected override string IsAnyTableRemarkSql |
|||
{ |
|||
get |
|||
{ |
|||
return "select * from user_tab_comments where Table_Name='{0}'order by Table_Name"; |
|||
} |
|||
} |
|||
|
|||
protected override string RenameTableSql |
|||
{ |
|||
get |
|||
{ |
|||
return "alter table {0} rename to {1}"; |
|||
} |
|||
} |
|||
protected override string IsAnyProcedureSql |
|||
{ |
|||
get |
|||
{ |
|||
return "SELECT COUNT(*) FROM user_objects WHERE OBJECT_TYPE = 'PROCEDURE' AND OBJECT_NAME ='{0}'"; |
|||
} |
|||
} |
|||
#endregion
|
|||
|
|||
#region Check
|
|||
protected override string CheckSystemTablePermissionsSql |
|||
{ |
|||
get |
|||
{ |
|||
return "select t.table_name from user_tables t where rownum=1"; |
|||
} |
|||
} |
|||
#endregion
|
|||
|
|||
#region Scattered
|
|||
protected override string CreateTableNull |
|||
{ |
|||
get |
|||
{ |
|||
return ""; |
|||
} |
|||
} |
|||
protected override string CreateTableNotNull |
|||
{ |
|||
get |
|||
{ |
|||
return " NOT NULL "; |
|||
} |
|||
} |
|||
protected override string CreateTablePirmaryKey |
|||
{ |
|||
get |
|||
{ |
|||
return "PRIMARY KEY"; |
|||
} |
|||
} |
|||
protected override string CreateTableIdentity |
|||
{ |
|||
get |
|||
{ |
|||
return ""; |
|||
} |
|||
} |
|||
#endregion
|
|||
|
|||
#region Methods
|
|||
public override List<string> GetIndexList(string tableName) |
|||
{ |
|||
var sql = $"SELECT index_name FROM user_ind_columns\r\nWHERE table_name = '{tableName}'"; |
|||
return this.Context.Ado.SqlQuery<string>(sql); |
|||
} |
|||
public override List<string> GetProcList(string dbName) |
|||
{ |
|||
var sql = $"SELECT OBJECT_NAME FROM ALL_OBJECTS WHERE OBJECT_TYPE = 'PROCEDURE' AND OWNER = '{dbName.ToUpper()}'"; |
|||
return this.Context.Ado.SqlQuery<string>(sql); |
|||
} |
|||
public override bool AddColumn(string tableName, DbColumnInfo columnInfo) |
|||
{ |
|||
if (columnInfo.DataType == "varchar" && columnInfo.Length == 0) |
|||
{ |
|||
columnInfo.DataType = "varchar2"; |
|||
columnInfo.Length = 50; |
|||
} |
|||
return base.AddColumn(tableName, columnInfo); |
|||
} |
|||
public override bool CreateIndex(string tableName, string[] columnNames, bool isUnique = false) |
|||
{ |
|||
string sql = string.Format(CreateIndexSql, tableName, string.Join(",", columnNames), string.Join("_", columnNames.Select(it => (it + "abc").Substring(0, 3))), isUnique ? "UNIQUE" : ""); |
|||
this.Context.Ado.ExecuteCommand(sql); |
|||
return true; |
|||
} |
|||
public override bool AddDefaultValue(string tableName, string columnName, string defaultValue) |
|||
{ |
|||
if (defaultValue == "''") |
|||
{ |
|||
defaultValue = ""; |
|||
} |
|||
if (defaultValue.ToLower().IsIn("sysdate")) |
|||
{ |
|||
var template = AddDefaultValueSql.Replace("'", ""); |
|||
string sql = string.Format(template, tableName, columnName, defaultValue); |
|||
this.Context.Ado.ExecuteCommand(sql); |
|||
return true; |
|||
} |
|||
else |
|||
{ |
|||
return base.AddDefaultValue(tableName, columnName, defaultValue); |
|||
} |
|||
} |
|||
public override bool CreateDatabase(string databaseDirectory = null) |
|||
{ |
|||
if (this.Context.Ado.IsValidConnection()) |
|||
{ |
|||
return true; |
|||
} |
|||
Check.ExceptionEasy("Oracle no support create database ", "Oracle不支持建库方法,请写有效连接字符串可以正常运行该方法。"); |
|||
return true; |
|||
} |
|||
public override bool CreateDatabase(string databaseName, string databaseDirectory = null) |
|||
{ |
|||
throw new NotSupportedException(); |
|||
} |
|||
public override bool AddRemark(EntityInfo entity) |
|||
{ |
|||
var db = this.Context; |
|||
var columns = entity.Columns.Where(it => it.IsIgnore == false).ToList(); |
|||
|
|||
foreach (var item in columns) |
|||
{ |
|||
if (item.ColumnDescription != null) |
|||
{ |
|||
//column remak
|
|||
if (db.DbMaintenance.IsAnyColumnRemark(item.DbColumnName.ToUpper(IsUppper), item.DbTableName.ToUpper(IsUppper))) |
|||
{ |
|||
db.DbMaintenance.DeleteColumnRemark(this.SqlBuilder.GetTranslationColumnName(item.DbColumnName), item.DbTableName.ToUpper(IsUppper)); |
|||
db.DbMaintenance.AddColumnRemark(this.SqlBuilder.GetTranslationColumnName(item.DbColumnName), item.DbTableName.ToUpper(IsUppper), item.ColumnDescription); |
|||
} |
|||
else |
|||
{ |
|||
db.DbMaintenance.AddColumnRemark(item.DbColumnName.ToUpper(IsUppper), item.DbTableName.ToUpper(IsUppper), item.ColumnDescription); |
|||
} |
|||
} |
|||
} |
|||
|
|||
//table remak
|
|||
if (entity.TableDescription != null) |
|||
{ |
|||
if (db.DbMaintenance.IsAnyTableRemark(entity.DbTableName)) |
|||
{ |
|||
db.DbMaintenance.DeleteTableRemark(entity.DbTableName); |
|||
db.DbMaintenance.AddTableRemark(entity.DbTableName, entity.TableDescription); |
|||
} |
|||
else |
|||
{ |
|||
db.DbMaintenance.AddTableRemark(entity.DbTableName, entity.TableDescription); |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName, bool isCache = true) |
|||
{ |
|||
string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower(); |
|||
cacheKey = GetCacheKey(cacheKey); |
|||
if (!isCache) |
|||
return GetColumnInfosByTableName(tableName); |
|||
else |
|||
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey, |
|||
() => |
|||
{ |
|||
return GetColumnInfosByTableName(tableName); |
|||
|
|||
}); |
|||
} |
|||
|
|||
private List<DbColumnInfo> GetColumnInfosByTableName(string tableName) |
|||
{ |
|||
List<DbColumnInfo> columns = GetOracleDbType(tableName); |
|||
string sql = "select * /* " + Guid.NewGuid() + " */ from " + SqlBuilder.GetTranslationTableName(tableName) + " WHERE 1=2 "; |
|||
if (!this.GetTableInfoList(false).Any(it => it.Name == SqlBuilder.GetTranslationTableName(tableName).TrimStart('\"').TrimEnd('\"'))) |
|||
{ |
|||
sql = "select * /* " + Guid.NewGuid() + " */ from \"" + tableName + "\" WHERE 1=2 "; |
|||
} |
|||
this.Context.Utilities.RemoveCache<List<DbColumnInfo>>("DbMaintenanceProvider.GetFieldComment." + tableName); |
|||
this.Context.Utilities.RemoveCache<List<string>>("DbMaintenanceProvider.GetPrimaryKeyByTableNames." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower()); |
|||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent; |
|||
this.Context.Ado.IsEnableLogEvent = false; |
|||
using (DbDataReader reader = (DbDataReader)this.Context.Ado.GetDataReader(sql)) |
|||
{ |
|||
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog; |
|||
List<DbColumnInfo> result = new List<DbColumnInfo>(); |
|||
var schemaTable = reader.GetSchemaTable(); |
|||
foreach (System.Data.DataRow row in schemaTable.Rows) |
|||
{ |
|||
DbColumnInfo column = new DbColumnInfo() |
|||
{ |
|||
TableName = tableName, |
|||
DataType = row["DataType"].ToString().Replace("System.", "").Trim(), |
|||
IsNullable = (bool)row["AllowDBNull"], |
|||
//IsIdentity = (bool)row["IsAutoIncrement"],
|
|||
ColumnDescription = GetFieldComment(tableName, row["ColumnName"].ToString()), |
|||
DbColumnName = row["ColumnName"].ToString(), |
|||
//DefaultValue = row["defaultValue"].ToString(),
|
|||
IsPrimarykey = GetPrimaryKeyByTableNames(tableName).Any(it => it.Equals(row["ColumnName"].ToString(), StringComparison.CurrentCultureIgnoreCase)), |
|||
Length = row["ColumnSize"].ObjToInt(), |
|||
Scale = row["numericscale"].ObjToInt() |
|||
}; |
|||
var current = columns.FirstOrDefault(it => it.DbColumnName.EqualCase(column.DbColumnName)); |
|||
if (current != null) |
|||
{ |
|||
column.OracleDataType = current.DataType; |
|||
if (current.DataType.EqualCase("number")) |
|||
{ |
|||
column.Length = row["numericprecision"].ObjToInt(); |
|||
column.Scale = row["numericscale"].ObjToInt(); |
|||
column.DecimalDigits = row["numericscale"].ObjToInt(); |
|||
if (column.Length == 38 && column.Scale == 0) |
|||
{ |
|||
column.Length = 22; |
|||
} |
|||
} |
|||
} |
|||
result.Add(column); |
|||
} |
|||
return result; |
|||
} |
|||
} |
|||
|
|||
private List<DbColumnInfo> GetOracleDbType(string tableName) |
|||
{ |
|||
var sql0 = $@"select
|
|||
t1.table_name as TableName, |
|||
t6.comments, |
|||
t1.column_id, |
|||
t1.column_name as DbColumnName, |
|||
t5.comments, |
|||
t1.data_type as DataType, |
|||
t1.data_length as Length, |
|||
t1.char_length, |
|||
t1.data_precision, |
|||
t1.data_scale, |
|||
t1.nullable, |
|||
t4.index_name, |
|||
t4.column_position, |
|||
t4.descend |
|||
from user_tab_columns t1 |
|||
left join (select t2.table_name, |
|||
t2.column_name, |
|||
t2.column_position, |
|||
t2.descend, |
|||
t3.index_name |
|||
from user_ind_columns t2 |
|||
left join user_indexes t3 |
|||
on t2.table_name = t3.table_name and t2.index_name = t3.index_name |
|||
and t3.status = 'valid' and t3.uniqueness = 'unique') t4 --unique:唯一索引 |
|||
on t1.table_name = t4.table_name and t1.column_name = t4.column_name |
|||
left join user_col_comments t5 on t1.table_name = t5.table_name and t1.column_name = t5.column_name |
|||
left join user_tab_comments t6 on t1.table_name = t6.table_name |
|||
where upper(t1.table_name)=upper('{tableName}') |
|||
order by t1.table_name, t1.column_id";
|
|||
|
|||
var columns = this.Context.Ado.SqlQuery<DbColumnInfo>(sql0); |
|||
return columns; |
|||
} |
|||
|
|||
private List<string> GetPrimaryKeyByTableNames(string tableName) |
|||
{ |
|||
string cacheKey = "DbMaintenanceProvider.GetPrimaryKeyByTableNames." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower(); |
|||
cacheKey = GetCacheKey(cacheKey); |
|||
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey, |
|||
() => |
|||
{ |
|||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent; |
|||
this.Context.Ado.IsEnableLogEvent = false; |
|||
string sql = @" select distinct cu.COLUMN_name KEYNAME from user_cons_columns cu, user_constraints au
|
|||
where cu.constraint_name = au.constraint_name |
|||
and au.constraint_type = 'P' and au.table_name = '" + tableName.ToUpper(IsUppper) + @"'";
|
|||
var pks = this.Context.Ado.SqlQuery<string>(sql); |
|||
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog; |
|||
return pks; |
|||
}); |
|||
} |
|||
|
|||
public string GetTableComment(string tableName) |
|||
{ |
|||
string cacheKey = "DbMaintenanceProvider.GetTableComment." + tableName; |
|||
var comments = this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey, |
|||
() => |
|||
{ |
|||
string sql = "SELECT COMMENTS FROM USER_TAB_COMMENTS WHERE TABLE_NAME =@tableName ORDER BY TABLE_NAME"; |
|||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent; |
|||
this.Context.Ado.IsEnableLogEvent = false; |
|||
var pks = this.Context.Ado.SqlQuery<string>(sql, new { tableName = tableName.ToUpper(IsUppper) }); |
|||
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog; |
|||
return pks; |
|||
}); |
|||
return comments.HasValue() ? comments.First() : ""; |
|||
} |
|||
|
|||
public string GetFieldComment(string tableName, string filedName) |
|||
{ |
|||
string cacheKey = "DbMaintenanceProvider.GetFieldComment." + tableName; |
|||
var comments = this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey, |
|||
() => |
|||
{ |
|||
string sql = "SELECT TABLE_NAME AS TableName, COLUMN_NAME AS DbColumnName,COMMENTS AS ColumnDescription FROM user_col_comments WHERE TABLE_NAME =@tableName ORDER BY TABLE_NAME"; |
|||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent; |
|||
this.Context.Ado.IsEnableLogEvent = false; |
|||
var pks = this.Context.Ado.SqlQuery<DbColumnInfo>(sql, new { tableName = tableName.ToUpper(IsUppper) }); |
|||
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog; |
|||
return pks; |
|||
}); |
|||
return comments.HasValue() ? comments.First(it => it.DbColumnName.Equals(filedName, StringComparison.CurrentCultureIgnoreCase)).ColumnDescription : ""; |
|||
|
|||
} |
|||
|
|||
public override bool CreateTable(string tableName, List<DbColumnInfo> columns, bool isCreatePrimaryKey = true) |
|||
{ |
|||
if (columns.HasValue()) |
|||
{ |
|||
foreach (var item in columns) |
|||
{ |
|||
if (item.DbColumnName.Equals("GUID", StringComparison.CurrentCultureIgnoreCase) && item.Length == 0) |
|||
{ |
|||
item.Length = 50; |
|||
} |
|||
if (item.DataType == "varchar" && item.Length == 0) |
|||
{ |
|||
item.Length = 50; |
|||
} |
|||
if (item.IsIdentity && this.Context.CurrentConnectionConfig?.MoreSettings?.EnableOracleIdentity == true) |
|||
{ |
|||
item.DataType = "NUMBER GENERATED ALWAYS AS IDENTITY"; |
|||
} |
|||
} |
|||
} |
|||
string sql = GetCreateTableSql(tableName, columns); |
|||
this.Context.Ado.ExecuteCommand(sql); |
|||
if (isCreatePrimaryKey) |
|||
{ |
|||
var pkColumns = columns.Where(it => it.IsPrimarykey).ToList(); |
|||
if (pkColumns.Count <= 1) |
|||
{ |
|||
foreach (var item in pkColumns) |
|||
{ |
|||
this.Context.DbMaintenance.AddPrimaryKey(tableName, item.DbColumnName); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
this.Context.DbMaintenance.AddPrimaryKey(tableName, string.Join(",", pkColumns.Select(it => this.SqlBuilder.GetTranslationColumnName(it.DbColumnName)).ToArray())); |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
#endregion
|
|||
|
|||
#region Helper
|
|||
public bool IsUppper |
|||
{ |
|||
get |
|||
{ |
|||
if (this.Context.CurrentConnectionConfig.MoreSettings == null) |
|||
{ |
|||
return true; |
|||
} |
|||
else |
|||
{ |
|||
return this.Context.CurrentConnectionConfig.MoreSettings.IsAutoToUpper == true; |
|||
} |
|||
} |
|||
} |
|||
#endregion
|
|||
} |
|||
} |
@ -0,0 +1,345 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data; |
|||
using System.Data.Common; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using System.Xml.Linq; |
|||
using System.Data.Odbc; |
|||
using System.Text.RegularExpressions; |
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
public class OceanBaseForOracleProvider : AdoProvider |
|||
{ |
|||
public OceanBaseForOracleProvider() { } |
|||
public override IDbConnection Connection |
|||
{ |
|||
get |
|||
{ |
|||
if (base._DbConnection == null) |
|||
{ |
|||
try |
|||
{ |
|||
base._DbConnection = new OdbcConnection(base.Context.CurrentConnectionConfig.ConnectionString); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
throw ex; |
|||
} |
|||
} |
|||
return base._DbConnection; |
|||
} |
|||
set |
|||
{ |
|||
base._DbConnection = value; |
|||
} |
|||
} |
|||
|
|||
public string SplitCommandTag => UtilConstants.ReplaceCommaKey.Replace("{", "").Replace("}", ""); |
|||
|
|||
|
|||
public override object GetScalar(string sql, params SugarParameter[] parameters) |
|||
{ |
|||
if (this.Context.Ado.Transaction != null) |
|||
{ |
|||
return _GetScalar(sql, parameters); |
|||
} |
|||
else |
|||
{ |
|||
try |
|||
{ |
|||
this.Context.Ado.BeginTran(); |
|||
var result = _GetScalar(sql, parameters); |
|||
this.Context.Ado.CommitTran(); |
|||
return result; |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
this.Context.Ado.RollbackTran(); |
|||
throw ex; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override async Task<object> GetScalarAsync(string sql, params SugarParameter[] parameters) |
|||
{ |
|||
if (this.Context.Ado.Transaction != null) |
|||
{ |
|||
return await GetScalarAsync(sql, parameters); |
|||
} |
|||
else |
|||
{ |
|||
try |
|||
{ |
|||
this.Context.Ado.BeginTran(); |
|||
var result = await GetScalarAsync(sql, parameters); |
|||
this.Context.Ado.CommitTran(); |
|||
return result; |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
this.Context.Ado.RollbackTran(); |
|||
throw ex; |
|||
} |
|||
} |
|||
} |
|||
private object _GetScalar(string sql, SugarParameter[] parameters) |
|||
{ |
|||
if (sql == null) throw new Exception("sql is null"); |
|||
if (sql.IndexOf(this.SplitCommandTag) > 0) |
|||
{ |
|||
var sqlParts = Regex.Split(sql, this.SplitCommandTag).Where(it => !string.IsNullOrEmpty(it)).ToList(); |
|||
object result = 0; |
|||
foreach (var item in sqlParts) |
|||
{ |
|||
if (item.TrimStart('\r').TrimStart('\n') != "") |
|||
{ |
|||
result = base.GetScalar(item, parameters); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
else |
|||
{ |
|||
return base.GetScalar(sql, parameters); |
|||
} |
|||
} |
|||
private async Task<object> _GetScalarAsync(string sql, SugarParameter[] parameters) |
|||
{ |
|||
if (sql == null) throw new Exception("sql is null"); |
|||
if (sql.IndexOf(this.SplitCommandTag) > 0) |
|||
{ |
|||
var sqlParts = Regex.Split(sql, this.SplitCommandTag).Where(it => !string.IsNullOrEmpty(it)).ToList(); |
|||
object result = 0; |
|||
foreach (var item in sqlParts) |
|||
{ |
|||
if (item.TrimStart('\r').TrimStart('\n') != "") |
|||
{ |
|||
result = await base.GetScalarAsync(item, parameters); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
else |
|||
{ |
|||
return await base.GetScalarAsync(sql, parameters); |
|||
} |
|||
} |
|||
|
|||
public override int ExecuteCommand(string sql, SugarParameter[] parameters) |
|||
{ |
|||
if (sql == null) throw new Exception("sql is null"); |
|||
if (sql.IndexOf(this.SplitCommandTag) > 0) |
|||
{ |
|||
var sqlParts = Regex.Split(sql, this.SplitCommandTag).Where(it => !string.IsNullOrEmpty(it)).ToList(); |
|||
int result = 0; |
|||
foreach (var item in sqlParts) |
|||
{ |
|||
if (item.TrimStart('\r').TrimStart('\n') != "") |
|||
{ |
|||
result += base.ExecuteCommand(item, parameters); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
else |
|||
{ |
|||
return base.ExecuteCommand(sql, parameters); |
|||
} |
|||
} |
|||
public override async Task<int> ExecuteCommandAsync(string sql, SugarParameter[] parameters) |
|||
{ |
|||
if (sql == null) throw new Exception("sql is null"); |
|||
if (sql.IndexOf(this.SplitCommandTag) > 0) |
|||
{ |
|||
var sqlParts = Regex.Split(sql, this.SplitCommandTag).Where(it => !string.IsNullOrEmpty(it)).ToList(); |
|||
int result = 0; |
|||
foreach (var item in sqlParts) |
|||
{ |
|||
if (item.TrimStart('\r').TrimStart('\n') != "") |
|||
{ |
|||
result += await base.ExecuteCommandAsync(item, parameters); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
else |
|||
{ |
|||
return base.ExecuteCommand(sql, parameters); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Only Odbc
|
|||
/// </summary>
|
|||
/// <param name="transactionName"></param>
|
|||
public override void BeginTran(string transactionName) |
|||
{ |
|||
CheckConnection(); |
|||
base.Transaction = ((OdbcConnection)this.Connection).BeginTransaction(); |
|||
} |
|||
/// <summary>
|
|||
/// Only Odbc
|
|||
/// </summary>
|
|||
/// <param name="iso"></param>
|
|||
/// <param name="transactionName"></param>
|
|||
public override void BeginTran(IsolationLevel iso, string transactionName) |
|||
{ |
|||
CheckConnection(); |
|||
base.Transaction = ((OdbcConnection)this.Connection).BeginTransaction(iso); |
|||
} |
|||
|
|||
public override IDataAdapter GetAdapter() |
|||
{ |
|||
return new OceanBaseForOracleDataAdapter(); |
|||
} |
|||
public override DbCommand GetCommand(string sql, SugarParameter[] parameters) |
|||
{ |
|||
var helper = new OceanBaseForOracleInsertBuilder(); |
|||
helper.Context = this.Context; |
|||
List<SugarParameter> orderParameters = new List<SugarParameter>(); |
|||
if (parameters.HasValue()) |
|||
{ |
|||
//由于Odbc参数都为?,用顺序进行匹配,则进行参数排序
|
|||
string reg = string.Join('|', parameters.Select(m => m.ParameterName)); |
|||
//通过正则匹配,为顺序输出,相同也会重复匹配
|
|||
Regex parametersRegx = new Regex(reg); |
|||
MatchCollection matches = parametersRegx.Matches(sql); |
|||
for(int index = 0;index< parameters.Length; index++) |
|||
{ |
|||
Match pMatch = matches[index]; |
|||
SugarParameter mP = parameters.FirstOrDefault(m => m.ParameterName == pMatch.Value); |
|||
if (mP != null) |
|||
{ |
|||
orderParameters.Add(mP); |
|||
} |
|||
} |
|||
foreach (var param in parameters.OrderByDescending(it => it.ParameterName.Length)) |
|||
{ |
|||
sql = sql.Replace(param.ParameterName, "?"); |
|||
} |
|||
} |
|||
OdbcCommand sqlCommand = new OdbcCommand(sql, (OdbcConnection)this.Connection); |
|||
sqlCommand.CommandType = this.CommandType; |
|||
sqlCommand.CommandTimeout = this.CommandTimeOut; |
|||
if (this.Transaction != null) |
|||
{ |
|||
sqlCommand.Transaction = (OdbcTransaction)this.Transaction; |
|||
} |
|||
if (parameters.HasValue()) |
|||
{ |
|||
OdbcParameter[] ipars = GetSqlParameter(orderParameters.ToArray()); |
|||
sqlCommand.Parameters.AddRange(ipars); |
|||
} |
|||
CheckConnection(); |
|||
return sqlCommand; |
|||
} |
|||
public override void SetCommandToAdapter(IDataAdapter dataAdapter, DbCommand command) |
|||
{ |
|||
((OceanBaseForOracleDataAdapter)dataAdapter).SelectCommand = (OdbcCommand)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 new OdbcParameter[] { }; |
|||
OdbcParameter[] result = new OdbcParameter[parameters.Length]; |
|||
int index = 0; |
|||
foreach (var parameter in parameters) |
|||
{ |
|||
if (parameter.Value == null) parameter.Value = DBNull.Value; |
|||
var sqlParameter = new OdbcParameter(); |
|||
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.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput, ParameterDirection.ReturnValue)) |
|||
{ |
|||
if (this.OutputParameters == null) this.OutputParameters = new List<IDataParameter>(); |
|||
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName); |
|||
this.OutputParameters.Add(sqlParameter); |
|||
} |
|||
++index; |
|||
} |
|||
return result; |
|||
} |
|||
/// <summary>
|
|||
/// if mysql return MySqlParameter[] pars
|
|||
/// if sqlerver return SqlParameter[] pars ...
|
|||
/// </summary>
|
|||
/// <param name="parameters"></param>
|
|||
/// <returns></returns>
|
|||
public OdbcParameter[] GetSqlParameter(params SugarParameter[] parameters) |
|||
{ |
|||
if (parameters == null || parameters.Length == 0) return null; |
|||
OdbcParameter[] result = new OdbcParameter[parameters.Length]; |
|||
int index = 0; |
|||
foreach (var parameter in parameters) |
|||
{ |
|||
if (parameter.Value == null) parameter.Value = DBNull.Value; |
|||
var sqlParameter = new OdbcParameter(); |
|||
sqlParameter.ParameterName = parameter.ParameterName; |
|||
//sqlParameter.UdtTypeName = parameter.UdtTypeName;
|
|||
sqlParameter.Size = parameter.Size; |
|||
sqlParameter.Value = parameter.Value; |
|||
sqlParameter.DbType = GetDbType(parameter); |
|||
var isTime = parameter.DbType == System.Data.DbType.Time; |
|||
if (isTime) |
|||
{ |
|||
sqlParameter.Value = DateTime.Parse(parameter.Value?.ToString()).TimeOfDay; |
|||
} |
|||
if (sqlParameter.Value != null && sqlParameter.Value != DBNull.Value && sqlParameter.DbType == System.Data.DbType.DateTime) |
|||
{ |
|||
var date = Convert.ToDateTime(sqlParameter.Value); |
|||
if (date == DateTime.MinValue) |
|||
{ |
|||
sqlParameter.Value = UtilMethods.GetMinDate(this.Context.CurrentConnectionConfig); |
|||
} |
|||
} |
|||
if (parameter.Direction == 0) |
|||
{ |
|||
parameter.Direction = ParameterDirection.Input; |
|||
} |
|||
sqlParameter.Direction = parameter.Direction; |
|||
result[index] = sqlParameter; |
|||
if (sqlParameter.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput, ParameterDirection.ReturnValue)) |
|||
{ |
|||
if (this.OutputParameters == null) this.OutputParameters = new List<IDataParameter>(); |
|||
this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName); |
|||
this.OutputParameters.Add(sqlParameter); |
|||
} |
|||
|
|||
++index; |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
private static System.Data.DbType GetDbType(SugarParameter parameter) |
|||
{ |
|||
if (parameter.DbType == System.Data.DbType.UInt16) |
|||
{ |
|||
return System.Data.DbType.Int16; |
|||
} |
|||
else if (parameter.DbType == System.Data.DbType.UInt32) |
|||
{ |
|||
return System.Data.DbType.Int32; |
|||
} |
|||
else if (parameter.DbType == System.Data.DbType.UInt64) |
|||
{ |
|||
return System.Data.DbType.Int64; |
|||
} |
|||
else |
|||
{ |
|||
return parameter.DbType; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,65 @@ |
|||
using SqlSugar; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Expressions; |
|||
using System.Text; |
|||
|
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
public class OceanBaseForOracleQueryable<T>:QueryableProvider<T> |
|||
{ |
|||
public override ISugarQueryable<T> With(string withString) |
|||
{ |
|||
return this; |
|||
} |
|||
protected override List<string> GetIdentityKeys() |
|||
{ |
|||
return this.EntityInfo.Columns.Where(it => it.OracleSequenceName.HasValue()).Select(it => it.DbColumnName).ToList(); |
|||
} |
|||
} |
|||
public class OceanBaseForOracleQueryable<T,T2> : QueryableProvider<T,T2> |
|||
{ |
|||
|
|||
} |
|||
public class OceanBaseForOracleQueryable<T, T2,T3> : QueryableProvider<T, T2,T3> |
|||
{ |
|||
|
|||
} |
|||
public class OceanBaseForOracleQueryable<T, T2,T3,T4> : QueryableProvider<T, T2,T3,T4> |
|||
{ |
|||
|
|||
} |
|||
public class OceanBaseForOracleQueryable<T, T2, T3, T4,T5> : QueryableProvider<T, T2, T3, T4,T5> |
|||
{ |
|||
|
|||
} |
|||
public class OceanBaseForOracleQueryable<T, T2, T3, T4, T5,T6> : QueryableProvider<T, T2, T3, T4, T5,T6> |
|||
{ |
|||
|
|||
} |
|||
public class OceanBaseForOracleQueryable<T, T2, T3, T4, T5, T6,T7> : QueryableProvider<T, T2, T3, T4, T5, T6,T7> |
|||
{ |
|||
|
|||
} |
|||
public class OceanBaseForOracleQueryable<T, T2, T3, T4, T5, T6, T7,T8> : QueryableProvider<T, T2, T3, T4, T5, T6, T7,T8> |
|||
{ |
|||
|
|||
} |
|||
public class OceanBaseForOracleQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> : QueryableProvider<T, T2, T3, T4, T5, T6, T7, T8, T9> |
|||
{ |
|||
|
|||
} |
|||
public class OceanBaseForOracleQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> : QueryableProvider<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> |
|||
{ |
|||
|
|||
} |
|||
public class OceanBaseForOracleQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> : QueryableProvider<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> |
|||
{ |
|||
|
|||
} |
|||
public class OceanBaseForOracleQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> : QueryableProvider<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> |
|||
{ |
|||
|
|||
} |
|||
} |
@ -0,0 +1,154 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data; |
|||
using Microsoft.Data.SqlClient; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
public class OceanBaseForOracleBlukCopy |
|||
{ |
|||
internal List<IGrouping<int, DbColumnInfo>> DbColumnInfoList { get; set; } |
|||
internal SqlSugarProvider Context { get; set; } |
|||
internal ISqlBuilder Builder { get; set; } |
|||
internal InsertBuilder InsertBuilder { get; set; } |
|||
internal object[] Inserts { get; set; } |
|||
|
|||
public int ExecuteBulkCopy() |
|||
{ |
|||
if (DbColumnInfoList == null || DbColumnInfoList.Count == 0) return 0; |
|||
|
|||
if (Inserts.First().GetType() == typeof(DataTable)) |
|||
{ |
|||
return WriteToServer(); |
|||
} |
|||
DataTable dt = GetCopyData(); |
|||
SqlBulkCopy bulkCopy = GetBulkCopyInstance(); |
|||
bulkCopy.DestinationTableName = InsertBuilder.GetTableNameString; |
|||
try |
|||
{ |
|||
bulkCopy.WriteToServer(dt); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
CloseDb(); |
|||
throw ex; |
|||
} |
|||
CloseDb(); |
|||
return DbColumnInfoList.Count; |
|||
} |
|||
|
|||
public async Task<int> ExecuteBulkCopyAsync() |
|||
{ |
|||
if (DbColumnInfoList == null || DbColumnInfoList.Count == 0) return 0; |
|||
|
|||
if (Inserts.First().GetType() == typeof(DataTable)) |
|||
{ |
|||
return WriteToServer(); |
|||
} |
|||
DataTable dt=GetCopyData(); |
|||
SqlBulkCopy bulkCopy = GetBulkCopyInstance(); |
|||
bulkCopy.DestinationTableName = InsertBuilder.GetTableNameString; |
|||
try |
|||
{ |
|||
await bulkCopy.WriteToServerAsync(dt); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
CloseDb(); |
|||
throw ex; |
|||
} |
|||
CloseDb(); |
|||
return DbColumnInfoList.Count; |
|||
} |
|||
|
|||
private int WriteToServer() |
|||
{ |
|||
var dt = this.Inserts.First() as DataTable; |
|||
if (dt == null) |
|||
return 0; |
|||
Check.Exception(dt.TableName == "Table", "dt.TableName can't be null "); |
|||
dt = GetCopyWriteDataTable(dt); |
|||
SqlBulkCopy copy = GetBulkCopyInstance(); |
|||
copy.DestinationTableName = this.Builder.GetTranslationColumnName(dt.TableName); |
|||
copy.WriteToServer(dt); |
|||
CloseDb(); |
|||
return dt.Rows.Count; |
|||
} |
|||
private DataTable GetCopyWriteDataTable(DataTable dt) |
|||
{ |
|||
var result = this.Context.Ado.GetDataTable("select top 0 * from " + this.Builder.GetTranslationColumnName(dt.TableName)); |
|||
foreach (DataRow item in dt.Rows) |
|||
{ |
|||
DataRow dr= result.NewRow(); |
|||
foreach (DataColumn column in result.Columns) |
|||
{ |
|||
|
|||
if (dt.Columns.Cast<DataColumn>().Select(it => it.ColumnName.ToLower()).Contains(column.ColumnName.ToLower())) |
|||
{ |
|||
dr[column.ColumnName] = item[column.ColumnName]; |
|||
if (dr[column.ColumnName] == null) |
|||
{ |
|||
dr[column.ColumnName] = DBNull.Value; |
|||
} |
|||
} |
|||
} |
|||
result.Rows.Add(dr); |
|||
} |
|||
result.TableName = dt.TableName; |
|||
return result; |
|||
} |
|||
private SqlBulkCopy GetBulkCopyInstance() |
|||
{ |
|||
SqlBulkCopy copy; |
|||
if (this.Context.Ado.Transaction == null) |
|||
{ |
|||
copy = new SqlBulkCopy((SqlConnection)this.Context.Ado.Connection); |
|||
} |
|||
else |
|||
{ |
|||
copy = new SqlBulkCopy((SqlConnection)this.Context.Ado.Connection, SqlBulkCopyOptions.CheckConstraints, (SqlTransaction)this.Context.Ado.Transaction); |
|||
} |
|||
if (this.Context.Ado.Connection.State == ConnectionState.Closed) |
|||
{ |
|||
this.Context.Ado.Connection.Open(); |
|||
} |
|||
copy.BulkCopyTimeout = this.Context.Ado.CommandTimeOut; |
|||
return copy; |
|||
} |
|||
private DataTable GetCopyData() |
|||
{ |
|||
var dt = this.Context.Ado.GetDataTable("select top 0 * from " + InsertBuilder.GetTableNameString); |
|||
foreach (var rowInfos in DbColumnInfoList) |
|||
{ |
|||
var dr = dt.NewRow(); |
|||
foreach (var value in rowInfos) |
|||
{ |
|||
if (value.Value != null && UtilMethods.GetUnderType(value.Value.GetType()) == UtilConstants.DateType) |
|||
{ |
|||
if (value.Value != null && value.Value.ToString() == DateTime.MinValue.ToString()) |
|||
{ |
|||
value.Value = Convert.ToDateTime("1753/01/01"); |
|||
} |
|||
} |
|||
if (value.Value == null) |
|||
{ |
|||
value.Value = DBNull.Value; |
|||
} |
|||
dr[value.DbColumnName] = value.Value; |
|||
} |
|||
dt.Rows.Add(dr); |
|||
} |
|||
return dt; |
|||
} |
|||
private void CloseDb() |
|||
{ |
|||
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Context.Ado.Transaction == null) |
|||
{ |
|||
this.Context.Ado.Connection.Close(); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,81 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Text.RegularExpressions; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
public class OceanBaseForOracleBuilder : SqlBuilderProvider |
|||
{ |
|||
public override string SqlParameterKeyWord |
|||
{ |
|||
get |
|||
{ |
|||
return ":"; |
|||
} |
|||
} |
|||
public override string SqlDateNow |
|||
{ |
|||
get |
|||
{ |
|||
return "sysdate"; |
|||
} |
|||
} |
|||
public override string FullSqlDateNow |
|||
{ |
|||
get |
|||
{ |
|||
return "select systimestamp from dual"; |
|||
} |
|||
} |
|||
public override string SqlTranslationLeft { get { return "\""; } } |
|||
public override string SqlTranslationRight { get { return "\""; } } |
|||
public override string GetTranslationTableName(string name) |
|||
{ |
|||
var result = base.GetTranslationTableName(name); |
|||
if (result.Contains("(") && result.Contains(")")) |
|||
return result; |
|||
else |
|||
return result.ToUpper(IsUppper); |
|||
} |
|||
public override string GetTranslationColumnName(string entityName, string propertyName) |
|||
{ |
|||
var result = base.GetTranslationColumnName(entityName, propertyName); |
|||
return result.ToUpper(IsUppper); |
|||
} |
|||
public override string GetTranslationColumnName(string propertyName) |
|||
{ |
|||
var result = base.GetTranslationColumnName(propertyName); |
|||
return result.ToUpper(IsUppper); |
|||
} |
|||
public override string RemoveParentheses(string sql) |
|||
{ |
|||
if (sql.StartsWith("(") && sql.EndsWith(")")) |
|||
{ |
|||
sql = sql.Substring(1, sql.Length - 2); |
|||
} |
|||
|
|||
return sql; |
|||
} |
|||
#region Helper
|
|||
public bool IsUppper |
|||
{ |
|||
get |
|||
{ |
|||
if (this.Context.CurrentConnectionConfig.MoreSettings == null) |
|||
{ |
|||
return true; |
|||
} |
|||
else |
|||
{ |
|||
return this.Context.CurrentConnectionConfig.MoreSettings.IsAutoToUpper == true; |
|||
} |
|||
} |
|||
} |
|||
#endregion
|
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,13 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
public class OceanBaseForOracleDeleteBuilder : DeleteBuilder |
|||
{ |
|||
|
|||
} |
|||
} |
@ -0,0 +1,386 @@ |
|||
using System; |
|||
using System.Collections; |
|||
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.OceanBaseForOracle |
|||
{ |
|||
public partial class OceanBaseForOracleExpressionContext : ExpressionContext, ILambdaExpressions |
|||
{ |
|||
public SqlSugarProvider Context { get; set; } |
|||
public OceanBaseForOracleExpressionContext() |
|||
{ |
|||
base.DbMehtods = new OceanBaseForOracleMethod(); |
|||
} |
|||
public override string SqlParameterKeyWord |
|||
{ |
|||
get |
|||
{ |
|||
return ":"; |
|||
} |
|||
} |
|||
public override string SqlTranslationLeft { get { return "\""; } } |
|||
public override string SqlTranslationRight { get { return "\""; } } |
|||
public override string GetTranslationTableName(string entityName, bool isMapping = true) |
|||
{ |
|||
return base.GetTranslationTableName(entityName, isMapping).ToUpper(IsUppper); |
|||
} |
|||
public override string GetTranslationColumnName(string columnName) |
|||
{ |
|||
if (columnName == "systimestamp") |
|||
{ |
|||
return columnName; |
|||
} |
|||
if (columnName.Contains(":")) |
|||
return base.GetTranslationColumnName(columnName); |
|||
else if (columnName.Contains("\".\"")) |
|||
{ |
|||
return columnName; |
|||
} |
|||
else |
|||
return base.GetTranslationColumnName(columnName).ToUpper(IsUppper); |
|||
} |
|||
public override string GetDbColumnName(string entityName, string propertyName) |
|||
{ |
|||
return base.GetDbColumnName(entityName, propertyName).ToUpper(IsUppper); |
|||
} |
|||
public override bool IsTranslationText(string name) |
|||
{ |
|||
if (!string.IsNullOrEmpty(name) && name.ToLower() == "sysdate") |
|||
{ |
|||
return true; |
|||
} |
|||
var result = name.IsContainsIn(SqlTranslationLeft, SqlTranslationRight, UtilConstants.Space, ExpressionConst.LeftParenthesis, ExpressionConst.RightParenthesis); |
|||
return result; |
|||
} |
|||
public bool IsUppper |
|||
{ |
|||
get |
|||
{ |
|||
if (this.SugarContext?.Context?.Context?.CurrentConnectionConfig?.MoreSettings == null) |
|||
{ |
|||
return true; |
|||
} |
|||
else |
|||
{ |
|||
return this.SugarContext?.Context?.Context?.CurrentConnectionConfig?.MoreSettings.IsAutoToUpper == true; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override string GetLimit() |
|||
{ |
|||
return "AND ROWNUM=1"; |
|||
} |
|||
} |
|||
public partial class OceanBaseForOracleMethod : DefaultDbMethod, IDbMethods |
|||
{ |
|||
public override string WeekOfYear(MethodCallExpressionModel mode) |
|||
{ |
|||
var parameterNameA = mode.Args[0].MemberName; |
|||
return $"TO_NUMBER(TO_CHAR({parameterNameA}, 'WW')) "; |
|||
} |
|||
public override string BitwiseAnd(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
var parameter2 = model.Args[1]; |
|||
return string.Format(" BITAND({0},{1}) ", parameter.MemberName, parameter2.MemberName); |
|||
} |
|||
public override string BitwiseInclusiveOR(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
var parameter2 = model.Args[1]; |
|||
return string.Format(" BITOR({0},{1}) ", parameter.MemberName, parameter2.MemberName); |
|||
} |
|||
public override string ParameterKeyWord { get; set; } = ":"; |
|||
public override string Modulo(MethodCallExpressionModel model) |
|||
{ |
|||
return " MOD(" + model.Args[0].MemberName + " , " + model.Args[1].MemberName + ")"; |
|||
} |
|||
public override string GetStringJoinSelector(string result, string separator) |
|||
{ |
|||
return $"listagg(to_char({result}),'{separator}') within group(order by {result}) "; |
|||
} |
|||
public override string HasValue(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
return string.Format("( {0} IS NOT NULL ) ", parameter.MemberName); |
|||
} |
|||
|
|||
public override string DateDiff(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = (DateType)(Enum.Parse(typeof(DateType), model.Args[0].MemberValue.ObjToString())); |
|||
var begin = model.Args[1].MemberName; |
|||
var end = model.Args[2].MemberName; |
|||
switch (parameter) |
|||
{ |
|||
case DateType.Year: |
|||
return $" ( cast((months_between( {end} , {begin}))/12 as number(9,0) ) )"; |
|||
case DateType.Month: |
|||
return $" ( cast((months_between( {end} , {begin})) as number(9,0) ) )"; |
|||
case DateType.Day: |
|||
return $" ( ROUND(TO_NUMBER(cast({end} as date) - cast({begin} as date))) )"; |
|||
case DateType.Hour: |
|||
return $" ( ROUND(TO_NUMBER(cast({end} as date) - cast({begin} as date)) * 24) )"; |
|||
case DateType.Minute: |
|||
return $" ( ROUND(TO_NUMBER(cast({end} as date) - cast({begin} as date)) * 24 * 60) )"; |
|||
case DateType.Second: |
|||
return $" ( ROUND(TO_NUMBER(cast({end} as date) - cast({begin} as date)) * 24 * 60 * 60) )"; |
|||
case DateType.Millisecond: |
|||
return $" ( ROUND(TO_NUMBER(cast({end} as date) - cast({begin} as date)) * 24 * 60 * 60 * 60) )"; |
|||
default: |
|||
break; |
|||
} |
|||
throw new Exception(parameter + " datediff no support"); |
|||
} |
|||
private void PageEach<T>(IEnumerable<T> pageItems, int pageSize, Action<List<T>> action) |
|||
{ |
|||
if (pageItems != null && pageItems.Any()) |
|||
{ |
|||
int totalRecord = pageItems.Count(); |
|||
int pageCount = (totalRecord + pageSize - 1) / pageSize; |
|||
for (int i = 1; i <= pageCount; i++) |
|||
{ |
|||
var list = pageItems.Skip((i - 1) * pageSize).Take(pageSize).ToList(); |
|||
action(list); |
|||
} |
|||
} |
|||
} |
|||
public override string ContainsArray(MethodCallExpressionModel model) |
|||
{ |
|||
if (model.Args[0].MemberValue == null) |
|||
{ |
|||
return base.ContainsArray(model); |
|||
} |
|||
var inValueIEnumerable = ((IEnumerable)model.Args[0].MemberValue).Cast<object>().ToArray(); |
|||
if (inValueIEnumerable.Count() < 1000) |
|||
{ |
|||
return base.ContainsArray(model); |
|||
} |
|||
else |
|||
{ |
|||
string result = ""; |
|||
PageEach(inValueIEnumerable, 999, it => |
|||
{ |
|||
model.Args.First().MemberValue = it; |
|||
result += (base.ContainsArray(model) + " OR "); |
|||
|
|||
}); |
|||
return " ( " + result.TrimEnd(' ').TrimEnd('R').TrimEnd('O') + " ) "; |
|||
} |
|||
} |
|||
public override string ToInt64(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
return string.Format(" CAST({0} AS Number)", parameter.MemberName); |
|||
} |
|||
|
|||
public override string ToTime(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
return string.Format(" to_timestamp({0},'0000-01-01 hh24:mi:ss') ", parameter.MemberName); |
|||
} |
|||
public override string Substring(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
var parameter2 = model.Args[1]; |
|||
var parameter3 = model.Args[2]; |
|||
return string.Format("SUBSTR({0},1 + {1},{2})", parameter.MemberName, parameter2.MemberName, parameter3.MemberName); |
|||
} |
|||
public override string DateValue(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
var parameter2 = model.Args[1]; |
|||
var type = (DateType)Enum.Parse(typeof(DateType), parameter2.MemberValue.ObjToString(), false); |
|||
switch (type) |
|||
{ |
|||
case DateType.Year: |
|||
return string.Format("(CAST(TO_CHAR({0},'yyyy') AS NUMBER))", parameter.MemberName); |
|||
case DateType.Month: |
|||
return string.Format("(CAST(TO_CHAR({0},'mm') AS NUMBER))", parameter.MemberName); |
|||
case DateType.Hour: |
|||
return string.Format("(CAST(TO_CHAR({0},'hh24') AS NUMBER))", parameter.MemberName); |
|||
case DateType.Second: |
|||
return string.Format("(CAST(TO_CHAR({0},'ss') AS NUMBER))", parameter.MemberName); |
|||
case DateType.Minute: |
|||
return string.Format("(CAST(TO_CHAR({0},'mi') AS NUMBER))", parameter.MemberName); |
|||
case DateType.Millisecond: |
|||
return string.Format("(CAST(TO_CHAR({0},'ff3') AS NUMBER))", parameter.MemberName); |
|||
case DateType.Weekday: |
|||
return $" to_char({parameter.MemberName},'day') "; |
|||
case DateType.Day: |
|||
default: |
|||
return string.Format("(CAST(TO_CHAR({0},'dd') AS NUMBER))", parameter.MemberName); |
|||
} |
|||
} |
|||
public override string DateAddByType(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
var parameter2 = model.Args[1]; |
|||
var parameter3 = model.Args[2]; |
|||
var type = (DateType)Enum.Parse(typeof(DateType), parameter3.MemberValue.ObjToString(), false); |
|||
double time = 1; |
|||
switch (type) |
|||
{ |
|||
case DateType.Year: |
|||
time = 1 * 365; |
|||
break; |
|||
case DateType.Month: |
|||
time = 1 * 30; |
|||
break; |
|||
case DateType.Day: |
|||
break; |
|||
case DateType.Hour: |
|||
time = 1 / 24.0; |
|||
break; |
|||
case DateType.Second: |
|||
time = 1 / 24.0 / 60.0 / 60.0; |
|||
break; |
|||
case DateType.Minute: |
|||
time = 1 / 24.0 / 60.0; |
|||
break; |
|||
case DateType.Millisecond: |
|||
time = 1 / 24.0 / 60.0 / 60.0 / 1000; |
|||
break; |
|||
} |
|||
return string.Format("({0}+({1}*{2})) ", parameter.MemberName, time, parameter2.MemberName); |
|||
} |
|||
|
|||
public override string DateAddDay(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
var parameter2 = model.Args[1]; |
|||
return string.Format("({0}+(1*{1})) ", parameter.MemberName, parameter2.MemberName); |
|||
} |
|||
|
|||
public override string ToString(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
return string.Format(" CAST({0} AS VARCHAR2(4000))", parameter.MemberName); |
|||
} |
|||
|
|||
public override string ToDecimal(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
return string.Format(" CAST({0} AS Number)", parameter.MemberName); |
|||
} |
|||
|
|||
public override string ToDate(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
return string.Format(" cast({0} as TIMESTAMP)", parameter.MemberName); |
|||
} |
|||
public override string ToDateShort(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
return string.Format(" TRUNC({0},'dd') ", parameter.MemberName); |
|||
} |
|||
public override string Contains(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
var parameter2 = model.Args[1]; |
|||
return string.Format(" ({0} like '%'||{1}||'%') ", parameter.MemberName, parameter2.MemberName); |
|||
} |
|||
public override string StartsWith(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
var parameter2 = model.Args[1]; |
|||
return string.Format(" ({0} like {1}||'%') ", parameter.MemberName, parameter2.MemberName); |
|||
} |
|||
public override string EndsWith(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
var parameter2 = model.Args[1]; |
|||
return string.Format(" ({0} like '%'||{1}) ", parameter.MemberName, parameter2.MemberName); |
|||
} |
|||
public override string Trim(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
return string.Format(" trim({0}) ", parameter.MemberName); |
|||
} |
|||
public override string DateIsSameDay(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
var parameter2 = model.Args[1]; |
|||
return string.Format(" ( cast({0} as date)= cast( {1} as date) ) ", parameter.MemberName, parameter2.MemberName); ; |
|||
} |
|||
public override string DateIsSameByType(MethodCallExpressionModel model) |
|||
{ |
|||
throw new NotSupportedException("Oracle NotSupportedException DateIsSameDay"); |
|||
} |
|||
public override string Length(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
return string.Format(" LENGTH({0}) ", parameter.MemberName); |
|||
} |
|||
|
|||
public override string IsNull(MethodCallExpressionModel model) |
|||
{ |
|||
var parameter = model.Args[0]; |
|||
var parameter1 = model.Args[1]; |
|||
return string.Format("NVL({0},{1})", parameter.MemberName, parameter1.MemberName); |
|||
} |
|||
|
|||
public override string MergeString(params string[] strings) |
|||
{ |
|||
return string.Join("||", strings); |
|||
} |
|||
|
|||
public override string GetDate() |
|||
{ |
|||
return "systimestamp"; |
|||
} |
|||
|
|||
public override string GetRandom() |
|||
{ |
|||
return "dbms_random.value"; |
|||
} |
|||
|
|||
public override string Collate(MethodCallExpressionModel model) |
|||
{ |
|||
var name = model.Args[0].MemberName; |
|||
return $" NLSSORT({0}, 'NLS_SORT = Latin_CI') "; |
|||
} |
|||
|
|||
public override string JsonField(MethodCallExpressionModel model) |
|||
{ |
|||
return $"JSON_VALUE({model.Args[0].MemberName}, '$.{model.Args[1].MemberValue.ToString().ToSqlFilter()}')"; |
|||
//"JSON_VALUE(j.kingorder, '$.Id') = '1'";
|
|||
} |
|||
|
|||
public override string CharIndex(MethodCallExpressionModel model) |
|||
{ |
|||
return string.Format("instr ({0},{1},1,1) ", model.Args[0].MemberName, model.Args[1].MemberName); |
|||
} |
|||
public override string TrimEnd(MethodCallExpressionModel mode) |
|||
{ |
|||
var parameterNameA = mode.Args[0].MemberName; |
|||
var parameterNameB = mode.Args[1].MemberName; |
|||
return $" RTRIM({parameterNameA}, {parameterNameB}) "; |
|||
} |
|||
public override string TrimStart(MethodCallExpressionModel mode) |
|||
{ |
|||
|
|||
var parameterNameA = mode.Args[0].MemberName; |
|||
var parameterNameB = mode.Args[1].MemberName; |
|||
return $" LTRIM({parameterNameA}, {parameterNameB}) "; |
|||
} |
|||
public override string Left(MethodCallExpressionModel mode) |
|||
{ |
|||
var parameterNameA = mode.Args[0].MemberName; |
|||
var parameterNameB = mode.Args[1].MemberName; |
|||
return $" SUBSTR({parameterNameA}, 1, {parameterNameB}) "; |
|||
} |
|||
public override string Right(MethodCallExpressionModel mode) |
|||
{ |
|||
var parameterNameA = mode.Args[0].MemberName; |
|||
var parameterNameB = mode.Args[1].MemberName; |
|||
return $" SUBSTR({parameterNameA}, -2, {parameterNameB}) "; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,88 @@ |
|||
using Microsoft.Data.SqlClient; |
|||
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.OceanBaseForOracle |
|||
{ |
|||
|
|||
public class OceanBaseForOracleFastBuilder : FastBuilder,IFastBuilder |
|||
{ |
|||
private EntityInfo entityInfo; |
|||
|
|||
public OceanBaseForOracleFastBuilder(EntityInfo entityInfo) |
|||
{ |
|||
this.entityInfo = entityInfo; |
|||
} |
|||
|
|||
public override string UpdateSql { get; set; } = "UPDATE (SELECT {4} FROM {2} TM,{3} TE WHERE {1})SET {0}"; |
|||
public override async Task CreateTempAsync<T>(DataTable dt) |
|||
{ |
|||
var sqlBuilder = this.Context.Queryable<object>().SqlBuilder; |
|||
var dts = dt.Columns.Cast<DataColumn>().Select(it => sqlBuilder.GetTranslationColumnName(it.ColumnName)).ToList(); |
|||
//await Task.FromResult(0);
|
|||
//throw new Exception("Oracle no support BulkUpdate");
|
|||
var oldTableName = dt.TableName; |
|||
var columns = this.Context.EntityMaintenance.GetEntityInfo<T>().Columns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName).ToList(); |
|||
dt.TableName = "Temp" + SnowFlakeSingle.instance.getID().ToString(); |
|||
if (columns.Count() == 0 && DbFastestProperties != null && DbFastestProperties.WhereColumns.HasValue()) |
|||
{ |
|||
columns.AddRange(DbFastestProperties.WhereColumns); |
|||
} |
|||
var sql = this.Context.Queryable<T>().AS(oldTableName).Where(it => false).Select(string.Join(",", dts)).ToSql().Key; |
|||
await this.Context.Ado.ExecuteCommandAsync($"create table {dt.TableName} as {sql} "); |
|||
this.Context.DbMaintenance.AddPrimaryKeys(dt.TableName, columns.ToArray(), "Pk_" + SnowFlakeSingle.instance.getID().ToString()); |
|||
} |
|||
public override async Task<int> UpdateByTempAsync(string tableName, string tempName, string[] updateColumns, string[] whereColumns) |
|||
{ |
|||
var sqlBuilder = this.Context.Queryable<object>().SqlBuilder; |
|||
Check.ArgumentNullException(!updateColumns.Any(), "update columns count is 0"); |
|||
Check.ArgumentNullException(!whereColumns.Any(), "where columns count is 0"); |
|||
var sets = string.Join(",", updateColumns.Select(it => $"TM{it}=TE{it}")); |
|||
var wheres = string.Join(" AND ", whereColumns.Select(it => $"TM.{sqlBuilder.GetTranslationColumnName(it)}=TE.{sqlBuilder.GetTranslationColumnName(it)}")); |
|||
var forms = string.Join(",", updateColumns.Select(it => $" TM.{sqlBuilder.GetTranslationColumnName(it)} TM{it},TE.{sqlBuilder.GetTranslationColumnName(it)} TE{it}")); ; |
|||
string sql = string.Format(UpdateSql, sets, wheres, tableName, tempName, forms); |
|||
return await this.Context.Ado.ExecuteCommandAsync(sql); |
|||
} |
|||
|
|||
public async Task<int> ExecuteBulkCopyAsync(DataTable dt) |
|||
{ |
|||
|
|||
SqlBulkCopy bulkCopy = GetBulkCopyInstance(); |
|||
bulkCopy.DestinationTableName = dt.TableName; |
|||
try |
|||
{ |
|||
await bulkCopy.WriteToServerAsync(dt); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
CloseDb(); |
|||
throw ex; |
|||
} |
|||
CloseDb(); |
|||
return dt.Rows.Count; |
|||
} |
|||
public SqlBulkCopy GetBulkCopyInstance() |
|||
{ |
|||
SqlBulkCopy copy; |
|||
if (this.Context.Ado.Transaction == null) |
|||
{ |
|||
copy = new SqlBulkCopy((SqlConnection)this.Context.Ado.Connection); |
|||
} |
|||
else |
|||
{ |
|||
copy = new SqlBulkCopy((SqlConnection)this.Context.Ado.Connection, SqlBulkCopyOptions.CheckConstraints, (SqlTransaction)this.Context.Ado.Transaction); |
|||
} |
|||
if (this.Context.Ado.Connection.State == ConnectionState.Closed) |
|||
{ |
|||
this.Context.Ado.Connection.Open(); |
|||
} |
|||
copy.BulkCopyTimeout = this.Context.Ado.CommandTimeOut; |
|||
return copy; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,217 @@ |
|||
using SqlSugar.OceanBaseForOracle; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
public class OceanBaseForOracleInsertBuilder : InsertBuilder |
|||
{ |
|||
public override string SqlTemplate |
|||
{ |
|||
get |
|||
{ |
|||
return @"INSERT INTO {0}
|
|||
({1}) |
|||
VALUES |
|||
({2}) ";
|
|||
|
|||
} |
|||
} |
|||
public override string SqlTemplateBatch |
|||
{ |
|||
get |
|||
{ |
|||
return "INSERT INTO {0} ({1})"; |
|||
} |
|||
} |
|||
public override string ToSqlString() |
|||
{ |
|||
var identities = this.EntityInfo.Columns.Where(it => it.OracleSequenceName.HasValue()).ToList(); |
|||
if (IsNoInsertNull) |
|||
{ |
|||
DbColumnInfoList = DbColumnInfoList.Where(it => it.Value != null).ToList(); |
|||
} |
|||
if (this.Context.CurrentConnectionConfig?.MoreSettings?.EnableOracleIdentity == true) |
|||
{ |
|||
this.DbColumnInfoList = this.DbColumnInfoList.Where(it => it.IsIdentity == false).ToList(); |
|||
} |
|||
var groupList = DbColumnInfoList.GroupBy(it => it.TableId).ToList(); |
|||
var isSingle = groupList.Count() == 1; |
|||
string columnsString = string.Join(",", groupList.First().Select(it => Builder.GetTranslationColumnName(it.DbColumnName))); |
|||
if (isSingle && this.EntityInfo.EntityName != "Dictionary`2") |
|||
{ |
|||
|
|||
string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it => base.GetDbColumn(it, Builder.SqlParameterKeyWord + it.DbColumnName))); |
|||
if (identities.HasValue()) |
|||
{ |
|||
columnsString = columnsString.TrimEnd(',') + "," + string.Join(",", identities.Select(it => Builder.GetTranslationColumnName(it.DbColumnName))); |
|||
columnParametersString = columnParametersString.TrimEnd(',') + "," + string.Join(",", identities.Select(it => it.OracleSequenceName + ".nextval")); |
|||
} |
|||
ActionMinDate(); |
|||
return string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString); |
|||
} |
|||
else |
|||
{ |
|||
var bigSize = 500; |
|||
if (groupList.Count < bigSize) |
|||
{ |
|||
string result = Small(identities, groupList, columnsString); |
|||
return result; |
|||
} |
|||
else |
|||
{ |
|||
string result = Big(identities, groupList, columnsString); |
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
private string Big(List<EntityColumnInfo> identities, List<IGrouping<int, DbColumnInfo>> groupList, string columnsString) |
|||
{ |
|||
this.Context.Utilities.PageEach(groupList, 100, groupListPasge => |
|||
{ |
|||
this.Parameters = new List<SugarParameter>(); |
|||
var sql = Small(identities, groupListPasge, columnsString); |
|||
this.Context.Ado.ExecuteCommand(sql, this.Parameters); |
|||
}); |
|||
if (identities != null & identities.Count > 0 && this.OracleSeqInfoList != null && this.OracleSeqInfoList.Any()) |
|||
{ |
|||
return $"SELECT {this.OracleSeqInfoList.First().Value - 1} FROM DUAL"; |
|||
} |
|||
else |
|||
{ |
|||
return $"SELECT {groupList.Count} FROM DUAL"; |
|||
} |
|||
} |
|||
|
|||
private string Small(List<EntityColumnInfo> identities, List<IGrouping<int, DbColumnInfo>> groupList, string columnsString) |
|||
{ |
|||
StringBuilder batchInsetrSql = new StringBuilder(); |
|||
batchInsetrSql.AppendLine("INSERT ALL"); |
|||
foreach (var item in groupList) |
|||
{ |
|||
batchInsetrSql.Append("INTO " + GetTableNameString + " "); |
|||
string insertColumns = ""; |
|||
|
|||
batchInsetrSql.Append("("); |
|||
batchInsetrSql.Append(columnsString); |
|||
if (identities.HasValue() && this.IsOffIdentity == false) |
|||
{ |
|||
batchInsetrSql.Append("," + string.Join(",", identities.Select(it => Builder.GetTranslationColumnName(it.DbColumnName)))); |
|||
} |
|||
batchInsetrSql.Append(") VALUES"); |
|||
|
|||
|
|||
batchInsetrSql.Append("("); |
|||
insertColumns = string.Join(",", item.Select(it => GetDbColumn(it, FormatValue(it.Value, it.PropertyName)))); |
|||
batchInsetrSql.Append(insertColumns); |
|||
if (this.IsOffIdentity == false) |
|||
{ |
|||
if (identities.HasValue()) |
|||
{ |
|||
batchInsetrSql.Append(","); |
|||
foreach (var idn in identities) |
|||
{ |
|||
var seqvalue = this.OracleSeqInfoList[idn.OracleSequenceName]; |
|||
this.OracleSeqInfoList[idn.OracleSequenceName] = this.OracleSeqInfoList[idn.OracleSequenceName] + 1; |
|||
if (identities.Last() == idn) |
|||
{ |
|||
batchInsetrSql.Append(seqvalue); |
|||
} |
|||
else |
|||
{ |
|||
batchInsetrSql.Append(seqvalue + ","); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
batchInsetrSql.AppendLine(") "); |
|||
|
|||
} |
|||
if (identities.HasValue()) |
|||
{ |
|||
batchInsetrSql.AppendLine("SELECT " + (this.OracleSeqInfoList.First().Value - 1) + " FROM DUAL"); |
|||
} |
|||
else |
|||
{ |
|||
batchInsetrSql.AppendLine("SELECT 1 FROM DUAL"); |
|||
} |
|||
var result = batchInsetrSql.ToString(); |
|||
return result; |
|||
} |
|||
|
|||
int i = 0; |
|||
public object FormatValue(object value, string name) |
|||
{ |
|||
if (value == null) |
|||
{ |
|||
return "NULL"; |
|||
} |
|||
else |
|||
{ |
|||
string N = this.Context.GetN(); |
|||
var type = UtilMethods.GetUnderType(value.GetType()); |
|||
if (type == UtilConstants.StringType && value.ToString().Contains("{SugarSeq:=}")) |
|||
{ |
|||
return value.ToString().Replace("{SugarSeq:=}", ""); |
|||
} |
|||
if (type == UtilConstants.DateType) |
|||
{ |
|||
var date = value.ObjToDate(); |
|||
if (date < UtilMethods.GetMinDate(this.Context.CurrentConnectionConfig)) |
|||
{ |
|||
date = UtilMethods.GetMinDate(this.Context.CurrentConnectionConfig); |
|||
} |
|||
if (this.Context.CurrentConnectionConfig?.MoreSettings?.DisableMillisecond == true) |
|||
{ |
|||
return "to_date('" + date.ToString("yyyy-MM-dd HH:mm:ss") + "', 'YYYY-MM-DD HH24:MI:SS') "; |
|||
} |
|||
else |
|||
{ |
|||
return "to_timestamp('" + date.ToString("yyyy-MM-dd HH:mm:ss.ffffff") + "', 'YYYY-MM-DD HH24:MI:SS.FF') "; |
|||
} |
|||
} |
|||
else if (type.IsEnum()) |
|||
{ |
|||
return Convert.ToInt64(value); |
|||
} |
|||
else if (type == UtilConstants.ByteArrayType) |
|||
{ |
|||
++i; |
|||
var parameterName = this.Builder.SqlParameterKeyWord + name + i; |
|||
this.Parameters.Add(new SugarParameter(parameterName, value, System.Data.DbType.Binary)); |
|||
return parameterName; |
|||
} |
|||
else if (type == UtilConstants.BoolType) |
|||
{ |
|||
return value.ObjToBool() ? "1" : "0"; |
|||
} |
|||
else if (type == UtilConstants.DateTimeOffsetType) |
|||
{ |
|||
var date = UtilMethods.ConvertFromDateTimeOffset((DateTimeOffset)value); |
|||
return "to_timestamp('" + date.ToString("yyyy-MM-dd HH:mm:ss.ffffff") + "', 'YYYY-MM-DD HH24:MI:SS.FF') "; |
|||
} |
|||
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType) |
|||
{ |
|||
if (value.ToString().Length > 1000) |
|||
{ |
|||
++i; |
|||
var parameterName = this.Builder.SqlParameterKeyWord + name + i; |
|||
this.Parameters.Add(new SugarParameter(parameterName, value)); |
|||
return parameterName; |
|||
} |
|||
else |
|||
{ |
|||
return N + "'" + value.ToString().ToSqlFilter() + "'"; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
return N + "'" + value.ToString() + "'"; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,136 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Text.RegularExpressions; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
public class OceanBaseForOracleQueryBuilder : QueryBuilder |
|||
{ |
|||
public override bool IsSelectNoAll { get; set; } = true; |
|||
public override bool IsComplexModel(string sql) |
|||
{ |
|||
return Regex.IsMatch(sql, @"AS ""\w+\.\w+""") || Regex.IsMatch(sql, @"AS ""\w+\.\w+\.\w+"""); |
|||
} |
|||
public override string SqlTemplate |
|||
{ |
|||
get |
|||
{ |
|||
return "SELECT {0}{" + UtilConstants.ReplaceKey + "} FROM {1}{2}{3}{4}"; |
|||
} |
|||
} |
|||
public override string ToSqlString() |
|||
{ |
|||
//OB的Oracle模式,暂不支持Offsetpage
|
|||
//if (this.Offset == "true")
|
|||
//{
|
|||
// return OffsetPage();
|
|||
//}
|
|||
var oldTake = Take; |
|||
var oldSkip = Skip; |
|||
var isDistinctPage = IsDistinct && (Take > 1 || Skip > 1); |
|||
//if (isDistinctPage)
|
|||
//{
|
|||
// return OffsetPage();
|
|||
//}
|
|||
var result = _ToSqlString(); |
|||
//if (isDistinctPage)
|
|||
//{
|
|||
// if (this.OrderByValue.HasValue())
|
|||
// {
|
|||
// Take = int.MaxValue;
|
|||
// result = result.Replace("DISTINCT", $" DISTINCT TOP {int.MaxValue} ");
|
|||
// }
|
|||
// Take = oldTake;
|
|||
// Skip = oldSkip;
|
|||
// result = this.Context.SqlQueryable<object>(result).Skip(Skip??0).Take(Take??0).ToSql().Key;
|
|||
|
|||
|
|||
//}
|
|||
if (TranLock != null) |
|||
{ |
|||
result = result + TranLock; |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
private string OffsetPage() |
|||
{ |
|||
var skip = this.Skip; |
|||
var take = this.Take; |
|||
this.Skip = null; |
|||
this.Take = null; |
|||
this.Offset = null; |
|||
var pageSql = $"SELECT * FROM ( SELECT PAGETABLE1.*,ROWNUM PAGEINDEX FROM( {this.ToSqlString()}) PAGETABLE1 WHERE ROWNUM<={skip + take}) WHERE PAGEINDEX>={skip + 1}"; |
|||
return pageSql; |
|||
} |
|||
|
|||
public string _ToSqlString() |
|||
{ |
|||
string oldOrderBy = this.OrderByValue; |
|||
string externalOrderBy = oldOrderBy; |
|||
var isIgnoreOrderBy = this.IsCount && this.PartitionByValue.IsNullOrEmpty(); |
|||
AppendFilter(); |
|||
sql = new StringBuilder(); |
|||
if (this.OrderByValue == null && (Skip != null || Take != null)) this.OrderByValue = " ORDER BY " + this.Builder.SqlDateNow + " "; |
|||
if (this.PartitionByValue.HasValue()) |
|||
{ |
|||
this.OrderByValue = this.PartitionByValue + this.OrderByValue; |
|||
} |
|||
var isRowNumber = Skip != null || Take != null; |
|||
var rowNumberString = string.Format(",ROW_NUMBER() OVER({0}) AS RowIndex ", GetOrderByString); |
|||
string groupByValue = GetGroupByString + HavingInfos; |
|||
string orderByValue = (!isRowNumber && this.OrderByValue.HasValue()) ? GetOrderByString : null; |
|||
if (isIgnoreOrderBy) { orderByValue = null; } |
|||
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, groupByValue, orderByValue); |
|||
sql.Replace(UtilConstants.ReplaceKey, isRowNumber ? (isIgnoreOrderBy ? null : rowNumberString) : null); |
|||
if (isIgnoreOrderBy) { this.OrderByValue = oldOrderBy; return sql.ToString(); } |
|||
var result = ToPageSql(sql.ToString(), this.Take, this.Skip); |
|||
if (ExternalPageIndex > 0) |
|||
{ |
|||
if (externalOrderBy.IsNullOrEmpty()) |
|||
{ |
|||
externalOrderBy = " ORDER BY " + this.Builder.SqlDateNow + " "; |
|||
} |
|||
result = string.Format("SELECT ExternalTable.*,ROW_NUMBER() OVER({0}) AS RowIndex2 FROM ({1}) ExternalTable ", GetExternalOrderBy(externalOrderBy), result); |
|||
result = ToPageSql2(result, ExternalPageIndex, ExternalPageSize, true); |
|||
} |
|||
this.OrderByValue = oldOrderBy; |
|||
result = GetSqlQuerySql(result); |
|||
if (result.IndexOf("-- No table") > 0) |
|||
{ |
|||
return "-- No table"; |
|||
} |
|||
return result; |
|||
} |
|||
public override string ToPageSql(string sql, int? take, int? skip, bool isExternal = false) |
|||
{ |
|||
string temp = isExternal ? ExternalPageTempalte : PageTempalte; |
|||
if (skip != null && take == null) |
|||
{ |
|||
return string.Format(temp, sql.ToString(), skip.ObjToInt() + 1, long.MaxValue); |
|||
} |
|||
else if (skip == null && take != null) |
|||
{ |
|||
return string.Format(temp, sql.ToString(), 1, take.ObjToInt()); |
|||
} |
|||
else if (skip != null && take != null) |
|||
{ |
|||
return string.Format(temp, sql.ToString(), skip.ObjToInt() + 1, skip.ObjToInt() + take.ObjToInt()); |
|||
} |
|||
else |
|||
{ |
|||
return sql.ToString(); |
|||
} |
|||
} |
|||
|
|||
public override string ToPageSql2(string sql, int? pageIndex, int? pageSize, bool isExternal = false) |
|||
{ |
|||
string temp = isExternal ? ExternalPageTempalte : PageTempalte; |
|||
return string.Format(temp, sql.ToString(), (pageIndex - 1) * pageSize + 1, pageIndex * pageSize); |
|||
} |
|||
|
|||
} |
|||
} |
@ -0,0 +1,150 @@ |
|||
using SqlSugar.OceanBaseForOracle; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Text.RegularExpressions; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
public class OceanBaseForOracleUpdateBuilder : UpdateBuilder |
|||
{ |
|||
public override string ReSetValueBySqlExpListType { get; set; } = "oracle"; |
|||
protected override string TomultipleSqlString(List<IGrouping<int, DbColumnInfo>> groupList) |
|||
{ |
|||
if (groupList.Count == 0) |
|||
{ |
|||
return " select 0 from dual"; |
|||
} |
|||
StringBuilder sb = new StringBuilder(); |
|||
sb.AppendLine("Begin"); |
|||
sb.AppendLine(string.Join("\r\n", groupList.Select(t => |
|||
{ |
|||
var updateTable = string.Format("UPDATE {0} SET", base.GetTableNameStringNoWith); |
|||
var setValues = string.Join(",", t.Where(s => !s.IsPrimarykey).Select(m => GetOracleUpdateColums(m)).ToArray()); |
|||
var pkList = t.Where(s => s.IsPrimarykey).ToList(); |
|||
List<string> whereList = new List<string>(); |
|||
foreach (var item in pkList) |
|||
{ |
|||
var isFirst = pkList.First() == item; |
|||
var whereString = isFirst ? " " : " AND "; |
|||
whereString += GetOracleUpdateColums(item); |
|||
whereList.Add(whereString); |
|||
} |
|||
return string.Format("{0} {1} WHERE {2};", updateTable, setValues, string.Join("", whereList)); |
|||
}).ToArray())); |
|||
sb.AppendLine("End;"); |
|||
return sb.ToString(); |
|||
} |
|||
|
|||
private string GetOracleUpdateColums(DbColumnInfo m) |
|||
{ |
|||
return string.Format("\"{0}\"={1}", m.DbColumnName.ToUpper(IsUppper), base.GetDbColumn(m, FormatValue(m.Value, m.IsPrimarykey, m.PropertyName))); |
|||
} |
|||
int i = 0; |
|||
public object FormatValue(object value, bool isPrimaryKey, string name) |
|||
{ |
|||
if (value == null) |
|||
{ |
|||
return "NULL"; |
|||
} |
|||
else |
|||
{ |
|||
string N = this.Context.GetN(); |
|||
if (isPrimaryKey) |
|||
{ |
|||
N = ""; |
|||
} |
|||
var type = UtilMethods.GetUnderType(value.GetType()); |
|||
if (type == UtilConstants.DateType) |
|||
{ |
|||
var date = value.ObjToDate(); |
|||
if (date < UtilMethods.GetMinDate(this.Context.CurrentConnectionConfig)) |
|||
{ |
|||
date = UtilMethods.GetMinDate(this.Context.CurrentConnectionConfig); |
|||
} |
|||
if (this.Context.CurrentConnectionConfig?.MoreSettings?.DisableMillisecond == true) |
|||
{ |
|||
return "to_date('" + date.ToString("yyyy-MM-dd HH:mm:ss") + "', 'YYYY-MM-DD HH24:MI:SS') "; |
|||
} |
|||
else |
|||
{ |
|||
return "to_timestamp('" + date.ToString("yyyy-MM-dd HH:mm:ss.ffffff") + "', 'YYYY-MM-DD HH24:MI:SS.FF') "; |
|||
} |
|||
} |
|||
else if (type.IsEnum()) |
|||
{ |
|||
return Convert.ToInt64(value); |
|||
} |
|||
else if (type.IsIn(UtilConstants.IntType, UtilConstants.LongType, UtilConstants.ShortType)) |
|||
{ |
|||
return value; |
|||
} |
|||
else if (type == UtilConstants.GuidType) |
|||
{ |
|||
return "'" + value.ToString() + "'"; |
|||
} |
|||
else if (type == UtilConstants.ByteArrayType) |
|||
{ |
|||
string bytesString = "0x" + BitConverter.ToString((byte[])value).Replace("-", ""); |
|||
return bytesString; |
|||
} |
|||
else if (type == UtilConstants.BoolType) |
|||
{ |
|||
return value.ObjToBool() ? "1" : "0"; |
|||
} |
|||
else if (type == UtilConstants.DateTimeOffsetType) |
|||
{ |
|||
var date = UtilMethods.ConvertFromDateTimeOffset((DateTimeOffset)value); |
|||
return "to_timestamp('" + date.ToString("yyyy-MM-dd HH:mm:ss.ffffff") + "', 'YYYY-MM-DD HH24:MI:SS.FF') "; |
|||
} |
|||
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType) |
|||
{ |
|||
if (value.ToString().Length > 1000) |
|||
{ |
|||
++i; |
|||
var parameterName = this.Builder.SqlParameterKeyWord + name + i; |
|||
this.Parameters.Add(new SugarParameter(parameterName, value)); |
|||
return parameterName; |
|||
} |
|||
else |
|||
{ |
|||
return N + "'" + value.ToString().ToSqlFilter() + "'"; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
return N + "'" + value.ToString() + "'"; |
|||
} |
|||
} |
|||
} |
|||
protected override string GetJoinUpdate(string columnsString, ref string whereString) |
|||
{ |
|||
var joinString = $" {Builder.GetTranslationColumnName(this.TableName)} {Builder.GetTranslationColumnName(this.ShortName)} "; |
|||
foreach (var item in this.JoinInfos) |
|||
{ |
|||
joinString += $"\r\n USING {Builder.GetTranslationColumnName(item.TableName)} {Builder.GetTranslationColumnName(item.ShortName)} ON {item.JoinWhere} "; |
|||
} |
|||
var tableName = joinString + "\r\n "; |
|||
var newTemp = SqlTemplate.Replace("UPDATE", "MERGE INTO").Replace("SET", "WHEN MATCHED THEN \r\nUPDATE SET"); |
|||
return string.Format(newTemp, tableName, columnsString, whereString); |
|||
} |
|||
#region Helper
|
|||
public bool IsUppper |
|||
{ |
|||
get |
|||
{ |
|||
if (this.Context.CurrentConnectionConfig.MoreSettings == null) |
|||
{ |
|||
return true; |
|||
} |
|||
else |
|||
{ |
|||
return this.Context.CurrentConnectionConfig.MoreSettings.IsAutoToUpper == true; |
|||
} |
|||
} |
|||
} |
|||
#endregion
|
|||
} |
|||
} |
@ -0,0 +1,17 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net6.0</TargetFramework> |
|||
<ImplicitUsings>enable</ImplicitUsings> |
|||
<Nullable>enable</Nullable> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="System.Data.Odbc" Version="7.0.0" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\SqlSugar\SqlSugar.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
@ -0,0 +1,24 @@ |
|||
<?xml version="1.0"?> |
|||
<package > |
|||
<metadata> |
|||
<id>SqlSugar.OdbcCore</id> |
|||
<version>5.1.4.2</version> |
|||
<authors>sunkaixuan</authors> |
|||
<owners>Landa</owners> |
|||
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl> |
|||
<projectUrl>https://github.com/sunkaixuan/SqlSugar</projectUrl> |
|||
<iconUrl>https://secure.gravatar.com/avatar/a82c03402497b2e58fd65038a3699b30</iconUrl> |
|||
<requireLicenseAcceptance>false</requireLicenseAcceptance> |
|||
<description> SqlSugar 通过ODBC连接数据库 </description> |
|||
<copyright>Copyright 2016</copyright> |
|||
<tags>Asp.net core orm</tags> |
|||
<dependencies> |
|||
<group targetFramework=".NETStandard2.1"> |
|||
<dependency id="System.Data.Odbc" version="4.6" /> |
|||
</group> |
|||
</dependencies> |
|||
</metadata> |
|||
<files> |
|||
<file src="G:\Git\SqlSugar\Src\Asp.NetCore2\SqlSugar.OdbcCore\bin\Debug\netstandard2.1\SqlSugar.OdbcCore.dll" target="lib\netstandard2.1"></file> |
|||
</files> |
|||
</package> |
@ -0,0 +1,64 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
internal static partial class ErrorMessage |
|||
{ |
|||
internal static LanguageType SugarLanguageType { get; set; } = LanguageType.Default; |
|||
internal static string ObjNotExist |
|||
{ |
|||
get |
|||
{ |
|||
return GetThrowMessage("{0} does not exist.", |
|||
"{0}不存在。"); |
|||
} |
|||
} |
|||
internal static string EntityMappingError |
|||
{ |
|||
get |
|||
{ |
|||
return GetThrowMessage("Entity mapping error.{0}", |
|||
"实体与表映射出错。{0}"); |
|||
} |
|||
} |
|||
|
|||
public static string NotSupportedDictionary |
|||
{ |
|||
get |
|||
{ |
|||
return GetThrowMessage("This type of Dictionary is not supported for the time being. You can try Dictionary<string, string>, or contact the author!!", |
|||
"暂时不支持该类型的Dictionary 你可以试试 Dictionary<string ,string>或者联系作者!!"); |
|||
} |
|||
} |
|||
|
|||
public static string NotSupportedArray |
|||
{ |
|||
get |
|||
{ |
|||
return GetThrowMessage("This type of Array is not supported for the time being. You can try object[] or contact the author!!", |
|||
"暂时不支持该类型的Array 你可以试试 object[] 或者联系作者!!"); |
|||
} |
|||
} |
|||
|
|||
internal static string GetThrowMessage(string enMessage, string cnMessage, params string[] args) |
|||
{ |
|||
if (SugarLanguageType == LanguageType.Default) |
|||
{ |
|||
List<string> formatArgs = new List<string>() { enMessage, cnMessage }; |
|||
formatArgs.AddRange(args); |
|||
return string.Format(@"中文提示 : {1}
|
|||
English Message : {0}", formatArgs.ToArray());
|
|||
} |
|||
else if (SugarLanguageType == LanguageType.English) |
|||
{ |
|||
return enMessage; |
|||
} |
|||
else |
|||
{ |
|||
return cnMessage; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,20 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Expressions; |
|||
using System.Text; |
|||
|
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
internal class ExpressionConst |
|||
{ |
|||
public const string Const = "Const"; |
|||
public const string FormatSymbol = "{0}"; |
|||
public const string RightParenthesis = ")"; |
|||
public const string LeftParenthesis = "("; |
|||
public const string MethodConst = "MethodConst"; |
|||
public const string SqlFuncFullName = "SqlSugar.SqlFunc"; |
|||
public const string BinaryFormatString = " ( {0} {1} {2} ) "; |
|||
public const string ExpressionReplace = "46450BDC-77B7-4025-B2A6-3F048CA85AD0"; |
|||
} |
|||
} |
@ -0,0 +1,70 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
internal class FileHelper |
|||
{ |
|||
public static void CreateFile(string filePath, string text, Encoding encoding) |
|||
{ |
|||
try |
|||
{ |
|||
if (IsExistFile(filePath)) |
|||
{ |
|||
DeleteFile(filePath); |
|||
} |
|||
if (!IsExistFile(filePath)) |
|||
{ |
|||
string directoryPath = GetDirectoryFromFilePath(filePath); |
|||
CreateDirectory(directoryPath); |
|||
|
|||
//Create File
|
|||
FileInfo file = new FileInfo(filePath); |
|||
using (FileStream stream = file.Create()) |
|||
{ |
|||
using (StreamWriter writer = new StreamWriter(stream, encoding)) |
|||
{ |
|||
writer.Write(text); |
|||
writer.Flush(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
catch(Exception ex) |
|||
{ |
|||
throw ex; |
|||
} |
|||
} |
|||
public static bool IsExistDirectory(string directoryPath) |
|||
{ |
|||
return Directory.Exists(directoryPath); |
|||
} |
|||
public static void CreateDirectory(string directoryPath) |
|||
{ |
|||
if (!IsExistDirectory(directoryPath)) |
|||
{ |
|||
Directory.CreateDirectory(directoryPath); |
|||
} |
|||
} |
|||
public static void DeleteFile(string filePath) |
|||
{ |
|||
if (IsExistFile(filePath)) |
|||
{ |
|||
File.Delete(filePath); |
|||
} |
|||
} |
|||
public static string GetDirectoryFromFilePath(string filePath) |
|||
{ |
|||
FileInfo file = new FileInfo(filePath); |
|||
DirectoryInfo directory = file.Directory; |
|||
return directory.FullName; |
|||
} |
|||
public static bool IsExistFile(string filePath) |
|||
{ |
|||
return File.Exists(filePath); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,73 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Dynamic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
internal static class UtilConstants |
|||
{ |
|||
public const string Dot = "."; |
|||
public const char DotChar = '.'; |
|||
internal const string Space = " "; |
|||
internal const char SpaceChar =' '; |
|||
internal const string AssemblyName = "SqlSugar"; |
|||
internal const string ReplaceKey = "{662E689B-17A1-4D06-9D27-F29EAB8BC3D6}"; |
|||
internal const string ReplaceCommaKey = "{112A689B-17A1-4A06-9D27-A39EAB8BC3D5}"; |
|||
|
|||
internal static Type IntType = typeof(int); |
|||
internal static Type LongType = typeof(long); |
|||
internal static Type GuidType = typeof(Guid); |
|||
internal static Type BoolType = typeof(bool); |
|||
internal static Type BoolTypeNull = typeof(bool?); |
|||
internal static Type ByteType = typeof(Byte); |
|||
internal static Type ObjType = typeof(object); |
|||
internal static Type DobType = typeof(double); |
|||
internal static Type FloatType = typeof(float); |
|||
internal static Type ShortType = typeof(short); |
|||
internal static Type DecType = typeof(decimal); |
|||
internal static Type StringType = typeof(string); |
|||
internal static Type DateType = typeof(DateTime); |
|||
internal static Type DateTimeOffsetType = typeof(DateTimeOffset); |
|||
internal static Type TimeSpanType = typeof(TimeSpan); |
|||
internal static Type ByteArrayType = typeof(byte[]); |
|||
internal static Type ModelType= typeof(ModelContext); |
|||
internal static Type DynamicType = typeof(ExpandoObject); |
|||
internal static Type Dicii = typeof(KeyValuePair<int, int>); |
|||
internal static Type DicIS = typeof(KeyValuePair<int, string>); |
|||
internal static Type DicSi = typeof(KeyValuePair<string, int>); |
|||
internal static Type DicSS = typeof(KeyValuePair<string, string>); |
|||
internal static Type DicOO = typeof(KeyValuePair<object, object>); |
|||
internal static Type DicSo = typeof(KeyValuePair<string, object>); |
|||
internal static Type DicArraySS = typeof(Dictionary<string, string>); |
|||
internal static Type DicArraySO = typeof(Dictionary<string, object>); |
|||
|
|||
public static Type SugarType = typeof(SqlSugarProvider); |
|||
|
|||
|
|||
internal static Type[] NumericalTypes = new Type[] |
|||
{ |
|||
typeof(int), |
|||
typeof(uint), |
|||
typeof(byte), |
|||
typeof(sbyte), |
|||
typeof(long), |
|||
typeof(ulong), |
|||
typeof(short), |
|||
typeof(ushort), |
|||
}; |
|||
|
|||
|
|||
internal static string[] DateTypeStringList = new string[] |
|||
{ |
|||
"Year", |
|||
"Month", |
|||
"Day", |
|||
"Hour", |
|||
"Second" , |
|||
"Minute", |
|||
"Millisecond", |
|||
"Date" |
|||
}; |
|||
} |
|||
} |
@ -0,0 +1,158 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
/// <summary>
|
|||
///Common Extensions for external users
|
|||
/// </summary>
|
|||
public static class UtilExtensions |
|||
{ |
|||
public static bool EqualCase(this string thisValue, string equalValue) |
|||
{ |
|||
if (thisValue != null && equalValue != null) |
|||
{ |
|||
return thisValue.ToLower() == equalValue.ToLower(); |
|||
} |
|||
else |
|||
{ |
|||
return thisValue == equalValue; |
|||
} |
|||
} |
|||
public static string ToLower(this string value, bool isLower) |
|||
{ |
|||
if (isLower) |
|||
{ |
|||
return value.ObjToString().ToLower(); |
|||
} |
|||
return value.ObjToString(); |
|||
} |
|||
public static int ObjToInt(this object thisValue) |
|||
{ |
|||
int reval = 0; |
|||
if (thisValue == null) return 0; |
|||
if (thisValue is Enum) |
|||
{ |
|||
return (int)thisValue; |
|||
} |
|||
if (thisValue != null && thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out reval)) |
|||
{ |
|||
return reval; |
|||
} |
|||
return reval; |
|||
} |
|||
|
|||
public static int ObjToInt(this object thisValue, int errorValue) |
|||
{ |
|||
int reval = 0; |
|||
if (thisValue is Enum) |
|||
{ |
|||
return (int)thisValue; |
|||
} |
|||
if (thisValue != null && thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out reval)) |
|||
{ |
|||
return reval; |
|||
} |
|||
return errorValue; |
|||
} |
|||
|
|||
public static double ObjToMoney(this object thisValue) |
|||
{ |
|||
double reval = 0; |
|||
if (thisValue != null && thisValue != DBNull.Value && double.TryParse(thisValue.ToString(), out reval)) |
|||
{ |
|||
return reval; |
|||
} |
|||
return 0; |
|||
} |
|||
|
|||
public static double ObjToMoney(this object thisValue, double errorValue) |
|||
{ |
|||
double reval = 0; |
|||
if (thisValue != null && thisValue != DBNull.Value && double.TryParse(thisValue.ToString(), out reval)) |
|||
{ |
|||
return reval; |
|||
} |
|||
return errorValue; |
|||
} |
|||
|
|||
public static string ObjToString(this object thisValue) |
|||
{ |
|||
if (thisValue != null) return thisValue.ToString().Trim(); |
|||
return ""; |
|||
} |
|||
|
|||
public static string ObjToString(this object thisValue, string errorValue) |
|||
{ |
|||
if (thisValue != null) return thisValue.ToString().Trim(); |
|||
return errorValue; |
|||
} |
|||
|
|||
public static Decimal ObjToDecimal(this object thisValue) |
|||
{ |
|||
Decimal reval = 0; |
|||
if (thisValue != null && thisValue != DBNull.Value && decimal.TryParse(thisValue.ToString(), out reval)) |
|||
{ |
|||
return reval; |
|||
} |
|||
return 0; |
|||
} |
|||
|
|||
public static Decimal ObjToDecimal(this object thisValue, decimal errorValue) |
|||
{ |
|||
Decimal reval = 0; |
|||
if (thisValue != null && thisValue != DBNull.Value && decimal.TryParse(thisValue.ToString(), out reval)) |
|||
{ |
|||
return reval; |
|||
} |
|||
return errorValue; |
|||
} |
|||
|
|||
public static DateTime ObjToDate(this object thisValue) |
|||
{ |
|||
DateTime reval = DateTime.MinValue; |
|||
if (thisValue != null && thisValue != DBNull.Value && DateTime.TryParse(thisValue.ToString(), out reval)) |
|||
{ |
|||
reval = Convert.ToDateTime(thisValue); |
|||
} |
|||
return reval; |
|||
} |
|||
|
|||
public static DateTime ObjToDate(this object thisValue, DateTime errorValue) |
|||
{ |
|||
DateTime reval = DateTime.MinValue; |
|||
if (thisValue != null && thisValue != DBNull.Value && DateTime.TryParse(thisValue.ToString(), out reval)) |
|||
{ |
|||
return reval; |
|||
} |
|||
return errorValue; |
|||
} |
|||
|
|||
public static bool ObjToBool(this object thisValue) |
|||
{ |
|||
bool reval = false; |
|||
if (thisValue != null && thisValue != DBNull.Value && bool.TryParse(thisValue.ToString(), out reval)) |
|||
{ |
|||
return reval; |
|||
} |
|||
return reval; |
|||
} |
|||
public static string ToUpper(this string value, bool isAutoToUpper) |
|||
{ |
|||
if (value == null) return null; |
|||
if (isAutoToUpper == false) return value; |
|||
return value.ToUpper(); |
|||
} |
|||
|
|||
public static string GetN(this SqlSugarProvider Context) |
|||
{ |
|||
var N = "N"; |
|||
if (Context.CurrentConnectionConfig.MoreSettings != null && Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar) |
|||
{ |
|||
N = ""; |
|||
} |
|||
return N; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,507 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel; |
|||
using System.Data; |
|||
using System.Diagnostics; |
|||
using System.Globalization; |
|||
using System.Linq; |
|||
using System.Linq.Expressions; |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Security.Cryptography; |
|||
using System.Text; |
|||
using System.Text.RegularExpressions; |
|||
|
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
public class UtilMethods |
|||
{ |
|||
internal static DateTime GetMinDate(ConnectionConfig currentConnectionConfig) |
|||
{ |
|||
if (currentConnectionConfig.MoreSettings == null) |
|||
{ |
|||
return Convert.ToDateTime("1900-01-01"); |
|||
} |
|||
else if (currentConnectionConfig.MoreSettings.DbMinDate == null) |
|||
{ |
|||
return Convert.ToDateTime("1900-01-01"); |
|||
} |
|||
else |
|||
{ |
|||
return currentConnectionConfig.MoreSettings.DbMinDate.Value; |
|||
} |
|||
} |
|||
internal static DateTime ConvertFromDateTimeOffset(DateTimeOffset dateTime) |
|||
{ |
|||
if (dateTime.Offset.Equals(TimeSpan.Zero)) |
|||
return dateTime.UtcDateTime; |
|||
else if (dateTime.Offset.Equals(TimeZoneInfo.Local.GetUtcOffset(dateTime.DateTime))) |
|||
return DateTime.SpecifyKind(dateTime.DateTime, DateTimeKind.Local); |
|||
else |
|||
return dateTime.DateTime; |
|||
} |
|||
|
|||
internal static object To(object value, Type destinationType) |
|||
{ |
|||
return To(value, destinationType, CultureInfo.InvariantCulture); |
|||
} |
|||
|
|||
internal static object To(object value, Type destinationType, CultureInfo culture) |
|||
{ |
|||
if (value != null) |
|||
{ |
|||
destinationType = UtilMethods.GetUnderType(destinationType); |
|||
var sourceType = value.GetType(); |
|||
|
|||
var destinationConverter = TypeDescriptor.GetConverter(destinationType); |
|||
if (destinationConverter != null && destinationConverter.CanConvertFrom(value.GetType())) |
|||
return destinationConverter.ConvertFrom(null, culture, value); |
|||
|
|||
var sourceConverter = TypeDescriptor.GetConverter(sourceType); |
|||
if (sourceConverter != null && sourceConverter.CanConvertTo(destinationType)) |
|||
return sourceConverter.ConvertTo(null, culture, value, destinationType); |
|||
|
|||
if (destinationType.IsEnum && value is int) |
|||
return Enum.ToObject(destinationType, (int)value); |
|||
|
|||
if (!destinationType.IsInstanceOfType(value)) |
|||
return Convert.ChangeType(value, destinationType, culture); |
|||
} |
|||
return value; |
|||
} |
|||
public static bool IsAnyAsyncMethod(StackFrame[] methods) |
|||
{ |
|||
bool isAsync = false; |
|||
foreach (var item in methods) |
|||
{ |
|||
if (UtilMethods.IsAsyncMethod(item.GetMethod())) |
|||
{ |
|||
isAsync = true; |
|||
break; |
|||
} |
|||
} |
|||
return isAsync; |
|||
} |
|||
|
|||
public static bool IsAsyncMethod(MethodBase method) |
|||
{ |
|||
if (method == null) |
|||
{ |
|||
return false; |
|||
} |
|||
if (method.DeclaringType != null) |
|||
{ |
|||
if (method.DeclaringType.GetInterfaces().Contains(typeof(IAsyncStateMachine))) |
|||
{ |
|||
return true; |
|||
} |
|||
} |
|||
var name = method.Name; |
|||
if (name.Contains("OutputAsyncCausalityEvents")) |
|||
{ |
|||
return true; |
|||
} |
|||
if (name.Contains("OutputWaitEtwEvents")) |
|||
{ |
|||
return true; |
|||
} |
|||
if (name.Contains("ExecuteAsync")) |
|||
{ |
|||
return true; |
|||
} |
|||
Type attType = typeof(AsyncStateMachineAttribute); |
|||
var attrib = (AsyncStateMachineAttribute)method.GetCustomAttribute(attType); |
|||
return (attrib != null); |
|||
} |
|||
|
|||
public static StackTraceInfo GetStackTrace() |
|||
{ |
|||
|
|||
StackTrace st = new StackTrace(true); |
|||
StackTraceInfo info = new StackTraceInfo(); |
|||
info.MyStackTraceList = new List<StackTraceInfoItem>(); |
|||
info.SugarStackTraceList = new List<StackTraceInfoItem>(); |
|||
for (int i = 0; i < st.FrameCount; i++) |
|||
{ |
|||
var frame = st.GetFrame(i); |
|||
if (frame.GetMethod().Module.Name.ToLower() != "sqlsugar.dll" && frame.GetMethod().Name.First() != '<') |
|||
{ |
|||
info.MyStackTraceList.Add(new StackTraceInfoItem() |
|||
{ |
|||
FileName = frame.GetFileName(), |
|||
MethodName = frame.GetMethod().Name, |
|||
Line = frame.GetFileLineNumber() |
|||
}); |
|||
} |
|||
else |
|||
{ |
|||
info.SugarStackTraceList.Add(new StackTraceInfoItem() |
|||
{ |
|||
FileName = frame.GetFileName(), |
|||
MethodName = frame.GetMethod().Name, |
|||
Line = frame.GetFileLineNumber() |
|||
}); |
|||
} |
|||
} |
|||
return info; |
|||
} |
|||
|
|||
internal static T To<T>(object value) |
|||
{ |
|||
return (T)To(value, typeof(T)); |
|||
} |
|||
internal static Type GetUnderType(Type oldType) |
|||
{ |
|||
Type type = Nullable.GetUnderlyingType(oldType); |
|||
return type == null ? oldType : type; |
|||
} |
|||
public static string ReplaceSqlParameter(string itemSql, SugarParameter itemParameter, string newName) |
|||
{ |
|||
itemSql = Regex.Replace(itemSql, string.Format(@"{0} ", "\\" + itemParameter.ParameterName), newName + " ", RegexOptions.IgnoreCase); |
|||
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\)", "\\" + itemParameter.ParameterName), newName + ")", RegexOptions.IgnoreCase); |
|||
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\,", "\\" + itemParameter.ParameterName), newName + ",", RegexOptions.IgnoreCase); |
|||
itemSql = Regex.Replace(itemSql, string.Format(@"{0}$", "\\" + itemParameter.ParameterName), newName, RegexOptions.IgnoreCase); |
|||
itemSql = Regex.Replace(itemSql, string.Format(@"\+{0}\+", "\\" + itemParameter.ParameterName), "+" + newName + "+", RegexOptions.IgnoreCase); |
|||
itemSql = Regex.Replace(itemSql, string.Format(@"\+{0} ", "\\" + itemParameter.ParameterName), "+" + newName + " ", RegexOptions.IgnoreCase); |
|||
itemSql = Regex.Replace(itemSql, string.Format(@" {0}\+", "\\" + itemParameter.ParameterName), " " + newName + "+", RegexOptions.IgnoreCase); |
|||
itemSql = Regex.Replace(itemSql, string.Format(@"\|\|{0}\|\|", "\\" + itemParameter.ParameterName), "||" + newName + "||", RegexOptions.IgnoreCase); |
|||
itemSql = Regex.Replace(itemSql, string.Format(@"\={0}\+", "\\" + itemParameter.ParameterName), "=" + newName + "+", RegexOptions.IgnoreCase); |
|||
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\|\|", "\\" + itemParameter.ParameterName), newName + "||", RegexOptions.IgnoreCase); |
|||
return itemSql; |
|||
} |
|||
internal static Type GetRootBaseType(Type entityType) |
|||
{ |
|||
var baseType = entityType.BaseType; |
|||
while (baseType != null && baseType.BaseType != UtilConstants.ObjType) |
|||
{ |
|||
baseType = baseType.BaseType; |
|||
} |
|||
return baseType; |
|||
} |
|||
|
|||
|
|||
internal static Type GetUnderType(PropertyInfo propertyInfo, ref bool isNullable) |
|||
{ |
|||
Type unType = Nullable.GetUnderlyingType(propertyInfo.PropertyType); |
|||
isNullable = unType != null; |
|||
unType = unType ?? propertyInfo.PropertyType; |
|||
return unType; |
|||
} |
|||
|
|||
internal static Type GetUnderType(PropertyInfo propertyInfo) |
|||
{ |
|||
Type unType = Nullable.GetUnderlyingType(propertyInfo.PropertyType); |
|||
unType = unType ?? propertyInfo.PropertyType; |
|||
return unType; |
|||
} |
|||
|
|||
internal static bool IsNullable(PropertyInfo propertyInfo) |
|||
{ |
|||
Type unType = Nullable.GetUnderlyingType(propertyInfo.PropertyType); |
|||
return unType != null; |
|||
} |
|||
|
|||
internal static bool IsNullable(Type type) |
|||
{ |
|||
Type unType = Nullable.GetUnderlyingType(type); |
|||
return unType != null; |
|||
} |
|||
//internal static T IsNullReturnNew<T>(T returnObj) where T : new()
|
|||
//{
|
|||
// if (returnObj.IsNullOrEmpty())
|
|||
// {
|
|||
// returnObj = new T();
|
|||
// }
|
|||
// return returnObj;
|
|||
//}
|
|||
public static object ChangeType2(object value, Type type) |
|||
{ |
|||
if (value == null && type.IsGenericType) return Activator.CreateInstance(type); |
|||
if (value == null) return null; |
|||
if (type == value.GetType()) return value; |
|||
if (type.IsEnum) |
|||
{ |
|||
if (value is string) |
|||
return Enum.Parse(type, value as string); |
|||
else |
|||
return Enum.ToObject(type, value); |
|||
} |
|||
if (!type.IsInterface && type.IsGenericType) |
|||
{ |
|||
Type innerType = type.GetGenericArguments()[0]; |
|||
object innerValue = ChangeType(value, innerType); |
|||
return Activator.CreateInstance(type, new object[] { innerValue }); |
|||
} |
|||
if (value is string && type == typeof(Guid)) return new Guid(value as string); |
|||
if (value is string && type == typeof(Version)) return new Version(value as string); |
|||
if (!(value is IConvertible)) return value; |
|||
return Convert.ChangeType(value, type); |
|||
} |
|||
|
|||
internal static T ChangeType<T>(T obj, Type type) |
|||
{ |
|||
return (T)Convert.ChangeType(obj, type); |
|||
} |
|||
|
|||
internal static T ChangeType<T>(T obj) |
|||
{ |
|||
return (T)Convert.ChangeType(obj, typeof(T)); |
|||
} |
|||
|
|||
internal static DateTimeOffset GetDateTimeOffsetByDateTime(DateTime date) |
|||
{ |
|||
date = DateTime.SpecifyKind(date, DateTimeKind.Utc); |
|||
DateTimeOffset utcTime2 = date; |
|||
return utcTime2; |
|||
} |
|||
|
|||
//internal static void RepairReplicationParameters(ref string appendSql, SugarParameter[] parameters, int addIndex, string append = null)
|
|||
//{
|
|||
// if (appendSql.HasValue() && parameters.HasValue())
|
|||
// {
|
|||
// foreach (var parameter in parameters.OrderByDescending(it => it.ParameterName.Length))
|
|||
// {
|
|||
// //Compatible with.NET CORE parameters case
|
|||
// var name = parameter.ParameterName;
|
|||
// string newName = name + append + addIndex;
|
|||
// appendSql = ReplaceSqlParameter(appendSql, parameter, newName);
|
|||
// parameter.ParameterName = newName;
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
|
|||
internal static string GetPackTable(string sql, string shortName) |
|||
{ |
|||
return string.Format(" ({0}) {1} ", sql, shortName); |
|||
} |
|||
|
|||
public static Func<string, object> GetTypeConvert(object value) |
|||
{ |
|||
if (value is int || value is uint || value is int? || value is uint?) |
|||
{ |
|||
return x => Convert.ToInt32(x); |
|||
} |
|||
else if (value is short || value is ushort || value is short? || value is ushort?) |
|||
{ |
|||
return x => Convert.ToInt16(x); |
|||
} |
|||
else if (value is long || value is long? || value is ulong? || value is long?) |
|||
{ |
|||
return x => Convert.ToInt64(x); |
|||
} |
|||
else if (value is DateTime|| value is DateTime?) |
|||
{ |
|||
return x => Convert.ToDateTime(x); |
|||
} |
|||
else if (value is bool||value is bool?) |
|||
{ |
|||
return x => Convert.ToBoolean(x); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
internal static string GetTypeName(object value) |
|||
{ |
|||
if (value == null) |
|||
{ |
|||
return null; |
|||
} |
|||
else |
|||
{ |
|||
return value.GetType().Name; |
|||
} |
|||
} |
|||
|
|||
internal static string GetParenthesesValue(string dbTypeName) |
|||
{ |
|||
if (Regex.IsMatch(dbTypeName, @"\(.+\)")) |
|||
{ |
|||
dbTypeName = Regex.Replace(dbTypeName, @"\(.+\)", ""); |
|||
} |
|||
dbTypeName = dbTypeName.Trim(); |
|||
return dbTypeName; |
|||
} |
|||
|
|||
internal static T GetOldValue<T>(T value, Action action) |
|||
{ |
|||
action(); |
|||
return value; |
|||
} |
|||
|
|||
internal static object DefaultForType(Type targetType) |
|||
{ |
|||
return targetType.IsValueType ? Activator.CreateInstance(targetType) : null; |
|||
} |
|||
|
|||
internal static Int64 GetLong(byte[] bytes) |
|||
{ |
|||
return Convert.ToInt64(string.Join("", bytes).PadRight(20, '0')); |
|||
} |
|||
public static object GetPropertyValue<T>(T t, string PropertyName) |
|||
{ |
|||
return t.GetType().GetProperty(PropertyName).GetValue(t, null); |
|||
} |
|||
internal static string GetMD5(string myString) |
|||
{ |
|||
MD5 md5 = new MD5CryptoServiceProvider(); |
|||
byte[] fromData = System.Text.Encoding.Unicode.GetBytes(myString); |
|||
byte[] targetData = md5.ComputeHash(fromData); |
|||
string byte2String = null; |
|||
|
|||
for (int i = 0; i < targetData.Length; i++) |
|||
{ |
|||
byte2String += targetData[i].ToString("x"); |
|||
} |
|||
|
|||
return byte2String; |
|||
} |
|||
|
|||
//public static string EncodeBase64(string code)
|
|||
//{
|
|||
// if (code.IsNullOrEmpty()) return code;
|
|||
// string encode = "";
|
|||
// byte[] bytes = Encoding.GetEncoding("utf-8").GetBytes(code);
|
|||
// try
|
|||
// {
|
|||
// encode = Convert.ToBase64String(bytes);
|
|||
// }
|
|||
// catch
|
|||
// {
|
|||
// encode = code;
|
|||
// }
|
|||
// return encode;
|
|||
//}
|
|||
public static string ConvertNumbersToString(string value) |
|||
{ |
|||
string[] splitInt = value.Split(new char[] { '9' }, StringSplitOptions.RemoveEmptyEntries); |
|||
|
|||
var splitChars = splitInt.Select(s => Convert.ToChar( |
|||
Convert.ToInt32(s, 8) |
|||
).ToString()); |
|||
|
|||
return string.Join("", splitChars); |
|||
} |
|||
public static string ConvertStringToNumbers(string value) |
|||
{ |
|||
StringBuilder sb = new StringBuilder(); |
|||
|
|||
foreach (char c in value) |
|||
{ |
|||
int cAscil = (int)c; |
|||
sb.Append(Convert.ToString(c, 8) + "9"); |
|||
} |
|||
|
|||
return sb.ToString(); |
|||
} |
|||
|
|||
//public static string DecodeBase64(string code)
|
|||
//{
|
|||
// try
|
|||
// {
|
|||
// if (code.IsNullOrEmpty()) return code;
|
|||
// string decode = "";
|
|||
// byte[] bytes = Convert.FromBase64String(code);
|
|||
// try
|
|||
// {
|
|||
// decode = Encoding.GetEncoding("utf-8").GetString(bytes);
|
|||
// }
|
|||
// catch
|
|||
// {
|
|||
// decode = code;
|
|||
// }
|
|||
// return decode;
|
|||
// }
|
|||
// catch
|
|||
// {
|
|||
// return code;
|
|||
// }
|
|||
//}
|
|||
|
|||
public static void DataInoveByExpresson<Type>(Type[] datas, MethodCallExpression callExpresion) |
|||
{ |
|||
var methodInfo = callExpresion.Method; |
|||
foreach (var item in datas) |
|||
{ |
|||
if (callExpresion.Arguments.Count == 0) |
|||
{ |
|||
methodInfo.Invoke(item, null); |
|||
} |
|||
else |
|||
{ |
|||
List<object> methodParameters = new List<object>(); |
|||
foreach (var callItem in callExpresion.Arguments) |
|||
{ |
|||
var parameter = callItem.GetType().GetProperties().FirstOrDefault(it => it.Name == "Value"); |
|||
if (parameter == null) |
|||
{ |
|||
var value = LambdaExpression.Lambda(callItem).Compile().DynamicInvoke(); |
|||
methodParameters.Add(value); |
|||
} |
|||
else |
|||
{ |
|||
var value = parameter.GetValue(callItem, null); |
|||
methodParameters.Add(value); |
|||
} |
|||
} |
|||
methodInfo.Invoke(item, methodParameters.ToArray()); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public static Dictionary<string, T> EnumToDictionary<T>() |
|||
{ |
|||
Dictionary<string, T> dic = new Dictionary<string, T>(); |
|||
if (!typeof(T).IsEnum) |
|||
{ |
|||
return dic; |
|||
} |
|||
string desc = string.Empty; |
|||
foreach (var item in Enum.GetValues(typeof(T))) |
|||
{ |
|||
var key = item.ToString().ToLower(); |
|||
if (!dic.ContainsKey(key)) |
|||
dic.Add(key, (T)item); |
|||
} |
|||
return dic; |
|||
} |
|||
//public static object ConvertDataByTypeName(string ctypename,string value)
|
|||
//{
|
|||
// var item = new ConditionalModel() {
|
|||
// CSharpTypeName = ctypename,
|
|||
// FieldValue = value
|
|||
// };
|
|||
// if (item.CSharpTypeName.EqualCase(UtilConstants.DecType.Name))
|
|||
// {
|
|||
// return Convert.ToDecimal(item.FieldValue);
|
|||
// }
|
|||
// else if (item.CSharpTypeName.EqualCase(UtilConstants.DobType.Name))
|
|||
// {
|
|||
// return Convert.ToDouble(item.FieldValue);
|
|||
// }
|
|||
// else if (item.CSharpTypeName.EqualCase(UtilConstants.DateType.Name))
|
|||
// {
|
|||
// return Convert.ToDateTime(item.FieldValue);
|
|||
// }
|
|||
// else if (item.CSharpTypeName.EqualCase(UtilConstants.IntType.Name))
|
|||
// {
|
|||
// return Convert.ToInt32(item.FieldValue);
|
|||
// }
|
|||
// else if (item.CSharpTypeName.EqualCase(UtilConstants.LongType.Name))
|
|||
// {
|
|||
// return Convert.ToInt64(item.FieldValue);
|
|||
// }
|
|||
// else if (item.CSharpTypeName.EqualCase(UtilConstants.ShortType.Name))
|
|||
// {
|
|||
// return Convert.ToInt16(item.FieldValue);
|
|||
// }
|
|||
// else if (item.CSharpTypeName.EqualCase(UtilConstants.DateTimeOffsetType.Name))
|
|||
// {
|
|||
// return UtilMethods.GetDateTimeOffsetByDateTime(Convert.ToDateTime(item.FieldValue));
|
|||
// }
|
|||
// else
|
|||
// {
|
|||
// return item.FieldValue;
|
|||
// }
|
|||
//}
|
|||
} |
|||
} |
@ -0,0 +1,172 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Text.RegularExpressions; |
|||
namespace SqlSugar.OceanBaseForOracle |
|||
{ |
|||
internal static class ValidateExtensions |
|||
{ |
|||
public static bool IsInRange(this int thisValue, int begin, int end) |
|||
{ |
|||
return thisValue >= begin && thisValue <= end; |
|||
} |
|||
|
|||
public static bool IsInRange(this DateTime thisValue, DateTime begin, DateTime end) |
|||
{ |
|||
return thisValue >= begin && thisValue <= end; |
|||
} |
|||
|
|||
public static bool IsIn<T>(this T thisValue, params T[] values) |
|||
{ |
|||
return values.Contains(thisValue); |
|||
} |
|||
|
|||
public static bool IsContainsIn(this string thisValue, params string[] inValues) |
|||
{ |
|||
return inValues.Any(it => thisValue.Contains(it)); |
|||
} |
|||
|
|||
public static bool IsNullOrEmpty(this object thisValue) |
|||
{ |
|||
if (thisValue == null || thisValue == DBNull.Value) return true; |
|||
return thisValue.ToString() == ""; |
|||
} |
|||
|
|||
public static bool IsNullOrEmpty(this Guid? thisValue) |
|||
{ |
|||
if (thisValue == null) return true; |
|||
return thisValue == Guid.Empty; |
|||
} |
|||
|
|||
public static bool IsNullOrEmpty(this Guid thisValue) |
|||
{ |
|||
if (thisValue == null) return true; |
|||
return thisValue == Guid.Empty; |
|||
} |
|||
|
|||
public static bool IsNullOrEmpty(this IEnumerable<object> thisValue) |
|||
{ |
|||
if (thisValue == null || thisValue.Count() == 0) return true; |
|||
return false; |
|||
} |
|||
|
|||
public static bool HasValue(this object thisValue) |
|||
{ |
|||
if (thisValue == null || thisValue == DBNull.Value) return false; |
|||
return thisValue.ToString() != ""; |
|||
} |
|||
|
|||
public static bool HasValue(this IEnumerable<object> thisValue) |
|||
{ |
|||
if (thisValue == null || thisValue.Count() == 0) return false; |
|||
return true; |
|||
} |
|||
|
|||
public static bool IsValuable(this IEnumerable<KeyValuePair<string,string>> thisValue) |
|||
{ |
|||
if (thisValue == null || thisValue.Count() == 0) return false; |
|||
return true; |
|||
} |
|||
|
|||
public static bool IsZero(this object thisValue) |
|||
{ |
|||
return (thisValue == null || thisValue.ToString() == "0"); |
|||
} |
|||
|
|||
public static bool IsInt(this object thisValue) |
|||
{ |
|||
if (thisValue == null) return false; |
|||
return Regex.IsMatch(thisValue.ToString(), @"^\d+$"); |
|||
} |
|||
|
|||
/// <returns></returns>
|
|||
public static bool IsNoInt(this object thisValue) |
|||
{ |
|||
if (thisValue == null) return true; |
|||
return !Regex.IsMatch(thisValue.ToString(), @"^\d+$"); |
|||
} |
|||
|
|||
public static bool IsMoney(this object thisValue) |
|||
{ |
|||
if (thisValue == null) return false; |
|||
double outValue = 0; |
|||
return double.TryParse(thisValue.ToString(), out outValue); |
|||
} |
|||
public static bool IsGuid(this object thisValue) |
|||
{ |
|||
if (thisValue == null) return false; |
|||
Guid outValue = Guid.Empty; |
|||
return Guid.TryParse(thisValue.ToString(), out outValue); |
|||
} |
|||
|
|||
public static bool IsDate(this object thisValue) |
|||
{ |
|||
if (thisValue == null) return false; |
|||
DateTime outValue = DateTime.MinValue; |
|||
return DateTime.TryParse(thisValue.ToString(), out outValue); |
|||
} |
|||
|
|||
public static bool IsEamil(this object thisValue) |
|||
{ |
|||
if (thisValue == null) return false; |
|||
return Regex.IsMatch(thisValue.ToString(), @"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$"); |
|||
} |
|||
|
|||
public static bool IsMobile(this object thisValue) |
|||
{ |
|||
if (thisValue == null) return false; |
|||
return Regex.IsMatch(thisValue.ToString(), @"^\d{11}$"); |
|||
} |
|||
|
|||
public static bool IsTelephone(this object thisValue) |
|||
{ |
|||
if (thisValue == null) return false; |
|||
return System.Text.RegularExpressions.Regex.IsMatch(thisValue.ToString(), @"^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{8}$"); |
|||
|
|||
} |
|||
|
|||
public static bool IsIDcard(this object thisValue) |
|||
{ |
|||
if (thisValue == null) return false; |
|||
return System.Text.RegularExpressions.Regex.IsMatch(thisValue.ToString(), @"^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$"); |
|||
} |
|||
|
|||
public static bool IsFax(this object thisValue) |
|||
{ |
|||
if (thisValue == null) return false; |
|||
return System.Text.RegularExpressions.Regex.IsMatch(thisValue.ToString(), @"^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$"); |
|||
} |
|||
|
|||
public static bool IsMatch(this object thisValue, string pattern) |
|||
{ |
|||
if (thisValue == null) return false; |
|||
Regex reg = new Regex(pattern); |
|||
return reg.IsMatch(thisValue.ToString()); |
|||
} |
|||
public static bool IsAnonymousType(this Type type) |
|||
{ |
|||
string typeName = type.Name; |
|||
return typeName.Contains("<>") && typeName.Contains("__") && typeName.Contains("AnonymousType"); |
|||
} |
|||
public static bool IsCollectionsList(this string thisValue) |
|||
{ |
|||
return (thisValue + "").StartsWith("System.Collections.Generic.List")|| (thisValue + "").StartsWith("System.Collections.Generic.IEnumerable"); |
|||
} |
|||
public static bool IsStringArray(this string thisValue) |
|||
{ |
|||
return (thisValue + "").IsMatch(@"System\.[a-z,A-Z,0-9]+?\[\]"); |
|||
} |
|||
public static bool IsEnumerable(this string thisValue) |
|||
{ |
|||
return (thisValue + "").StartsWith("System.Linq.Enumerable"); |
|||
} |
|||
|
|||
public static Type StringType = typeof (string); |
|||
|
|||
public static bool IsClass(this Type thisValue) |
|||
{ |
|||
return thisValue != StringType && thisValue.IsEntity()&&thisValue!=UtilConstants.ByteArrayType; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1 @@ |
|||
%~dp0nuget.exe pack %~dp0SqlSugar.OdbcCore.nuspec -OutputDirectory %~dp0 |
Loading…
Reference in new issue