Inheritance: INullable
Beispiel #1
0
 public static SqlChars ConvertToPinyin(SqlChars input)
 {
     if (input.IsNull)
         return input;
     var str = new string(input.Value);
     return new SqlChars(StringConverter.GetChineseSpell(str));
 }
 public static SqlChars RegexGroup( SqlChars input, SqlString pattern, SqlString name )
 {
     Regex regex = new Regex( pattern.Value, Options );
       Match match = regex.Match( new string( input.Value ) );
       return match.Success ?
         new SqlChars( match.Groups[name.Value].Value ) : SqlChars.Null;
 }
 public static void FillMatch(object obj, out int index, out int length, out SqlChars value)
     {
     Match match = (Match)obj;
     index = match.Index;
     length = match.Length;
     value = new SqlChars(match.Value);
     }
 public static void FillMatchRow( object data,
    out SqlInt32 index, out SqlChars text )
 {
     MatchNode node = (MatchNode)data;
       index = new SqlInt32( node.Index );
       text = new SqlChars( node.Value.ToCharArray( ) );
 }
Beispiel #5
0
		public void SqlCharsItem ()
		{
			SqlChars chars = new SqlChars ();
			try {
				Assert.AreEqual (chars [0], 0, "#1 Should throw SqlNullValueException");
				Assert.Fail ("Should throw SqlNullValueException");
			} catch (Exception ex) {
				Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "Should throw SqlNullValueException");
			}
			char [] b = null;
			chars = new SqlChars (b);
			try {
				Assert.AreEqual (chars [0], 0, "#2 Should throw SqlNullValueException");
				Assert.Fail ("Should throw SqlNullValueException");
			} catch (Exception ex) {
				Assert.AreEqual (typeof (SqlNullValueException), ex.GetType (), "Should throw SqlNullValueException");
			}
			b = new char [10];
			chars = new SqlChars (b);
			Assert.AreEqual (chars [0], 0, "");
			try {
				Assert.AreEqual (chars [-1], 0, "");
				Assert.Fail ("Should throw ArgumentOutOfRangeException");
			} catch (Exception ex) {
				Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "Should throw ArgumentOutOfRangeException");
			}
			try {
				Assert.AreEqual (chars [10], 0, "");
				Assert.Fail ("Should throw ArgumentOutOfRangeException");
			} catch (Exception ex) {
				Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "Should throw ArgumentOutOfRangeException");
			}
		}
 internal static SqlString TrimEnd(SqlString src, SqlChars des)
 {
     if (IsAllNull(des)) return src;
     if (IsAllNull(src)) return SqlString.Null;
     string _s = src.Value;
     return new SqlString(_s.TrimEnd(des.Value));
 }
    public static SqlString RegexReplace(SqlChars input, SqlString pattern, SqlChars replacement)
    {
        Regex regex = new Regex(pattern.Value, Options);

        return regex.Replace(new string(input.Value),new string(replacement.Value));
        ///return regex.IsMatch(new string(input.Value)); ///The SQL datatype here is a BIT
    }
 override public void SetCapacity(int capacity) {
     SqlChars[] newValues = new SqlChars[capacity];
     if (null != values) {
         Array.Copy(values, 0, newValues, 0, Math.Min(capacity, values.Length));
     }
     values = newValues;
 }
Beispiel #9
0
 /// <summary>
 /// FillRow method to populate the output table
 /// </summary>
 /// <param name=”obj”>RegExRow passed as object</param>
 /// <param name=”rowId”>ID or the returned row</param>
 /// <param name=”matchId”>ID of returned Match</param>
 /// <param name=”groupID”>ID of group in the Match</param>
 /// <param name=”value”>Value of the Group</param>
 public static void FillRegExRow( Object obj, out int rowId, out int matchId, out int groupID, out SqlChars value )
 {
     RegExRow r = (RegExRow)obj;
     rowId = r.RowId;
     matchId = r.MatchId;
     groupID = r.GroupID;
     value = new SqlChars( r.Value );
 }
 public static void FillGroupRow( object data,
    out SqlInt32 index, out SqlChars group, out SqlChars text )
 {
     GroupNode node = (GroupNode)data;
       index = new SqlInt32( node.Index );
       group = new SqlChars( node.Name.ToCharArray( ) );
       text = new SqlChars( node.Value.ToCharArray( ) );
 }
