get() { Object stream = getStream(); // Reader rdr; if (stream == null) { return(null); } else if (stream is InputStream) { return(cnvtIS2Rdr((InputStream)stream)); } else if (stream is Reader) { return((Reader)stream); } else { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); } } // get
setString(String value) { if (value == null) { setNull(); } else { Decimal temp; try { temp = DecimalParseInvariant(value); } catch (FormatException /* ex */) { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); } // this.value = checkPrecision(temp); this.value = temp; setNotNull(); } truncated = false; return; } // setString
parseOffset(String tzOffset) { /* ** Validate offset format. */ if ( tzOffset.Length != TZ_FMT.Length || (tzOffset[0] != '+' && tzOffset[0] != '-') || !Char.IsDigit(tzOffset[1]) || !Char.IsDigit(tzOffset[2]) || tzOffset[3] != ':' || !Char.IsDigit(tzOffset[4]) || !Char.IsDigit(tzOffset[5]) ) { throw SqlEx.get(ERR_GC401B_INVALID_DATE); } int hours = Convert.ToInt32(tzOffset[1] - '0') * 10 + Convert.ToInt32(tzOffset[2] - '0'); int minutes = Convert.ToInt32(tzOffset[4] - '0') * 10 + Convert.ToInt32(tzOffset[5] - '0'); int offset = hours * 60 + minutes; if (tzOffset[0] == '-') { offset = -offset; } return(offset); } // parseOffset
setStream(Object stream) { lock (this) { if (stream == null) { setNull(); } else { if ( !(stream is InputStream) && !(stream is Reader) ) { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); } setNotNull(); active = false; this.stream = stream; if (stream is IStreamSource) // (ByteSegIS and Ucs2SegRdr) { ((IStreamSource)stream).addStreamListener(listener, this); } } } return; } // set
strm2str(Reader inReader, int limit) { char[] cb = new char[8192]; StringBuilder sb = new StringBuilder(); int len; try { while ((limit < 0 || sb.Length < limit) && (len = inReader.read(cb, 0, cb.Length)) >= 0) { if (limit >= 0) { len = Math.Min(len, limit - sb.Length); } if (len > 0) { sb.Append(cb, 0, len); } } } catch (IOException) { throw SqlEx.get(ERR_GC4007_BLOB_IO); } finally { try { inReader.close(); } catch (IOException) {} } return(sb.ToString()); } // strm2str
get(OutputStream os) { Object stream = getStream(); if (stream != null) { if (stream is InputStream) { copyIs2Os((InputStream)stream, os); } else if (stream is Reader) { OutputStreamWriter wtr; try { wtr = charSet.getOSW(os); } catch (Exception /* ex */) // Should not happen! { throw SqlEx.get(ERR_GC401E_CHAR_ENCODE); } copyRdr2Wtr((Reader)stream, wtr); } else { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); } } return; } // get
getTime(TimeZone tz) { /* ** Ingres dates are overloaded with 'empty' date, ** date only, timestamp and interval values. The ** first three types are handled explicitly below. ** Intervals will either cause an exception while ** attempting to parse the value or as the default ** action for an unrecognized format. */ try { if (value.Length == 0 || // Empty date value.Length == SqlDates.D_FMT.Length) // Date only { /* ** There is no time component, so create a time EPOCH value. ** If no timezone is provided, we can return the local epoch ** constant. Otherwise, the epoch value for the requested ** timezone must be generated. */ return((tz == null) ? SqlDates.getEpochTime() : SqlDates.parseTime(SqlDates.T_EPOCH, tz)); } else if (value.Length == SqlDates.TS_FMT.Length) // Timestamp { /* ** Remove the date component but retain correct time: ** ** 1. Convert to GMT timestamp using TZ for current connection. ** 2. Re-format as time only using local TZ to get local time. ** 3. Generate Time value using requested/local TZ. */ DateTime ts = SqlDates.parseTimestamp(value, use_gmt); String str = SqlDates.formatTime(ts, false); return((osql_dates && tz != null) ? SqlDates.parseTime(str, tz) : SqlDates.parseTime(str, false)); } else // Interval { /* ** Can't support intervals with Time objects. */ throw SqlEx.get(ERR_GC401B_INVALID_DATE); } } catch (SqlEx ex) { /* ** Any parsing error is assumed to be caused by an interval. */ interval = true; throw ex; } } // getTime
getLong() { long value; try { value = Int64.Parse(getString(length)); } catch (FormatException) { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); } return(value); } // getLong
getDecimal() { Decimal value; try { value = DecimalParseInvariant(getString()); } catch (FormatException) { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); } return(value); } // getDecimal
getDouble() { double value; try { value = Double.Parse(getString(length)); } catch (FormatException) { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); } return(value); } // getDouble
getString(int limit) { if (limit > length) { limit = length; } try { return(charSet.getString(value, 0, limit)); } catch (Exception ex) { throw SqlEx.get(ERR_GC401E_CHAR_ENCODE, ex); } } // getString
getInt() { int value; try { value = Int32.Parse(getString()); } catch (FormatException) { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); } return(value); } // getInt
getFloat() { float value; try { value = Single.Parse(getString()); } catch (FormatException) { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); } return(value); } // getFloat
getShort() { short value; try { value = Int16.Parse(getString(length)); } catch (FormatException /* ex */) { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); } return(value); } // getShort
getByte() { byte value; try { value = Byte.Parse(getString()); } catch (FormatException) { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); } return(value); } // getByte
setString(String value) { if (value == null) { setNull(); } else { byte[] ba; try { ba = charSet.getBytes(value); } catch (Exception ex) { throw SqlEx.get(ERR_GC401E_CHAR_ENCODE, ex); } /* ** Normally, ensure() would be used to size the internal ** array, possibly allocating a new array. The problem ** is that a new array is already going to be allocated ** for Unicode conversion. Rather than use ensure, which ** at best will do nothing and at worst will allocate an ** additional array, we simply use the longer of internal ** of conversion array. */ if (ba.Length > this.value.Length) { /* ** First determine the length of the new string ** (apply limit if applicable). */ int length = ba.Length; if (limit >= 0 && length > limit) { length = limit; } /* ** Now replace the internal buffer with the new string. */ setNotNull(); this.value = ba; this.length = length; } else { /* ** Since the converted string will fit in the current ** internal buffer, we can just use standard access ** methods to save the string. */ clear(); put(ba); } } return; } // setString
cnvtIS2Rdr(InputStream stream) { try { return(charSet.getISR(stream)); } catch (Exception ex) // Should not happen! { throw SqlEx.get(ERR_GC401E_CHAR_ENCODE, ex); } } // cnvtIS2Rdr
checkAccess() { lock (this) { if (active) { throw SqlEx.get(ERR_GC401C_BLOB_DONE); } active = true; } return; } // checkAccess
setDouble(double value) { Decimal temp; try { temp = Convert.ToDecimal(value); } catch (FormatException /* ex */) { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); } // this.value = checkPrecision(temp); this.value = temp; setNotNull(); truncated = false; return; } // setDouble
SqlInterval(short dbms_type) : base(true) { switch (dbms_type) { case DBMS_TYPE_INTYM: case DBMS_TYPE_INTDS: this.dbms_type = dbms_type; break; default: /* Should not happen! */ throw SqlEx.get(ERR_GC401B_INVALID_DATE); } } // SqlInterval
getAsciiStream() { byte[] bytes; try { System.Text.Encoding ASCIIEncoding = System.Text.Encoding.ASCII; bytes = ASCIIEncoding.GetBytes(value); } catch (Exception) // Should not happen! { throw SqlEx.get(ERR_GC401E_CHAR_ENCODE); } return(new ByteArrayInputStream(bytes)); } // getAsciiStream
getUnicode(String str) { byte[] bytes; try { System.Text.Encoding UTF8Encoding = System.Text.Encoding.UTF8; bytes = UTF8Encoding.GetBytes(str); } catch (Exception) // Should not happen! { throw SqlEx.get(ERR_GC401E_CHAR_ENCODE); } return(new ByteArrayInputStream(bytes)); } // getUnicode
SqlTime(short dbms_type) : base(true) { switch (dbms_type) { case DBMS_TYPE_TIME: case DBMS_TYPE_TMWO: case DBMS_TYPE_TMTZ: this.dbms_type = dbms_type; break; default: /* Should not happen! */ throw SqlEx.get(ERR_GC401B_INVALID_DATE); } } // SqlTime
setString(String _value) { if (_value == null) { setNull(); } else { setNotNull(); try { this.Value = BooleanParse(_value); } catch (FormatException /* ex */) { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); } } return; } // setString
getBinary() { checkAccess(); if (stream == null) { return(null); } if (stream is InputStream) { return((InputStream)stream); } else { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); } } // getBinary
parseDate(String str, TimeZone tz) { DateTime date; if (str.Length != D_FMT.Length) { throw SqlEx.get(ERR_GC401B_INVALID_DATE); } lock (df_d_val) { df_d_val.setTimeZone(tz); try { date = df_d_val.parse(str); } catch (Exception) { throw SqlEx.get(ERR_GC401B_INVALID_DATE); } } return(date.Date); } // parseDate
get(TimeZone tz) { DateTime ts; switch (dbms_type) { case DBMS_TYPE_TS: /* ** DAS formats local time using GMT. */ ts = SqlDates.parseTimestamp(value, true); break; case DBMS_TYPE_TSWO: /* ** Interpret as local time in requested or default timezone. */ ts = (tz != null) ? SqlDates.parseTimestamp(value, tz) : SqlDates.parseTimestamp(value, false); break; case DBMS_TYPE_TSTZ: /* ** Apply explicit timezone. */ ts = SqlDates.parseTimestamp(value, SqlDates.getTZ(timezone)); break; default: // should never happen since constructor checked throw SqlEx.get(ERR_GC401B_INVALID_DATE); } // ts.setNanos(nanos); if (nanos > 0) { TimeSpan span = new TimeSpan(nanos / 100L); // one tick = 100 nanos ts += span; // add the nanos back in } return(ts); } // get
set(String value) { if (value == null) { setNull(); } else { /* ** Separate explicit timezone. */ if (dbms_type == DBMS_TYPE_TMTZ) { if (value.Length < (SqlDates.T_FMT.Length + SqlDates.TZ_FMT.Length)) { throw SqlEx.get(ERR_GC401B_INVALID_DATE); } int offset = value.Length - SqlDates.TZ_FMT.Length; timezone = value.Substring(offset); value = value.Substring(0, offset); } /* ** Separate fractional seconds. */ if (value.Length > SqlDates.T_FMT.Length) { nanos = SqlDates.parseFrac( value.Substring(SqlDates.T_FMT.Length)); value = value.Substring(0, SqlDates.T_FMT.Length); } setNotNull(); this.value = value; } return; } // set
get(TimeZone tz) { DateTime time; switch (dbms_type) { case DBMS_TYPE_TIME: time = SqlDates.parseTime(value, true); time = time.ToLocalTime(); break; case DBMS_TYPE_TMWO: /* ** Interpret as local time using requested or default timezone. */ time = (tz != null) ? SqlDates.parseTime(value, tz) : SqlDates.parseTime(value, false); break; case DBMS_TYPE_TMTZ: /* ** TIME WITH TIMEZONE values are local with ** explicit timezone offset. */ time = SqlDates.parseTime(value, SqlDates.getTZ(timezone)); time = time.ToLocalTime(); break; default: // should never happen since constructor checked throw SqlEx.get(ERR_GC401B_INVALID_DATE); } // end switch if (nanos > 0) { TimeSpan span = new TimeSpan(nanos / 100L); // one tick = 100 nanos time += span; // add the nanos back in } return(time); } // get
setString(String value) { if (value == null) { setNull(); } else { DateTime date; /* ** Validate format by converting to DateTime. */ try { date = DateTime.Parse(value); } catch (Exception /* ignore */) { throw SqlEx.get(ERR_GC401A_CONVERSION_ERR); } setDate(date, null); } return; } // setString