/// <summary> /// Retrieves the character position at which the specified /// <c>IClob</c> object <c>searchString</c> appears in this /// <c>IClob</c> object. The search begins at position /// <c>start</c>. /// </summary> /// <param name="searchString"> /// The <c>IClob</c> object for which to search. /// </param> /// <param name="start"> /// The position at which to begin searching; /// the first position is 1. /// </param> /// <returns> /// The position at which the <c>searchString</c> appears or -1 /// if it is not present; the first position is 1. /// </returns> /// <exception cref="HsqlDataSourceException"> /// If there is an error accessing the <c>CLOB</c> value. /// </exception> long IClob.Position(IClob searchString, long start) { lock (this) { CheckFree(); try { java.sql.Clob wrapped = searchString.UnWrap() as java.sql.Clob; if (wrapped == null) { long length = searchString.Length; if (length > int.MaxValue) { throw new ArgumentException( "Maximum input length exceeded", "searchString"); } // TODO: this is *very* inefficient for large values. string s = searchString.GetSubString(0, (int)length); return(m_clob.position(s, start)); } else { return(m_clob.position(wrapped, start)); } } catch (java.sql.SQLException se) { throw new HsqlDataSourceException(se); } catch (java.lang.Exception e) { throw new HsqlDataSourceException(e.toString(), e); } } }
/// <summary> /// Retrieves the character position at which the specified /// <c>IClob</c> object <c>searchString</c> appears in this /// <c>IClob</c> object. The search begins at position /// <c>start</c>. /// </summary> /// <param name="searchString"> /// The <c>IClob</c> object for which to search. /// </param> /// <param name="start"> /// The position at which to begin searching; /// the first position is 1. /// </param> /// <returns> /// The position at which the <c>searchString</c> appears or -1 /// if it is not present; the first position is 1. /// </returns> /// <exception cref="HsqlDataSourceException"> /// If there is an error accessing the <c>CLOB</c> value. /// </exception> long IClob.Position(IClob searchString, long start) { lock (this) { CheckFree(); try { java.sql.Clob wrapped = searchString.UnWrap() as java.sql.Clob; if (wrapped == null) { long length = searchString.Length; if (length > int.MaxValue) { throw new ArgumentException( "Maximum input length exceeded", "searchString"); } // TODO: this is *very* inefficient for large values. string s = searchString.GetSubString(0, (int)length); return m_clob.position(s, start); } else { return m_clob.position(wrapped, start); } } catch (java.sql.SQLException se) { throw new HsqlDataSourceException(se); } catch (java.lang.Exception e) { throw new HsqlDataSourceException(e.toString(), e); } } }
public void GetSubString() { IClob testSubject = NewTestSubject(); string actual = testSubject.GetSubString(1, LobCharsLength); Assert.AreEqual(LobChars, actual); for (int i = 0; i < testSubject.Length; i++) { string substring = testSubject.GetSubString(i + 1, (int)testSubject.Length - i); Assert.AreEqual((int)testSubject.Length - i, substring.Length); Assert.AreEqual(LobChars.Substring(i, (int)testSubject.Length - i), substring); } try { // CHECKME: determine if this degnenerate borderline case should really be allowed.... actual = testSubject.GetSubString(LobCharsLength + 1, 0); } catch (Exception ex) { Assert.Fail( "failed invocation of GetSubString(pos,len) with zero len and pos one greater than max valid data position: " + ex.Message); } try { actual = testSubject.GetSubString(0, LobCharsLength); Assert.Fail("successful invocation of GetSubString(pos,len) with pos value too small (< 1)"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(HsqlDataSourceException), ex); } try { actual = testSubject.GetSubString(LobCharsLength + 1, 1); Assert.Fail("successful invocation of GetSubString(pos,len) with pos value too large (> LobCharsLength)"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(HsqlDataSourceException), ex); } try { actual = testSubject.GetSubString(LobCharsLength, 2); Assert.Fail("successful invocation of GetSubString(pos,len) with pos value too large (LobCharsLength) for len (2)"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(HsqlDataSourceException), ex); } try { actual = testSubject.GetSubString(1, -1); Assert.Fail("successful invocation of GetSubString(pos,len) with negative len"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(HsqlDataSourceException), ex); } try { actual = testSubject.GetSubString(1, LobCharsLength + 1); Assert.Fail("successful invocation of GetSubString(pos,len) with len > LobCharsLength"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(HsqlDataSourceException), ex); } }
public void Free() { IClob testSubject = NewTestSubject(); long length = testSubject.Length; Assert.AreEqual(LobCharsLength, length); try { testSubject.Wrap("5678"); Assert.Fail("successful invocation of Wrap(object) before Free()"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(InvalidOperationException), ex); } testSubject.Free(); try { Stream stream = testSubject.GetAsciiStream(); Assert.Fail("successful invocation of GetAsciiStream() after Free()"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(InvalidOperationException), ex); } try { TextReader reader = testSubject.GetCharacterStream(); Assert.Fail("successful invocation of GetCharactertream() after Free()"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(InvalidOperationException), ex); } try { string chars = testSubject.GetSubString(0L, (int)length); Assert.Fail("successful invocation of GetSubString(long,int) after Free()"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(InvalidOperationException), ex); } try { long len = testSubject.Length; Assert.Fail("successful invocation of Length property after Free()"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(InvalidOperationException), ex); } try { long pos = testSubject.Position("234", 1); Assert.Fail("successful invocation of Position(string,long) after Free()"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(InvalidOperationException), ex); } try { long pos = testSubject.Position(new JdbcClob("234"), 1); Assert.Fail("successful invocation of Position(IClob,long) after Free()"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(InvalidOperationException), ex); } try { Stream stream = testSubject.SetAsciiStream(1); Assert.Fail("successful invocation of SetAsciiStream(long) after Free()"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(InvalidOperationException), ex); } try { TextWriter writer = testSubject.SetCharacterStream(1); Assert.Fail("successful invocation of SetCharacterStream(long) after Free()"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(InvalidOperationException), ex); } try { testSubject.SetString(1, "234"); Assert.Fail("successful invocation of SetString(long,string) after Free()"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(InvalidOperationException), ex); } try { testSubject.SetString(1, "234", 0, 3); Assert.Fail("successful invocation of SetString(long,string,int,int) after Free()"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(InvalidOperationException), ex); } try { testSubject.Truncate(0); Assert.Fail("successful invocation of Truncate(long) after Free()"); } catch (AssertionException) { throw; } catch (Exception ex) { Assert.IsInstanceOfType(typeof(InvalidOperationException), ex); } try { testSubject.Wrap("1234"); } catch (Exception ex) { Assert.Fail("Wrap(object) raised exception after Free(): " + ex.Message); } }