Skip to content

Commit cf60da1

Browse files
committed
Merged from Athari pull request
2 parents 03891c3 + 1b3c37d commit cf60da1

37 files changed

Lines changed: 478 additions & 409 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ obj
22
bin
33
deploy
44
*.csproj.user
5+
*.DotSettings.user
56
*.suo
67
*.cache
78
*.nupkg
@@ -39,4 +40,4 @@ packages/Modernizr.2.5.3/
3940
packages/jQuery.1.7.1.1/
4041
packages/jQuery.UI.Combined.1.8.20.1/
4142
packages/jQuery.Validation.1.9.0.1/
42-
Simple.Data.sln.ide
43+
Simple.Data.sln.ide

Simple.Data.Ado/AdoAdapter.IAdapterWithTransactions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public int UpdateMany(string tableName, IEnumerable<IDictionary<string, object>>
5858
public int Update(string tableName, IDictionary<string, object> data, IAdapterTransaction adapterTransaction)
5959
{
6060
string[] keyFieldNames = GetKeyNames(tableName).ToArray();
61-
if (keyFieldNames.Length == 0) throw new AdoAdapterException("No Primary Key found for implicit update");
61+
if (keyFieldNames.Length == 0) throw new AdoAdapterException(string.Format("No primary key found for implicit update of table '{0}'.", tableName));
6262
return Update(tableName, data, GetCriteria(tableName, keyFieldNames, data), adapterTransaction);
6363
}
6464

Simple.Data.Ado/AdoAdapterException.cs

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,77 +3,75 @@
33
using System.Data;
44
using System.Linq;
55
using System.Runtime.Serialization;
6-
using System.Text;
76
using Simple.Data.Extensions;
87

98
namespace Simple.Data.Ado
109
{
11-
using System.Security;
12-
1310
[Serializable]
1411
public class AdoAdapterException : AdapterException
1512
{
1613
public AdoAdapterException() : base(typeof(AdoAdapter))
14+
{}
15+
16+
public AdoAdapterException(string message)
17+
: base(message, typeof(AdoAdapter))
18+
{}
19+
20+
public AdoAdapterException(string message, Exception inner)
21+
: base(message, inner, typeof(AdoAdapter))
22+
{}
23+
24+
public AdoAdapterException(string message, IDbCommand command)
25+
: base(message, typeof(AdoAdapter))
1726
{
27+
CommandText = command.CommandText;
28+
Parameters = command.Parameters.Cast<IDbDataParameter>()
29+
.ToDictionary(p => p.ParameterName, p => p.Value);
1830
}
1931

20-
public AdoAdapterException(string message, IDbCommand command) : base(message, typeof(AdoAdapter))
32+
public AdoAdapterException(string message, IDbCommand command, Exception inner)
33+
: base(message, inner, typeof(AdoAdapter))
2134
{
2235
CommandText = command.CommandText;
2336
Parameters = command.Parameters.Cast<IDbDataParameter>()
2437
.ToDictionary(p => p.ParameterName, p => p.Value);
2538
}
2639

27-
public AdoAdapterException(string commandText, IEnumerable<KeyValuePair<string,object>> parameters)
28-
:base(typeof(AdoAdapter))
40+
public AdoAdapterException(string commandText, IEnumerable<KeyValuePair<string, object>> parameters)
41+
: base(typeof(AdoAdapter)) // never used outside tests?
2942
{
3043
CommandText = commandText;
3144
Parameters = parameters.ToDictionary();
3245
}
3346

34-
35-
public AdoAdapterException(string message) : base(message, typeof(AdoAdapter))
36-
{
37-
}
38-
39-
public AdoAdapterException(string message, string commandText, IEnumerable<KeyValuePair<string,object>> parameters)
40-
:base(message, typeof(AdoAdapter))
47+
public AdoAdapterException(string message, string commandText, IEnumerable<KeyValuePair<string, object>> parameters)
48+
: base(message, typeof(AdoAdapter))
4149
{
4250
CommandText = commandText;
4351
Parameters = parameters.ToDictionary();
4452
}
4553

46-
public AdoAdapterException(string message, Exception inner) : base(message, inner, typeof(AdoAdapter))
54+
public AdoAdapterException(string message, string commandText, IEnumerable<KeyValuePair<string, object>> parameters, Exception inner)
55+
: base(message, inner, typeof(AdoAdapter))
4756
{
57+
CommandText = commandText;
58+
Parameters = parameters.ToDictionary();
4859
}
4960

5061
protected AdoAdapterException(SerializationInfo info, StreamingContext context)
5162
: base(info, context)
52-
{
53-
//CommandText = info.GetString("CommandText");
54-
//try
55-
//{
56-
// var array = info.GetValue("Parameters", typeof(KeyValuePair<string, object>[]));
57-
// if (array != null)
58-
// {
59-
// Parameters = ((KeyValuePair<string, object>[])array);
60-
// }
61-
//}
62-
//catch (SerializationException)
63-
//{
64-
//}
65-
}
63+
{}
6664

6765
public IDictionary<string, object> Parameters
6866
{
69-
get { return Data.Contains("Parameters") ? ((KeyValuePair<string,object>[])Data["Parameters"]).ToDictionary() : null; }
67+
get { return Data.Contains("Parameters") ? ((KeyValuePair<string, object>[])Data["Parameters"]).ToDictionary() : null; }
7068
private set { Data["Parameters"] = value.ToArray(); }
7169
}
7270

7371
public string CommandText
7472
{
75-
get { return Data.Contains("CommandText") ? Data["CommandText"].ToString() : null; }
73+
get { return Data.Contains("CommandText") ? Data["CommandText"].ToString() : null; }
7674
private set { Data["CommandText"] = value; }
7775
}
7876
}
79-
}
77+
}

