/// <summary> /// Updates a record in the <c>TableSequence</c> table. /// </summary> /// <param name="value">The <see cref="TableSequenceRow"/> /// object used to update the table record.</param> /// <returns>true if the record was updated; otherwise, false.</returns> public virtual bool Update(TableSequenceRow value) { string sqlStr = "UPDATE [dbo].[TableSequence] SET " + "[Value]=" + _db.CreateSqlParameterName("Value") + " WHERE " + "[TableName]=" + _db.CreateSqlParameterName("TableName"); IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "Value", value.Value); AddParameter(cmd, "TableName", value.TableName); return(0 != cmd.ExecuteNonQuery()); }
/// <summary> /// Adds a new record into the <c>TableSequence</c> table. /// </summary> /// <param name="value">The <see cref="TableSequenceRow"/> object to be inserted.</param> public virtual void Insert(TableSequenceRow value) { string sqlStr = "INSERT INTO [dbo].[TableSequence] (" + "[TableName], " + "[Value]" + ") VALUES (" + _db.CreateSqlParameterName("TableName") + ", " + _db.CreateSqlParameterName("Value") + ")"; IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "TableName", value.TableName); AddParameter(cmd, "Value", value.Value); cmd.ExecuteNonQuery(); }
/// <summary> /// Converts <see cref="System.Data.DataRow"/> to <see cref="TableSequenceRow"/>. /// </summary> /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param> /// <returns>A reference to the <see cref="TableSequenceRow"/> object.</returns> protected virtual TableSequenceRow MapRow(DataRow row) { TableSequenceRow mappedObject = new TableSequenceRow(); DataTable dataTable = row.Table; DataColumn dataColumn; // Column "TableName" dataColumn = dataTable.Columns["TableName"]; if (!row.IsNull(dataColumn)) { mappedObject.TableName = (string)row[dataColumn]; } // Column "Value" dataColumn = dataTable.Columns["Value"]; if (!row.IsNull(dataColumn)) { mappedObject.Value = (long)row[dataColumn]; } return(mappedObject); }
/// <summary> /// Reads data from the provided data reader and returns /// an array of mapped objects. /// </summary> /// <param name="reader">The <see cref="System.Data.IDataReader"/> object to read data from the table.</param> /// <param name="startIndex">The index of the first record to map.</param> /// <param name="length">The number of records to map.</param> /// <param name="totalRecordCount">A reference parameter that returns the total number /// of records in the reader object if 0 was passed into the method; otherwise it returns -1.</param> /// <returns>An array of <see cref="TableSequenceRow"/> objects.</returns> protected virtual TableSequenceRow[] MapRecords(IDataReader reader, int startIndex, int length, ref int totalRecordCount) { if (0 > startIndex) { throw new ArgumentOutOfRangeException("startIndex", startIndex, "StartIndex cannot be less than zero."); } if (0 > length) { throw new ArgumentOutOfRangeException("length", length, "Length cannot be less than zero."); } int tableNameColumnIndex = reader.GetOrdinal("TableName"); int valueColumnIndex = reader.GetOrdinal("Value"); System.Collections.ArrayList recordList = new System.Collections.ArrayList(); int ri = -startIndex; while (reader.Read()) { ri++; if (ri > 0 && ri <= length) { TableSequenceRow record = new TableSequenceRow(); recordList.Add(record); record.TableName = Convert.ToString(reader.GetValue(tableNameColumnIndex)); record.Value = Convert.ToInt64(reader.GetValue(valueColumnIndex)); if (ri == length && 0 != totalRecordCount) { break; } } } totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1; return((TableSequenceRow[])(recordList.ToArray(typeof(TableSequenceRow)))); }
/// <summary> /// Deletes the specified object from the <c>TableSequence</c> table. /// </summary> /// <param name="value">The <see cref="TableSequenceRow"/> object to delete.</param> /// <returns>true if the record was deleted; otherwise, false.</returns> public bool Delete(TableSequenceRow value) { return(DeleteByPrimaryKey(value.TableName)); }