using System; using System.Collections; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; public class CLR_fix { private class fixstep : IEnumerator { string _str; int itemlen; int _start_ix; int _end_ix; int _listpos; public string str { get { return this._str; } } public int start_ix { get { return this._start_ix; } } public int end_ix { get { return this._end_ix; } } public int listpos { get { return this._listpos; } } public fixstep(SqlString str, SqlByte itemlen) { this._str = str.IsNull ? "" : str.Value; this.itemlen = itemlen.IsNull ? this._str.Length : itemlen.Value; Reset(); } public bool MoveNext() { this._start_ix = this._end_ix; if (this._start_ix == this._str.Length) { return false; } this._end_ix = this._start_ix + this.itemlen; this._listpos++; if (this._end_ix > this._str.Length) { this._end_ix = this._str.Length; } return true; } public Object Current { get { return this; } } public void Reset() { this._start_ix = -1; this._end_ix = 0; this._listpos = 0; } } [SqlFunction(FillRowMethodName="CharlistFillRow")] public static IEnumerator CLR_charlist_fix(SqlString str, SqlByte itemlen) { return new fixstep(str, itemlen); } public static void CharlistFillRow(object obj, out int listpos, out string str) { fixstep iter = (fixstep) obj; listpos = iter.listpos; str = iter.str.Substring(iter.start_ix, iter.end_ix - iter.start_ix); str = str.Trim(); } [SqlFunction(FillRowMethodName="IntlistFillRow")] public static IEnumerator CLR_intlist_fix(SqlString str, SqlByte itemlen) { return new fixstep(str, itemlen); } public static void IntlistFillRow(object obj, out int listpos, out int number) { fixstep iter = (fixstep) obj; listpos = iter.listpos; string str = iter.str.Substring(iter.start_ix, iter.end_ix - iter.start_ix); number = System.Convert.ToInt32(str); } }