public int ExecuteNonQuery() { using (QueryTime.Measure(this)) { return(this.sqlCommand.ExecuteNonQuery()); } }
public bool IsCooldownPassed() { TimeSpan pauseMin = TimeSpan.FromMinutes(1.5); DateTime compare = QueryTime.Add(pauseMin); return(DateTime.Now >= compare); }
public SqlDataReader ExecuteReader() { using (QueryTime.Measure(this)) { return(this.sqlCommand.ExecuteReader()); } }
public SqlDataReader ExecuteReader(CommandBehavior behavior) { using (QueryTime.Measure(this)) { return(this.sqlCommand.ExecuteReader(behavior)); } }
public static int ExecuteNonQueryBatch(IReadOnlyList <DbSqlCommand> sqlCommands, SqlConnection sqlConnection) { if (sqlCommands == null) { throw new ArgumentNullException(nameof(sqlCommands)); } if (sqlConnection == null) { throw new ArgumentNullException(nameof(sqlConnection)); } if (sqlCommands.Count == 0) { return(0); } var connectionsCount = sqlCommands.Count(c => c.Connection != null && c.Connection != sqlConnection); if (connectionsCount > 1) { throw new InvalidOperationException("All commands of a batch must use the same connection."); } var commandSet = new SqlCommandSet(); commandSet.CommandTimeout = (int)TimeSpan.FromMinutes(5).TotalSeconds; foreach (var sqlCommand in sqlCommands) { commandSet.Append(sqlCommand.SqlCommand); } using (QueryTime.MeasureBatch(commandSet)) { return(SqlCommands.ExecuteSqlCommand(() => { bool wasOpened = false; if (sqlConnection.State != ConnectionState.Open) { sqlConnection.Open(); wasOpened = true; } try { commandSet.Connection = sqlConnection; var changesCount = commandSet.ExecuteNonQuery(); return changesCount; } finally { if (wasOpened) { sqlConnection.Close(); } } })); } }
public Timer(string input, bool shouldShowAll) { stopwatch = new Stopwatch(); stopwatch.Start(); queryTime = new QueryTime(); queryTime.Query = input; queryTime.ShowAll = shouldShowAll; queryTime.Now = DateTime.Now; }
public int CompareTo(InvestmentQuery other) { var priorityCompare = Priority.CompareTo(other.Priority); if (priorityCompare != 0) { return(priorityCompare); } return(QueryTime.CompareTo(other.QueryTime)); }
public override int GetHashCode() { int hashcode = 157; unchecked { hashcode = (hashcode * 397) + Path.GetHashCode(); hashcode = (hashcode * 397) + QueryTime.GetHashCode(); hashcode = (hashcode * 397) + BeforeRange.GetHashCode(); hashcode = (hashcode * 397) + QueryId.GetHashCode(); hashcode = (hashcode * 397) + Requester.GetHashCode(); hashcode = (hashcode * 397) + Header.GetHashCode(); hashcode = (hashcode * 397) + DataTypeOrdinal.GetHashCode(); hashcode = (hashcode * 397) + TCollections.GetHashCode(DeviceMeasurements); } return(hashcode); }
public T SelectSingleValue <T>() { if (SqlCommand.Connection == null) { throw new InvalidOperationException("SqlCommand.Connection is not set."); } using (QueryTime.Measure(this)) { var value = sqlCommand.ExecuteScalar(); if (value == null) { return(default(T)); } // Special case for Id<> and LongId<> var targetConvertType = typeof(T); if (IdTypeExtension.IsIdType(targetConvertType)) { var constructor = targetConvertType.GetConstructor(new[] { typeof(int) }); if (constructor == null) { throw new InvalidCastException("The Id<> type has no constructor taking int as a parameter."); } return((T)constructor.Invoke(new object[] { Convert.ToInt32(value) })); } else if (LongIdTypeExtension.IsLongIdType(targetConvertType)) { var constructor = targetConvertType.GetConstructor(new[] { typeof(long) }); if (constructor == null) { throw new InvalidCastException("The LongId<> type has no constructor taking long as a parameter."); } return((T)constructor.Invoke(new object[] { Convert.ToInt64(value) })); } // Just execute the query, don't close the connection return(DataRowExtensionsCustom.Get <T>(value)); } }
/// <summary> /// 分时模式 (新增、修改) /// </summary> /// <param name="model"></param> /// <returns></returns> public ResultRate SaveTimePrice(QueryTime model) { ResultRate resultModel = new ResultRate(); string sql = ""; //if (model.listPrice != null) //{ // foreach (TimePrice m in model.listPrice) // { // if (m != null) // if (m.ID == 0) // { // sql += string.Format(@" insert into TB_TIME_PERIOD_SET (ItemID,Price) values({0},{1}); ", m.ItemID, m.Price); // } // else // { // sql += string.Format(@" update TB_Price_TimeBill set Price={0} where ID={1}", m.Price, m.ID); // } // } //} //if (model.ListRule != null) //{ // foreach (TimeRule m in model.ListRule) // { // if (m != null) // if (m.RuleID == 0) // { // sql += string.Format(@" insert into TB_Rule_TimeBill (StartTime,EndTime,ItemID) values({0},{1},{2}); ", m.StartTime, m.EndTime, m.ItemID); // } // else // { // sql += string.Format(@" update TB_Rule_TimeBill set StartTime={0},EndTime={1} where RuleID={2}", m.StartTime, m.EndTime, m.RuleID); // } // } //} resultModel.IsSucess = _dal.SaveRatePrice(sql); return(resultModel); }
void HandleQueryTime(QueryTime packet) { SendQueryTimeResponse(); }
void QueryTimer_Tick(object sender, EventArgs e) { QueryTime = QueryTime.Add(new TimeSpan(0, 0, 1)); }