mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-15 20:49:31 +08:00
Update HANA
This commit is contained in:
parent
d0aea1173a
commit
1c25d6eef8
@ -1,16 +1,45 @@
|
|||||||
|
|
||||||
using SqlSugar;
|
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",
|
internal class Program
|
||||||
DbType = DbType.HANA,
|
{
|
||||||
IsAutoCloseConnection = true,
|
static void Main(string[] args)
|
||||||
});
|
{
|
||||||
|
//这行代码扔程序启动时
|
||||||
|
InstanceFactory.CustomAssemblies = new System.Reflection.Assembly[] {
|
||||||
|
typeof(SqlSugar.HANAConnector.HANAProvider).Assembly };
|
||||||
|
|
||||||
db.Open();
|
var db = new SqlSugarClient(new ConnectionConfig()
|
||||||
db.Close();
|
{
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -60,6 +60,7 @@ namespace SqlSugar.HANAConnector
|
|||||||
}
|
}
|
||||||
public override DbCommand GetCommand(string sql, SugarParameter[] parameters)
|
public override DbCommand GetCommand(string sql, SugarParameter[] parameters)
|
||||||
{
|
{
|
||||||
|
sql = ReplaceKeyWordParameterName(sql, parameters);
|
||||||
HanaCommand sqlCommand = new HanaCommand(sql, (HanaConnection)this.Connection);
|
HanaCommand sqlCommand = new HanaCommand(sql, (HanaConnection)this.Connection);
|
||||||
sqlCommand.CommandType = this.CommandType;
|
sqlCommand.CommandType = this.CommandType;
|
||||||
sqlCommand.CommandTimeout = this.CommandTimeOut;
|
sqlCommand.CommandTimeout = this.CommandTimeOut;
|
||||||
@ -139,6 +140,42 @@ namespace SqlSugar.HANAConnector
|
|||||||
return false;
|
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
|
#region async
|
||||||
public async Task CloseAsync()
|
public async Task CloseAsync()
|
||||||
|
@ -6,8 +6,8 @@ namespace SqlSugar.HANAConnector
|
|||||||
{
|
{
|
||||||
public class HANABuilder : SqlBuilderProvider
|
public class HANABuilder : SqlBuilderProvider
|
||||||
{
|
{
|
||||||
public override string SqlTranslationLeft { get { return "`"; } }
|
public override string SqlTranslationLeft { get { return "\""; } }
|
||||||
public override string SqlTranslationRight { get { return "`"; } }
|
public override string SqlTranslationRight { get { return "\""; } }
|
||||||
public override string SqlDateNow
|
public override string SqlDateNow
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -12,8 +12,8 @@ namespace SqlSugar.HANAConnector
|
|||||||
{
|
{
|
||||||
base.DbMehtods = new HANAMethod();
|
base.DbMehtods = new HANAMethod();
|
||||||
}
|
}
|
||||||
public override string SqlTranslationLeft { get { return "`"; } }
|
public override string SqlTranslationLeft { get { return "\""; } }
|
||||||
public override string SqlTranslationRight { get { return "`"; } }
|
public override string SqlTranslationRight { get { return "\""; } }
|
||||||
}
|
}
|
||||||
public class HANAMethod : DefaultDbMethod, IDbMethods
|
public class HANAMethod : DefaultDbMethod, IDbMethods
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user