提交 b2754e8e 编写于 作者: N Nigrimmist

- pr fixes

上级 7e8eab6a
......@@ -34,7 +34,6 @@
using System.Globalization;
using System.Linq.Expressions;
using System.Data.Common;
using System.Data.SqlClient;
namespace Dapper
{
......@@ -90,13 +89,11 @@ internal static CommandDefinition ForCallback(object parameters)
internal void OnCompleted()
{
var parametersCallbacks = parameters as SqlMapper.IParameterCallbacks;
if (parametersCallbacks != null)
if (parameters is SqlMapper.IParameterCallbacks)
{
parametersCallbacks.OnCompleted();
((SqlMapper.IParameterCallbacks)parameters).OnCompleted();
}
}
/// <summary>
/// The command (sql or a stored-procedure name) to execute
/// </summary>
......@@ -379,10 +376,9 @@ object ITypeHandler.Parse(Type destinationType, object value)
void ITypeHandler.SetValue(IDbDataParameter parameter, object value)
{
parameter.Value = SanitizeParameterValue(value);
var sqlParameter = parameter as SqlParameter;
if (sqlParameter != null)
if (parameter is System.Data.SqlClient.SqlParameter)
{
sqlParameter.UdtTypeName = udtTypeName;
((System.Data.SqlClient.SqlParameter)parameter).UdtTypeName = udtTypeName;
}
}
}
......@@ -2806,7 +2802,7 @@ public static void PackListParameters(IDbCommand command, string namePrefix, obj
listParam.Size = -1;
}
}
if (isDbString && item is DbString)
if (isDbString && item as DbString != null)
{
var str = item as DbString;
str.AddParameter(command, listParam.ParameterName);
......@@ -3040,7 +3036,14 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
var matches = literalTokens.Matches(sql);
var found = new HashSet<string>(StringComparer.Ordinal);
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;
}
......@@ -3092,7 +3095,15 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
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
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)
{
// pre-sorted; the reflection gods have smiled upon us
......
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
......
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
......
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
......@@ -23,8 +26,8 @@ public partial class Table<T, TId>
paramNames.Remove("Id");
string cols = string.Join(",", paramNames);
string colsParams = string.Join(",", paramNames.Select(p => "@" + p));
var sql = "set nocount on insert " + TableName + " (" + cols + ") values (" + colsParams + ") select cast(scope_identity() as int)";
string cols_params = string.Join(",", paramNames.Select(p => "@" + p));
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();
}
......
......@@ -131,7 +131,7 @@ internal static List<string> GetParamNames(object o)
{
var attribs = prop.GetCustomAttributes(typeof(IgnorePropertyAttribute), true);
var attr = attribs.FirstOrDefault() as IgnorePropertyAttribute;
if (attr==null || !attr.Value)
if (attr==null || (!attr.Value))
{
paramNames.Add(prop.Name);
}
......
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
......
......@@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;
using System.Reflection.Emit;
......
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
......
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 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.Text;
namespace Dapper
{
......@@ -104,7 +106,7 @@ public Template AddTemplate(string sql, dynamic parameters = null)
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;
if (!data.TryGetValue(name, out clauses))
......@@ -112,7 +114,7 @@ void AddClause(string name, string sql, object parameters, string joiner, string
clauses = new Clauses(joiner, prefix, postfix);
data[name] = clauses;
}
clauses.Add(new Clause { Sql = sql, Parameters = parameters, IsInclusive = isInclusive });
clauses.Add(new Clause { Sql = sql, Parameters = parameters, IsInclusive = IsInclusive });
seq++;
}
......@@ -148,7 +150,7 @@ public SqlBuilder Where(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;
}
......
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if DNXCORE50
using ApplicationException = global::System.InvalidOperationException;
......
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Text.RegularExpressions;
namespace Massive
{
......@@ -34,13 +37,13 @@ public static void AddParam(this DbCommand cmd, object item)
}
else
{
if (item is Guid)
if (item.GetType() == typeof(Guid))
{
p.Value = item.ToString();
p.DbType = DbType.String;
p.Size = 4000;
}
else if (item is ExpandoObject)
else if (item.GetType() == typeof(ExpandoObject))
{
var d = (IDictionary<string, object>)item;
p.Value = d.Values.FirstOrDefault();
......@@ -50,7 +53,7 @@ public static void AddParam(this DbCommand cmd, object item)
p.Value = item;
}
//from DataChomp
if (item is string)
if (item.GetType() == typeof(string))
p.Size = 4000;
}
cmd.Parameters.Add(p);
......@@ -82,7 +85,7 @@ public static dynamic ToExpando(this object o)
{
var result = new ExpandoObject();
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)))
{
var nv = (NameValueCollection)o;
......@@ -148,7 +151,7 @@ public virtual IEnumerable<dynamic> Query(string sql, params object[] args)
var rdr = CreateCommand(sql, conn, args).ExecuteReader();
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
{
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
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;
sql += string.Format(" WHERE Row >={0} AND Row <={1}", pageStart, (pageStart + pageSize));
countSQL += where;
......
using NHibernate;
using System.Data;
using NHibernate;
using NHibernate.Cfg;
namespace SqlMapper.NHibernate
......
......@@ -174,7 +174,8 @@ public void Run(int iterations)
var nhSession4 = NHibernateHelper.OpenSession();
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();
tests.Add(id => nhSession5.Get<Post>(id), "NHibernate Session.Get");
......@@ -313,7 +314,7 @@ public static string GetNullableString(this SqlDataReader reader, int index)
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);
if (tmp != DBNull.Value)
......
......@@ -283,13 +283,13 @@ static void AddParam(DbCommand cmd, object item, string ParameterPrefix)
}
else
{
if (item is Guid)
if (item.GetType() == typeof(Guid))
{
p.Value = item.ToString();
p.DbType = DbType.String;
p.Size = 4000;
}
else if (item is string)
else if (item.GetType() == typeof(string))
{
p.Size = (item as string).Length + 1;
if (p.Size < 4000)
......@@ -344,13 +344,13 @@ public DbCommand CreateCommand(DbConnection connection, string sql, params objec
}
else
{
if (item is Guid)
if (item.GetType() == typeof(Guid))
{
p.Value = item.ToString();
p.DbType = DbType.String;
p.Size = 4000;
}
else if (item is string)
else if (item.GetType() == typeof(string))
{
p.Size = (item as string).Length + 1;
if (p.Size < 4000)
......@@ -1034,7 +1034,7 @@ public string LastCommand
sb.Append("\r\n\r\n");
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();
......@@ -1185,13 +1185,13 @@ public PocoData(Type t)
// Standard DateTime->Utc mapper
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
if (converter == null && !dstType.IsAssignableFrom(srcType))
{
converter = src => Convert.ChangeType(src, dstType, null);
converter = delegate(object src) { return Convert.ChangeType(src, dstType, null); };
}
// Fast
......@@ -1222,10 +1222,11 @@ public PocoData(Type t)
if (!Handled)
{
// Setup stack for call to converter
if (converter != null)
int converterIndex = -1;
if (converter != null)
{
// Add the converter
var converterIndex = m_Converters.Count;
converterIndex = m_Converters.Count;
m_Converters.Add(converter);
// Generate IL to push the converter onto the stack
......
......@@ -141,8 +141,12 @@ public partial class Post: IActiveRecord
internal static IRepository<Post> GetRepo(string connectionString, string providerName){
tempdbDB db;
db = String.IsNullOrEmpty(connectionString) ? new tempdbDB() : new tempdbDB(connectionString, providerName);
SubSonic.tempdbDB db;
if(String.IsNullOrEmpty(connectionString)){
db=new SubSonic.tempdbDB();
}else{
db=new SubSonic.tempdbDB(connectionString, providerName);
}
IRepository<Post> _repo;
if(db.TestMode){
......@@ -162,7 +166,7 @@ public partial class Post: IActiveRecord
var repo = GetRepo();
var results=repo.Find(expression);
Post single=null;
if(results.Any()){
if(results.Count() > 0){
single=results.ToList()[0];
single.OnLoaded();
single.SetIsLoaded(true);
......@@ -176,7 +180,7 @@ public partial class Post: IActiveRecord
var repo = GetRepo(connectionString,providerName);
var results=repo.Find(expression);
Post single=null;
if(results.Any()){
if(results.Count() > 0){
single=results.ToList()[0];
}
......@@ -251,7 +255,7 @@ public object KeyValue()
}
public override string ToString(){
return this.Text;
return this.Text.ToString();
}
public override bool Equals(object obj){
......@@ -270,7 +274,7 @@ public object KeyValue()
public string DescriptorValue()
{
return this.Text;
return this.Text.ToString();
}
public string DescriptorColumn() {
......
......@@ -31,9 +31,14 @@ 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();
}
......
using System;
using SubSonic.Schema;
using System.Collections.Generic;
using SubSonic.DataProviders;
using System.Data;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册