mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Update Demo
This commit is contained in:
parent
7ebb7b1352
commit
37c1e5970e
@ -8,6 +8,6 @@ namespace OrmTest
|
||||
{
|
||||
public class Config
|
||||
{
|
||||
public static string ConnectionString = "Database=SqlSugar4xTest;Data Source=127.0.0.1;User Id=root;Password=root;pooling=false;CharSet=utf8;port=3306";
|
||||
public static string ConnectionString = "Database=SqlSugar4xTest;Data Source=127.0.0.1;User Id=root;Password=haosql;pooling=false;CharSet=utf8;port=3306";
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace OrmTest.Demo
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.MySql, IsAutoCloseConnection = true });
|
||||
db.Ado.IsEnableLogEvent = true;
|
||||
db.Ado.LogEventStarting = (sql, pars) =>
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + "\r\n" +db.Utilities.SerializeObject(pars.ToDictionary(s=>s.ParameterName,s=>s.Value)));
|
||||
Console.WriteLine();
|
||||
|
@ -72,8 +72,7 @@ namespace OrmTest.UnitTest
|
||||
public SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.MySql });
|
||||
db.Ado.IsEnableLogEvent = true;
|
||||
db.Ado.LogEventStarting = (sql, pars) =>
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + " " + pars);
|
||||
};
|
||||
|
@ -30,7 +30,7 @@ namespace OrmTest.UnitTest
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
//db.Database.IsEnableLogEvent = true;
|
||||
db.Ado.LogEventStarting = (sql, pars) =>
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + " " + pars);
|
||||
};
|
||||
|
@ -8,8 +8,8 @@ namespace OrmTest
|
||||
{
|
||||
public class Config
|
||||
{
|
||||
public static string ConnectionString = "PORT=5432;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=jhl52771;USER ID=postgres";
|
||||
public static string ConnectionString2 = "PORT=5432;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=jhl52771;USER ID=postgres";
|
||||
public static string ConnectionString3 = "PORT=5432;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=jhl52771;USER ID=postgres";
|
||||
public static string ConnectionString = "PORT=5432;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=haosql;USER ID=postgres";
|
||||
public static string ConnectionString2 = "PORT=5432;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=haosql;USER ID=postgres";
|
||||
public static string ConnectionString3 = "PORT=5432;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=haosql;USER ID=postgres";
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ namespace OrmTest.Demo
|
||||
});
|
||||
|
||||
//Processing prior to execution of SQL
|
||||
db.Ado.ProcessingEventStartingSQL = (sql, par) =>
|
||||
db.Aop.OnExecutingChangeSql = (sql, par) =>
|
||||
{
|
||||
if (sql.Contains("{0}"))
|
||||
{
|
||||
|
@ -250,50 +250,60 @@ namespace SqlSugar
|
||||
{
|
||||
string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
||||
cacheKey = GetCacheKey(cacheKey);
|
||||
if (!isCache)
|
||||
if (isCache)
|
||||
{
|
||||
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate<List<DbColumnInfo>>(cacheKey, () =>
|
||||
{
|
||||
return GetColumnInfosByTableName(tableName);
|
||||
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetColumnInfosByTableName(tableName);
|
||||
}
|
||||
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
|
||||
() =>
|
||||
{
|
||||
return GetColumnsByTableName(tableName);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
public override bool AddRemark(EntityInfo entity)
|
||||
private List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
private List<DbColumnInfo> GetColumnsByTableName(string tableName)
|
||||
{
|
||||
string sql = "select * from " + tableName + " limit 0,1";
|
||||
string sql = "PRAGMA table_info(" + tableName + ")";
|
||||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||
this.Context.Ado.IsEnableLogEvent = false;
|
||||
using (DbDataReader reader = (SqliteDataReader)this.Context.Ado.GetDataReader(sql))
|
||||
using (DbDataReader dataReader = (SqliteDataReader)this.Context.Ado.GetDataReader(sql))
|
||||
{
|
||||
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
|
||||
List<DbColumnInfo> result = new List<DbColumnInfo>();
|
||||
var schemaTable = reader.GetSchemaTable();
|
||||
foreach (DataRow row in schemaTable.Rows)
|
||||
while (dataReader.Read())
|
||||
{
|
||||
var type = dataReader.GetValue(2).ObjToString();
|
||||
var length = 0;
|
||||
if (type.Contains("("))
|
||||
{
|
||||
type = type.Split('(').First();
|
||||
length = type.Split('(').Last().TrimEnd(')').ObjToInt();
|
||||
}
|
||||
DbColumnInfo column = new DbColumnInfo()
|
||||
{
|
||||
TableName = tableName,
|
||||
DataType = row["DataTypeName"].ToString().Trim(),
|
||||
IsNullable = (bool)row["AllowDBNull"],
|
||||
IsIdentity = (bool)row["IsAutoIncrement"],
|
||||
DataType = type,
|
||||
IsNullable = !dataReader.GetBoolean(3),
|
||||
IsIdentity = dataReader.GetBoolean(3) && dataReader.GetBoolean(5).ObjToBool() && (type.IsIn("integer", "int", "int32", "int64", "long")),
|
||||
ColumnDescription = null,
|
||||
DbColumnName = row["ColumnName"].ToString(),
|
||||
DefaultValue = row["defaultValue"].ToString(),
|
||||
IsPrimarykey = (bool)row["IsKey"],
|
||||
Length = Convert.ToInt32(row["ColumnSize"])
|
||||
DbColumnName = dataReader.GetString(1),
|
||||
DefaultValue = dataReader.GetValue(4).ObjToString(),
|
||||
IsPrimarykey = dataReader.GetBoolean(5).ObjToBool(),
|
||||
Length = length
|
||||
};
|
||||
result.Add(column);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public override bool AddRemark(EntityInfo entity)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public override bool BackupTable(string oldTableName, string newTableName, int maxBackupDataRows = int.MaxValue)
|
||||
{
|
||||
oldTableName = this.SqlBuilder.GetTranslationTableName(oldTableName);
|
||||
|
Binary file not shown.
@ -11,8 +11,7 @@ namespace OrmTest.Demo
|
||||
public static SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.Sqlite, IsAutoCloseConnection = true });
|
||||
db.Ado.IsEnableLogEvent = true;
|
||||
db.Ado.LogEventStarting = (sql, pars) =>
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + "\r\n" + db.Utilities.SerializeObject(pars.ToDictionary(s => s.ParameterName, s => s.Value)));
|
||||
Console.WriteLine();
|
||||
|
@ -72,8 +72,7 @@ namespace OrmTest.UnitTest
|
||||
public SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.Sqlite });
|
||||
db.Ado.IsEnableLogEvent = true;
|
||||
db.Ado.LogEventStarting = (sql, pars) =>
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + " " + pars);
|
||||
};
|
||||
|
@ -30,7 +30,7 @@ namespace OrmTest.UnitTest
|
||||
using (var db = GetInstance())
|
||||
{
|
||||
//db.Database.IsEnableLogEvent = true;
|
||||
db.Ado.LogEventStarting = (sql, pars) =>
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + " " + pars);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user