private static void DisplayDebug(IDbCommand command) { #if DEBUG OrmDebug.Trace(command.CommandText); foreach (IDbDataParameter commandParameter in command.Parameters) { string value; if (commandParameter.Value == DBNull.Value) { value = "NULL"; } else if (commandParameter.Value is DateTime) { value = ((DateTime)commandParameter.Value).ToString("MM/dd/yyyy HH:mm:ss.fff"); } else if (commandParameter.Value is byte[] byteArrayValue) { value = Encoding.UTF8.GetString(byteArrayValue, 0, byteArrayValue.Length); } else { value = commandParameter.Value.ToString(); } OrmDebug.Trace($"\t{commandParameter.ParameterName}:{value}"); } #endif }
private void CreateIndex(Index index) { var connection = SqlDataStore.GetWriteConnection(); using var command = connection.CreateCommand(); var sql = index.GetCreateSqlQuery(); OrmDebug.Trace(sql); command.CommandText = sql; command.ExecuteNonQuery(); }
public string ToStatement(List <IDataParameter> @params) { var result = new StringBuilder(); result.Append($"UPDATE [{_entityName}]"); result.Append(_setFieldList.ToStatement(@params)); result.Append(_where.ToStatement(@params)); var sql = result.Append(";").ToString(); OrmDebug.Trace(sql); return(sql); }
protected override void CreateForeignKey(ForeignKey foreignKey) { var connection = SqlDataStore.GetConnection(); using (var command = connection.CreateCommand()) { var sql = foreignKey.GetCreateSqlQuery(); OrmDebug.Trace(sql); command.CommandText = sql; command.ExecuteNonQuery(); } }
public string ToStatement(List <IDataParameter> @params) { var result = new StringBuilder(); result.Append(FromStatement()); result.Append(JoinStatement(@params)); result.Append(_where.ToStatement(@params)); result.Append(_groupBy.ToStatement()); result.Append(_orderBy.ToStatement()); var sql = result.Append(";").ToString(); OrmDebug.Trace(sql); return(sql); }
public void ApplyDelete(IEntityConflict entityConflict) { var entity = GetSyncableEntity(); foreach (var row in Delete) { var existing = FindExisting(row); if (existing == null) { OrmDebug.Trace(string.Format("Entity:{0}. deleted on remote but does not exist locally.", EntityName)); continue; } ApplyDeletetWhenExistInLocal(entityConflict, existing, entity, row); } }
private IDbConnection GetPoolConnection() { if (IsDisposed) { throw new ObjectDisposedException("SqlStoreBase"); } lock (_connectionPool) { IDbConnection connection; do { connection = GetFreeConnectionInPool(); if (connection != null) { if (Open(connection)) { return(connection); } // Broken connection, maybe disposed _connectionPool.Remove(connection); } if (_connectionPool.Count < ConnectionPoolSize) { connection = _dbEngine.GetNewConnection(); connection.Open(); _connectionPool.Add(connection); Interlocked.Increment(ref _connectionCount); OrmDebug.Trace("Creating pooled connection"); return(connection); } // pool is full, we have to wait Thread.Sleep(1000); // TODO: add a timeout? } while (connection == null); // this should never happen throw new TimeoutException("Unable to get a pooled connection."); } }
public void Populate() { var entity = GetSyncableEntity(); OrmDebug.Trace(""); PopulateInsert(entity); OrmDebug.Trace(GetChangeDisplay("Inserted", Insert)); PopulateUpdate(entity); OrmDebug.Trace(GetChangeDisplay("Updated", Update)); if (entity.IsDeleteTrackEnable) { PopulateDelete(entity); OrmDebug.Trace(GetChangeDisplay("Deleted", Delete)); } PopulateLastSync(entity); OrmDebug.Trace(GetChangeDisplay("LastSync", Update)); }
public IDbConnection GetConnection() { if (IsDisposed) { throw new ObjectDisposedException("ConnectionPool"); } lock (_pool) { IDbConnection connection; do { connection = GetFreeConnectionInPool(); if (connection != null) { if (Open(connection)) { return(connection); } // Broken connection, maybe disposed connection.Dispose(); _pool.Remove(connection); } if (_pool.Count < ConnectionPoolSize) { connection = _dbEngine.GetNewConnection(); connection.Open(); _pool.Add(connection); OrmDebug.Trace("Creating pooled connection"); return(connection); } OrmDebug.Trace("Pool full waiting for free connection"); Thread.Sleep(1000); // TODO: add a timeout? } while (connection == null); throw new TimeoutException("Unable to get a pooled connection."); } }
/// <summary> /// </summary> /// <param name="sql"></param> /// <returns></returns> /// <remarks>You <b>MUST</b> call CloseReader after calling this method to prevent a leak</remarks> public virtual IDataReader ExecuteReader(string sql) { try { var connection = GetReadConnection(); var command = SqlFactory.CreateCommand(); command.CommandText = sql; command.Connection = connection; command.Transaction = CurrentTransaction; var reader = command.ExecuteReader(CommandBehavior.Default); return(reader); } catch (Exception ex) { OrmDebug.Trace("SQLStoreBase::ExecuteReader threw: " + ex.Message); throw; } }
private static void DisplayDebug(IDbCommand command) { #if DEBUG OrmDebug.Trace(command.CommandText); foreach (IDbDataParameter commandParameter in command.Parameters) { string value; if (commandParameter.Value == DBNull.Value) { value = "NULL"; } else if (commandParameter.Value is DateTime) { value = ((DateTime)commandParameter.Value).ToString("MM/dd/yyyy HH:mm:ss.fff"); } else { value = commandParameter.Value.ToString(); } OrmDebug.Trace(string.Format("\t{0}:{1}", commandParameter.ParameterName, value)); } #endif }