Commit b2754e8e authored by Nigrimmist's avatar Nigrimmist

- pr fixes

parent 7e8eab6a
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
using System.Globalization; using System.Globalization;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Data.Common; using System.Data.Common;
using System.Data.SqlClient;
namespace Dapper namespace Dapper
{ {
...@@ -90,13 +89,11 @@ internal static CommandDefinition ForCallback(object parameters) ...@@ -90,13 +89,11 @@ internal static CommandDefinition ForCallback(object parameters)
internal void OnCompleted() internal void OnCompleted()
{ {
var parametersCallbacks = parameters as SqlMapper.IParameterCallbacks; if (parameters is SqlMapper.IParameterCallbacks)
if (parametersCallbacks != null)
{ {
parametersCallbacks.OnCompleted(); ((SqlMapper.IParameterCallbacks)parameters).OnCompleted();
} }
} }
/// <summary> /// <summary>
/// The command (sql or a stored-procedure name) to execute /// The command (sql or a stored-procedure name) to execute
/// </summary> /// </summary>
...@@ -379,10 +376,9 @@ object ITypeHandler.Parse(Type destinationType, object value) ...@@ -379,10 +376,9 @@ object ITypeHandler.Parse(Type destinationType, object value)
void ITypeHandler.SetValue(IDbDataParameter parameter, object value) void ITypeHandler.SetValue(IDbDataParameter parameter, object value)
{ {
parameter.Value = SanitizeParameterValue(value); parameter.Value = SanitizeParameterValue(value);
var sqlParameter = parameter as SqlParameter; if (parameter is System.Data.SqlClient.SqlParameter)
if (sqlParameter != null)
{ {
sqlParameter.UdtTypeName = udtTypeName; ((System.Data.SqlClient.SqlParameter)parameter).UdtTypeName = udtTypeName;
} }
} }
} }
...@@ -2806,7 +2802,7 @@ public static void PackListParameters(IDbCommand command, string namePrefix, obj ...@@ -2806,7 +2802,7 @@ public static void PackListParameters(IDbCommand command, string namePrefix, obj
listParam.Size = -1; listParam.Size = -1;
} }
} }
if (isDbString && item is DbString) if (isDbString && item as DbString != null)
{ {
var str = item as DbString; var str = item as DbString;
str.AddParameter(command, listParam.ParameterName); str.AddParameter(command, listParam.ParameterName);
...@@ -3040,7 +3036,14 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql) ...@@ -3040,7 +3036,14 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
var matches = literalTokens.Matches(sql); var matches = literalTokens.Matches(sql);
var found = new HashSet<string>(StringComparer.Ordinal); var found = new HashSet<string>(StringComparer.Ordinal);
List<LiteralToken> list = new List<LiteralToken>(matches.Count); List<LiteralToken> list = new List<LiteralToken>(matches.Count);
list.AddRange(from Match match in matches let token = match.Value where found.Add(match.Value) select new LiteralToken(token, match.Groups[1].Value)); foreach(Match match in matches)
{
string token = match.Value;
if(found.Add(match.Value))
{
list.Add(new LiteralToken(token, match.Groups[1].Value));
}
}
return list.Count == 0 ? LiteralToken.None : list; return list.Count == 0 ? LiteralToken.None : list;
} }
...@@ -3092,7 +3095,15 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql) ...@@ -3092,7 +3095,15 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
if (ctors.Length == 1 && propsArr.Length == (ctorParams = ctors[0].GetParameters()).Length) if (ctors.Length == 1 && propsArr.Length == (ctorParams = ctors[0].GetParameters()).Length)
{ {
// check if reflection was kind enough to put everything in the right order for us // check if reflection was kind enough to put everything in the right order for us
bool ok = !propsArr.Where((t, i) => !string.Equals(t.Name, ctorParams[i].Name, StringComparison.OrdinalIgnoreCase)).Any(); bool ok = true;
for (int i = 0; i < propsArr.Length; i++)
{
if (!string.Equals(propsArr[i].Name, ctorParams[i].Name, StringComparison.OrdinalIgnoreCase))
{
ok = false;
break;
}
}
if(ok) if(ok)
{ {
// pre-sorted; the reflection gods have smiled upon us // pre-sorted; the reflection gods have smiled upon us
......
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
......
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
......
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Data.Common;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -23,8 +26,8 @@ public partial class Table<T, TId> ...@@ -23,8 +26,8 @@ public partial class Table<T, TId>
paramNames.Remove("Id"); paramNames.Remove("Id");
string cols = string.Join(",", paramNames); string cols = string.Join(",", paramNames);
string colsParams = string.Join(",", paramNames.Select(p => "@" + p)); string cols_params = string.Join(",", paramNames.Select(p => "@" + p));
var sql = "set nocount on insert " + TableName + " (" + cols + ") values (" + colsParams + ") select cast(scope_identity() as int)"; var sql = "set nocount on insert " + TableName + " (" + cols + ") values (" + cols_params + ") select cast(scope_identity() as int)";
return (await database.QueryAsync<int?>(sql, o).ConfigureAwait(false)).Single(); return (await database.QueryAsync<int?>(sql, o).ConfigureAwait(false)).Single();
} }
......
...@@ -131,7 +131,7 @@ internal static List<string> GetParamNames(object o) ...@@ -131,7 +131,7 @@ internal static List<string> GetParamNames(object o)
{ {
var attribs = prop.GetCustomAttributes(typeof(IgnorePropertyAttribute), true); var attribs = prop.GetCustomAttributes(typeof(IgnorePropertyAttribute), true);
var attr = attribs.FirstOrDefault() as IgnorePropertyAttribute; var attr = attribs.FirstOrDefault() as IgnorePropertyAttribute;
if (attr==null || !attr.Value) if (attr==null || (!attr.Value))
{ {
paramNames.Add(prop.Name); paramNames.Add(prop.Name);
} }
......
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Web;
using System.Reflection; using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
......
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
......
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
......
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
namespace Dapper namespace Dapper
{ {
...@@ -104,7 +106,7 @@ public Template AddTemplate(string sql, dynamic parameters = null) ...@@ -104,7 +106,7 @@ public Template AddTemplate(string sql, dynamic parameters = null)
return new Template(this, sql, parameters); return new Template(this, sql, parameters);
} }
void AddClause(string name, string sql, object parameters, string joiner, string prefix = "", string postfix = "", bool isInclusive = false) void AddClause(string name, string sql, object parameters, string joiner, string prefix = "", string postfix = "", bool IsInclusive = false)
{ {
Clauses clauses; Clauses clauses;
if (!data.TryGetValue(name, out clauses)) if (!data.TryGetValue(name, out clauses))
...@@ -112,7 +114,7 @@ void AddClause(string name, string sql, object parameters, string joiner, string ...@@ -112,7 +114,7 @@ void AddClause(string name, string sql, object parameters, string joiner, string
clauses = new Clauses(joiner, prefix, postfix); clauses = new Clauses(joiner, prefix, postfix);
data[name] = clauses; data[name] = clauses;
} }
clauses.Add(new Clause { Sql = sql, Parameters = parameters, IsInclusive = isInclusive }); clauses.Add(new Clause { Sql = sql, Parameters = parameters, IsInclusive = IsInclusive });
seq++; seq++;
} }
...@@ -148,7 +150,7 @@ public SqlBuilder Where(string sql, dynamic parameters = null) ...@@ -148,7 +150,7 @@ public SqlBuilder Where(string sql, dynamic parameters = null)
public SqlBuilder OrWhere(string sql, dynamic parameters = null) public SqlBuilder OrWhere(string sql, dynamic parameters = null)
{ {
AddClause("where", sql, parameters, " AND ", prefix: "WHERE ", postfix: "\n", isInclusive: true); AddClause("where", sql, parameters, " AND ", prefix: "WHERE ", postfix: "\n", IsInclusive: true);
return this; return this;
} }
......
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
#if DNXCORE50 #if DNXCORE50
using ApplicationException = global::System.InvalidOperationException; using ApplicationException = global::System.InvalidOperationException;
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Configuration;
using System.Data; using System.Data;
using System.Data.Common; using System.Data.Common;
using System.Dynamic; using System.Dynamic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Collections;
using System.Text.RegularExpressions;
namespace Massive namespace Massive
{ {
...@@ -34,13 +37,13 @@ public static void AddParam(this DbCommand cmd, object item) ...@@ -34,13 +37,13 @@ public static void AddParam(this DbCommand cmd, object item)
} }
else else
{ {
if (item is Guid) if (item.GetType() == typeof(Guid))
{ {
p.Value = item.ToString(); p.Value = item.ToString();
p.DbType = DbType.String; p.DbType = DbType.String;
p.Size = 4000; p.Size = 4000;
} }
else if (item is ExpandoObject) else if (item.GetType() == typeof(ExpandoObject))
{ {
var d = (IDictionary<string, object>)item; var d = (IDictionary<string, object>)item;
p.Value = d.Values.FirstOrDefault(); p.Value = d.Values.FirstOrDefault();
...@@ -50,7 +53,7 @@ public static void AddParam(this DbCommand cmd, object item) ...@@ -50,7 +53,7 @@ public static void AddParam(this DbCommand cmd, object item)
p.Value = item; p.Value = item;
} }
//from DataChomp //from DataChomp
if (item is string) if (item.GetType() == typeof(string))
p.Size = 4000; p.Size = 4000;
} }
cmd.Parameters.Add(p); cmd.Parameters.Add(p);
...@@ -82,7 +85,7 @@ public static dynamic ToExpando(this object o) ...@@ -82,7 +85,7 @@ public static dynamic ToExpando(this object o)
{ {
var result = new ExpandoObject(); var result = new ExpandoObject();
var d = result as IDictionary<string, object>; //work with the Expando as a Dictionary var d = result as IDictionary<string, object>; //work with the Expando as a Dictionary
if (o is ExpandoObject) return o; //shouldn't have to... but just in case if (o.GetType() == typeof(ExpandoObject)) return o; //shouldn't have to... but just in case
if (o.GetType() == typeof(NameValueCollection) || o.GetType().IsSubclassOf(typeof(NameValueCollection))) if (o.GetType() == typeof(NameValueCollection) || o.GetType().IsSubclassOf(typeof(NameValueCollection)))
{ {
var nv = (NameValueCollection)o; var nv = (NameValueCollection)o;
...@@ -148,7 +151,7 @@ public virtual IEnumerable<dynamic> Query(string sql, params object[] args) ...@@ -148,7 +151,7 @@ public virtual IEnumerable<dynamic> Query(string sql, params object[] args)
var rdr = CreateCommand(sql, conn, args).ExecuteReader(); var rdr = CreateCommand(sql, conn, args).ExecuteReader();
while (rdr.Read()) while (rdr.Read())
{ {
yield return rdr.RecordToExpando(); yield return rdr.RecordToExpando(); ;
} }
} }
} }
...@@ -158,7 +161,7 @@ public virtual IEnumerable<dynamic> Query(string sql, DbConnection connection, p ...@@ -158,7 +161,7 @@ public virtual IEnumerable<dynamic> Query(string sql, DbConnection connection, p
{ {
while (rdr.Read()) while (rdr.Read())
{ {
yield return rdr.RecordToExpando(); yield return rdr.RecordToExpando(); ;
} }
} }
...@@ -417,7 +420,7 @@ public virtual dynamic Paged(string where = "", string orderBy = "", string colu ...@@ -417,7 +420,7 @@ public virtual dynamic Paged(string where = "", string orderBy = "", string colu
where = "WHERE " + where; where = "WHERE " + where;
} }
} }
var sql = string.Format("SELECT {0} FROM (SELECT ROW_NUMBER() OVER (ORDER BY {2}) AS Row, {0} FROM {3} {4}) AS Paged ", columns, orderBy, TableName, where); var sql = string.Format("SELECT {0} FROM (SELECT ROW_NUMBER() OVER (ORDER BY {2}) AS Row, {0} FROM {3} {4}) AS Paged ", columns, pageSize, orderBy, TableName, where);
var pageStart = (currentPage - 1) * pageSize; var pageStart = (currentPage - 1) * pageSize;
sql += string.Format(" WHERE Row >={0} AND Row <={1}", pageStart, (pageStart + pageSize)); sql += string.Format(" WHERE Row >={0} AND Row <={1}", pageStart, (pageStart + pageSize));
countSQL += where; countSQL += where;
......
using NHibernate; using System.Data;
using NHibernate;
using NHibernate.Cfg; using NHibernate.Cfg;
namespace SqlMapper.NHibernate namespace SqlMapper.NHibernate
......
...@@ -174,7 +174,8 @@ public void Run(int iterations) ...@@ -174,7 +174,8 @@ public void Run(int iterations)
var nhSession4 = NHibernateHelper.OpenSession(); var nhSession4 = NHibernateHelper.OpenSession();
tests.Add(id => nhSession4 tests.Add(id => nhSession4
.Query<Post>().First(p => p.Id == id), "NHibernate LINQ"); .Query<Post>()
.Where(p => p.Id == id).First(), "NHibernate LINQ");
var nhSession5 = NHibernateHelper.OpenSession(); var nhSession5 = NHibernateHelper.OpenSession();
tests.Add(id => nhSession5.Get<Post>(id), "NHibernate Session.Get"); tests.Add(id => nhSession5.Get<Post>(id), "NHibernate Session.Get");
...@@ -313,7 +314,7 @@ public static string GetNullableString(this SqlDataReader reader, int index) ...@@ -313,7 +314,7 @@ public static string GetNullableString(this SqlDataReader reader, int index)
return null; return null;
} }
public static T? GetNullableValue<T>(this SqlDataReader reader, int index) where T : struct public static Nullable<T> GetNullableValue<T>(this SqlDataReader reader, int index) where T : struct
{ {
object tmp = reader.GetValue(index); object tmp = reader.GetValue(index);
if (tmp != DBNull.Value) if (tmp != DBNull.Value)
......
...@@ -283,13 +283,13 @@ static void AddParam(DbCommand cmd, object item, string ParameterPrefix) ...@@ -283,13 +283,13 @@ static void AddParam(DbCommand cmd, object item, string ParameterPrefix)
} }
else else
{ {
if (item is Guid) if (item.GetType() == typeof(Guid))
{ {
p.Value = item.ToString(); p.Value = item.ToString();
p.DbType = DbType.String; p.DbType = DbType.String;
p.Size = 4000; p.Size = 4000;
} }
else if (item is string) else if (item.GetType() == typeof(string))
{ {
p.Size = (item as string).Length + 1; p.Size = (item as string).Length + 1;
if (p.Size < 4000) if (p.Size < 4000)
...@@ -344,13 +344,13 @@ public DbCommand CreateCommand(DbConnection connection, string sql, params objec ...@@ -344,13 +344,13 @@ public DbCommand CreateCommand(DbConnection connection, string sql, params objec
} }
else else
{ {
if (item is Guid) if (item.GetType() == typeof(Guid))
{ {
p.Value = item.ToString(); p.Value = item.ToString();
p.DbType = DbType.String; p.DbType = DbType.String;
p.Size = 4000; p.Size = 4000;
} }
else if (item is string) else if (item.GetType() == typeof(string))
{ {
p.Size = (item as string).Length + 1; p.Size = (item as string).Length + 1;
if (p.Size < 4000) if (p.Size < 4000)
...@@ -1034,7 +1034,7 @@ public string LastCommand ...@@ -1034,7 +1034,7 @@ public string LastCommand
sb.Append("\r\n\r\n"); sb.Append("\r\n\r\n");
for (int i = 0; i < _lastArgs.Length; i++) for (int i = 0; i < _lastArgs.Length; i++)
{ {
sb.AppendFormat("{0} - {1}\r\n", i, _lastArgs[i]); sb.AppendFormat("{0} - {1}\r\n", i, _lastArgs[i].ToString());
} }
} }
return sb.ToString(); return sb.ToString();
...@@ -1185,13 +1185,13 @@ public PocoData(Type t) ...@@ -1185,13 +1185,13 @@ public PocoData(Type t)
// Standard DateTime->Utc mapper // Standard DateTime->Utc mapper
if (ForceDateTimesToUtc && converter == null && srcType == typeof(DateTime) && (dstType == typeof(DateTime) || dstType == typeof(DateTime?))) if (ForceDateTimesToUtc && converter == null && srcType == typeof(DateTime) && (dstType == typeof(DateTime) || dstType == typeof(DateTime?)))
{ {
converter = src => new DateTime(((DateTime) src).Ticks, DateTimeKind.Utc); converter = delegate(object src) { return new DateTime(((DateTime)src).Ticks, DateTimeKind.Utc); };
} }
// Forced type conversion // Forced type conversion
if (converter == null && !dstType.IsAssignableFrom(srcType)) if (converter == null && !dstType.IsAssignableFrom(srcType))
{ {
converter = src => Convert.ChangeType(src, dstType, null); converter = delegate(object src) { return Convert.ChangeType(src, dstType, null); };
} }
// Fast // Fast
...@@ -1222,10 +1222,11 @@ public PocoData(Type t) ...@@ -1222,10 +1222,11 @@ public PocoData(Type t)
if (!Handled) if (!Handled)
{ {
// Setup stack for call to converter // Setup stack for call to converter
int converterIndex = -1;
if (converter != null) if (converter != null)
{ {
// Add the converter // Add the converter
var converterIndex = m_Converters.Count; converterIndex = m_Converters.Count;
m_Converters.Add(converter); m_Converters.Add(converter);
// Generate IL to push the converter onto the stack // Generate IL to push the converter onto the stack
......
...@@ -141,8 +141,12 @@ public partial class Post: IActiveRecord ...@@ -141,8 +141,12 @@ public partial class Post: IActiveRecord
internal static IRepository<Post> GetRepo(string connectionString, string providerName){ internal static IRepository<Post> GetRepo(string connectionString, string providerName){
tempdbDB db; SubSonic.tempdbDB db;
db = String.IsNullOrEmpty(connectionString) ? new tempdbDB() : new tempdbDB(connectionString, providerName); if(String.IsNullOrEmpty(connectionString)){
db=new SubSonic.tempdbDB();
}else{
db=new SubSonic.tempdbDB(connectionString, providerName);
}
IRepository<Post> _repo; IRepository<Post> _repo;
if(db.TestMode){ if(db.TestMode){
...@@ -162,7 +166,7 @@ public partial class Post: IActiveRecord ...@@ -162,7 +166,7 @@ public partial class Post: IActiveRecord
var repo = GetRepo(); var repo = GetRepo();
var results=repo.Find(expression); var results=repo.Find(expression);
Post single=null; Post single=null;
if(results.Any()){ if(results.Count() > 0){
single=results.ToList()[0]; single=results.ToList()[0];
single.OnLoaded(); single.OnLoaded();
single.SetIsLoaded(true); single.SetIsLoaded(true);
...@@ -176,7 +180,7 @@ public partial class Post: IActiveRecord ...@@ -176,7 +180,7 @@ public partial class Post: IActiveRecord
var repo = GetRepo(connectionString,providerName); var repo = GetRepo(connectionString,providerName);
var results=repo.Find(expression); var results=repo.Find(expression);
Post single=null; Post single=null;
if(results.Any()){ if(results.Count() > 0){
single=results.ToList()[0]; single=results.ToList()[0];
} }
...@@ -251,7 +255,7 @@ public object KeyValue() ...@@ -251,7 +255,7 @@ public object KeyValue()
} }
public override string ToString(){ public override string ToString(){
return this.Text; return this.Text.ToString();
} }
public override bool Equals(object obj){ public override bool Equals(object obj){
...@@ -270,7 +274,7 @@ public object KeyValue() ...@@ -270,7 +274,7 @@ public object KeyValue()
public string DescriptorValue() public string DescriptorValue()
{ {
return this.Text; return this.Text.ToString();
} }
public string DescriptorColumn() { public string DescriptorColumn() {
......
...@@ -33,7 +33,12 @@ public bool TestMode ...@@ -33,7 +33,12 @@ public bool TestMode
public tempdbDB() public tempdbDB()
{ {
DataProvider = DefaultDataProvider ?? ProviderFactory.GetProvider("Smackdown.Properties.Settings.tempdbConnectionString"); if (DefaultDataProvider == null) {
DataProvider = ProviderFactory.GetProvider("Smackdown.Properties.Settings.tempdbConnectionString");
}
else {
DataProvider = DefaultDataProvider;
}
Init(); Init();
} }
......
using System;
using SubSonic.Schema; using SubSonic.Schema;
using System.Collections.Generic;
using SubSonic.DataProviders; using SubSonic.DataProviders;
using System.Data; using System.Data;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment