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