added CHANGELOG.md
 
@@ -0,0 +1,12 @@
1
+ # v0.1.1-dev
2
+
3
+ * Bug Fixes
4
+ * Adding missing date time decoders
5
+ * Fixed issue with Bitn always returning true
6
+ * Fixed missing data return for char data decoding
7
+
8
+ * General
9
+ * Cleaned up logger functions
10
+
11
+ # v0.1.0 (2015-02-02)
12
+ * First Release
\ No newline at end of file
changed hex_metadata.config
 
@@ -7,8 +7,8 @@
7
7
[<<"lib/tds.ex">>,<<"lib/tds/binary_utils.ex">>,<<"lib/tds/connection.ex">>,
8
8
<<"lib/tds/error.ex">>,<<"lib/tds/messages.ex">>,<<"lib/tds/parameter.ex">>,
9
9
<<"lib/tds/protocol.ex">>,<<"lib/tds/result.ex">>,<<"lib/tds/tokens.ex">>,
10
- <<"lib/tds/types.ex">>,<<"lib/tds/utils.ex">>,<<"mix.exs">>,
11
- <<"README.md">>]}.
10
+ <<"lib/tds/types.ex">>,<<"lib/tds/utils.ex">>,<<"mix.exs">>,<<"README.md">>,
11
+ <<"CHANGELOG.md">>]}.
12
12
{<<"licenses">>,[<<"Apache 2.0">>]}.
13
13
{<<"links">>,#{<<"Github">> => <<"https://github.com/livehelpnow/tds">>}}.
14
14
{<<"name">>,<<"tds">>}.
 
@@ -17,4 +17,4 @@
17
17
<<"timex">> => #{<<"app">> => <<"timex">>,
18
18
<<"optional">> => nil,
19
19
<<"requirement">> => <<"~> 0.12.9">>}}}.
20
- {<<"version">>,<<"0.1.0">>}.
20
+ {<<"version">>,<<"0.1.1">>}.
changed lib/tds/messages.ex
 
@@ -250,7 +250,7 @@ defmodule Tds.Messages do
250
250
251
251
header = encode_header(0x03, data)
252
252
pak = header <> data
253
- Logger.debug "RPC #{Tds.Utils.to_hex_string pak}"
253
+ #Logger.debug "RPC #{Tds.Utils.to_hex_string pak}"
254
254
pak
255
255
end
changed lib/tds/tokens.ex
 
@@ -124,7 +124,7 @@ defmodule Tds.Tokens do
124
124
125
125
#data_type = Enum.find(Types.data_types, fn(x) -> x[:byte] == <<type>> end)
126
126
#Logger.debug "Decode Data Type: #{Tds.Utils.to_hex_string data}"
127
- Logger.debug "Decode Column: #{Tds.Utils.to_hex_string tail}"
127
+ #Logger.debug "Decode Column: #{Tds.Utils.to_hex_string tail}"
128
128
{info, tail} = Types.decode_info(tail)
129
129
{name, tail} = decode_column_name(tail)
130
130
info
 
@@ -168,7 +168,7 @@ defmodule Tds.Tokens do
168
168
169
169
defp decode_row_column(<<tail::binary>>, column) do
170
170
#data_type = column[:data_type_code]
171
- Logger.debug "Decode Row Column: #{Tds.Utils.to_hex_string tail}"
171
+ #Logger.debug "Decode Row Column: #{Tds.Utils.to_hex_string tail}"
172
172
Types.decode_data(column, tail)
173
173
end
changed lib/tds/types.ex
 
@@ -248,6 +248,8 @@
248
248
@tds_data_type_variant
249
249
] ->
250
250
<<length::signed-32, tail::binary>> = tail
251
+ col_info = col_info
252
+ |> Map.put(:length, length)
251
253
cond do
252
254
@data_type_code in [@tds_data_type_text, @tds_data_type_ntext] ->
253
255
<<collation::binary-size(5), tail::binary>> = tail
 
@@ -265,6 +267,7 @@
265
267
true -> Logger.debug "Not Implemented"
266
268
end
267
269
270
+
268
271
end
269
272
{col_info,tail}
270
273
end
 
