mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
Add TDengine.Ado.Data
This commit is contained in:
parent
205c221d7e
commit
2587109284
@ -8,7 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MongoDb.Ado.data\MongoDb.Ado.data.csproj" />
|
||||
<ProjectReference Include="..\MongoDb.Ado.data\MongoDb.Ado.Data.csproj" />
|
||||
<ProjectReference Include="..\SqlSugar.MongoDbCore\SqlSugar.MongoDbCore.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MongoDb.Ado.data\MongoDb.Ado.data.csproj" />
|
||||
<ProjectReference Include="..\MongoDb.Ado.data\MongoDb.Ado.Data.csproj" />
|
||||
<ProjectReference Include="..\SqlSugar\SqlSugar.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -100,12 +100,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DuckDBTest", "DuckDBTest\Du
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AdoProvider", "AdoProvider", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDb.Ado.data", "MongoDb.Ado.data\MongoDb.Ado.data.csproj", "{9D7D900A-01ED-4E7C-A97A-1D3325F67AA2}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDb.Ado.Data", "MongoDb.Ado.data\MongoDb.Ado.Data.csproj", "{9D7D900A-01ED-4E7C-A97A-1D3325F67AA2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDbTest", "MongoDbTest\MongoDbTest.csproj", "{C6547EB1-B5AE-426A-A04D-3E2685AD7114}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlSugar.MongoDbCore", "SqlSugar.MongoDbCore\SqlSugar.MongoDbCore.csproj", "{47298939-4904-4997-848B-ADB32D4163D0}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TDengine.Ado.Data", "TDengine.Ado.Data\SqlSugar.TDengine\TDengine.Ado.Data.csproj", "{14D14094-34AD-9085-1C96-B63177762C10}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -680,6 +682,18 @@ Global
|
||||
{47298939-4904-4997-848B-ADB32D4163D0}.Release|ARM32.Build.0 = Release|Any CPU
|
||||
{47298939-4904-4997-848B-ADB32D4163D0}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{47298939-4904-4997-848B-ADB32D4163D0}.Release|x86.Build.0 = Release|Any CPU
|
||||
{14D14094-34AD-9085-1C96-B63177762C10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{14D14094-34AD-9085-1C96-B63177762C10}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{14D14094-34AD-9085-1C96-B63177762C10}.Debug|ARM32.ActiveCfg = Debug|Any CPU
|
||||
{14D14094-34AD-9085-1C96-B63177762C10}.Debug|ARM32.Build.0 = Debug|Any CPU
|
||||
{14D14094-34AD-9085-1C96-B63177762C10}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{14D14094-34AD-9085-1C96-B63177762C10}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{14D14094-34AD-9085-1C96-B63177762C10}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{14D14094-34AD-9085-1C96-B63177762C10}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{14D14094-34AD-9085-1C96-B63177762C10}.Release|ARM32.ActiveCfg = Release|Any CPU
|
||||
{14D14094-34AD-9085-1C96-B63177762C10}.Release|ARM32.Build.0 = Release|Any CPU
|
||||
{14D14094-34AD-9085-1C96-B63177762C10}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{14D14094-34AD-9085-1C96-B63177762C10}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -702,6 +716,7 @@ Global
|
||||
{02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {88992AAF-146B-4253-9AD7-493E8F415B57}
|
||||
{9D7D900A-01ED-4E7C-A97A-1D3325F67AA2} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
||||
{47298939-4904-4997-848B-ADB32D4163D0} = {88992AAF-146B-4253-9AD7-493E8F415B57}
|
||||
{14D14094-34AD-9085-1C96-B63177762C10} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {230A85B9-54F1-41B1-B1DA-80086581B2B4}
|
||||
|
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar.TDengineAdo
|
||||
{
|
||||
internal class DbConnectionHelper
|
||||
{
|
||||
}
|
||||
}
|
123
Src/Asp.NetCore2/TDengine.Ado.Data/SqlSugar.TDengine/Helper.cs
Normal file
123
Src/Asp.NetCore2/TDengine.Ado.Data/SqlSugar.TDengine/Helper.cs
Normal file
@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar.TDengineAdo
|
||||
{
|
||||
internal class Helper
|
||||
{
|
||||
|
||||
//public static bool HasMicrosecondPrecision(DateTime dateTime)
|
||||
//{
|
||||
// const long ticksPerMicrosecond = TimeSpan.TicksPerMillisecond / 1000;
|
||||
|
||||
// // Extract the microseconds by shifting and masking the ticks value
|
||||
// int microseconds = (int)((dateTime.Ticks / ticksPerMicrosecond) % 1000000);
|
||||
|
||||
// return microseconds>0;
|
||||
//}
|
||||
/// <summary>
|
||||
/// 将时间转为19位纳秒
|
||||
/// </summary>
|
||||
/// <param name="dateTime"></param>
|
||||
/// <returns></returns>
|
||||
public static long DateTimeToLong19(DateTime dateTime)
|
||||
{
|
||||
DateTimeOffset dateTimeOffset;
|
||||
|
||||
if (dateTime.Kind == DateTimeKind.Utc)
|
||||
{
|
||||
dateTimeOffset = new DateTimeOffset(dateTime, TimeSpan.Zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
dateTimeOffset = new DateTimeOffset(dateTime.ToUniversalTime());
|
||||
}
|
||||
|
||||
long unixTimeSeconds = dateTimeOffset.ToUnixTimeSeconds();
|
||||
long nanoseconds = dateTimeOffset.Ticks % TimeSpan.TicksPerSecond * 100;
|
||||
|
||||
return unixTimeSeconds * 1000000000 + nanoseconds;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取时间根据16位Long
|
||||
/// </summary>
|
||||
/// <param name="timestampInMicroseconds"></param>
|
||||
/// <returns></returns>
|
||||
public static DateTime Long16ToDateTime(long timestampInMicroseconds)
|
||||
{
|
||||
// 计算秒和微秒部分
|
||||
long seconds = timestampInMicroseconds / 1000000;
|
||||
long microseconds = timestampInMicroseconds % 1000000;
|
||||
|
||||
// 创建 DateTimeOffset 对象,设置秒和微秒部分
|
||||
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(seconds).AddTicks(microseconds * 10);
|
||||
|
||||
// 转换为本地时间
|
||||
DateTime localDateTime = dateTimeOffset.LocalDateTime;
|
||||
|
||||
return localDateTime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取时间根据19位Long
|
||||
/// </summary>
|
||||
/// <param name="timestampInMicroseconds"></param>
|
||||
/// <returns></returns>
|
||||
public static DateTime Long19ToDateTime(long timestampInNanoseconds)
|
||||
{
|
||||
// 计算秒和纳秒部分
|
||||
long seconds = timestampInNanoseconds / 1000000000;
|
||||
long nanoseconds = timestampInNanoseconds % 1000000000;
|
||||
|
||||
// 创建 DateTimeOffset 对象,设置秒和纳秒部分
|
||||
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(seconds).AddTicks(nanoseconds / 100);
|
||||
|
||||
// 转换为本地时间
|
||||
DateTime localDateTime = dateTimeOffset.LocalDateTime;
|
||||
|
||||
return localDateTime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将时间转为16位
|
||||
/// </summary>
|
||||
/// <param name="dateTime"></param>
|
||||
/// <returns></returns>
|
||||
public static long DateTimeToLong16(DateTime dateTime)
|
||||
{
|
||||
DateTimeOffset dateTimeOffset;
|
||||
|
||||
if (dateTime.Kind == DateTimeKind.Utc)
|
||||
{
|
||||
dateTimeOffset = new DateTimeOffset(dateTime, TimeSpan.Zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
dateTimeOffset = new DateTimeOffset(dateTime.ToUniversalTime());
|
||||
}
|
||||
|
||||
long unixTimeSeconds = dateTimeOffset.ToUnixTimeSeconds();
|
||||
long microseconds = dateTimeOffset.Ticks % TimeSpan.TicksPerSecond / (TimeSpan.TicksPerMillisecond / 1000);
|
||||
|
||||
return unixTimeSeconds * 1000000 + microseconds;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Method to convert a local DateTime to Unix timestamp (long)
|
||||
public static long ToUnixTimestamp(DateTime dateTime)
|
||||
{
|
||||
// If the DateTime is Utc, use ToUnixTimeMilliseconds directly
|
||||
if (dateTime.Kind == DateTimeKind.Utc)
|
||||
{
|
||||
return new DateTimeOffset(dateTime).ToUnixTimeMilliseconds();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Convert local DateTime to Utc before converting to Unix timestamp
|
||||
return new DateTimeOffset(dateTime.ToUniversalTime()).ToUnixTimeMilliseconds();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
Src/Asp.NetCore2/TDengine.Ado.Data/SqlSugar.TDengine/NuGet.exe
Normal file
BIN
Src/Asp.NetCore2/TDengine.Ado.Data/SqlSugar.TDengine/NuGet.exe
Normal file
Binary file not shown.
@ -0,0 +1,172 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar.TDengineAdo
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 数据填充器
|
||||
/// </summary>
|
||||
public class TDengineDataAdapter : IDataAdapter
|
||||
{
|
||||
private TDengineCommand command;
|
||||
private string sql;
|
||||
private TDengineConnection _TDengineConnection;
|
||||
|
||||
/// <summary>
|
||||
/// SqlDataAdapter
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
public TDengineDataAdapter(TDengineCommand command)
|
||||
{
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public TDengineDataAdapter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SqlDataAdapter
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <param name="_TDengineConnection"></param>
|
||||
public TDengineDataAdapter(string sql, TDengineConnection _TDengineConnection)
|
||||
{
|
||||
this.sql = sql;
|
||||
this._TDengineConnection = _TDengineConnection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SelectCommand
|
||||
/// </summary>
|
||||
public TDengineCommand SelectCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.command == null)
|
||||
{
|
||||
this.command = new TDengineCommand(this.sql, this._TDengineConnection);
|
||||
}
|
||||
return this.command;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.command = value;
|
||||
}
|
||||
}
|
||||
|
||||
public MissingMappingAction MissingMappingAction { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public MissingSchemaAction MissingSchemaAction { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public ITableMappingCollection TableMappings => throw new NotImplementedException();
|
||||
|
||||
/// <summary>
|
||||
/// Fill
|
||||
/// </summary>
|
||||
/// <param name="dt"></param>
|
||||
public void Fill(DataTable dt)
|
||||
{
|
||||
if (dt == null)
|
||||
{
|
||||
dt = new DataTable();
|
||||
}
|
||||
var columns = dt.Columns;
|
||||
var rows = dt.Rows;
|
||||
using (DbDataReader 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)??DBNull.Value;
|
||||
}
|
||||
dt.Rows.Add(daRow);
|
||||
}
|
||||
}
|
||||
|
||||
dt.AcceptChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fill
|
||||
/// </summary>
|
||||
/// <param name="ds"></param>
|
||||
public void Fill(DataSet ds)
|
||||
{
|
||||
if (ds == null)
|
||||
{
|
||||
ds = new DataSet();
|
||||
}
|
||||
using (DbDataReader 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 (!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());
|
||||
}
|
||||
}
|
||||
|
||||
int IDataAdapter.Fill(DataSet dataSet)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public DataTable[] FillSchema(DataSet dataSet, SchemaType schemaType)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IDataParameter[] GetFillParameters()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public int Update(DataSet dataSet)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0"?>
|
||||
<package >
|
||||
<metadata>
|
||||
<id>TDengine.Ado.Data</id>
|
||||
<version>3.1.07</version>
|
||||
<authors>sunkaixuan</authors>
|
||||
<owners>Landa</owners>
|
||||
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
|
||||
<projectUrl>https://github.com/sunkaixuan/SqlSugar</projectUrl>
|
||||
<iconUrl>https://secure.gravatar.com/avatar/a82c03402497b2e58fd65038a3699b30</iconUrl>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description> TDengine ADO.NET驱动,使用用例看:https://github.com/DotNetNext/SqlSugar/blob/master/Src/Asp.NetCore2/TDengineTest/Program.cs </description>
|
||||
<copyright>Copyright 2016</copyright>
|
||||
<tags>TDengine orm</tags>
|
||||
<dependencies>
|
||||
<group targetFramework=".NETStandard2.1">
|
||||
<dependency id="TDengine.Connector" version="3.1" />
|
||||
</group>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="G:\Git\TDengine.Ado.Data\TDengineTest\SqlSugar.TDengine\bin\Debug\netstandard2.1\SqlSugar.TDengine.dll" target="lib\netstandard2.1"></file>
|
||||
</files>
|
||||
</package>
|
@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TDengine.Connector" Version="3.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="TDengineCommand.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Update="TDengineConnection.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,207 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using TDengine.Data.Client;
|
||||
namespace SqlSugar.TDengineAdo
|
||||
{
|
||||
public class TDengineCommand : DbCommand
|
||||
{
|
||||
private string commandText;
|
||||
private TDengineConnection connection;
|
||||
private IntPtr currentRes;
|
||||
public TDengineCommand()
|
||||
{
|
||||
// Add any required initialization logic here.
|
||||
}
|
||||
|
||||
public TDengineCommand(string commandText, TDengineConnection connection)
|
||||
{
|
||||
this.CommandText = commandText;
|
||||
this.Connection = connection;
|
||||
}
|
||||
|
||||
public override string CommandText
|
||||
{
|
||||
get => commandText;
|
||||
set => commandText = value;
|
||||
}
|
||||
|
||||
public override int CommandTimeout { get; set; }
|
||||
|
||||
public override CommandType CommandType { get; set; }
|
||||
|
||||
public override bool DesignTimeVisible { get; set; }
|
||||
|
||||
public override UpdateRowSource UpdatedRowSource { get; set; }
|
||||
|
||||
protected override DbConnection DbConnection
|
||||
{
|
||||
get => connection;
|
||||
set => connection = (TDengineConnection)value;
|
||||
}
|
||||
private TDengineParameterCollection _DbParameterCollection;
|
||||
protected override DbParameterCollection DbParameterCollection
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_DbParameterCollection == null)
|
||||
{
|
||||
_DbParameterCollection = new TDengineParameterCollection();
|
||||
}
|
||||
return _DbParameterCollection;
|
||||
}
|
||||
}
|
||||
|
||||
protected override DbTransaction DbTransaction { get; set; }
|
||||
|
||||
public override void Cancel()
|
||||
{
|
||||
// Implement if needed
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override int ExecuteNonQuery()
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
var sql = GetNoParameterSql(commandText);
|
||||
long res = connection.connection.Exec(sql);
|
||||
|
||||
connection.Close();
|
||||
return res > int.MaxValue ? int.MaxValue : Convert.ToInt32(res);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
connection.Close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public override object ExecuteScalar()
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
var sql = GetNoParameterSql(commandText);
|
||||
|
||||
var res = connection.connection.Query(sql);
|
||||
using (res)
|
||||
{
|
||||
res.Read();
|
||||
connection.Close();
|
||||
return res.GetValue(0);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
connection.Close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public new DbDataReader ExecuteReader()
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
var sql = GetNoParameterSql(commandText);
|
||||
|
||||
var res = connection.connection.Query(sql);
|
||||
TDengineDataReader reader = new TDengineDataReader(res);
|
||||
|
||||
connection.Close();
|
||||
return reader;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
connection.Close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Prepare()
|
||||
{
|
||||
// Implement if needed
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
//// Release the result pointer if it exists
|
||||
//if (currentRes != IntPtr.Zero)
|
||||
//{
|
||||
// TDengine.FreeResult(connection.connection);
|
||||
// currentRes = IntPtr.Zero;
|
||||
//}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
protected override DbParameter CreateDbParameter()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
|
||||
{
|
||||
return ExecuteReader();
|
||||
}
|
||||
|
||||
#region Helper
|
||||
string GetNoParameterSql(string sql)
|
||||
{
|
||||
foreach (TDengineParameter item in this.Parameters.Cast<TDengineParameter>().OrderByDescending(it => it.parameterName.Length))
|
||||
{
|
||||
if (!item.parameterName.Contains("@"))
|
||||
{
|
||||
item.parameterName = "@" + item.parameterName;
|
||||
}
|
||||
var value = item.value;
|
||||
if (item.value == null || item.value == DBNull.Value)
|
||||
{
|
||||
sql = Regex.Replace(sql, item.parameterName, "null", RegexOptions.IgnoreCase);
|
||||
}
|
||||
else if (item.value is DateTime)
|
||||
{
|
||||
var dt = (DateTime)item.value;
|
||||
if (item.IsMicrosecond)//有微妙
|
||||
{
|
||||
sql = Regex.Replace(sql, item.parameterName, Helper.DateTimeToLong16(dt) + "", RegexOptions.IgnoreCase);
|
||||
}
|
||||
else if (item.IsNanosecond)//有纳妙
|
||||
{
|
||||
sql = Regex.Replace(sql, item.parameterName, Helper.DateTimeToLong19(dt) + "", RegexOptions.IgnoreCase);
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = Regex.Replace(sql, item.parameterName, Helper.ToUnixTimestamp(dt) + "", RegexOptions.IgnoreCase);
|
||||
}
|
||||
}
|
||||
else if (!(item.value is string || item.value is object))
|
||||
{
|
||||
sql = Regex.Replace(sql, item.parameterName, "'" + item.value + "'", RegexOptions.IgnoreCase);
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = Regex.Replace(sql, item.parameterName, "'" + item.value.ToString().Replace("'", "''") + "'", RegexOptions.IgnoreCase);
|
||||
}
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Net.Http.Headers;
|
||||
using TDengine.Driver;
|
||||
using TDengine.Driver.Client;
|
||||
namespace SqlSugar.TDengineAdo
|
||||
{
|
||||
public class TDengineConnection : DbConnection
|
||||
{
|
||||
private readonly string host;
|
||||
private readonly short port;
|
||||
private readonly string username;
|
||||
private readonly string password;
|
||||
private string dbname;
|
||||
internal ITDengineClient connection;
|
||||
|
||||
public TDengineConnection(string connectionString)
|
||||
{
|
||||
connection = DbDriver.Open(new ConnectionStringBuilder(connectionString));
|
||||
var builder = new DbConnectionStringBuilder();
|
||||
builder.ConnectionString = connectionString;
|
||||
|
||||
if (builder.TryGetValue("Host", out object hostValue))
|
||||
{
|
||||
host = Convert.ToString(hostValue);
|
||||
}
|
||||
if (builder.TryGetValue("Port", out object portValue))
|
||||
{
|
||||
port = Convert.ToInt16(portValue);
|
||||
}
|
||||
if (builder.TryGetValue("Username", out object usernameValue))
|
||||
{
|
||||
username = Convert.ToString(usernameValue);
|
||||
}
|
||||
if (builder.TryGetValue("Password", out object passwordValue))
|
||||
{
|
||||
password = Convert.ToString(passwordValue);
|
||||
}
|
||||
if (builder.TryGetValue("Database", out object dbnameValue))
|
||||
{
|
||||
dbname = Convert.ToString(dbnameValue);
|
||||
}
|
||||
}
|
||||
public TDengineConnection(string host, short port, string username, string password, string dbname)
|
||||
{
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.dbname = dbname;
|
||||
connection = DbDriver.Open(new ConnectionStringBuilder(ConnectionString));
|
||||
}
|
||||
|
||||
public override string ConnectionString
|
||||
{
|
||||
get { return $"Host={host};Port={port};Username={username};Password={password};Database={dbname}"; }
|
||||
set { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public override string Database => dbname;
|
||||
|
||||
public override string DataSource => host;
|
||||
|
||||
public override string ServerVersion => "Unknown"; // You may provide the actual version if available.
|
||||
|
||||
public override ConnectionState State => connection==null? ConnectionState.Closed : ConnectionState.Open;
|
||||
|
||||
protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
|
||||
{
|
||||
throw new NotSupportedException("BeginDbTransaction");
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
if (connection != null)
|
||||
{
|
||||
|
||||
connection.Dispose();
|
||||
connection = null;
|
||||
}
|
||||
}
|
||||
public override void Open()
|
||||
{
|
||||
if (connection == null)
|
||||
{
|
||||
connection = DbDriver.Open(new ConnectionStringBuilder(ConnectionString));
|
||||
}
|
||||
else if(connection == null)
|
||||
{
|
||||
connection = DbDriver.Open(new ConnectionStringBuilder(ConnectionString));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Database))
|
||||
{
|
||||
connection.Exec("use " + Database);
|
||||
}
|
||||
}
|
||||
|
||||
protected override DbCommand CreateDbCommand()
|
||||
{
|
||||
return new TDengineCommand();
|
||||
}
|
||||
protected DbCommand CreateDbCommand(string commandText)
|
||||
{
|
||||
return new TDengineCommand(commandText, this);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
public override void ChangeDatabase(string databaseName)
|
||||
{
|
||||
dbname = databaseName;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
using SqlSugar.TDengineAdo;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar.TDengineAdo
|
||||
{
|
||||
public class TDengineParameterCollection : DbParameterCollection
|
||||
{
|
||||
private List<TDengineParameter> parameters = new List<TDengineParameter>();
|
||||
|
||||
public override int Count => parameters.Count;
|
||||
|
||||
public override object SyncRoot => ((ICollection)parameters).SyncRoot;
|
||||
|
||||
public override int Add(object value)
|
||||
{
|
||||
parameters.Add((TDengineParameter)value);
|
||||
return parameters.Count - 1;
|
||||
}
|
||||
|
||||
public override void AddRange(Array values)
|
||||
{
|
||||
foreach (var value in values)
|
||||
{
|
||||
parameters.Add((TDengineParameter)value);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
parameters.Clear();
|
||||
}
|
||||
|
||||
public override bool Contains(string value)
|
||||
{
|
||||
foreach (var param in parameters)
|
||||
{
|
||||
if (param.ParameterName.Equals(value, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool Contains(object value)
|
||||
{
|
||||
return parameters.Contains((TDengineParameter)value);
|
||||
}
|
||||
|
||||
public override void CopyTo(Array array, int index)
|
||||
{
|
||||
for (int i = 0; i < parameters.Count; i++)
|
||||
{
|
||||
array.SetValue(parameters[i], index + i);
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerator GetEnumerator()
|
||||
{
|
||||
return parameters.GetEnumerator();
|
||||
}
|
||||
|
||||
public override int IndexOf(string parameterName)
|
||||
{
|
||||
for (int i = 0; i < parameters.Count; i++)
|
||||
{
|
||||
if (parameters[i].ParameterName.Equals(parameterName, StringComparison.OrdinalIgnoreCase))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public override int IndexOf(object value)
|
||||
{
|
||||
return parameters.IndexOf((TDengineParameter)value);
|
||||
}
|
||||
|
||||
public override void Insert(int index, object value)
|
||||
{
|
||||
parameters.Insert(index, (TDengineParameter)value);
|
||||
}
|
||||
|
||||
public override void Remove(object value)
|
||||
{
|
||||
parameters.Remove((TDengineParameter)value);
|
||||
}
|
||||
|
||||
public override void RemoveAt(int index)
|
||||
{
|
||||
parameters.RemoveAt(index);
|
||||
}
|
||||
|
||||
public override void RemoveAt(string parameterName)
|
||||
{
|
||||
int index = IndexOf(parameterName);
|
||||
if (index >= 0)
|
||||
parameters.RemoveAt(index);
|
||||
}
|
||||
|
||||
protected override DbParameter GetParameter(int index)
|
||||
{
|
||||
return parameters[index];
|
||||
}
|
||||
|
||||
protected override DbParameter GetParameter(string parameterName)
|
||||
{
|
||||
int index = IndexOf(parameterName);
|
||||
if (index >= 0)
|
||||
return parameters[index];
|
||||
return null;
|
||||
}
|
||||
protected override void SetParameter(int index, DbParameter value)
|
||||
{
|
||||
if (index < 0 || index >= parameters.Count)
|
||||
throw new IndexOutOfRangeException("Index is out of range.");
|
||||
|
||||
if (value == null)
|
||||
throw new ArgumentNullException(nameof(value), "Parameter cannot be null.");
|
||||
|
||||
parameters[index] = (TDengineParameter)value;
|
||||
}
|
||||
|
||||
protected override void SetParameter(string parameterName, DbParameter value)
|
||||
{
|
||||
int index = IndexOf(parameterName);
|
||||
if (index == -1)
|
||||
throw new IndexOutOfRangeException("Parameter not found.");
|
||||
|
||||
if (value == null)
|
||||
throw new ArgumentNullException(nameof(value), "Parameter cannot be null.");
|
||||
|
||||
parameters[index] = (TDengineParameter)value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar.TDengineAdo
|
||||
{
|
||||
public class TDengineParameter:DbParameter
|
||||
{
|
||||
// Private fields to store the parameter properties
|
||||
public object value { get; set; }
|
||||
public string parameterName;
|
||||
private int size;
|
||||
private System.Data.DbType dbType;
|
||||
public bool IsMicrosecond { get; set; }
|
||||
public bool IsNanosecond { get; set; }
|
||||
|
||||
// Constructor to initialize the parameter
|
||||
public TDengineParameter(string parameterName,object value,System.Data.DbType dbType= System.Data.DbType.Object, int size=0)
|
||||
{
|
||||
this.parameterName = parameterName;
|
||||
this.value = value;
|
||||
this.size = size;
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
// Implementing abstract properties and methods
|
||||
public override System.Data.DbType DbType
|
||||
{
|
||||
get { return this.dbType; }
|
||||
set { this.dbType = value; }
|
||||
}
|
||||
|
||||
public override int Size
|
||||
{
|
||||
get { return size; }
|
||||
set { size = value; }
|
||||
}
|
||||
|
||||
public override string ParameterName
|
||||
{
|
||||
get { return parameterName; }
|
||||
set { parameterName = value; }
|
||||
}
|
||||
|
||||
public override object Value
|
||||
{
|
||||
get { return this.value; }
|
||||
set { this.value = value; }
|
||||
}
|
||||
|
||||
// Other properties and methods can be implemented as needed
|
||||
|
||||
// The following methods are abstract, so they must be implemented
|
||||
|
||||
public override void ResetDbType()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string SourceColumn
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool IsNullable
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override DataRowVersion SourceVersion
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
public override ParameterDirection Direction { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public override bool SourceColumnNullMapping { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
}
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
namespace SqlSugar.TDengineAdo
|
||||
{
|
||||
internal class TDengineType
|
||||
{
|
||||
|
||||
public static object GetObjectByType(object dataValue, byte typeValue)
|
||||
{
|
||||
if (dataValue is string &&dataValue?.ToString().ToUpper() == "NULL")
|
||||
{
|
||||
return null;
|
||||
}
|
||||
switch (typeValue)
|
||||
{
|
||||
case 1: // BOOL
|
||||
return Convert.ToBoolean(dataValue);
|
||||
case 2: // TINYINT
|
||||
return Convert.ToSByte(dataValue);
|
||||
case 3: // SMALLINT
|
||||
return Convert.ToInt16(dataValue);
|
||||
case 4: // INT
|
||||
return Convert.ToInt32(dataValue);
|
||||
case 5: // BIGINT
|
||||
return Convert.ToInt64(dataValue);
|
||||
case 11: // TINYINT UNSIGNED
|
||||
return Convert.ToByte(dataValue);
|
||||
case 12: // SMALLINT UNSIGNED
|
||||
return Convert.ToUInt16(dataValue);
|
||||
case 13: // INT UNSIGNED
|
||||
return Convert.ToUInt32(dataValue);
|
||||
case 14: // BIGINT UNSIGNED
|
||||
return Convert.ToUInt64(dataValue);
|
||||
case 6: // FLOAT
|
||||
return Convert.ToSingle(dataValue);
|
||||
case 7: // DOUBLE
|
||||
return Convert.ToDouble(dataValue);
|
||||
case 8: // BINARY
|
||||
return dataValue?.ToString();
|
||||
case 9: // TIMESTAMP
|
||||
if (dataValue?.ToString()?.Length == 16)
|
||||
{
|
||||
var dt = Helper.Long16ToDateTime(Convert.ToInt64(dataValue));
|
||||
return dt;
|
||||
}
|
||||
else if (dataValue?.ToString()?.Length == 19)
|
||||
{
|
||||
var dt = Helper.Long19ToDateTime(Convert.ToInt64(dataValue));
|
||||
return dt;
|
||||
}
|
||||
else
|
||||
{
|
||||
var dt = DateTimeOffset.FromUnixTimeMilliseconds(Convert.ToInt64(dataValue)).DateTime.ToLocalTime();
|
||||
return dt;
|
||||
}
|
||||
case 10: // NCHAR
|
||||
case 15: // JSON
|
||||
return dataValue?.ToString();
|
||||
default:
|
||||
return dataValue; // Return as is if the type is not recognized
|
||||
}
|
||||
}
|
||||
public static string GetDataTypeName(byte typeValue)
|
||||
{
|
||||
return typeValue switch
|
||||
{
|
||||
1 => typeof(bool).Name,
|
||||
2 => typeof(sbyte).Name,
|
||||
3 => typeof(short).Name,
|
||||
4 => typeof(int).Name,
|
||||
5 => typeof(long).Name,
|
||||
11 => typeof(byte).Name,
|
||||
12 => typeof(ushort).Name,
|
||||
13 => typeof(uint).Name,
|
||||
14 => typeof(ulong).Name,
|
||||
6 => typeof(float).Name,
|
||||
7 => typeof(double).Name,
|
||||
8 => typeof(string).Name,
|
||||
9 => typeof(DateTime).Name,
|
||||
10 => typeof(string).Name,
|
||||
15 => typeof(string).Name, // Assuming JSON is represented as a string
|
||||
_ => typeof(string).Name,
|
||||
};
|
||||
}
|
||||
public static Type GetDataType(int typeValue)
|
||||
{
|
||||
return typeValue switch
|
||||
{
|
||||
1 => typeof(bool),
|
||||
2 => typeof(sbyte),
|
||||
3 => typeof(short),
|
||||
4 => typeof(int),
|
||||
5 => typeof(long),
|
||||
11 => typeof(byte),
|
||||
12 => typeof(ushort),
|
||||
13 => typeof(uint),
|
||||
14 => typeof(ulong),
|
||||
6 => typeof(float),
|
||||
7 => typeof(double),
|
||||
8 => typeof(string),
|
||||
9 => typeof(DateTime),
|
||||
10 => typeof(string),
|
||||
15 => typeof(string), // Assuming JSON is represented as a string
|
||||
_ => typeof(string),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
%~dp0nuget.exe pack %~dp0SqlSugar.OdbcCore.nuspec -OutputDirectory %~dp0
|
Loading…
Reference in New Issue
Block a user