/// <summary> /// Updates an existing session record /// </summary> /// <param name="session"> /// The session to update /// </param> /// <returns> /// The updated session record /// </returns> public Session UpdateSession(Session session) { Execute( "UPDATE Session SET " + "State = @p1, " + "Flags = @p2, " + "RateLimit = @p3, " + "CheckpointLength = @p4, " + "EstimatedLength = @p5, " + "ActualLength = @p6 " + "WHERE ID = @p0;", session.ID, session.State, session.Flags, session.RateLimit, session.CheckpointLength, session.EstimatedLength, session.ActualLength ); return session; }
/// <summary> /// Inserts a new session record /// </summary> /// <param name="session"> /// The session to insert /// </param> /// <returns> /// The inserted session, including the generated primary key /// </returns> public Session InsertSession(Session session) { Execute( "INSERT INTO Session (" + "State, " + "Flags, " + "RateLimit, " + "CheckpointLength, " + "EstimatedLength, " + "ActualLength, " + "Created) " + "VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6);", session.State, session.Flags, session.RateLimit, session.CheckpointLength, session.EstimatedLength, session.ActualLength, session.Created = DateTime.UtcNow ); session.ID = GetLastRowID(); return session; }
/// <summary> /// Searches for the next pending entry record /// </summary> /// <param name="session"> /// The session to query /// </param> /// <returns> /// The next entry record with a status of pending, if any /// Null otherwise /// </returns> public Entry LookupNextEntry(Session session) { return Fetch( "SELECT " + "ID, " + "NodeID, " + "BlobID, " + "State, " + "Offset, " + "Length, " + "Crc32 " + "FROM Entry " + "WHERE SessionID = @p0 " + "AND State = @p1 " + "LIMIT 1;", new Object[] { session.ID, EntryState.Pending }, reader => new Entry() { ID = Convert.ToInt32(reader[0]), Session = session, Node = FetchNode(Convert.ToInt32(reader[1])), Blob = (!reader.IsDBNull(2)) ? FetchBlob(Convert.ToInt32(reader[2])) : null, State = (EntryState)Convert.ToInt32(reader[3]), Offset = Convert.ToInt64(reader[4]), Length = Convert.ToInt64(reader[5]), Crc32 = BitConverter.ToUInt32((Byte[])reader[6], 0) } ); }
/// <summary> /// Deletes an existing session /// </summary> /// <param name="session"> /// The session to delete /// </param> public void DeleteSession(Session session) { Execute( "DELETE FROM Session WHERE ID = @p0;", session.ID ); }