Update HANA

This commit is contained in:
sunkaixuan 2025-03-10 16:13:42 +08:00
parent d0aea1173a
commit 1c25d6eef8
4 changed files with 79 additions and 13 deletions

View File

@ -1,16 +1,45 @@

using SqlSugar;
var db = new SqlSugarClient(new ConnectionConfig()
namespace GbaseTest
{
ConnectionString = "DRIVER={HANAQAS64};SERVERNODE=172.16.10.12:32015;UID=WLH_BPM_TASK;PWD=BPM4pass1;DATABASENAME=Q00",
DbType = DbType.HANA,
IsAutoCloseConnection = true,
});
internal class Program
{
static void Main(string[] args)
{
//这行代码扔程序启动时
InstanceFactory.CustomAssemblies = new System.Reflection.Assembly[] {
typeof(SqlSugar.HANAConnector.HANAProvider).Assembly };
db.Open();
db.Close();
var db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = "DRIVER={HANAQAS64};SERVERNODE=172.16.10.12:32015;UID=WLH_BPM_TASK;PWD=BPM4pass1;DATABASENAME=Q00",
DbType = DbType.HANA,
IsAutoCloseConnection = true,
}, db =>
{
var dt = db.Ado.GetDataTable("SELECT 1 as id");
Console.WriteLine("Hello, World!");
db.Aop.OnLogExecuting = (x, y) =>
{
Console.WriteLine(x);
};
});
db.Open();
db.Close();
var dt = db.Ado.GetDataTable("SELECT * from DF_MM_POINFO where id=:id ", new { id = 1 });
var list = db.Queryable<DF_MM_POINFO>().Where(IT => IT.ID > 0).ToList();
Console.WriteLine("Hello, World!");
}
public class DF_MM_POINFO
{
public int ID { get; set; }
}
}
}

View File

@ -60,6 +60,7 @@ namespace SqlSugar.HANAConnector
}
public override DbCommand GetCommand(string sql, SugarParameter[] parameters)
{
sql = ReplaceKeyWordParameterName(sql, parameters);
HanaCommand sqlCommand = new HanaCommand(sql, (HanaConnection)this.Connection);
sqlCommand.CommandType = this.CommandType;
sqlCommand.CommandTimeout = this.CommandTimeOut;
@ -139,6 +140,42 @@ namespace SqlSugar.HANAConnector
return false;
}
private static string[] KeyWord = new string[] { };
private static string ReplaceKeyWordParameterName(string sql, SugarParameter[] parameters)
{
sql = ReplaceKeyWordWithAd(sql, parameters);
if (parameters.HasValue() && parameters.Count(it => it.ParameterName.ToLower().IsIn(KeyWord)) > 0)
{
int i = 0;
foreach (var Parameter in parameters.OrderByDescending(it => it.ParameterName.Length))
{
if (Parameter.ParameterName != null && Parameter.ParameterName.ToLower().IsContainsIn(KeyWord))
{
var newName = ":p" + i + 100;
sql =System.Text.RegularExpressions.Regex.Replace(sql, Parameter.ParameterName, newName, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
Parameter.ParameterName = newName;
i++;
}
}
}
return sql;
}
private static string ReplaceKeyWordWithAd(string sql, SugarParameter[] parameters)
{
if (parameters != null && sql != null && sql.Contains("@"))
{
foreach (var item in parameters.OrderByDescending(it => it.ParameterName.Length))
{
if (item.ParameterName.StartsWith("@"))
{
item.ParameterName = ":" + item.ParameterName.TrimStart('@');
}
sql = System.Text.RegularExpressions.Regex.Replace(sql, "@" + item.ParameterName.TrimStart(':'), item.ParameterName, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
}
}
return sql;
}
#region async
public async Task CloseAsync()

View File

@ -6,8 +6,8 @@ namespace SqlSugar.HANAConnector
{
public class HANABuilder : SqlBuilderProvider
{
public override string SqlTranslationLeft { get { return "`"; } }
public override string SqlTranslationRight { get { return "`"; } }
public override string SqlTranslationLeft { get { return "\""; } }
public override string SqlTranslationRight { get { return "\""; } }
public override string SqlDateNow
{
get

View File

@ -12,8 +12,8 @@ namespace SqlSugar.HANAConnector
{
base.DbMehtods = new HANAMethod();
}
public override string SqlTranslationLeft { get { return "`"; } }
public override string SqlTranslationRight { get { return "`"; } }
public override string SqlTranslationLeft { get { return "\""; } }
public override string SqlTranslationRight { get { return "\""; } }
}
public class HANAMethod : DefaultDbMethod, IDbMethods
{