Beispiel #11
0
 public static void FillRow(Object obj, out SqlDateTime timeWritten, out SqlChars message, out SqlChars category, out long instanceId)
 {
     EventLogEntry eventLogEntry = (EventLogEntry)obj;
     timeWritten = new SqlDateTime(eventLogEntry.TimeWritten);
     message = new SqlChars(eventLogEntry.Message);
     category = new SqlChars(eventLogEntry.Category);
     instanceId = eventLogEntry.InstanceId;
 }
Beispiel #12
0
 public static void FillAdjustedPrice(Object obj, out SqlInt32 itemId, out SqlMoney adjustedPrice, out SqlMoney averagePrice, out SqlChars itemName)
 {
     CCPDatum Item = (CCPDatum)obj;
     itemId = new SqlInt32(Item.item_id);
     adjustedPrice = new SqlMoney(Item.adjustedPrice);
     averagePrice = Item.averagePrice.HasValue ? new SqlMoney(Item.averagePrice.Value) : SqlMoney.Null;
     itemName = new SqlChars(Item.item_name);
 }
Beispiel #13
0
 /// <summary>
 /// 把每个值进行累加
 /// </summary>
 /// <param name="value"></param>
 public void Accumulate(SqlChars value, SqlString connector)
 {
     if (value.IsNull)
         return;
     if (splitterLength == 0)
         splitterLength = (connector.IsNull ? "," : connector.Value).Length;
     // 在此处放置代码
     result.Append(value.Value).Append(connector.IsNull ? "," : connector.Value);
 }
    public static SqlChars ConvertToTraditionalChinese(SqlChars input)
    {
        if (input.IsNull)
            return input;

        var str = new string(input.Value);
        // 在此处放置代码
        return new SqlChars(Strings.StrConv(str, VbStrConv.TraditionalChinese, 0));
    }
    public static SqlChars ConvertToProperCase(SqlChars input)
    {
        if (input.IsNull)
            return input;

        var str = new string(input.Value);
        // 在此处放置代码
        return new SqlChars(Strings.StrConv(str, VbStrConv.ProperCase, 0));
    }
 internal static SqlString TrimStartAndEnd(SqlString src, SqlChars startDes, SqlChars endDes)
 {
     if (IsAllNull(startDes, endDes)) return src;
     if (IsAllNull(src)) return SqlString.Null;
     string _s = src.Value;
     if (!endDes.IsNull) _s = _s.TrimEnd(endDes.Value);
     if (!startDes.IsNull) _s = _s.TrimStart(startDes.Value);
     return new SqlString(_s);
 }
 public static SqlString RegexReplaceRecursive(SqlChars input, SqlString pattern, SqlChars replacement)
 {
     string output = new string( input.Value );
     Regex regex = new Regex(pattern.Value, Options);
     while (regex.IsMatch( output ))
     {
         output = regex.Replace(output, new string(replacement.Value));
     }
     return output;
 }
Beispiel #18
0
 public static SqlBoolean ContainsAny(SqlChars input, string search)
 {
     string strTemp = new string(input.Value);
     foreach (string item in search.Split(','))
     {
         if (strTemp.Contains(item))
         {
             return true;
         }
     }
     return false;
 }
    public static SqlString ToSafeFileNameWith(SqlString text, SqlChars substitution)
    {
        if (text.IsNull || String.IsNullOrWhiteSpace(text.Value)) return SqlString.Null;

        var textValue = text.Value.Trim();

        var substitutionChar = substitution.Value[0];

        var fileName = Path.GetInvalidFileNameChars().Aggregate(textValue, (current, c) => current.Replace(c, substitutionChar));

        return new SqlString(fileName, text.LCID);
    }
Beispiel #20
0
    public static SqlChars PadRight(SqlChars input, SqlInt32 totalWidth, char paddingChar)
    {
        if (input.IsNull)
            return input;

        if (paddingChar == (char)0)
            return input;

        if (totalWidth.IsNull || totalWidth < 0)
            totalWidth = 0;

        // 在此处放置代码
        return new SqlChars(new string(input.Value).PadRight(totalWidth.Value, paddingChar));
    }
