/// <summary> /// 指定替换对象更新 /// </summary> /// <param name="sql"></param> /// <param name="types"></param> /// <returns></returns> public int Execute(string sql, params Type[] types) { sql = AutoFormat(sql, types); sql = _DBAdapter.SqlFormat(sql); int count = helper.Execute(sql); ClearParame(); return(count); }
internal static int Execute(CoreHelper.DBHelper __DbHelper, string sql) { int n = 0; var el = Run(() => { n = __DbHelper.Execute(sql); }); Base.SaveSQLRunningtme(sql, el); return(n); }
/// <summary> /// 获取插入语法 /// </summary> /// <param name="obj"></param> /// <param name="helper"></param> /// <returns></returns> public override int InsertObject(IModel obj, CoreHelper.DBHelper helper) { Type type = obj.GetType(); string table = TypeCache.GetTableName(type); var typeArry = TypeCache.GetProperties(type, true).Values; string sql = string.Format("insert into {0}(", table); string sql1 = ""; string sql2 = ""; string sequenceName = string.Format("{0}_sequence", table); var sqlGetIndex = string.Format("select {0}.nextval from dual", sequenceName);//oracle不能同时执行多条语句 int id = Convert.ToInt32(helper.ExecScalar(sqlGetIndex)); foreach (Attribute.FieldAttribute info in typeArry) { string name = info.Name; if (info.IsPrimaryKey) { //continue;//手动插入ID } if (!string.IsNullOrEmpty(info.VirtualField)) { continue; } object value = info.GetValue(obj); value = ObjectConvert.SetNullValue(value, info.PropertyType); sql1 += string.Format("{0},", info.KeyWordName); sql2 += string.Format("@{0},", info.KeyWordName); helper.AddParam(info.KeyWordName, value); } sql1 = sql1.Substring(0, sql1.Length - 1); sql2 = sql2.Substring(0, sql2.Length - 1); sql += sql1 + ") values( " + sql2 + ")"; sql = SqlFormat(sql); var primaryKey = TypeCache.GetTable(obj.GetType()).PrimaryKey; helper.SetParam(primaryKey.Name, id); helper.Execute(sql); //var helper2 = helper as CoreHelper.OracleHelper; //int id = helper2.Insert(sql,sequenceName); return(id); }