This commit is contained in:
@@ -48,7 +48,8 @@ namespace DynamORM.Builders
|
|||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
sb.AppendFormat("DELETE FROM {0}", TableName);
|
sb.Append("DELETE FROM ");
|
||||||
|
DynamicTable.Database.DecorateName(sb, TableName);
|
||||||
|
|
||||||
FillWhere(command, sb);
|
FillWhere(command, sb);
|
||||||
|
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ namespace DynamORM.Builders
|
|||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return command.SetCommand("INSERT INTO {0} ({1}) VALUES ({2})", TableName, builderColumns, builderValues);
|
return command.SetCommand("INSERT INTO {0} ({1}) VALUES ({2})", db.DecorateName(TableName), builderColumns, builderValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Execute this builder.</summary>
|
/// <summary>Execute this builder.</summary>
|
||||||
|
|||||||
@@ -10,7 +10,9 @@
|
|||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>DynamORM</RootNamespace>
|
<RootNamespace>DynamORM</RootNamespace>
|
||||||
<AssemblyName>DynamORM</AssemblyName>
|
<AssemblyName>DynamORM</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<TargetFrameworkProfile />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace DynamORM
|
|||||||
lock (_db.SyncLock)
|
lock (_db.SyncLock)
|
||||||
{
|
{
|
||||||
if (!_db.CommandsPool.ContainsKey(_con.Connection))
|
if (!_db.CommandsPool.ContainsKey(_con.Connection))
|
||||||
throw new InvalidOperationException("Can't create transaction using disposed connection.");
|
throw new InvalidOperationException("Can't create command using disposed connection.");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_command = _con.Connection.CreateCommand();
|
_command = _con.Connection.CreateCommand();
|
||||||
@@ -60,16 +60,28 @@ namespace DynamORM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Initializes a new instance of the <see cref="DynamicCommand"/> class.</summary>
|
||||||
|
/// <param name="db">The databas manager.</param>
|
||||||
|
/// <remarks>Used intenaly to create command without context.</remarks>
|
||||||
|
internal DynamicCommand(DynamicDatabase db)
|
||||||
|
{
|
||||||
|
_db = db;
|
||||||
|
_command = db.Provider.CreateCommand();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Prepare command for execution.</summary>
|
/// <summary>Prepare command for execution.</summary>
|
||||||
/// <returns>Returns edited <see cref="System.Data.IDbCommand"/> instance.</returns>
|
/// <returns>Returns edited <see cref="System.Data.IDbCommand"/> instance.</returns>
|
||||||
private IDbCommand PrepareForExecution()
|
internal IDbCommand PrepareForExecution()
|
||||||
{
|
{
|
||||||
if (_poolStamp < _db.PoolStamp)
|
// TODO: Fix that
|
||||||
|
// if (_poolStamp < _db.PoolStamp)
|
||||||
{
|
{
|
||||||
_command.CommandTimeout = _commandTimeout ?? _db.CommandTimeout ?? _command.CommandTimeout;
|
_command.CommandTimeout = _commandTimeout ?? _db.CommandTimeout ?? _command.CommandTimeout;
|
||||||
|
|
||||||
if (_db.TransactionPool[_command.Connection].Count > 0)
|
if (_db.TransactionPool[_command.Connection].Count > 0)
|
||||||
_command.Transaction = _db.TransactionPool[_command.Connection].Peek();
|
_command.Transaction = _db.TransactionPool[_command.Connection].Peek();
|
||||||
|
else
|
||||||
|
_command.Transaction = null;
|
||||||
|
|
||||||
_poolStamp = _db.PoolStamp;
|
_poolStamp = _db.PoolStamp;
|
||||||
}
|
}
|
||||||
@@ -106,7 +118,26 @@ namespace DynamORM
|
|||||||
/// <summary>Gets or sets the <see cref="T:System.Data.IDbConnection"/>
|
/// <summary>Gets or sets the <see cref="T:System.Data.IDbConnection"/>
|
||||||
/// used by this instance of the <see cref="T:System.Data.IDbCommand"/>.</summary>
|
/// used by this instance of the <see cref="T:System.Data.IDbCommand"/>.</summary>
|
||||||
/// <returns>The connection to the data source.</returns>
|
/// <returns>The connection to the data source.</returns>
|
||||||
public IDbConnection Connection { get { return _con; } set { _con = (DynamicConnection)value; } }
|
public IDbConnection Connection
|
||||||
|
{
|
||||||
|
get { return _con; }
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_con = value as DynamicConnection;
|
||||||
|
|
||||||
|
if (_con != null)
|
||||||
|
{
|
||||||
|
_poolStamp = 0;
|
||||||
|
_command.Connection = _con.Connection;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_command.Transaction = null;
|
||||||
|
_command.Connection = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Creates a new instance of an
|
/// <summary>Creates a new instance of an
|
||||||
/// <see cref="T:System.Data.IDbDataParameter"/> object.</summary>
|
/// <see cref="T:System.Data.IDbDataParameter"/> object.</summary>
|
||||||
@@ -191,10 +222,13 @@ namespace DynamORM
|
|||||||
{
|
{
|
||||||
lock (_db.SyncLock)
|
lock (_db.SyncLock)
|
||||||
{
|
{
|
||||||
var pool = _db.CommandsPool.TryGetValue(_con.Connection);
|
if (_con != null)
|
||||||
|
{
|
||||||
|
var pool = _db.CommandsPool.TryGetValue(_con.Connection);
|
||||||
|
|
||||||
if (pool != null)
|
if (pool != null && pool.Contains(_command))
|
||||||
pool.Remove(_command);
|
pool.Remove(_command);
|
||||||
|
}
|
||||||
|
|
||||||
_command.Dispose();
|
_command.Dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,24 @@ namespace DynamORM
|
|||||||
/// <summary>Gets or sets timestamp of last transaction pool or configuration change.</summary>
|
/// <summary>Gets or sets timestamp of last transaction pool or configuration change.</summary>
|
||||||
/// <remarks>This property is used to allow commands to determine if
|
/// <remarks>This property is used to allow commands to determine if
|
||||||
/// they need to update transaction object or not.</remarks>
|
/// they need to update transaction object or not.</remarks>
|
||||||
internal long PoolStamp { get { return _poolStamp; } set { lock (SyncLock) _poolStamp = value; } }
|
internal long PoolStamp
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
long r = 0;
|
||||||
|
|
||||||
|
lock (SyncLock)
|
||||||
|
r = _poolStamp;
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
lock (SyncLock)
|
||||||
|
_poolStamp = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Gets pool of connections and transactions.</summary>
|
/// <summary>Gets pool of connections and transactions.</summary>
|
||||||
internal Dictionary<IDbConnection, Stack<IDbTransaction>> TransactionPool { get; private set; }
|
internal Dictionary<IDbConnection, Stack<IDbTransaction>> TransactionPool { get; private set; }
|
||||||
@@ -83,6 +100,9 @@ namespace DynamORM
|
|||||||
/// <summary>Gets or sets command timeout.</summary>
|
/// <summary>Gets or sets command timeout.</summary>
|
||||||
public int? CommandTimeout { get { return _commandTimeout; } set { _commandTimeout = value; _poolStamp = DateTime.Now.Ticks; } }
|
public int? CommandTimeout { get { return _commandTimeout; } set { _commandTimeout = value; _poolStamp = DateTime.Now.Ticks; } }
|
||||||
|
|
||||||
|
/// <summary>Gets the database provider.</summary>
|
||||||
|
public DbProviderFactory Provider { get { return _provider; } }
|
||||||
|
|
||||||
/// <summary>Gets or sets a value indicating whether
|
/// <summary>Gets or sets a value indicating whether
|
||||||
/// dump commands to console or not.</summary>
|
/// dump commands to console or not.</summary>
|
||||||
public bool DumpCommands { get; set; }
|
public bool DumpCommands { get; set; }
|
||||||
|
|||||||
@@ -255,33 +255,34 @@ namespace DynamORM
|
|||||||
var p = cmd.CreateParameter();
|
var p = cmd.CreateParameter();
|
||||||
p.ParameterName = builder.DynamicTable.Database.GetParameterName(cmd.Parameters.Count);
|
p.ParameterName = builder.DynamicTable.Database.GetParameterName(cmd.Parameters.Count);
|
||||||
|
|
||||||
if (item.Value == null)
|
var col = builder.Schema.TryGetNullable(item.ColumnName.ToLower());
|
||||||
p.Value = DBNull.Value;
|
|
||||||
else
|
if (col.HasValue)
|
||||||
{
|
{
|
||||||
var col = builder.Schema.TryGetNullable(item.ColumnName.ToLower());
|
p.DbType = col.Value.Type;
|
||||||
|
|
||||||
if (col.HasValue)
|
if (builder.SupportSchema)
|
||||||
{
|
{
|
||||||
p.DbType = col.Value.Type;
|
p.Size = col.Value.Size;
|
||||||
|
p.Precision = col.Value.Precision;
|
||||||
|
p.Scale = col.Value.Scale;
|
||||||
|
|
||||||
if (builder.SupportSchema)
|
// Quick fix - review that
|
||||||
{
|
if (p.Scale > p.Precision)
|
||||||
p.Size = col.Value.Size;
|
p.Scale = 4;
|
||||||
p.Precision = col.Value.Precision;
|
|
||||||
p.Scale = col.Value.Scale;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p.DbType = TypeMap.TryGetNullable(item.Value.GetType()) ?? DbType.String;
|
|
||||||
|
|
||||||
if (p.DbType == DbType.String)
|
|
||||||
p.Size = item.Value.ToString().Length > 4000 ? -1 : 4000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Value = item.Value;
|
p.Value = item.Value;
|
||||||
}
|
}
|
||||||
|
else if (item.Value == null || item.Value == DBNull.Value)
|
||||||
|
p.Value = DBNull.Value;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p.DbType = TypeMap.TryGetNullable(item.Value.GetType()) ?? DbType.String;
|
||||||
|
|
||||||
|
if (p.DbType == DbType.String)
|
||||||
|
p.Size = item.Value.ToString().Length > 4000 ? -1 : 4000;
|
||||||
|
}
|
||||||
|
|
||||||
cmd.Parameters.Add(p);
|
cmd.Parameters.Add(p);
|
||||||
|
|
||||||
@@ -666,12 +667,16 @@ namespace DynamORM
|
|||||||
|
|
||||||
if (command.Parameters.Count > 0)
|
if (command.Parameters.Count > 0)
|
||||||
{
|
{
|
||||||
writer.Write("Parameters:");
|
writer.WriteLine("Parameters:");
|
||||||
|
|
||||||
foreach (IDbDataParameter param in command.Parameters)
|
foreach (IDbDataParameter param in command.Parameters)
|
||||||
{
|
{
|
||||||
writer.Write(" '{0}'({1}) = '{2}'({3});",
|
writer.WriteLine(" '{0}' ({1} (s:{2} p:{3} s:{4})) = '{5}' ({6});",
|
||||||
param.ParameterName, param.DbType,
|
param.ParameterName,
|
||||||
|
param.DbType,
|
||||||
|
param.Scale,
|
||||||
|
param.Precision,
|
||||||
|
param.Scale,
|
||||||
param.Value ?? "NULL",
|
param.Value ?? "NULL",
|
||||||
param.Value != null ? param.Value.GetType().Name : "DBNull");
|
param.Value != null ? param.Value.GetType().Name : "DBNull");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user