mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-30 06:32:49 +08:00

> 注意:尽量不要使用带点的表名,只有 MySql/Sqlite 对此类表名支持 CodeFirst。但是它不影响 CRUD 功能,使用 [Table(Name = "`sys.config`")] 解决
79 lines
2.5 KiB
C#
79 lines
2.5 KiB
C#
using FreeSql.DataAnnotations;
|
|
using FreeSql;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Xunit;
|
|
using System.Linq;
|
|
using Newtonsoft.Json.Linq;
|
|
using NpgsqlTypes;
|
|
using Npgsql.LegacyPostgis;
|
|
using System.Linq.Expressions;
|
|
using System.Threading.Tasks;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Threading;
|
|
using System.Data.SqlClient;
|
|
using kwlib;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Text;
|
|
using FreeSql.Internal;
|
|
|
|
namespace FreeSql.InternalTests
|
|
{
|
|
public class CommonUtilsTest
|
|
{
|
|
|
|
[Fact]
|
|
public void GetSplitTableNames()
|
|
{
|
|
var tbname = CommonUtils.GetSplitTableNames("table1", '`', '`', 2);
|
|
Assert.Equal("table1", tbname[0]);
|
|
|
|
tbname = CommonUtils.GetSplitTableNames("table1", '"', '"', 2);
|
|
Assert.Equal("table1", tbname[0]);
|
|
|
|
tbname = CommonUtils.GetSplitTableNames("table1", '[', ']', 2);
|
|
Assert.Equal("table1", tbname[0]);
|
|
|
|
//---
|
|
|
|
tbname = CommonUtils.GetSplitTableNames("schema1.table1", '`', '`', 2);
|
|
Assert.Equal("schema1", tbname[0]);
|
|
Assert.Equal("table1", tbname[1]);
|
|
|
|
tbname = CommonUtils.GetSplitTableNames("schema1.table1", '"', '"', 2);
|
|
Assert.Equal("schema1", tbname[0]);
|
|
Assert.Equal("table1", tbname[1]);
|
|
|
|
tbname = CommonUtils.GetSplitTableNames("schema1.table1", '[', ']', 2);
|
|
Assert.Equal("schema1", tbname[0]);
|
|
Assert.Equal("table1", tbname[1]);
|
|
|
|
//---
|
|
|
|
tbname = CommonUtils.GetSplitTableNames("`sys.table1`", '`', '`', 2);
|
|
Assert.Equal("sys.table1", tbname[0]);
|
|
|
|
tbname = CommonUtils.GetSplitTableNames("\"sys.table1\"", '"', '"', 2);
|
|
Assert.Equal("sys.table1", tbname[0]);
|
|
|
|
tbname = CommonUtils.GetSplitTableNames("[sys.table1]", '[', ']', 2);
|
|
Assert.Equal("sys.table1", tbname[0]);
|
|
|
|
//---
|
|
|
|
tbname = CommonUtils.GetSplitTableNames("`schema1`.`sys.table1`", '`', '`', 2);
|
|
Assert.Equal("schema1", tbname[0]);
|
|
Assert.Equal("sys.table1", tbname[1]);
|
|
|
|
tbname = CommonUtils.GetSplitTableNames("\"schema1\".\"sys.table1\"", '"', '"', 2);
|
|
Assert.Equal("schema1", tbname[0]);
|
|
Assert.Equal("sys.table1", tbname[1]);
|
|
|
|
tbname = CommonUtils.GetSplitTableNames("[schema1].[sys.table1]", '[', ']', 2);
|
|
Assert.Equal("schema1", tbname[0]);
|
|
Assert.Equal("sys.table1", tbname[1]);
|
|
}
|
|
}
|
|
}
|