@@ -274,7 +277,7 @@
274
277
#
275
278
276
279
def decode_data(%{data_type: :fixed, data_type_code: data_type_code, length: length}, <<tail::binary>>) do
277
- Logger.debug "Decoding Fixed Length Data: #{data_type_code}"
280
+ #Logger.debug "Decoding Fixed Length Data: #{data_type_code}"
278
281
<<value_binary::binary-size(length)-unit(8), tail::binary>> = tail
279
282
value = case data_type_code do
280
283
@tds_data_type_null ->
 
@@ -284,7 +287,6 @@
284
287
@tds_data_type_smalldatetime -> decode_smalldatetime(value_binary)
285
288
@tds_data_type_smallmoney -> decode_smallmoney(value_binary)
286
289
@tds_data_type_real ->
287
- Logger.debug "Real: #{Tds.Utils.to_hex_string value_binary}"
288
290
<<value::little-float-size(32)>> = value_binary
289
291
Float.round value, 4
290
292
@tds_data_type_datetime -> decode_datetime(value_binary)
 
@@ -299,9 +301,9 @@
299
301
end
300
302
301
303
# ByteLength Types
302
- def decode_data(%{data_reader: :bytelen}, <<0x00, tail::binary>> = data), do: {nil, tail}
304
+ def decode_data(%{data_reader: :bytelen}, <<0x00, tail::binary>>), do: {nil, tail}
303
305
def decode_data(%{data_type_code: data_type_code, data_reader: :bytelen, length: length} = data_info, <<size::unsigned-8, data::binary-size(size), tail::binary>>) do
304
- Logger.debug "Decoding Byte Length Data: #{data_type_code}"
306
+ #Logger.debug "Decoding Byte Length Data: #{data_type_code}"
305
307
value = cond do
306
308
data_type_code == @tds_data_type_daten -> decode_date(data)
307
309
data_type_code == @tds_data_type_timen -> decode_time(data_info[:scale], data)
 
@@ -316,8 +318,6 @@
316
318
4 -> <<value::little-signed-32, tail::binary>> = data
317
319
8 -> <<value::little-signed-64, tail::binary>> = data
318
320
end
319
- Logger.debug "Intn Value: #{value}"
320
- Logger.debug "Intn Tail: #{Tds.Utils.to_hex_string tail}"
321
321
value
322
322
data_type_code in [
323
323
@tds_data_type_decimal,
 
@@ -327,7 +327,7 @@
327
327
] ->
328
328
decode_decimal(data_info[:precision], data_info[:scale], data)
329
329
data_type_code == @tds_data_type_bitn ->
330
- data != 0x00
330
+ data != <<0x00>>
331
331
data_type_code == @tds_data_type_floatn ->
332
332
data = data <> tail
333
333
case length do
 