Simple.Data.Ado/AdoAdapterFinder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private IEnumerable<IDictionary<string, object>> TryExecuteQuery(IDbConnection c
139139
}
140140
catch (DbException ex)
141141
{
142-
throw new AdoAdapterException(ex.Message, command);
142+
throw new AdoAdapterException(ex.Message, command, ex);
143143
}
144144
}
145145

@@ -151,7 +151,7 @@ private IEnumerable<IDictionary<string, object>> TryExecuteQuery(IDbConnection c
151151
}
152152
catch (DbException ex)
153153
{
154-
throw new AdoAdapterException(ex.Message, command);
154+
throw new AdoAdapterException(ex.Message, command, ex);
155155
}
156156
}
157157

Simple.Data.Ado/AdoAdapterGetter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public AdoAdapterGetter(AdoAdapter adapter, IDbTransaction transaction)
3535
public Func<object[],IDictionary<string,object>> CreateGetDelegate(string tableName, params object[] keyValues)
3636
{
3737
var primaryKey = _adapter.GetSchema().FindTable(tableName).PrimaryKey;
38-
if (primaryKey == null) throw new InvalidOperationException("Table has no primary key.");
38+
if (primaryKey == null) throw new InvalidOperationException(string.Format("Table '{0}' has no primary key.", tableName));
3939
if (primaryKey.Length != keyValues.Length) throw new ArgumentException("Incorrect number of values for key.");
4040

4141

@@ -107,7 +107,7 @@ private static object FixObjectType(object value)
107107
public IDictionary<string, object> Get(string tableName, object[] parameterValues)
108108
{
109109
var primaryKey = _adapter.GetSchema().FindTable(tableName).PrimaryKey;
110-
if (primaryKey == null) throw new InvalidOperationException("Table has no primary key.");
110+
if (primaryKey == null) throw new InvalidOperationException(string.Format("Table '{0}' has no primary key.", tableName));
111111
if (primaryKey.Length != parameterValues.Length) throw new ArgumentException("Incorrect number of values for key.");
112112

113113

Simple.Data.Ado/AdoAdapterInserter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private void CheckInsertablePropertiesAreAvailable(Table table, IEnumerable<KeyV
9898

9999
if (!data.Any())
100100
{
101-
throw new SimpleDataException("No properties were found which could be mapped to the database.");
101+
throw new SimpleDataException(string.Format("No properties were found which could be mapped to table '{0}'.", table.ActualName));
102102
}
103103
}
104104

0 commit comments

Comments
 (0)