From dcb26669eedcfc22b6c6183a5a0563b0d5a116de Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 1 Oct 2017 20:36:51 +0800 Subject: [PATCH] - --- Src/Asp.Net/OracleTest/Demos/1_Query.cs | 28 +++++-------------- Src/Asp.Net/OracleTest/Models/Student.cs | 2 +- .../Realization/Oracle/OracleProvider.cs | 4 +++ .../Oracle/SqlBuilder/OracleInsertBuilder.cs | 10 +++---- 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/Src/Asp.Net/OracleTest/Demos/1_Query.cs b/Src/Asp.Net/OracleTest/Demos/1_Query.cs index 2fc880931..63bea8296 100644 --- a/Src/Asp.Net/OracleTest/Demos/1_Query.cs +++ b/Src/Asp.Net/OracleTest/Demos/1_Query.cs @@ -23,7 +23,7 @@ namespace OrmTest.Demo Group(); Sqlable(); Tran(); - StoredProcedure(); + //StoredProcedure(); Enum(); Simple(); } @@ -50,28 +50,14 @@ namespace OrmTest.Demo private static void StoredProcedure() { var db = GetInstance(); - //1. no result - db.Ado.UseStoredProcedure(() => - { - string spName = "sp_help"; - var getSpReslut = db.Ado.SqlQueryDynamic(spName, new { objname = "student" }); - }); - - //2. has result - var result = db.Ado.UseStoredProcedure(() => - { - string spName = "sp_help"; - return db.Ado.SqlQueryDynamic(spName, new { objname = "student" }); - }); - - //2. has output + object outPutValue; var outputResult = db.Ado.UseStoredProcedure(() => { - string spName = "sp_school"; - var p1 = new SugarParameter("@p1", "1"); - var p2 = new SugarParameter("@p2", null, true);//isOutput=true - var dbResult = db.Ado.SqlQueryDynamic(spName, new SugarParameter[] { p1, p2 }); + string spName = "SpGetSchool"; + var p1 = new SugarParameter("@id_in", "1"); + var p2 = new SugarParameter("@name_out", null, true);//isOutput=true + var dbResult = db.Ado.ExecuteCommand(spName, new SugarParameter[] { p1, p2 }); outPutValue = p2.Value; return dbResult; }); @@ -160,7 +146,7 @@ namespace OrmTest.Demo var getNew = db.Queryable().Where(it => it.Id == 1).Select(it => new { id = SqlFunc.IIF(it.Id == 0, 1, it.Id), it.Name, it.SchoolId }).ToList(); var getAllNoLock = db.Queryable().With(SqlWith.NoLock).ToList(); var getByPrimaryKey = db.Queryable().InSingle(2); - var getSingleOrDefault = db.Queryable().Single(); + var getSingleOrDefault = db.Queryable().Where(it=>it.Id==1).Single(); var getFirstOrDefault = db.Queryable().First(); var getByWhere = db.Queryable().Where(it => it.Id == 1 || it.Name == "a").ToList(); var getByFuns = db.Queryable().Where(it => SqlFunc.IsNullOrEmpty(it.Name)).ToList(); diff --git a/Src/Asp.Net/OracleTest/Models/Student.cs b/Src/Asp.Net/OracleTest/Models/Student.cs index 421b87bcf..3cf8fc78b 100644 --- a/Src/Asp.Net/OracleTest/Models/Student.cs +++ b/Src/Asp.Net/OracleTest/Models/Student.cs @@ -11,7 +11,7 @@ namespace OrmTest.Models [SugarTable("STudent")] public class Student { - [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "ID")] + [SugarColumn(IsPrimaryKey = true, ColumnName = "ID",OracleSequenceName = "seq_newsId")] public int Id { get; set; } public int? SchoolId { get; set; } public string Name { get; set; } diff --git a/Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs b/Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs index 98b4cdbe2..432b88c6e 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs @@ -104,6 +104,10 @@ namespace SqlSugar { sqlParameter.ParameterName = ':' + sqlParameter.ParameterName.Substring(1, sqlParameter.ParameterName.Length - 1); } + if (this.CommandType == CommandType.StoredProcedure) + { + sqlParameter.ParameterName = sqlParameter.ParameterName.TrimStart(':'); + } //sqlParameter.UdtTypeName = parameter.UdtTypeName; sqlParameter.Size = parameter.Size; sqlParameter.Value = parameter.Value; diff --git a/Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs b/Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs index 32f551603..5bf0428f4 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs @@ -15,7 +15,7 @@ namespace SqlSugar return @"INSERT INTO {0} ({1}) VALUES - ({2}) ;"; + ({2}) "; } } @@ -28,13 +28,13 @@ namespace SqlSugar } var groupList = DbColumnInfoList.GroupBy(it => it.TableId).ToList(); var isSingle = groupList.Count() == 1; - string columnsString = string.Join(UtilConstants.Dot, groupList.First().Select(it => Builder.GetTranslationColumnName(it.DbColumnName))); + string columnsString = string.Join(",", groupList.First().Select(it => Builder.GetTranslationColumnName(it.DbColumnName))); if (isSingle) { - string columnParametersString = string.Join(UtilConstants.Dot, this.DbColumnInfoList.Select(it => Builder.SqlParameterKeyWord + it.DbColumnName)); + string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it => Builder.SqlParameterKeyWord + it.DbColumnName)); if (identities.IsValuable()) { - columnsString = columnsString.TrimEnd(UtilConstants.DotChar) + UtilConstants.Dot + string.Join(UtilConstants.Dot, identities.Select(it=> Builder.GetTranslationColumnName(it.DbColumnName))); - columnParametersString = columnParametersString.TrimEnd(UtilConstants.DotChar) + UtilConstants.Dot + string.Join(UtilConstants.Dot, identities.Select(it =>it.OracleSequenceName)); + columnsString = columnsString.TrimEnd(',') + "," + string.Join(",", identities.Select(it=> Builder.GetTranslationColumnName(it.DbColumnName))); + columnParametersString = columnParametersString.TrimEnd(',') +"," + string.Join(",", identities.Select(it =>it.OracleSequenceName+ ".nextval")); } return string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString); }