diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/DataTableExtensions/OceanBaseForOracleDataAdapter.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/DataTableExtensions/OceanBaseForOracleDataAdapter.cs new file mode 100644 index 000000000..e3898c104 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/DataTableExtensions/OceanBaseForOracleDataAdapter.cs @@ -0,0 +1,157 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Odbc; +using System.Text; +namespace SqlSugar.OceanBaseForOracle +{ + /// + /// 数据填充器 + /// + public class OceanBaseForOracleDataAdapter : IDataAdapter + { + private OdbcCommand command; + private string sql; + private OdbcConnection _sqlConnection; + + /// + /// SqlDataAdapter + /// + /// + public OceanBaseForOracleDataAdapter(OdbcCommand command) + { + this.command = command; + } + + public OceanBaseForOracleDataAdapter() + { + + } + + /// + /// SqlDataAdapter + /// + /// + /// + public OceanBaseForOracleDataAdapter(string sql, OdbcConnection _sqlConnection) + { + this.sql = sql; + this._sqlConnection = _sqlConnection; + } + + /// + /// SelectCommand + /// + 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; + } + } + + /// + /// Fill + /// + /// + 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(); + } + + /// + /// Fill + /// + /// + 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()); + } + } + } + +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/NuGet.exe b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/NuGet.exe new file mode 100644 index 000000000..6bb79fe53 Binary files /dev/null and b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/NuGet.exe differ diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/CodeFirst/OceanBaseForOracleCodeFirst.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/CodeFirst/OceanBaseForOracleCodeFirst.cs new file mode 100644 index 000000000..2c5703b80 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/CodeFirst/OceanBaseForOracleCodeFirst.cs @@ -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; + } + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/DbBind/OceanBaseForOracleDbBind.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/DbBind/OceanBaseForOracleDbBind.cs new file mode 100644 index 000000000..3c2c914b3 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/DbBind/OceanBaseForOracleDbBind.cs @@ -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> 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> MappingTypesConst = new List>() + { + new KeyValuePair("int",CSharpDataType.@int), + new KeyValuePair("integer",CSharpDataType.@int), + new KeyValuePair("interval year to month",CSharpDataType.@int), + new KeyValuePair("interval day to second",CSharpDataType.@int), + + new KeyValuePair("number",CSharpDataType.@int), + new KeyValuePair("number",CSharpDataType.@float), + new KeyValuePair("number",CSharpDataType.@short), + new KeyValuePair("number",CSharpDataType.@byte), + new KeyValuePair("number",CSharpDataType.@double), + new KeyValuePair("number",CSharpDataType.@long), + new KeyValuePair("number",CSharpDataType.@bool), + new KeyValuePair("number",CSharpDataType.@decimal), + new KeyValuePair("number",CSharpDataType.Single), + new KeyValuePair("decimal",CSharpDataType.@decimal), + new KeyValuePair("decimal",CSharpDataType.Single), + + new KeyValuePair("varchar",CSharpDataType.@string), + new KeyValuePair("varchar2",CSharpDataType.@string), + new KeyValuePair("nvarchar2",CSharpDataType.@string), + new KeyValuePair("xmltype",CSharpDataType.@string), + new KeyValuePair("char",CSharpDataType.@string), + new KeyValuePair("nchar",CSharpDataType.@string), + new KeyValuePair("clob",CSharpDataType.@string), + new KeyValuePair("long",CSharpDataType.@string), + new KeyValuePair("nclob",CSharpDataType.@string), + new KeyValuePair("rowid",CSharpDataType.@string), + + new KeyValuePair("date",CSharpDataType.DateTime), + new KeyValuePair("timestamptz",CSharpDataType.DateTime), + new KeyValuePair("timestamp",CSharpDataType.DateTime), + new KeyValuePair("timestamp with local time zone",CSharpDataType.DateTime), + new KeyValuePair("timestamp with time zone",CSharpDataType.DateTime), + + new KeyValuePair("float",CSharpDataType.@decimal), + + new KeyValuePair("blob",CSharpDataType.byteArray), + new KeyValuePair("long raw",CSharpDataType.byteArray), + new KeyValuePair("longraw",CSharpDataType.byteArray), + new KeyValuePair("raw",CSharpDataType.byteArray), + new KeyValuePair("bfile",CSharpDataType.byteArray), + new KeyValuePair("varbinary",CSharpDataType.byteArray) }; + public override List StringThrow + { + get + { + return new List() { "int32", "datetime", "decimal", "double", "byte" }; + } + } + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/DbFirst/OceanBaseForOracleDbFirst.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/DbFirst/OceanBaseForOracleDbFirst.cs new file mode 100644 index 000000000..48e776e43 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/DbFirst/OceanBaseForOracleDbFirst.cs @@ -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 + { + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/DbMaintenance/OceanBaseForOracleDbMaintenance.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/DbMaintenance/OceanBaseForOracleDbMaintenance.cs new file mode 100644 index 000000000..6112badf5 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/DbMaintenance/OceanBaseForOracleDbMaintenance.cs @@ -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 GetIndexList(string tableName) + { + var sql = $"SELECT index_name FROM user_ind_columns\r\nWHERE table_name = '{tableName}'"; + return this.Context.Ado.SqlQuery(sql); + } + public override List GetProcList(string dbName) + { + var sql = $"SELECT OBJECT_NAME FROM ALL_OBJECTS WHERE OBJECT_TYPE = 'PROCEDURE' AND OWNER = '{dbName.ToUpper()}'"; + return this.Context.Ado.SqlQuery(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 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 GetColumnInfosByTableName(string tableName) + { + List 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>("DbMaintenanceProvider.GetFieldComment." + tableName); + this.Context.Utilities.RemoveCache>("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 result = new List(); + 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 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(sql0); + return columns; + } + + private List 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(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(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(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 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 + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/OceanBaseForOracleProvider.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/OceanBaseForOracleProvider.cs new file mode 100644 index 000000000..498961b44 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/OceanBaseForOracleProvider.cs @@ -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 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 _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 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); + } + } + + /// + /// Only Odbc + /// + /// + public override void BeginTran(string transactionName) + { + CheckConnection(); + base.Transaction = ((OdbcConnection)this.Connection).BeginTransaction(); + } + /// + /// Only Odbc + /// + /// + /// + 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 orderParameters = new List(); + 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; + } + /// + /// if mysql return MySqlParameter[] pars + /// if sqlerver return SqlParameter[] pars ... + /// + /// + /// + 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(); + this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName); + this.OutputParameters.Add(sqlParameter); + } + ++index; + } + return result; + } + /// + /// if mysql return MySqlParameter[] pars + /// if sqlerver return SqlParameter[] pars ... + /// + /// + /// + 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(); + 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; + } + } + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/Queryable/OceanBaseForOracleQueryable.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/Queryable/OceanBaseForOracleQueryable.cs new file mode 100644 index 000000000..629e75f6c --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/Queryable/OceanBaseForOracleQueryable.cs @@ -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:QueryableProvider + { + public override ISugarQueryable With(string withString) + { + return this; + } + protected override List GetIdentityKeys() + { + return this.EntityInfo.Columns.Where(it => it.OracleSequenceName.HasValue()).Select(it => it.DbColumnName).ToList(); + } + } + public class OceanBaseForOracleQueryable : QueryableProvider + { + + } + public class OceanBaseForOracleQueryable : QueryableProvider + { + + } + public class OceanBaseForOracleQueryable : QueryableProvider + { + + } + public class OceanBaseForOracleQueryable : QueryableProvider + { + + } + public class OceanBaseForOracleQueryable : QueryableProvider + { + + } + public class OceanBaseForOracleQueryable : QueryableProvider + { + + } + public class OceanBaseForOracleQueryable : QueryableProvider + { + + } + public class OceanBaseForOracleQueryable : QueryableProvider + { + + } + public class OceanBaseForOracleQueryable : QueryableProvider + { + + } + public class OceanBaseForOracleQueryable : QueryableProvider + { + + } + public class OceanBaseForOracleQueryable : QueryableProvider + { + + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleBlukCopy.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleBlukCopy.cs new file mode 100644 index 000000000..2d4c1784c --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleBlukCopy.cs @@ -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> 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 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().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(); + } + } + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleBuilder.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleBuilder.cs new file mode 100644 index 000000000..303ad558b --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleBuilder.cs @@ -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 + + } + +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleDeleteBuilder.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleDeleteBuilder.cs new file mode 100644 index 000000000..614ff42ca --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleDeleteBuilder.cs @@ -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 + { + + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleExpressionContext.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleExpressionContext.cs new file mode 100644 index 000000000..cb9b4920a --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleExpressionContext.cs @@ -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(IEnumerable pageItems, int pageSize, Action> 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().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}) "; + } + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleFastBuilder.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleFastBuilder.cs new file mode 100644 index 000000000..425231501 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleFastBuilder.cs @@ -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(DataTable dt) + { + var sqlBuilder = this.Context.Queryable().SqlBuilder; + var dts = dt.Columns.Cast().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().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().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 UpdateByTempAsync(string tableName, string tempName, string[] updateColumns, string[] whereColumns) + { + var sqlBuilder = this.Context.Queryable().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 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; + } + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleInsertBuilder.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleInsertBuilder.cs new file mode 100644 index 000000000..b62e051e9 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleInsertBuilder.cs @@ -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 identities, List> groupList, string columnsString) + { + this.Context.Utilities.PageEach(groupList, 100, groupListPasge => + { + this.Parameters = new List(); + 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 identities, List> 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() + "'"; + } + } + } + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleQueryBuilder.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleQueryBuilder.cs new file mode 100644 index 000000000..4c3909451 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleQueryBuilder.cs @@ -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(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); + } + + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleUpdateBuilder.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleUpdateBuilder.cs new file mode 100644 index 000000000..f473a9ba8 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/SqlBuilder/OceanBaseForOracleUpdateBuilder.cs @@ -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> 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 whereList = new List(); + 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 + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/SqlSugar.OceanBaseForOracle.csproj b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/SqlSugar.OceanBaseForOracle.csproj new file mode 100644 index 000000000..47fcf47b3 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/SqlSugar.OceanBaseForOracle.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/SqlSugar.OdbcCore.nuspec b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/SqlSugar.OdbcCore.nuspec new file mode 100644 index 000000000..90da52cf6 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/SqlSugar.OdbcCore.nuspec @@ -0,0 +1,24 @@ + + + + SqlSugar.OdbcCore + 5.1.4.2 + sunkaixuan + Landa + http://www.apache.org/licenses/LICENSE-2.0.html + https://github.com/sunkaixuan/SqlSugar + https://secure.gravatar.com/avatar/a82c03402497b2e58fd65038a3699b30 + false + SqlSugar 通过ODBC连接数据库 + Copyright 2016 + Asp.net core orm + + + + + + + + + + \ No newline at end of file diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/ErrorMessage.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/ErrorMessage.cs new file mode 100644 index 000000000..6edd96035 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/ErrorMessage.cs @@ -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, or contact the author!!", + "暂时不支持该类型的Dictionary 你可以试试 Dictionary或者联系作者!!"); + } + } + + 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 formatArgs = new List() { enMessage, cnMessage }; + formatArgs.AddRange(args); + return string.Format(@"中文提示 : {1} +English Message : {0}", formatArgs.ToArray()); + } + else if (SugarLanguageType == LanguageType.English) + { + return enMessage; + } + else + { + return cnMessage; + } + } + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/ExpressionConst.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/ExpressionConst.cs new file mode 100644 index 000000000..26f78559a --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/ExpressionConst.cs @@ -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"; + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/FileHelper.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/FileHelper.cs new file mode 100644 index 000000000..970cd83c5 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/FileHelper.cs @@ -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); + } + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/UtilConstants.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/UtilConstants.cs new file mode 100644 index 000000000..a5225abf4 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/UtilConstants.cs @@ -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); + internal static Type DicIS = typeof(KeyValuePair); + internal static Type DicSi = typeof(KeyValuePair); + internal static Type DicSS = typeof(KeyValuePair); + internal static Type DicOO = typeof(KeyValuePair); + internal static Type DicSo = typeof(KeyValuePair); + internal static Type DicArraySS = typeof(Dictionary); + internal static Type DicArraySO = typeof(Dictionary); + + 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" + }; + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/UtilExtensions.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/UtilExtensions.cs new file mode 100644 index 000000000..45162073a --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/UtilExtensions.cs @@ -0,0 +1,158 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +namespace SqlSugar.OceanBaseForOracle +{ + /// + ///Common Extensions for external users + /// + 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; + } + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/UtilMethods.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/UtilMethods.cs new file mode 100644 index 000000000..feb4fb09d --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/UtilMethods.cs @@ -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(); + info.SugarStackTraceList = new List(); + 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(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 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 obj, Type type) + { + return (T)Convert.ChangeType(obj, type); + } + + internal static T ChangeType(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 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 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, 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[] datas, MethodCallExpression callExpresion) + { + var methodInfo = callExpresion.Method; + foreach (var item in datas) + { + if (callExpresion.Arguments.Count == 0) + { + methodInfo.Invoke(item, null); + } + else + { + List methodParameters = new List(); + 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 EnumToDictionary() + { + Dictionary dic = new Dictionary(); + 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; + // } + //} + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/ValidateExtensions.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/ValidateExtensions.cs new file mode 100644 index 000000000..e041c747f --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/Tools/ValidateExtensions.cs @@ -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(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 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 thisValue) + { + if (thisValue == null || thisValue.Count() == 0) return false; + return true; + } + + public static bool IsValuable(this IEnumerable> 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+$"); + } + + /// + 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; + } + } +} diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/nuget.bat b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/nuget.bat new file mode 100644 index 000000000..2c287a5dd --- /dev/null +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/nuget.bat @@ -0,0 +1 @@ +%~dp0nuget.exe pack %~dp0SqlSugar.OdbcCore.nuspec -OutputDirectory %~dp0 \ No newline at end of file diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs index cb5c2a1c9..afc2f8088 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs @@ -478,6 +478,10 @@ namespace SqlSugar case DbType.Odbc: InstanceFactory.CustomDllName = SugarCompatible.IsFramework ? "SqlSugar.Odbc" : "SqlSugar.OdbcCore"; break; + case DbType.OceanBaseForOracle: + Check.Exception(SugarCompatible.IsFramework, "OceanBaseForOracle only support .net core"); + InstanceFactory.CustomDllName = SugarCompatible.IsFramework ? "SqlSugar.OceanBaseForOracle" : "SqlSugar.OceanBaseForOracleCore"; + break; default: throw new Exception("ConnectionConfig.DbType is null"); } diff --git a/Src/Asp.NetCore2/SqlSugar/Enum/DbType.cs b/Src/Asp.NetCore2/SqlSugar/Enum/DbType.cs index 1bfbd2715..00a9260fe 100644 --- a/Src/Asp.NetCore2/SqlSugar/Enum/DbType.cs +++ b/Src/Asp.NetCore2/SqlSugar/Enum/DbType.cs @@ -24,6 +24,7 @@ namespace SqlSugar ClickHouse, GBase, Odbc, + OceanBaseForOracle, Custom =900 } } diff --git a/Src/Asp.NetCore2/SqlSugarCore.sln b/Src/Asp.NetCore2/SqlSugarCore.sln index 6b10deb1c..9a7189c85 100644 --- a/Src/Asp.NetCore2/SqlSugarCore.sln +++ b/Src/Asp.NetCore2/SqlSugarCore.sln @@ -58,7 +58,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlSugar.OdbcCore", "SqlSug EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlSugar.HGCore", "SqlSugar.HG\SqlSugar.HGCore.csproj", "{517D3B1E-EECB-43C3-83B9-33613F45908A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HGTest", "HGTest\HGTest.csproj", "{59CF4F65-0337-4877-A35F-D1B7585A7DB3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HGTest", "HGTest\HGTest.csproj", "{59CF4F65-0337-4877-A35F-D1B7585A7DB3}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlSugar.OceanBaseForOracle", "SqlSugar.OceanBaseForOracle\SqlSugar.OceanBaseForOracle.csproj", "{7CEB3DFE-8337-4B83-AE6A-D159D73E3CD3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -370,6 +372,18 @@ Global {59CF4F65-0337-4877-A35F-D1B7585A7DB3}.Release|ARM32.Build.0 = Release|Any CPU {59CF4F65-0337-4877-A35F-D1B7585A7DB3}.Release|x86.ActiveCfg = Release|Any CPU {59CF4F65-0337-4877-A35F-D1B7585A7DB3}.Release|x86.Build.0 = Release|Any CPU + {7CEB3DFE-8337-4B83-AE6A-D159D73E3CD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7CEB3DFE-8337-4B83-AE6A-D159D73E3CD3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7CEB3DFE-8337-4B83-AE6A-D159D73E3CD3}.Debug|ARM32.ActiveCfg = Debug|Any CPU + {7CEB3DFE-8337-4B83-AE6A-D159D73E3CD3}.Debug|ARM32.Build.0 = Debug|Any CPU + {7CEB3DFE-8337-4B83-AE6A-D159D73E3CD3}.Debug|x86.ActiveCfg = Debug|Any CPU + {7CEB3DFE-8337-4B83-AE6A-D159D73E3CD3}.Debug|x86.Build.0 = Debug|Any CPU + {7CEB3DFE-8337-4B83-AE6A-D159D73E3CD3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7CEB3DFE-8337-4B83-AE6A-D159D73E3CD3}.Release|Any CPU.Build.0 = Release|Any CPU + {7CEB3DFE-8337-4B83-AE6A-D159D73E3CD3}.Release|ARM32.ActiveCfg = Release|Any CPU + {7CEB3DFE-8337-4B83-AE6A-D159D73E3CD3}.Release|ARM32.Build.0 = Release|Any CPU + {7CEB3DFE-8337-4B83-AE6A-D159D73E3CD3}.Release|x86.ActiveCfg = Release|Any CPU + {7CEB3DFE-8337-4B83-AE6A-D159D73E3CD3}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -380,6 +394,7 @@ Global {73861B80-AC53-441D-A178-C8F3C1FF0FB3} = {88992AAF-146B-4253-9AD7-493E8F415B57} {0320D162-4E7F-4AA1-844B-2FDF77EEC145} = {88992AAF-146B-4253-9AD7-493E8F415B57} {517D3B1E-EECB-43C3-83B9-33613F45908A} = {88992AAF-146B-4253-9AD7-493E8F415B57} + {7CEB3DFE-8337-4B83-AE6A-D159D73E3CD3} = {88992AAF-146B-4253-9AD7-493E8F415B57} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {230A85B9-54F1-41B1-B1DA-80086581B2B4}