60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
|
using SqlSugar;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace LeatherApp.Utils
|
|||
|
{
|
|||
|
public class DBUtils
|
|||
|
{
|
|||
|
private static SqlSugarClient db;
|
|||
|
//public static dbBackup()
|
|||
|
//{
|
|||
|
// //mysqldump -uroot-p123456 mydb > /data/mysqlDump/mydb.sql
|
|||
|
// //mysqldump - uroot - p123456 mydb > / data / mysqlDump / mydb.sql
|
|||
|
//}
|
|||
|
|
|||
|
public static SqlSugarClient getErpDBCon(SqlSugar.DbType dbType = SqlSugar.DbType.SqlServer)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(Config.ErpDBConStr))
|
|||
|
return null;
|
|||
|
if (db != null) return db;
|
|||
|
|
|||
|
db = new SqlSugarClient(new ConnectionConfig()
|
|||
|
{
|
|||
|
ConnectionString = Config.ErpDBConStr,
|
|||
|
DbType = dbType,
|
|||
|
IsAutoCloseConnection = true
|
|||
|
},
|
|||
|
db =>
|
|||
|
{
|
|||
|
db.Aop.OnLogExecuting = (sql, pars) =>
|
|||
|
{
|
|||
|
Console.WriteLine(sql);//输出sql,查看执行sql 性能无影响
|
|||
|
|
|||
|
//获取原生SQL推荐 5.1.4.63 性能OK
|
|||
|
//UtilMethods.GetNativeSql(sql,pars)
|
|||
|
|
|||
|
//获取无参数化SQL 对性能有影响,特别大的SQL参数多的,调试使用
|
|||
|
//UtilMethods.GetSqlString(DbType.SqlServer,sql,pars)
|
|||
|
};
|
|||
|
|
|||
|
});
|
|||
|
return db;
|
|||
|
}
|
|||
|
public static DataTable execSql(string sql, List<SugarParameter> parameters, SqlSugar.DbType dbType = SqlSugar.DbType.SqlServer)
|
|||
|
{
|
|||
|
//查询表的所有
|
|||
|
var mydb = getErpDBCon(dbType);
|
|||
|
if(mydb == null) return null;
|
|||
|
|
|||
|
if (!mydb.Ado.IsValidConnection())
|
|||
|
mydb.Ado.Open();
|
|||
|
return mydb.Ado.GetDataTable(sql, parameters);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|