Permalink
Browse files

Revert "Allow for an IDbDataParameter to be added directly to Sql"

This reverts commit 21d31fc.
  • Loading branch information...
asherber authored and pleb committed Nov 23, 2018
1 parent e3a5572 commit 92d534b111628010e2622ab5e90f08e1588400e3
Showing with 0 additions and 77 deletions.
  1. +0 −60 PetaPoco.Tests.Unit/Core/SqlTests.cs
  2. +0 −17 PetaPoco/Core/Sql.cs
@@ -5,7 +5,6 @@
// <date>2018/07/02</date>
using System;
using System.Data.SqlClient;
using PetaPoco.Tests.Unit.Models;
using Shouldly;
using Xunit;
@@ -367,64 +366,5 @@ public void Sql_CacheShouldBeResetAfterAdditionalChanges_ShouldBeValid()
sqlCapture2.Replace("\n", " ").ShouldBe("SELECT field FROM myTable");
sqlCapture3.Replace("\n", " ").ShouldBe("SELECT field FROM myTable WHERE (id = @0)");
}
[Fact]
public void AddParameter_GivenParam_ShouldBeValid()
{
var param = new SqlParameter();
_sql = Sql.Builder.AddParameter(param);
_sql.SQL.ShouldBeEmpty();
_sql.Arguments.Length.ShouldBe(1);
_sql.Arguments[0].ShouldBe(param);
}
[Fact]
public void AddParameter_GivenSimpleSqlAndParam_ShouldBeValid()
{
var param = new SqlParameter();
_sql = Sql.Builder
.Select("*")
.From("mytable")
.AddParameter(param);
_sql.SQL.ShouldBe("SELECT *\nFROM mytable");
_sql.Arguments.Length.ShouldBe(1);
_sql.Arguments[0].ShouldBe(param);
}
[Fact]
public void AddParameter_GivenComplexSqlAndParam_ShouldBeValid()
{
var param = new SqlParameter();
_sql = Sql.Builder
.Select("*")
.From("mytable")
.Where("myfield=@0", 4)
.AddParameter(param);
_sql.SQL.ShouldBe("SELECT *\nFROM mytable\nWHERE (myfield=@0)");
_sql.Arguments.Length.ShouldBe(2);
_sql.Arguments[0].ShouldBe(4);
_sql.Arguments[1].ShouldBe(param);
}
[Fact]
public void AddParameter_CombineTwoSqls_ShouldBeValid()
{
var param = new SqlParameter();
var paramSql = Sql.Builder.AddParameter(param);
_sql = Sql.Builder
.Select("*")
.From("mytable")
.Where("myfield=@0", 4)
.Append(paramSql);
_sql.SQL.ShouldBe("SELECT *\nFROM mytable\nWHERE (myfield=@0)");
_sql.Arguments.Length.ShouldBe(2);
_sql.Arguments[0].ShouldBe(4);
_sql.Arguments[1].ShouldBe(param);
}
}
}
@@ -6,7 +6,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using PetaPoco.Internal;
@@ -145,18 +144,12 @@ private void Build(StringBuilder sb, List<object> args, Sql lhs)
sb.Append(sql);
}
else
{
if (_args != null)
args.AddRange(_args.OfType<IDbDataParameter>());
}
// Now do rhs
if (_rhs != null)
_rhs.Build(sb, args, this);
}
/// <summary>
/// Appends an SQL SET clause to this SQL builder
/// </summary>
@@ -244,16 +237,6 @@ public SqlJoinClause LeftJoin(string table)
return Join("LEFT JOIN ", table);
}
/// <summary>
/// Appends an IDbDataParameter to this SQL builder
/// </summary>
/// <param name="param">The parameter to add</param>
/// <returns>A reference to this builder, allowing for fluent style concatenation</returns>
public Sql AddParameter(IDbDataParameter param)
{
return Append(new Sql(null, param));
}
/// <summary>
/// Returns the SQL statement.
/// </summary>

0 comments on commit 92d534b

Please sign in to comment.