public void WrongDataType() { object o = new object(); try { throw HsqlConvert.WrongDataType(o); } catch (HsqlDataSourceException hdse) { Assert.AreEqual(org.hsqldb.Trace.WRONG_DATA_TYPE, -hdse.ErrorCode); } }
/// <summary>Gets the value of the specified column as an XML value.</summary> /// <returns> /// A <see cref="SqlXml"/> value that contains /// the XML stored within the corresponding field. /// </returns> /// <param name="ordinal"> /// The zero-based column ordinal. /// </param> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// The index passed was outside the range of 0 to /// FieldCount - 1 /// </exception> /// <exception cref="T:System.InvalidCastException"> /// The retrieved data is not compatible with the /// <see cref="SqlXml"/> type. /// </exception> public SqlXml GetSqlXml(int ordinal) { CheckClosed(); CheckAvailable(); object value = m_currentRecord.data[ordinal]; if (value == null) { return(SqlXml.Null); } if (value is org.hsqldb.types.JavaObject) { bool isJavaObject; value = HsqlConvert.FromJava.UnWrap(value, out isJavaObject); } if (value is string) { string stringValue = value as string; MemoryStream ms = new MemoryStream(); using (GZipStream gzs = new GZipStream(ms, CompressionMode.Compress)) using (TextWriter writer = new StreamWriter(gzs, Encoding.UTF8)) { writer.Write(stringValue); writer.Flush(); } ms.Position = 0; return(new SqlXml(new GZipStream(ms, CompressionMode.Decompress))); } else if (value is org.hsqldb.types.Binary) { byte[] bytes = ((org.hsqldb.types.Binary)value).getBytes(); return(new SqlXml(new MemoryStream(bytes))); } else if (value is byte[]) { return(new SqlXml(new MemoryStream(value as byte[]))); } else if (value is char[]) { char[] chars = value as char[]; MemoryStream ms = new MemoryStream(1 + chars.Length / 2); using (GZipStream gzs = new GZipStream(ms, CompressionMode.Compress)) using (TextWriter writer = new StreamWriter(gzs, Encoding.UTF8)) { writer.Write(chars); writer.Flush(); } ms.Position = 0; return(new SqlXml(new GZipStream(ms, CompressionMode.Decompress))); } throw new InvalidCastException(GetDataTypeName(ordinal), HsqlConvert.WrongDataType(value)); }