Beispiel #21
0
 public void SqlCharsItem()
 {
     SqlChars chars = new SqlChars();
     try
     {
         Assert.Equal(chars[0], 0);
         Assert.False(true);
     }
     catch (Exception ex)
     {
         Assert.Equal(typeof(SqlNullValueException), ex.GetType());
     }
     char[] b = null;
     chars = new SqlChars(b);
     try
     {
         Assert.Equal(chars[0], 0);
         Assert.False(true);
     }
     catch (Exception ex)
     {
         Assert.Equal(typeof(SqlNullValueException), ex.GetType());
     }
     b = new char[10];
     chars = new SqlChars(b);
     Assert.Equal(chars[0], 0);
     try
     {
         Assert.Equal(chars[-1], 0);
         Assert.False(true);
     }
     catch (Exception ex)
     {
         Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType());
     }
     try
     {
         Assert.Equal(chars[10], 0);
         Assert.False(true);
     }
     catch (Exception ex)
     {
         Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType());
     }
 }
Beispiel #22
0
    public static IEnumerable SplitString(SqlChars input, SqlChars splitter)
    {
        string[] array;
        if (input.IsNull)
        {
            array = new string[] { null };
        }
        else if (splitter.IsNull)
        {
            array = new string[] { input.ToSqlString().Value };
        }
        else
        {
            string inputStr = input.ToSqlString().Value;
            string sepStr = splitter.ToSqlString().Value;
            string[] separatorsArray = sepStr.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            array = inputStr.Split(separatorsArray, StringSplitOptions.RemoveEmptyEntries);
        }
        return array;
    }
Beispiel #23
0
    public static SqlString Escaped(SqlString text, SqlChars escapeChar)
    {
        if (text.IsNull || String.IsNullOrWhiteSpace(text.Value)) return SqlString.Null;

        if (escapeChar.IsNull || escapeChar.Length != 1)
            throw new SqlTypeException("Escape character length must be 1.");

        var wildcards = new[] {'%', '_', '[', ']'};
        char escapeCh = escapeChar.Value[0];

        var output = new StringBuilder();

        foreach (char ch in text.Value)
        {
            if (wildcards.Contains(ch))
                output.Append(escapeCh);
            output.Append(ch);
        }

        return new SqlString(output.ToString(), text.LCID);
    }
Beispiel #24
0
        public static SqlBoolean RegexMatch(
            SqlChars input, SqlString pattern)
        {
            if (input == null || pattern == null || input.IsNull || pattern.IsNull)
                return false;

            try
            {
                Regex regex = new Regex(pattern.Value, Options);
                return regex.IsMatch(new string(input.Value));
            }
            catch (ArgumentException aEx)
            {
                return false;
            }
            //catch (ArgumentOutOfRangeException aEx)
            //{
            //    return false;
            //}

            return false;
        }
        protected override void Dispose(bool disposing) {           
			// When m_sqlchars is null, it means the stream has been closed, and
			// any opearation in the future should fail.
			// This is the only case that m_sqlchars is null.
			m_sqlchars = null;
        }
		// --------------------------------------------------------------
		//	  Constructor(s)
		// --------------------------------------------------------------

		internal StreamOnSqlChars(SqlChars s) {
			m_sqlchars = s;
			m_lPosition = 0;
        }
Beispiel #27
0
        public SqlChars Adjust(SqlChars value)
        {
            if (SqlDbType.Char == SqlDbType || SqlDbType.NChar == SqlDbType)
            {
                //DBG.Assert(Max!=MaxLength, "SqlMetaData.Adjust(SqlChars): Fixed-length type with Max length!");
                // Don't pad null values
                if (null != value && !value.IsNull)
                {
                    // Pad fixed-length types
                    long oldLength = value.Length;
                    if (oldLength < MaxLength)
                    {
                        // Make sure buffer is long enough
                        if (value.MaxLength < MaxLength)
                        {
                            char[] rgchNew = new char[(int)MaxLength];
                            Array.Copy(value.Buffer, 0, rgchNew, 0, (int)oldLength);
                            value = new SqlChars(rgchNew);
                        }

                        // pad extra space
                        char[] rgchTemp = value.Buffer;
                        for (long i = oldLength; i < MaxLength; i++)
                            rgchTemp[i] = ' ';

                        value.SetLength(MaxLength);
                        return value;
                    }
                }
            }
            else if (SqlDbType.VarChar != SqlDbType && SqlDbType.NVarChar != SqlDbType &&
                    SqlDbType.Text != SqlDbType && SqlDbType.NText != SqlDbType)
                ThrowInvalidType();

            // Handle null values after type check.
            if (null == value || value.IsNull)
            {
                return value;
            }

            // trim all types
            if (value.Length > MaxLength && Max != MaxLength)
                value.SetLength(MaxLength);

            return value;
        }
