From bc33c7a6123d5bbd7058e00fa6b7f766ceae12d7 Mon Sep 17 00:00:00 2001 From: "guoshun.du" Date: Wed, 19 Jul 2023 19:51:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?*=E4=BF=AE=E5=A4=8DODBC=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=8C=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OceanBase/OceanBaseForOracleProvider.cs | 5 ++--- .../SqlSugar.OceanBaseForOracleCore.csproj | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/OceanBaseForOracleProvider.cs b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/OceanBaseForOracleProvider.cs index 498961b44..656a2b368 100644 --- a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/OceanBaseForOracleProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/OceanBaseForOracleProvider.cs @@ -206,11 +206,10 @@ namespace SqlSugar.OceanBaseForOracle //通过正则匹配,为顺序输出,相同也会重复匹配 Regex parametersRegx = new Regex(reg); MatchCollection matches = parametersRegx.Matches(sql); - for(int index = 0;index< parameters.Length; index++) + foreach (Match pMatch in matches) { - Match pMatch = matches[index]; SugarParameter mP = parameters.FirstOrDefault(m => m.ParameterName == pMatch.Value); - if (mP != null) + if (mP != null) { orderParameters.Add(mP); } diff --git a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/SqlSugar.OceanBaseForOracleCore.csproj b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/SqlSugar.OceanBaseForOracleCore.csproj index 47fcf47b3..39e2067da 100644 --- a/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/SqlSugar.OceanBaseForOracleCore.csproj +++ b/Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/SqlSugar.OceanBaseForOracleCore.csproj @@ -1,9 +1,8 @@ - net6.0 - enable - enable + netstandard2.1 + enable From b9535987265b145fe4553f7ea94ab4947722b0b3 Mon Sep 17 00:00:00 2001 From: "guoshun.du" Date: Wed, 19 Jul 2023 19:51:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?*=E6=B7=BB=E5=8A=A0OceanBaseForOracleTest?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OceanBaseForOracleTest/Config.cs | 31 +++++++++++ .../Models/AttributeTable.cs | 20 +++++++ .../OceanBaseForOracleTest/Models/CarType.cs | 7 +++ .../OceanBaseForOracleTest/Models/Custom.cs | 14 +++++ .../Models/EntityMapper.cs | 15 ++++++ .../OceanBaseForOracleTest/Models/Mapper.cs | 54 +++++++++++++++++++ .../Models/MyCustomAttributeTable.cs | 20 +++++++ .../OceanBaseForOracleTest/Models/Order.cs | 25 +++++++++ .../Models/OrderItem.cs | 18 +++++++ .../OceanBaseForOracleTest/Models/TestTree.cs | 17 ++++++ .../OceanBaseForOracleTest/Models/Tree.cs | 20 +++++++ .../Models/ViewOrder.cs | 13 +++++ .../OceanBaseForOracleTest.csproj | 20 +++++++ .../OceanBaseForOracleTest/Program.cs | 54 +++++++++++++++++++ Src/Asp.NetCore2/SqlSugarCore.sln | 14 +++++ 15 files changed, 342 insertions(+) create mode 100644 Src/Asp.NetCore2/OceanBaseForOracleTest/Config.cs create mode 100644 Src/Asp.NetCore2/OceanBaseForOracleTest/Models/AttributeTable.cs create mode 100644 Src/Asp.NetCore2/OceanBaseForOracleTest/Models/CarType.cs create mode 100644 Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Custom.cs create mode 100644 Src/Asp.NetCore2/OceanBaseForOracleTest/Models/EntityMapper.cs create mode 100644 Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Mapper.cs create mode 100644 Src/Asp.NetCore2/OceanBaseForOracleTest/Models/MyCustomAttributeTable.cs create mode 100644 Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Order.cs create mode 100644 Src/Asp.NetCore2/OceanBaseForOracleTest/Models/OrderItem.cs create mode 100644 Src/Asp.NetCore2/OceanBaseForOracleTest/Models/TestTree.cs create mode 100644 Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Tree.cs create mode 100644 Src/Asp.NetCore2/OceanBaseForOracleTest/Models/ViewOrder.cs create mode 100644 Src/Asp.NetCore2/OceanBaseForOracleTest/OceanBaseForOracleTest.csproj create mode 100644 Src/Asp.NetCore2/OceanBaseForOracleTest/Program.cs diff --git a/Src/Asp.NetCore2/OceanBaseForOracleTest/Config.cs b/Src/Asp.NetCore2/OceanBaseForOracleTest/Config.cs new file mode 100644 index 000000000..e5c404d23 --- /dev/null +++ b/Src/Asp.NetCore2/OceanBaseForOracleTest/Config.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + /// + /// Setting up the database name does not require you to create the database + /// 设置好数据库名不需要你去手动建库 + /// + public class Config + { + /// + /// Account have permission to create database + /// 用有建库权限的数据库账号 + /// + public static string ConnectionString = "Driver={OceanBase ODBC 2.0 Driver};Server=172.19.9.9;Port=2883;Database=XIR_TRD;User=XIR_TRD@Xpia2C6G#obtest:1650773680;Password=aaAA11%%;Option=3;"; + /// + /// Account have permission to create database + /// 用有建库权限的数据库账号 + /// + public static string ConnectionString2 = "Driver={GBase ODBC DRIVER (64-Bit)};Host=localhost;Service=19088;Server=gbase01;Database=testdb;Protocol=onsoctcp;Uid=gbasedbt;Pwd=GBase123;Db_locale=zh_CN.utf8;Client_locale=zh_CN.utf8"; + /// + /// Account have permission to create database + /// 用有建库权限的数据库账号 + /// + public static string ConnectionString3 = "Driver={GBase ODBC DRIVER (64-Bit)};Host=localhost;Service=19088;Server=gbase01;Database=testdb;Protocol=onsoctcp;Uid=gbasedbt;Pwd=GBase123;Db_locale=zh_CN.utf8;Client_locale=zh_CN.utf8"; + } +} diff --git a/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/AttributeTable.cs b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/AttributeTable.cs new file mode 100644 index 000000000..c1a43ad12 --- /dev/null +++ b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/AttributeTable.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; + +namespace OrmTest +{ + [Table("MyAttributeTable")] + //[SugarTable("CustomAttributeTable")] + public class AttributeTable + { + + [Key] + //[SugarColumn(IsPrimaryKey =true)] + public string Id { get; set; } + public string Name { get; set; } + } +} diff --git a/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/CarType.cs b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/CarType.cs new file mode 100644 index 000000000..00dc12710 --- /dev/null +++ b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/CarType.cs @@ -0,0 +1,7 @@ +namespace OrmTest +{ + public class CarType + { + public bool State { get; set; } + } +} \ No newline at end of file diff --git a/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Custom.cs b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Custom.cs new file mode 100644 index 000000000..3b8871c57 --- /dev/null +++ b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Custom.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + public class Custom + { + public int Id { get; set; } + public string Name { get; set; } + } +} diff --git a/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/EntityMapper.cs b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/EntityMapper.cs new file mode 100644 index 000000000..b597012fb --- /dev/null +++ b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/EntityMapper.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; +namespace OrmTest +{ + [SugarTable("MyEntityMapper")] + public class EntityMapper + { + [SugarColumn(ColumnName ="MyName")] + public string Name { get; set; } + } +} diff --git a/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Mapper.cs b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Mapper.cs new file mode 100644 index 000000000..8d7991d6c --- /dev/null +++ b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Mapper.cs @@ -0,0 +1,54 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + [SugarTable("OrderDetail")] + public class OrderItemInfo + { + [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int ItemId { get; set; } + public int OrderId { get; set; } + public decimal? Price { get; set; } + [SqlSugar.SugarColumn(IsNullable = true)] + public DateTime? CreateTime { get; set; } + [SugarColumn(IsIgnore = true)] + public Order Order { get; set; } + } + [SugarTable("Order")] + public class OrderInfo + { + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + public string Name { get; set; } + [SugarColumn(IsIgnore = true)] + public List Items { get; set; } + } + public class ABMapping + { + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int AId { get; set; } + public int BId { get; set; } + [SugarColumn(IsIgnore = true)] + public A A { get; set; } + [SugarColumn(IsIgnore = true)] + public B B { get; set; } + + } + public class A + { + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + public string Name { get; set; } + } + public class B + { + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + public string Name { get; set; } + } +} diff --git a/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/MyCustomAttributeTable.cs b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/MyCustomAttributeTable.cs new file mode 100644 index 000000000..11359d062 --- /dev/null +++ b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/MyCustomAttributeTable.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; + +namespace OrmTest +{ + [Table("CustomAttributeTable")] + //[SugarTable("CustomAttributeTable")] + public class MyCustomAttributeTable + { + + [Key] + //[SugarColumn(IsPrimaryKey =true)] + public string Id { get; set; } + public string Name { get; set; } + } +} diff --git a/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Order.cs b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Order.cs new file mode 100644 index 000000000..cf6b11839 --- /dev/null +++ b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Order.cs @@ -0,0 +1,25 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OrmTest +{ + [SugarTable("ORDERTEST")] + public class Order + { + [SugarColumn(IsPrimaryKey = true)] + public decimal Id { get; set; } + + public string Name { get; set; } + public decimal Price { get; set; } + [SugarColumn(IsNullable = true)] + public DateTime CreateTime { get; set; } + [SugarColumn(IsNullable =true)] + public decimal CustomId { get; set; } + + [SugarColumn(IsIgnore = true)] + public string Idname { get; set; } + } +} diff --git a/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/OrderItem.cs b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/OrderItem.cs new file mode 100644 index 000000000..ae3262c7c --- /dev/null +++ b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/OrderItem.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OrmTest +{ + [SqlSugar.SugarTable("OrderDetail")] + public class OrderItem + { + [SqlSugar.SugarColumn(IsPrimaryKey =true, IsIdentity =true)] + public int ItemId { get; set; } + public int OrderId { get; set; } + public decimal? Price { get; set; } + [SqlSugar.SugarColumn(IsNullable = true)] + public DateTime? CreateTime { get; set; } + } +} diff --git a/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/TestTree.cs b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/TestTree.cs new file mode 100644 index 000000000..b8250828a --- /dev/null +++ b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/TestTree.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + public class TestTree + { + [SqlSugar.SugarColumn(ColumnDataType = "hierarchyid")] + public string TreeId { get; set; } + [SqlSugar.SugarColumn(ColumnDataType = "Geography")] + public string GId { get; set; } + public string Name { get; set; } + } +} diff --git a/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Tree.cs b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Tree.cs new file mode 100644 index 000000000..d2878de64 --- /dev/null +++ b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Tree.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + public class Tree + { + [SqlSugar.SugarColumn(IsPrimaryKey =true)] + public int Id { get; set; } + public string Name { get; set; } + public int ParentId { get; set; } + [SqlSugar.SugarColumn(IsIgnore = true)] + public Tree Parent { get; set; } + [SqlSugar.SugarColumn(IsIgnore = true)] + public List Child { get; set; } + } +} diff --git a/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/ViewOrder.cs b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/ViewOrder.cs new file mode 100644 index 000000000..fcd465747 --- /dev/null +++ b/Src/Asp.NetCore2/OceanBaseForOracleTest/Models/ViewOrder.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest +{ + public class ViewOrder:Order + { + public string CustomName { get; set; } + } +} diff --git a/Src/Asp.NetCore2/OceanBaseForOracleTest/OceanBaseForOracleTest.csproj b/Src/Asp.NetCore2/OceanBaseForOracleTest/OceanBaseForOracleTest.csproj new file mode 100644 index 000000000..0463e6217 --- /dev/null +++ b/Src/Asp.NetCore2/OceanBaseForOracleTest/OceanBaseForOracleTest.csproj @@ -0,0 +1,20 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/Src/Asp.NetCore2/OceanBaseForOracleTest/Program.cs b/Src/Asp.NetCore2/OceanBaseForOracleTest/Program.cs new file mode 100644 index 000000000..5836285f4 --- /dev/null +++ b/Src/Asp.NetCore2/OceanBaseForOracleTest/Program.cs @@ -0,0 +1,54 @@ +using OrmTest; +using SqlSugar; +using static Npgsql.Replication.PgOutput.Messages.RelationMessage; + +namespace OceanBaseForOracle +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine(""); + Console.WriteLine("#### MasterSlave Start ####"); + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() + { + ConnectionString = Config.ConnectionString,//Master Connection + DbType = DbType.OceanBaseForOracle, + InitKeyType = InitKeyType.Attribute, + IsAutoCloseConnection = true + }); + db.Aop.OnLogExecuted = (s, p) => + { + Console.WriteLine(db.Ado.Connection.ConnectionString); + }; + Console.WriteLine("Master:"); + db.Insertable(new Order() { Id=109,Name = "abc", CustomId = 1, CreateTime = DateTime.Now }).ExecuteCommand(); + db.Deleteable().Where(m => m.Id == 109).ExecuteCommand(); + db.Updateable().SetColumns(m => new Order + { + Name = "我是修改" + }).Where(m => m.Id == 2).ExecuteCommand(); + Console.WriteLine("Slave:"); + //var s = db.Queryable().First(); + //var list = db.Queryable().Select(m => new Order + //{ + // Id = m.Id, + // CreateTime = m.CreateTime, + // CustomId = m.CustomId, + // Idname = SqlFunc.Subqueryable().Where(s => s.Id == 2).Select(s => s.Name), + // Name = m.Name, + // Price = m.Price, + //}).ToList(); + //var grouplist = db.Queryable().OrderByDescending(m=>m.Id).GroupBy(m=>new {m.Id,m.Name}).SelectMergeTable(m => new Order + //{ + // Id = m.Id, + // Name = m.Name, + // CreateTime= SqlFunc.AggregateMin(m.CreateTime), + // Price= SqlFunc.AggregateSum(m.Price), + //}).OrderBy(m=>m.Id).Where(m=>m.Id==1).ToList(); + //var orderlist = db.Queryable().OrderBy(m => new { m.Id, m.Name }).ToList(); + var pageList = db.Queryable().OrderBy(m=>m.Id).ToOffsetPage(1, 3); + Console.WriteLine("#### MasterSlave End ####"); + } + } +} \ No newline at end of file diff --git a/Src/Asp.NetCore2/SqlSugarCore.sln b/Src/Asp.NetCore2/SqlSugarCore.sln index d78168a23..1b4186758 100644 --- a/Src/Asp.NetCore2/SqlSugarCore.sln +++ b/Src/Asp.NetCore2/SqlSugarCore.sln @@ -62,6 +62,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HGTest", "HGTest\HGTest.csp EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlSugar.OceanBaseForOracleCore", "SqlSugar.OceanBaseForOracle\SqlSugar.OceanBaseForOracleCore.csproj", "{7CEB3DFE-8337-4B83-AE6A-D159D73E3CD3}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OceanBaseForOracleTest", "OceanBaseForOracleTest\OceanBaseForOracleTest.csproj", "{5E119B71-D17F-42BA-8437-A9F5B941CFD7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -384,6 +386,18 @@ Global {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 + {5E119B71-D17F-42BA-8437-A9F5B941CFD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5E119B71-D17F-42BA-8437-A9F5B941CFD7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5E119B71-D17F-42BA-8437-A9F5B941CFD7}.Debug|ARM32.ActiveCfg = Debug|Any CPU + {5E119B71-D17F-42BA-8437-A9F5B941CFD7}.Debug|ARM32.Build.0 = Debug|Any CPU + {5E119B71-D17F-42BA-8437-A9F5B941CFD7}.Debug|x86.ActiveCfg = Debug|Any CPU + {5E119B71-D17F-42BA-8437-A9F5B941CFD7}.Debug|x86.Build.0 = Debug|Any CPU + {5E119B71-D17F-42BA-8437-A9F5B941CFD7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5E119B71-D17F-42BA-8437-A9F5B941CFD7}.Release|Any CPU.Build.0 = Release|Any CPU + {5E119B71-D17F-42BA-8437-A9F5B941CFD7}.Release|ARM32.ActiveCfg = Release|Any CPU + {5E119B71-D17F-42BA-8437-A9F5B941CFD7}.Release|ARM32.Build.0 = Release|Any CPU + {5E119B71-D17F-42BA-8437-A9F5B941CFD7}.Release|x86.ActiveCfg = Release|Any CPU + {5E119B71-D17F-42BA-8437-A9F5B941CFD7}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE