/// <summary> /// 获取 byte[] 类型的 SQL 片断 /// </summary> /// <param name="value">SQL值</param> protected virtual string GetSqlValueByBytes(object value) { byte[] bytes = (byte[])value; string hex = XfwCommon.BytesToHex(bytes, true, true); return(hex); }
// 获取 byte[] 类型的 SQL 片断 protected override string GetSqlValueByBytes(object value) { byte[] bytes = (byte[])value; string hex = XfwCommon.BytesToHex(bytes, false, true); hex = string.Format(@"X'{0}'", hex); return(hex); }
// 获取 byte[] 类型的 SQL 片断 protected override string GetSqlValueByBytes(object value) { byte[] bytes = (byte[])value; string hex = XfwCommon.BytesToHex(bytes, false, true); string result = string.Empty; if (string.IsNullOrEmpty(hex)) { result = "EMPTY_BLOB()"; } else { result = string.Format("TO_BLOB(HEXTORAW('{0}'))", hex); } return(result); }
/// <summary> /// 初始化 <see cref="DbContextBase"/> 类的新实例 /// <para> /// 默认读取 XFrameworkConnString 配置里的连接串 /// </para> /// </summary> public DbContextBase() : this(XfwCommon.GetConnString("XFrameworkConnString")) { }
//[STAThread] public static void Main(string[] args) { //DateTime myDateTime = DateTime.Parse("2019-11-06 12:11:11.1234567"); //Console.WriteLine(myDateTime.ToString("yyyy-MM-dd HH:mm:ss.fffffff") + " 刻度数:" + myDateTime.Ticks); //myDateTime = DateTime.Parse("2019-11-06 12:11:11.1234560"); //Console.WriteLine(myDateTime.ToString("yyyy-MM-dd HH:mm:ss.fffffff") + " 刻度数:" + myDateTime.Ticks); //Console.ReadKey(); bool isDebug = false; ITest test = null; string fileName = string.Empty; DatabaseType databaseType = DatabaseType.None; string s = args != null && args.Length > 0 ? args[0] : null; if (!string.IsNullOrEmpty(s)) { databaseType = (DatabaseType)Convert.ToByte(s); } // 命令拦截 var interceptor = new DbCommandInterceptor { OnExecuting = cmd => { var writer = System.IO.File.AppendText(fileName); writer.WriteLine(cmd.CommandText); if (cmd.Parameters != null) { for (int i = 0; i < cmd.Parameters.Count; i++) { IDbDataParameter p = (IDbDataParameter)cmd.Parameters[i]; writer.Write("-- "); writer.Write(p.ParameterName); writer.Write(" = "); writer.Write(p.Value == null ? string.Empty : (p.Value is byte[] ? XfwCommon.BytesToHex((byte[])p.Value, true, true) : p.Value)); writer.Write(", DbType = {0}, ", p.DbType); if (p.Size != default(int)) { writer.Write("Size = {0}, ", p.Size); } if (p.Precision != default(byte)) { writer.Write("Precision = {0}, ", p.Precision); } if (p.Scale != default(byte)) { writer.Write("Scale = {0}, ", p.Scale); } if (p.Direction != ParameterDirection.Input) { writer.Write("Direction = {0}, ", p.Direction); } writer.WriteLine(); if (i == cmd.Parameters.Count - 1) { writer.WriteLine(); } } } writer.Close(); }, OnExecuted = cmd => { } }; DbInterception.Add(interceptor); foreach (DatabaseType item in Enum.GetValues(typeof(DatabaseType))) { if (item == DatabaseType.None) { continue; } DatabaseType myDatabaseType = item; if (!string.IsNullOrEmpty(s)) { myDatabaseType = databaseType; } var obj = Activator.CreateInstance(null, string.Format("TZM.XFramework.UnitTest.{0}.{0}Test", myDatabaseType)); test = (ITest)(obj.Unwrap()); test.IsDebug = isDebug; string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; fileName = baseDirectory + @"\Log_" + myDatabaseType + ".sql"; if (System.IO.File.Exists(fileName)) { System.IO.File.Delete(fileName); } if (test != null) { Console.WriteLine(myDatabaseType + " BEGIN"); test.Run(myDatabaseType); Console.WriteLine(myDatabaseType + " END"); } if (!string.IsNullOrEmpty(s)) { break; } } Console.WriteLine("回车退出~"); Console.ReadLine(); }