Browse Source

!41 修复ODBC参数化问题,添加OceanBaseForOracleTest项目

Merge pull request !41 from Tyou/master
master
sunkaixuan 1 year ago
committed by Gitee
parent
commit
377176a021
No known key found for this signature in database GPG Key ID: 173E9B9CA92EEF8F
  1. 31
      Src/Asp.NetCore2/OceanBaseForOracleTest/Config.cs
  2. 20
      Src/Asp.NetCore2/OceanBaseForOracleTest/Models/AttributeTable.cs
  3. 7
      Src/Asp.NetCore2/OceanBaseForOracleTest/Models/CarType.cs
  4. 14
      Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Custom.cs
  5. 15
      Src/Asp.NetCore2/OceanBaseForOracleTest/Models/EntityMapper.cs
  6. 54
      Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Mapper.cs
  7. 20
      Src/Asp.NetCore2/OceanBaseForOracleTest/Models/MyCustomAttributeTable.cs
  8. 25
      Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Order.cs
  9. 18
      Src/Asp.NetCore2/OceanBaseForOracleTest/Models/OrderItem.cs
  10. 17
      Src/Asp.NetCore2/OceanBaseForOracleTest/Models/TestTree.cs
  11. 20
      Src/Asp.NetCore2/OceanBaseForOracleTest/Models/Tree.cs
  12. 13
      Src/Asp.NetCore2/OceanBaseForOracleTest/Models/ViewOrder.cs
  13. 20
      Src/Asp.NetCore2/OceanBaseForOracleTest/OceanBaseForOracleTest.csproj
  14. 54
      Src/Asp.NetCore2/OceanBaseForOracleTest/Program.cs
  15. 5
      Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/OceanBase/OceanBaseForOracleProvider.cs
  16. 5
      Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/SqlSugar.OceanBaseForOracleCore.csproj
  17. 14
      Src/Asp.NetCore2/SqlSugarCore.sln

31
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
{
/// <summary>
/// Setting up the database name does not require you to create the database
/// 设置好数据库名不需要你去手动建库
/// </summary>
public class Config
{
/// <summary>
/// Account have permission to create database
/// 用有建库权限的数据库账号
/// </summary>
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;";
/// <summary>
/// Account have permission to create database
/// 用有建库权限的数据库账号
/// </summary>
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";
/// <summary>
/// Account have permission to create database
/// 用有建库权限的数据库账号
/// </summary>
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";
}
}

20
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; }
}
}

7
Src/Asp.NetCore2/OceanBaseForOracleTest/Models/CarType.cs

@ -0,0 +1,7 @@
namespace OrmTest
{
public class CarType
{
public bool State { get; set; }
}
}

14
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; }
}
}

15
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; }
}
}

54
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<OrderItem> 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; }
}
}

20
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; }
}
}

25
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; }
}
}

18
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; }
}
}

17
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; }
}
}

20
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<Tree> Child { get; set; }
}
}

13
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; }
}
}

20
Src/Asp.NetCore2/OceanBaseForOracleTest/OceanBaseForOracleTest.csproj

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SqlSugar.OceanBaseForOracle\SqlSugar.OceanBaseForOracleCore.csproj" />
<ProjectReference Include="..\SqlSugar.OdbcCore\SqlSugar.OdbcCore.csproj" />
<ProjectReference Include="..\SqlSugar\SqlSugar.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Demo\" />
</ItemGroup>
</Project>

54
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<Order>().Where(m => m.Id == 109).ExecuteCommand();
db.Updateable<Order>().SetColumns(m => new Order
{
Name = "我是修改"
}).Where(m => m.Id == 2).ExecuteCommand();
Console.WriteLine("Slave:");
//var s = db.Queryable<Order>().First();
//var list = db.Queryable<Order>().Select(m => new Order
//{
// Id = m.Id,
// CreateTime = m.CreateTime,
// CustomId = m.CustomId,
// Idname = SqlFunc.Subqueryable<Order>().Where(s => s.Id == 2).Select(s => s.Name),
// Name = m.Name,
// Price = m.Price,
//}).ToList();
//var grouplist = db.Queryable<Order>().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<Order>().OrderBy(m => new { m.Id, m.Name }).ToList();
var pageList = db.Queryable<Order>().OrderBy(m=>m.Id).ToOffsetPage(1, 3);
Console.WriteLine("#### MasterSlave End ####");
}
}
}

5
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);
}

5
Src/Asp.NetCore2/SqlSugar.OceanBaseForOracle/SqlSugar.OceanBaseForOracleCore.csproj

@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>

14
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

Loading…
Cancel
Save