@@ -359,8 +359,8 @@
359
359
360
360
# ShortLength Types
361
361
def decode_data(%{data_reader: :shortlen}, <<0xFFFF, tail::binary>>), do: {nil, tail}
362
- def decode_data(%{data_type_code: data_type_code, data_reader: :shortlen, length: length} = data_info, <<size::little-unsigned-16, data::binary-size(size), tail::binary>>) do
363
- Logger.debug "Decoding Short Length Data: #{data_type_code}"
362
+ def decode_data(%{data_type_code: data_type_code, data_reader: :shortlen} = data_info, <<size::little-unsigned-16, data::binary-size(size), tail::binary>>) do
363
+ #Logger.debug "Decoding Short Length Data: #{data_type_code}"
364
364
value = cond do
365
365
data_type_code in [
366
366
@tds_data_type_bigvarchar,
 
@@ -390,8 +390,8 @@
390
390
# TODO PLP TYpes
391
391
# ShortLength Types
392
392
def decode_data(%{data_reader: :plp}, <<@tds_plp_null, tail::binary>>), do: {nil, tail}
393
- def decode_data(%{data_type_code: data_type_code, data_reader: :plp, length: length} = data_info, <<size::little-unsigned-64, tail::binary>>) do
394
- Logger.debug "Decoding PLP Data: #{data_type_code}"
393
+ def decode_data(%{data_type_code: data_type_code, data_reader: :plp} = data_info, <<_size::little-unsigned-64, tail::binary>>) do
394
+ #Logger.debug "Decoding PLP Data: #{data_type_code}"
395
395
{data, tail} = decode_plp_chunk(tail, <<>>)
396
396
397
397
value = cond do
 
@@ -426,8 +426,7 @@
426
426
decode_plp_chunk(tail, buf <> chunk)
427
427
end
428
428
429
- def decode_smalldatetime(<<days::little-unsigned-16, mins::little-unsigned-16>> = data) do
430
- Logger.debug "SmallDateTime: #{Tds.Utils.to_hex_string data}"
429
+ def decode_smalldatetime(<<days::little-unsigned-16, mins::little-unsigned-16>>) do
431
430
date = Date.shift(@datetime, days: days)
432
431
|> Date.shift(mins: mins)
433
432
{{date.year, date.month, date.day},{date.hour, date.minute, date.second}}
 
@@ -438,40 +437,36 @@
438
437
Float.round money, 4
439
438
end
440
439
441
- def decode_datetime(<<days::little-signed-32, sec::little-unsigned-32, tail::binary>>) do
440
+ def decode_datetime(<<days::little-signed-32, sec::little-unsigned-32>>) do
442
441
date = Date.shift(@datetime, days: days)
443
442
date = Date.shift(date, secs: (sec/300))
444
443
{{date.year, date.month, date.day}, {date.hour, date.minute, date.second}}
445
444
end
446
445
447
- def decode_money(<<money_m::little-signed-32, money_l::little-signed-32>>= data) do
448
- Logger.debug "Money: #{Tds.Utils.to_hex_string data}"
446
+ def decode_money(<<_money_m::little-signed-32, money_l::little-signed-32>>) do
449
447
money = pow10(money_l,(4 * -1))
450
- #money = money * money_m
451
448
Float.round money, 4
452
449
end
453
450
454
- def decode_time(scale, <<time::binary>>) do
455
-
451
+ def decode_time(_scale, <<_time::binary>>) do
452
+ # TODO
456
453
end
457
454
458
455
def decode_time_int() do
459
-
456
+ # TODO
460
457
end
461
458
462
- def decode_datetime2(scale, <<data::binary>>) do
463
-
459
+ def decode_datetime2(_scale, <<_data::binary>>) do
460
+ # TODO
464
461
end
465
462
466
- def decode_datetimeoffset(scale, <<data::binary>>) do
467
-
463
+ def decode_datetimeoffset(_scale, <<_data::binary>>) do
464
+ # TODO
468
465
end
469
466
470
467
def decode_date(<<days::little-size(3)-unit(8)>>) do
471
-
472
468
date = Date.from {{1, 1, 1}, {0, 0, 0}}
473
469
date = Date.shift(date, days: days)
474
- Logger.debug "Days: #{days}"
475
470
{date.year, date.month, date.day}
476
471
end
477
472
 
@@ -482,7 +477,6 @@
482
477
def decode_decimal(precision, scale, <<sign::int8, value::binary>>) do
483
478
size = byte_size(value)
484
479
<<value::little-size(size)-unit(8)>> = value
485
- IO.inspect value
486
480
d_ctx = Decimal.get_context
487
481
d_ctx = %{d_ctx | precision: precision}
488
482
Decimal.set_context d_ctx
 
@@ -496,8 +490,8 @@
496
490
end
497
491
end
498
492
499
- def decode_char(collation, <<data::binary>>) do
500
-
493
+ def decode_char(_collation, <<data::binary>>) do
494
+ data
501
495
end
502
496
503
497
def decode_nchar(<<data::binary>>) do
 
@@ -506,6 +500,7 @@
506
500
507
501
def decode_xml(data_info, <<data::binary>>) do
508
502
# TODO: Decode XML Data
503
+ nil
509
504
end
510
505
511
506
def decode_udt(%{} = data_info, <<data::binary>>) do
 
@@ -662,7 +657,7 @@
662
657
def encode_param_descriptor(%Parameter{name: name, value: value}) when is_binary(value) do
663
658
length = String.length(value)
664
659
if length <= 0, do: length = 1
665
- Logger.debug "#{name} nvarchar(#{length})"
660
+ #Logger.debug "#{name} nvarchar(#{length})"
666
661
"#{name} nvarchar(#{length})"
667
662
end
changed mix.exs
 
@@ -3,7 +3,7 @@ defmodule Tds.Mixfile do
3
3
4
4
def project do
5
5
[app: :tds,
6
- version: "0.1.0",
6
+ version: "0.1.1",
7
7
elixir: "~> 1.0.0",
8
8
deps: deps,
9
9
source_url: "https://github.com/livehelpnow/tds",