Class: Syspy::TdsParams
- Inherits:
-
TdsPackage
- Object
- TdsPackage
- Syspy::TdsParams
- Defined in:
- lib/tds_packages/tds_params.rb
Constant Summary collapse
- TIME_DIFF =
Time.at(0).utc - Time.utc(1900,1,1)
Instance Attribute Summary collapse
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#params_count ⇒ Object
readonly
Returns the value of attribute params_count.
Instance Method Summary collapse
-
#initialize(io, paramfmt) ⇒ TdsParams
constructor
A new instance of TdsParams.
- #read_data(io, format) ⇒ Object
- #read_datetime(io, data_type) ⇒ Object
Methods inherited from TdsPackage
#read_int, #read_int16, #read_int32, #read_text, #read_uint, #read_uint16, #read_uint32
Constructor Details
#initialize(io, paramfmt) ⇒ TdsParams
Returns a new instance of TdsParams.
8 9 10 11 12 13 |
# File 'lib/tds_packages/tds_params.rb', line 8 def initialize(io,paramfmt) @parameters = [] paramfmt.parameters.each(){|format| @parameters << read_data(io,format) } end |
Instance Attribute Details
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
6 7 8 |
# File 'lib/tds_packages/tds_params.rb', line 6 def parameters @parameters end |
#params_count ⇒ Object (readonly)
Returns the value of attribute params_count.
6 7 8 |
# File 'lib/tds_packages/tds_params.rb', line 6 def params_count @params_count end |
Instance Method Details
#read_data(io, format) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tds_packages/tds_params.rb', line 15 def read_data(io,format) data_type = format[:data_type] case data_type when TdsTypes::SYBINTN len = read_int(io) return Bytes.intle(io,len) when TdsTypes::SYBINT1 return Bytes.int(io) when TdsTypes::SYBINT2 return Bytes::int16le(io) when TdsTypes::SYBINT4 return Bytes::int32le(io) when TdsTypes::SYBCHAR, TdsTypes::SYBVARCHAR, TdsTypes::XSYBCHAR len = read_uint(io) if (len > 0) val = read_text(io,len) # In TDS 4/5 zero length varchars are stored as a # single space to distinguish them from nulls. if(len == 1 && data_type == TdsTypes::SYBVARCHAR) return " " == val ? "" : val end return val end when TdsTypes::SYBDATETIME4, TdsTypes::SYBDATETIMN, TdsTypes::SYBDATETIME read_datetime(io,data_type) else raise "Unhandled data type: #{TdsTypes.name(data_type)} (0x#{data_type.to_s(16)})" end end |
#read_datetime(io, data_type) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/tds_packages/tds_params.rb', line 47 def read_datetime(io,data_type) case data_type when TdsTypes::SYBDATETIMN len = read_uint(io) when TdsTypes::SYBDATETIME4 len = 4; else len = 8; end case len when 0 return nil when 8 days = read_int32(io) time = read_int32(io) return Time.at(days * 24 * 3600 - TIME_DIFF + time / 300).utc when 4 days = read_int16le(io) time = read_int16le(io) return Time.at(days * 24 * 3600 + time * 60).utc end end |