This commit is contained in:
@@ -48,7 +48,8 @@ namespace DynamORM.Builders
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.AppendFormat("DELETE FROM {0}", TableName);
|
||||
sb.Append("DELETE FROM ");
|
||||
DynamicTable.Database.DecorateName(sb, TableName);
|
||||
|
||||
FillWhere(command, sb);
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace DynamORM.Builders
|
||||
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>
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>DynamORM</RootNamespace>
|
||||
<AssemblyName>DynamORM</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace DynamORM
|
||||
lock (_db.SyncLock)
|
||||
{
|
||||
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
|
||||
{
|
||||
_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>
|
||||
/// <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;
|
||||
|
||||
if (_db.TransactionPool[_command.Connection].Count > 0)
|
||||
_command.Transaction = _db.TransactionPool[_command.Connection].Peek();
|
||||
else
|
||||
_command.Transaction = null;
|
||||
|
||||
_poolStamp = _db.PoolStamp;
|
||||
}
|
||||
@@ -106,7 +118,26 @@ namespace DynamORM
|
||||
/// <summary>Gets or sets the <see cref="T:System.Data.IDbConnection"/>
|
||||
/// used by this instance of the <see cref="T:System.Data.IDbCommand"/>.</summary>
|
||||
/// <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
|
||||
/// <see cref="T:System.Data.IDbDataParameter"/> object.</summary>
|
||||
@@ -190,11 +221,14 @@ namespace DynamORM
|
||||
public void Dispose()
|
||||
{
|
||||
lock (_db.SyncLock)
|
||||
{
|
||||
if (_con != null)
|
||||
{
|
||||
var pool = _db.CommandsPool.TryGetValue(_con.Connection);
|
||||
|
||||
if (pool != null)
|
||||
if (pool != null && pool.Contains(_command))
|
||||
pool.Remove(_command);
|
||||
}
|
||||
|
||||
_command.Dispose();
|
||||
}
|
||||
|
||||
@@ -59,7 +59,24 @@ namespace DynamORM
|
||||
/// <summary>Gets or sets timestamp of last transaction pool or configuration change.</summary>
|
||||
/// <remarks>This property is used to allow commands to determine if
|
||||
/// 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>
|
||||
internal Dictionary<IDbConnection, Stack<IDbTransaction>> TransactionPool { get; private set; }
|
||||
@@ -83,6 +100,9 @@ namespace DynamORM
|
||||
/// <summary>Gets or sets command timeout.</summary>
|
||||
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
|
||||
/// dump commands to console or not.</summary>
|
||||
public bool DumpCommands { get; set; }
|
||||
|
||||
@@ -255,10 +255,6 @@ namespace DynamORM
|
||||
var p = cmd.CreateParameter();
|
||||
p.ParameterName = builder.DynamicTable.Database.GetParameterName(cmd.Parameters.Count);
|
||||
|
||||
if (item.Value == null)
|
||||
p.Value = DBNull.Value;
|
||||
else
|
||||
{
|
||||
var col = builder.Schema.TryGetNullable(item.ColumnName.ToLower());
|
||||
|
||||
if (col.HasValue)
|
||||
@@ -270,8 +266,16 @@ namespace DynamORM
|
||||
p.Size = col.Value.Size;
|
||||
p.Precision = col.Value.Precision;
|
||||
p.Scale = col.Value.Scale;
|
||||
|
||||
// Quick fix - review that
|
||||
if (p.Scale > p.Precision)
|
||||
p.Scale = 4;
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -280,9 +284,6 @@ namespace DynamORM
|
||||
p.Size = item.Value.ToString().Length > 4000 ? -1 : 4000;
|
||||
}
|
||||
|
||||
p.Value = item.Value;
|
||||
}
|
||||
|
||||
cmd.Parameters.Add(p);
|
||||
|
||||
return cmd;
|
||||
@@ -666,12 +667,16 @@ namespace DynamORM
|
||||
|
||||
if (command.Parameters.Count > 0)
|
||||
{
|
||||
writer.Write("Parameters:");
|
||||
writer.WriteLine("Parameters:");
|
||||
|
||||
foreach (IDbDataParameter param in command.Parameters)
|
||||
{
|
||||
writer.Write(" '{0}'({1}) = '{2}'({3});",
|
||||
param.ParameterName, param.DbType,
|
||||
writer.WriteLine(" '{0}' ({1} (s:{2} p:{3} s:{4})) = '{5}' ({6});",
|
||||
param.ParameterName,
|
||||
param.DbType,
|
||||
param.Scale,
|
||||
param.Precision,
|
||||
param.Scale,
|
||||
param.Value ?? "NULL",
|
||||
param.Value != null ? param.Value.GetType().Name : "DBNull");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user