Beispiel #28
0
        internal static SqlChars GetSqlChars( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData, SmiContext context ) {
            SqlChars result;
            if ( CanAccessGetterDirectly( metaData, ExtendedClrTypeCode.SqlChars ) ) {
                if ( IsDBNull_Unchecked( sink, getters, ordinal ) ) {
                    result = SqlChars.Null;
                }
                else {
                    long length = GetCharsLength_Unchecked( sink, getters, ordinal );
                    if ( length < __maxCharChunkSize || !InOutOfProcHelper.InProc) {
                        char[] charBuffer = GetCharArray_Unchecked( sink, getters, ordinal );
                        result = new SqlChars( charBuffer );
                    }
                    else {    // InProc only
                        Stream s = new SmiGettersStream( sink, getters, ordinal, metaData );
                        SqlStreamChars sc = CopyIntoNewSmiScratchStreamChars( s, sink, context );
                        result = new SqlChars( sc );
                    }
                }
            }
            else {
                SqlString stringValue;
                if (SqlDbType.Xml == metaData.SqlDbType) {
                    SqlXml xmlValue = GetSqlXml_Unchecked( sink, getters, ordinal, null );

                    if (xmlValue.IsNull) {
                        result = SqlChars.Null;
                    }
                    else {
                        result = new SqlChars( xmlValue.Value.ToCharArray() );
                    }
                }
                else {
                    object obj = GetSqlValue( sink, getters, ordinal, metaData, null  );
                    if (null == obj) {
                        throw ADP.InvalidCast();
                    }
                    stringValue = (SqlString) obj;

                    if ( stringValue.IsNull ) {
                        result = SqlChars.Null;
                    }
                    else {
                        result = new SqlChars( stringValue.Value.ToCharArray() );
                    }
                }
            }

            return result;
        }
Beispiel #29
0
        private static void SetSqlChars_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SqlChars value, int offset, int length ) {
            if ( value.IsNull ) {
                setters.SetDBNull( sink, ordinal );
                sink.ProcessMessagesAndThrow();
            }
            else {
                int chunkSize;
                if ( length > __maxCharChunkSize || length < 0 ) {
                    chunkSize = __maxCharChunkSize;
                }
                else {
                    chunkSize = checked( (int)length );
                }

                char[] buffer = new char[ chunkSize ];
                long charsRead;
                long charsWritten = 1;  // prime value to get into write loop
                long currentOffset = offset;
                long lengthWritten = 0;

                while ( (length < 0  || lengthWritten < length) &&
                        0 != ( charsRead = value.Read( currentOffset, buffer, 0, chunkSize ) ) &&
                        0 != charsWritten ) {
                    charsWritten = setters.SetChars( sink, ordinal, currentOffset, buffer, 0, checked( (int) charsRead ) );
                    sink.ProcessMessagesAndThrow();
                    checked{ currentOffset += charsWritten; }
                    checked{ lengthWritten += charsWritten;}
                }

                // Make sure to trim any left-over data
                setters.SetCharsLength( sink, ordinal, currentOffset );
                sink.ProcessMessagesAndThrow();
            }
        }
Beispiel #30
0
 private static void SetSqlChars_LengthChecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SmiMetaData metaData, SqlChars value, int offset ) {
     int length = 0;
     if ( !value.IsNull ) {
         // Deal with large values by sending bufferLength of NoLengthLimit
         //  CheckXetParameters will ignore length checks in this case
         long bufferLength = value.Length;
         if ( bufferLength > Int32.MaxValue ) {
             bufferLength = NoLengthLimit;
         }
         length = CheckXetParameters( metaData.SqlDbType, metaData.MaxLength, NoLengthLimit /* actual */, 0, checked( (int) bufferLength ), offset, checked( (int) bufferLength - offset ) );
     }
     SetSqlChars_Unchecked( sink, setters, ordinal, value, 0, length ); 
 }
 protected override void Dispose(bool disposing)
 {
     this.m_sqlchars = null;
 }
 internal StreamOnSqlChars(SqlChars s)
 {
     this.m_sqlchars  = s;
     this.m_lPosition = 0L;
 }
Beispiel #33
0
        // --------------------------------------------------------------
        //	  Constructor(s)
        // --------------------------------------------------------------

        internal StreamOnSqlChars(SqlChars s)
        {
            _sqlchars  = s;
            _lPosition = 0;
        }