vertica 0.12.0 → 1.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -20
  3. data/lib/vertica.rb +15 -8
  4. data/lib/vertica/column.rb +32 -13
  5. data/lib/vertica/connection.rb +143 -119
  6. data/lib/vertica/{messages/backend_messages → protocol/backend}/authentication.rb +1 -1
  7. data/lib/vertica/{messages/backend_messages → protocol/backend}/backend_key_data.rb +1 -1
  8. data/lib/vertica/{messages/backend_messages → protocol/backend}/bind_complete.rb +1 -1
  9. data/lib/vertica/{messages/backend_messages → protocol/backend}/close_complete.rb +1 -1
  10. data/lib/vertica/{messages/backend_messages → protocol/backend}/command_complete.rb +1 -1
  11. data/lib/vertica/{messages/backend_messages → protocol/backend}/copy_in_response.rb +2 -2
  12. data/lib/vertica/{messages/backend_messages → protocol/backend}/data_row.rb +1 -1
  13. data/lib/vertica/{messages/backend_messages → protocol/backend}/empty_query_response.rb +1 -1
  14. data/lib/vertica/{messages/backend_messages → protocol/backend}/error_response.rb +1 -1
  15. data/lib/vertica/{messages/backend_messages → protocol/backend}/no_data.rb +1 -1
  16. data/lib/vertica/{messages/backend_messages → protocol/backend}/notice_response.rb +6 -6
  17. data/lib/vertica/{messages/backend_messages → protocol/backend}/parameter_description.rb +2 -2
  18. data/lib/vertica/{messages/backend_messages → protocol/backend}/parameter_status.rb +3 -3
  19. data/lib/vertica/{messages/backend_messages → protocol/backend}/parse_complete.rb +1 -1
  20. data/lib/vertica/{messages/backend_messages → protocol/backend}/portal_suspended.rb +1 -1
  21. data/lib/vertica/{messages/backend_messages → protocol/backend}/ready_for_query.rb +2 -2
  22. data/lib/vertica/{messages/backend_messages → protocol/backend}/row_description.rb +9 -9
  23. data/lib/vertica/{messages/backend_messages → protocol/backend}/unknown.rb +1 -1
  24. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/bind.rb +2 -3
  25. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/cancel_request.rb +3 -4
  26. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/close.rb +3 -3
  27. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/copy_data.rb +6 -6
  28. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/copy_done.rb +1 -1
  29. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/copy_fail.rb +5 -5
  30. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/describe.rb +3 -3
  31. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/execute.rb +3 -3
  32. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/flush.rb +1 -1
  33. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/parse.rb +3 -3
  34. data/lib/vertica/protocol/frontend/password.rb +32 -0
  35. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/query.rb +3 -4
  36. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/ssl_request.rb +2 -2
  37. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/startup.rb +2 -3
  38. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/sync.rb +1 -1
  39. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/terminate.rb +1 -1
  40. data/lib/vertica/protocol/message.rb +86 -0
  41. data/lib/vertica/query.rb +63 -44
  42. data/lib/vertica/result.rb +25 -47
  43. data/lib/vertica/row.rb +44 -0
  44. data/lib/vertica/row_description.rb +102 -0
  45. data/lib/vertica/version.rb +1 -1
  46. data/test/connection.yml.example +8 -8
  47. data/test/functional/functional_connection_test.rb +178 -0
  48. data/test/functional/{query_test.rb → functional_query_test.rb} +64 -67
  49. data/test/functional/functional_value_conversion_test.rb +117 -0
  50. data/test/test_helper.rb +1 -1
  51. data/test/unit/backend_message_test.rb +57 -57
  52. data/test/unit/column_test.rb +23 -23
  53. data/test/unit/frontend_message_test.rb +5 -5
  54. data/test/unit/quoting_test.rb +16 -5
  55. data/test/unit/result_test.rb +61 -0
  56. data/test/unit/row_description_test.rb +56 -0
  57. data/test/unit/row_test.rb +31 -0
  58. data/vertica.gemspec +1 -0
  59. metadata +67 -45
  60. data/lib/vertica/messages/frontend_messages/password.rb +0 -34
  61. data/lib/vertica/messages/message.rb +0 -79
  62. data/test/functional/connection_test.rb +0 -128
  63. data/test/functional/value_conversion_test.rb +0 -88
@@ -0,0 +1,117 @@
1
+ # encoding : UTF-8
2
+ require 'test_helper'
3
+
4
+ class FunctionalValueConversionTest < Minitest::Test
5
+
6
+ def setup
7
+ @connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
8
+
9
+ @connection.query <<-SQL
10
+ CREATE TABLE IF NOT EXISTS conversions_table (
11
+ "int_field" int,
12
+ "string_field" varchar(100),
13
+ "date_field" date,
14
+ "timestamp_field" timestamp,
15
+ "timestamptz_field" timestamptz,
16
+ "time_field" time,
17
+ "interval_field" interval,
18
+ "boolean_field" boolean,
19
+ "float_field" float,
20
+ "float_zero" float,
21
+ "binary_field" varbinary,
22
+ "long_varchar_field" long varchar
23
+ )
24
+ SQL
25
+ end
26
+
27
+
28
+ def teardown
29
+ @connection.query("DROP TABLE IF EXISTS conversions_table CASCADE;")
30
+ @connection.close
31
+ end
32
+
33
+ def test_value_conversions
34
+ @connection.query <<-SQL
35
+ INSERT INTO conversions_table VALUES (
36
+ 123,
37
+ 'hello world',
38
+ '2010-01-01',
39
+ '2010-01-01 12:00:00.123456',
40
+ '2010-01-01 12:00:00 +0930',
41
+ '12:00:00',
42
+ INTERVAL '1 DAY',
43
+ TRUE,
44
+ 1.0,
45
+ 0.0,
46
+ HEX_TO_BINARY('d09fd180d0b8d0b2d0b5d1822c2068656c6c6f21'),
47
+ 'hello world'
48
+ )
49
+ SQL
50
+
51
+ result = @connection.query <<-SQL
52
+ SELECT *,
53
+ float_field / float_zero as infinity,
54
+ float_field / float_zero - float_field / float_zero as nan
55
+ FROM conversions_table LIMIT 1
56
+ SQL
57
+
58
+ assert_equal result.rows.length, 1
59
+ assert_equal [
60
+ 123,
61
+ 'hello world',
62
+ Date.parse('2010-01-01'),
63
+ Time.new(2010, 1, 1, 12, 0, BigDecimal.new("0.123456")),
64
+ Time.new(2010, 1, 1, 12, 0, 0, '+09:30'),
65
+ "12:00:00",
66
+ "1",
67
+ true,
68
+ 1.0,
69
+ 0.0,
70
+ ['d09fd180d0b8d0b2d0b5d1822c2068656c6c6f21'].pack('H*'),
71
+ 'hello world',
72
+ Float::INFINITY,
73
+ Float::NAN
74
+ ], result[0].to_a
75
+ end
76
+
77
+ def test_nil_conversions
78
+ @connection.query "INSERT INTO conversions_table VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)"
79
+ result = @connection.query "SELECT * FROM conversions_table LIMIT 1"
80
+ assert_equal result.rows.length, 1
81
+ assert_equal [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], result[0].to_a
82
+ end
83
+
84
+ def test_string_decoding
85
+ assert_equal 'åßç∂ë', @connection.query("SELECT 'åßç∂ë'").the_value
86
+ assert_equal Encoding::UTF_8, @connection.query("SELECT 'åßç∂ë'").the_value.encoding
87
+ end
88
+
89
+ def test_binary_decoding
90
+ assert_equal ['d09fd180d0b8d0b2d0b5d1822c2068656c6c6f21'].pack('H*'), @connection.query("SELECT HEX_TO_BINARY('d09fd180d0b8d0b2d0b5d1822c2068656c6c6f21')").the_value
91
+ assert_equal Encoding::BINARY, @connection.query("SELECT HEX_TO_BINARY('d09fd180d0b8d0b2d0b5d1822c2068656c6c6f21')").the_value.encoding
92
+ end
93
+
94
+ def test_timestamp_decoding_with_utc_timezone_connection
95
+ @connection.query("SET TIMEZONE TO 'UTC'")
96
+
97
+ assert_equal Time.new(2013, 1, 2, 14, 15, 16), @connection.query("SELECT '2013-01-02 14:15:16'::timestamp").the_value
98
+ assert_equal Time.new(2013, 1, 2, 19, 15, 16), @connection.query("SELECT '2013-01-02 14:15:16 America/Toronto'::timestamp").the_value
99
+ assert_equal Time.new(2013, 1, 2, 4, 45, 16), @connection.query("SELECT '2013-01-02 14:15:16 +9:30'::timestamp").the_value
100
+
101
+ assert_equal Time.new(2013, 1, 2, 14, 15, 16, '+00:00'), @connection.query("SELECT '2013-01-02 14:15:16'::timestamptz").the_value
102
+ assert_equal Time.new(2013, 1, 2, 19, 15, 16, '+00:00'), @connection.query("SELECT '2013-01-02 14:15:16 America/Toronto'::timestamptz").the_value
103
+ assert_equal Time.new(2013, 1, 2, 4, 45, 16, '+00:00'), @connection.query("SELECT '2013-01-02 14:15:16 +09:30'::timestamptz").the_value
104
+ end
105
+
106
+ def test_timestamp_decoding_with_toronto_timezone_connection
107
+ @connection.query("SET TIMEZONE TO 'America/Toronto'")
108
+
109
+ assert_equal Time.new(2013, 1, 2, 14, 15, 16), @connection.query("SELECT '2013-01-02 14:15:16'::timestamp").the_value
110
+ assert_equal Time.new(2013, 1, 2, 14, 15, 16), @connection.query("SELECT '2013-01-02 14:15:16 America/Toronto'::timestamp").the_value
111
+ assert_equal Time.new(2013, 1, 1, 23, 45, 16), @connection.query("SELECT '2013-01-02 14:15:16 +9:30'::timestamp").the_value
112
+
113
+ assert_equal Time.new(2013, 1, 2, 14, 15, 16, '-05:00'), @connection.query("SELECT '2013-01-02 14:15:16'::timestamptz").the_value
114
+ assert_equal Time.new(2013, 1, 2, 14, 15, 16, '-05:00'), @connection.query("SELECT '2013-01-02 14:15:16 America/Toronto'::timestamptz").the_value
115
+ assert_equal Time.new(2013, 1, 1, 23, 45, 16, '-05:00'), @connection.query("SELECT '2013-01-02 14:15:16 +09:30'::timestamptz").the_value
116
+ end
117
+ end
@@ -1,9 +1,9 @@
1
- require 'rubygems'
2
1
  require 'bundler/setup'
3
2
 
4
3
  require 'yaml'
5
4
  require 'minitest/autorun'
6
5
  require 'minitest/pride'
6
+ require 'mocha/mini_test'
7
7
 
8
8
  require 'vertica'
9
9
 
@@ -1,61 +1,61 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class BackendMessageTest < Minitest::Test
4
-
4
+
5
5
  def test_cleartext_authentication_message
6
- msg = Vertica::Messages::Authentication.new("\x00\x00\x00\x03")
7
- assert_equal Vertica::Messages::Authentication::CLEARTEXT_PASSWORD , msg.code
6
+ msg = Vertica::Protocol::Authentication.new("\x00\x00\x00\x03")
7
+ assert_equal Vertica::Protocol::Authentication::CLEARTEXT_PASSWORD , msg.code
8
8
  assert_nil msg.salt
9
9
  assert_nil msg.auth_data
10
10
  end
11
-
11
+
12
12
  def test_parameter_status_message
13
- msg = Vertica::Messages::ParameterStatus.new("standard_conforming_strings\x00on\x00")
13
+ msg = Vertica::Protocol::ParameterStatus.new("standard_conforming_strings\x00on\x00")
14
14
  assert_equal "standard_conforming_strings", msg.name
15
15
  assert_equal "on", msg.value
16
16
  end
17
-
17
+
18
18
  def test_backend_key_data_message
19
- msg = Vertica::Messages::BackendKeyData.new("\x00\x01\xED\xD8\x02\xC4\"\t")
19
+ msg = Vertica::Protocol::BackendKeyData.new("\x00\x01\xED\xD8\x02\xC4\"\t")
20
20
  assert_equal 126424, msg.pid
21
21
  assert_equal 46408201, msg.key
22
22
  end
23
-
23
+
24
24
  def test_ready_for_query_message
25
- msg = Vertica::Messages::ReadyForQuery.new("I")
25
+ msg = Vertica::Protocol::ReadyForQuery.new("I")
26
26
  assert_equal :no_transaction, msg.transaction_status
27
27
  end
28
-
28
+
29
29
  def test_error_response_message
30
30
  data = "SFATAL\x00C3D000\x00Mdatabase \"nonexistant_db\" does not exist\x00F/scratch_a/release/vbuild/vertica/Basics/ClientAuthentication.cpp\x00L1496\x00RClientAuthentication\x00\x00"
31
- msg = Vertica::Messages::ErrorResponse.new(data)
31
+ msg = Vertica::Protocol::ErrorResponse.new(data)
32
32
  assert_equal msg.values, {
33
- "Severity" => "FATAL",
34
- "Sqlstate" => "3D000",
35
- "Message" => "database \"nonexistant_db\" does not exist",
36
- "File" => "/scratch_a/release/vbuild/vertica/Basics/ClientAuthentication.cpp",
37
- "Line" => "1496",
33
+ "Severity" => "FATAL",
34
+ "Sqlstate" => "3D000",
35
+ "Message" => "database \"nonexistant_db\" does not exist",
36
+ "File" => "/scratch_a/release/vbuild/vertica/Basics/ClientAuthentication.cpp",
37
+ "Line" => "1496",
38
38
  "Routine" => "ClientAuthentication"
39
39
  }
40
-
40
+
41
41
  assert_equal "Severity: FATAL, Message: database \"nonexistant_db\" does not exist, Sqlstate: 3D000, Routine: ClientAuthentication, File: /scratch_a/release/vbuild/vertica/Basics/ClientAuthentication.cpp, Line: 1496", msg.error_message
42
42
  end
43
-
43
+
44
44
  def test_error_response_fields
45
45
  data = "SFATAL\x00C3D000\x00Mdatabase \"nonexistant_db\" does not exist\x00F/scratch_a/release/vbuild/vertica/Basics/ClientAuthentication.cpp\x00L1496\x00RClientAuthentication\x00\x00"
46
- msg = Vertica::Messages::ErrorResponse.new(data)
46
+ msg = Vertica::Protocol::ErrorResponse.new(data)
47
47
 
48
48
  assert_equal "FATAL", msg.severity
49
49
  assert_equal "ClientAuthentication", msg.routine
50
50
  end
51
-
52
-
51
+
52
+
53
53
  def test_notice_response_values
54
54
  data = "SINFO\x00C00000\x00Mcannot commit; no transaction in progress\x00F/scratch_a/release/vbuild/vertica/Commands/PGCall.cpp\x00L3502\x00Rprocess_vertica_transaction\x00\x00"
55
- msg = Vertica::Messages::NoticeResponse.new(data)
56
-
55
+ msg = Vertica::Protocol::NoticeResponse.new(data)
56
+
57
57
  assert_equal msg.values, {
58
- "Severity" => "INFO",
58
+ "Severity" => "INFO",
59
59
  "Sqlstate" => "00000",
60
60
  "Message" => "cannot commit; no transaction in progress",
61
61
  "File" => "/scratch_a/release/vbuild/vertica/Commands/PGCall.cpp",
@@ -63,54 +63,54 @@ class BackendMessageTest < Minitest::Test
63
63
  "Routine" => "process_vertica_transaction"
64
64
  }
65
65
  end
66
-
66
+
67
67
  def test_row_description_message
68
- msg = Vertica::Messages::RowDescription.new("\x00\x01OUTPUT\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x00\b\x00\x00\x00\b\x00\x00")
68
+ msg = Vertica::Protocol::RowDescription.new("\x00\x01OUTPUT\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x00\b\x00\x00\x00\b\x00\x00")
69
69
  assert_equal 1, msg.fields.size
70
70
  assert_equal msg.fields[0], {
71
- :name => "OUTPUT",
72
- :table_oid => 0,
73
- :attribute_number => 0,
74
- :data_type_oid => 6,
75
- :data_type_size => 8,
76
- :type_modifier => 8,
77
- :format_code => 0
71
+ :name => "OUTPUT",
72
+ :table_oid => 0,
73
+ :attribute_number => 0,
74
+ :data_type_oid => 6,
75
+ :data_type_size => 8,
76
+ :data_type_modifier => 8,
77
+ :format_code => 0
78
78
  }
79
-
80
- msg = Vertica::Messages::RowDescription.new("\x00\x02id\x00\x00\np8\x00\x01\x00\x00\x00\x06\x00\b\xFF\xFF\xFF\xFF\x00\x00name\x00\x00\np8\x00\x02\x00\x00\x00\t\xFF\xFF\x00\x00\x00h\x00\x00")
79
+
80
+ msg = Vertica::Protocol::RowDescription.new("\x00\x02id\x00\x00\np8\x00\x01\x00\x00\x00\x06\x00\b\xFF\xFF\xFF\xFF\x00\x00name\x00\x00\np8\x00\x02\x00\x00\x00\t\xFF\xFF\x00\x00\x00h\x00\x00")
81
81
  assert_equal msg.fields[0], {
82
- :name => "id",
83
- :table_oid => 684088,
84
- :attribute_number => 1,
85
- :data_type_oid => 6,
86
- :data_type_size => 8,
87
- :type_modifier => 4294967295,
88
- :format_code => 0
82
+ :name => "id",
83
+ :table_oid => 684088,
84
+ :attribute_number => 1,
85
+ :data_type_oid => 6,
86
+ :data_type_size => 8,
87
+ :data_type_modifier => 4294967295,
88
+ :format_code => 0
89
89
  }
90
90
  assert_equal msg.fields[1], {
91
- :name => "name",
92
- :table_oid => 684088,
93
- :attribute_number => 2,
94
- :data_type_oid => 9,
95
- :data_type_size => 65535,
96
- :type_modifier => 104,
97
- :format_code => 0
91
+ :name => "name",
92
+ :table_oid => 684088,
93
+ :attribute_number => 2,
94
+ :data_type_oid => 9,
95
+ :data_type_size => 65535,
96
+ :data_type_modifier => 104,
97
+ :format_code => 0
98
98
  }
99
99
  end
100
-
100
+
101
101
  def test_data_row_message
102
- msg = Vertica::Messages::DataRow.new("\x00\x01\x00\x00\x00\x011")
102
+ msg = Vertica::Protocol::DataRow.new("\x00\x01\x00\x00\x00\x011")
103
103
  assert_equal ['1'], msg.values
104
-
105
- msg = Vertica::Messages::DataRow.new("\x00\x02\x00\x00\x00\x011\x00\x00\x00\x04matt")
104
+
105
+ msg = Vertica::Protocol::DataRow.new("\x00\x02\x00\x00\x00\x011\x00\x00\x00\x04matt")
106
106
  assert_equal ['1', 'matt'], msg.values
107
-
108
- msg = Vertica::Messages::DataRow.new("\x00\a\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF")
107
+
108
+ msg = Vertica::Protocol::DataRow.new("\x00\a\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF")
109
109
  assert_equal [nil,nil,nil,nil,nil,nil,nil], msg.values
110
110
  end
111
-
111
+
112
112
  def test_command_complete_message
113
- msg = Vertica::Messages::CommandComplete.new("CREATE TABLE\x00")
113
+ msg = Vertica::Protocol::CommandComplete.new("CREATE TABLE\x00")
114
114
  assert_equal "CREATE TABLE", msg.tag
115
115
  assert_nil msg.rows
116
116
  assert_nil msg.oid
@@ -4,30 +4,30 @@ class ColumnTest < Minitest::Test
4
4
 
5
5
  def test_initialize_from_row_description
6
6
  field_description = {
7
- :name => "OUTPUT",
8
- :table_oid => 0,
9
- :attribute_number => 0,
10
- :data_type_oid => 6,
11
- :data_type_size => 8,
12
- :type_modifier => 8,
13
- :format_code => 0
7
+ :name => "OUTPUT",
8
+ :table_oid => 0,
9
+ :attribute_number => 0,
10
+ :data_type_oid => 6,
11
+ :data_type_size => 8,
12
+ :data_type_modifier => 8,
13
+ :format_code => 0
14
14
  }
15
15
 
16
16
  column = Vertica::Column.new(field_description)
17
- assert_equal :OUTPUT, column.name
17
+ assert_equal 'OUTPUT', column.name
18
18
  assert_equal :integer, column.data_type
19
- assert_equal 8, column.type_modifier
19
+ assert_equal 8, column.data_type_modifier
20
20
  end
21
21
 
22
22
  def test_unknown_type_oid
23
23
  field_description = {
24
- :name => "OUTPUT",
25
- :table_oid => 0,
26
- :attribute_number => 0,
27
- :data_type_oid => 123456,
28
- :data_type_size => 8,
29
- :type_modifier => 8,
30
- :format_code => 0
24
+ :name => "OUTPUT",
25
+ :table_oid => 0,
26
+ :attribute_number => 0,
27
+ :data_type_oid => 123456,
28
+ :data_type_size => 8,
29
+ :data_type_modifier => 8,
30
+ :format_code => 0
31
31
  }
32
32
 
33
33
  assert_raises(Vertica::Error::UnknownTypeError) { Vertica::Column.new(field_description) }
@@ -35,13 +35,13 @@ class ColumnTest < Minitest::Test
35
35
 
36
36
  def test_integer_converter
37
37
  field_description = {
38
- :name => "OUTPUT",
39
- :table_oid => 0,
40
- :attribute_number => 0,
41
- :data_type_oid => 6,
42
- :data_type_size => 8,
43
- :type_modifier => 8,
44
- :format_code => 0
38
+ :name => "OUTPUT",
39
+ :table_oid => 0,
40
+ :attribute_number => 0,
41
+ :data_type_oid => 6,
42
+ :data_type_size => 8,
43
+ :data_type_modifier => 8,
44
+ :format_code => 0
45
45
  }
46
46
 
47
47
  column = Vertica::Column.new(field_description)
@@ -3,17 +3,17 @@ require 'test_helper'
3
3
  class FrontendMessageTest < Minitest::Test
4
4
 
5
5
  def test_copy_done_message
6
- message = Vertica::Messages::CopyDone.new
6
+ message = Vertica::Protocol::CopyDone.new
7
7
  assert_equal message.to_bytes, ['c', 0, 0, 0, 4].pack('AC4')
8
8
  end
9
-
9
+
10
10
  def test_copy_fail_message
11
- message = Vertica::Messages::CopyFail.new('sad panda')
11
+ message = Vertica::Protocol::CopyFail.new('sad panda')
12
12
  assert_equal message.to_bytes, ['f', 0, 0, 0, 14, "sad panda"].pack('AC4Z*')
13
13
  end
14
-
14
+
15
15
  def test_copy_data_message
16
- message = Vertica::Messages::CopyData.new("foo|bar\n")
16
+ message = Vertica::Protocol::CopyData.new("foo|bar\n")
17
17
  assert_equal message.to_bytes, ['d', 0, 0, 0, 12, "foo|bar\n"].pack('AC4A*')
18
18
  end
19
19
  end
@@ -1,31 +1,42 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class QuotingTest < Minitest::Test
4
-
5
4
  def test_quote_identifier
6
5
  assert_equal '"test"', Vertica.quote_identifier(:test)
7
6
  assert_equal '"te""st"', Vertica.quote_identifier('te"st')
8
7
  assert_equal '"te""""st"', Vertica.quote_identifier('te""st')
9
8
  end
10
9
 
11
- def test_quote
10
+ def test_quote_strings
12
11
  assert_equal "'test'", Vertica.quote('test')
13
12
  assert_equal "'te''st'", Vertica.quote("te'st")
14
13
  assert_equal "'te''''st'", Vertica.quote("te''st")
15
14
  assert_equal "'test'", Vertica.quote(:test)
15
+ end
16
16
 
17
+ def test_quote_null_and_booleans
17
18
  assert_equal 'NULL', Vertica.quote(nil)
18
19
  assert_equal 'TRUE', Vertica.quote(true)
19
20
  assert_equal 'FALSE', Vertica.quote(false)
21
+ end
20
22
 
23
+ def test_quote_numerics
21
24
  assert_equal '1', Vertica.quote(1)
22
25
  assert_equal '1.1', Vertica.quote(1.1)
23
26
  assert_equal '1.1', Vertica.quote(BigDecimal.new('1.1'))
27
+ end
24
28
 
29
+ def test_quote_date_and_timestamps
25
30
  assert_equal "'2010-02-27'::date", Vertica.quote(Date.parse('2010-02-27'))
26
- assert_equal "'2010-02-27 12:44:25'::timestamp", Vertica.quote(DateTime.parse('2010-02-27 12:44:25'))
27
- assert_equal "'2010-02-27 12:44:25'::timestamp", Vertica.quote(Time.utc(2010,2, 27, 12, 44, 25))
28
-
31
+ assert_equal "'2010-02-27T12:44:25.000000+0000'::timestamptz", Vertica.quote(DateTime.parse('2010-02-27 12:44:25'))
32
+ assert_equal "'2010-02-27T12:44:25.000000+0800'::timestamptz", Vertica.quote(DateTime.parse('2010-02-27 12:44:25 +8'))
33
+
34
+ assert_equal "'2010-02-27T12:44:25.123400+0000'::timestamptz", Vertica.quote(Time.utc(2010,2, 27, 12, 44, BigDecimal.new('25.1234')))
35
+ assert_equal "'2010-02-27T12:44:25.123400-0500'::timestamptz", Vertica.quote(Time.new(2010,2, 27, 12, 44, BigDecimal.new('25.1234'), '-05:00'))
36
+ assert_equal "'2010-02-27T12:44:25.123400+0900'::timestamptz", Vertica.quote(Time.new(2010,2, 27, 12, 44, BigDecimal.new('25.1234'), '+09:00'))
37
+ end
38
+
39
+ def test_quote_array
29
40
  assert_equal "NULL, 1, TRUE, 'test'", Vertica.quote([nil, 1, true, 'test'])
30
41
  end
31
42
  end
@@ -0,0 +1,61 @@
1
+ require 'test_helper'
2
+
3
+ class ResultTest < Minitest::Test
4
+ def setup
5
+ @result = Vertica::Result.build(
6
+ row_description: [
7
+ Vertica::Column.new(name: 'a', data_type_oid: 6),
8
+ Vertica::Column.new(name: 'b', data_type_oid: 6),
9
+ ],
10
+ rows: [
11
+ [1, 2],
12
+ [3, 4],
13
+ ],
14
+ tag: 'SELECT'
15
+ )
16
+ end
17
+
18
+ def test_basics
19
+ assert_equal 'SELECT', @result.tag
20
+ assert_equal 2, @result.size
21
+ refute_predicate @result, :empty?
22
+ end
23
+
24
+ def test_fetch_row
25
+ assert_equal [1, 2], @result.fetch(0).to_a
26
+ assert_equal [3, 4], @result.fetch(1).to_a
27
+
28
+ assert_raises(IndexError) { @result.fetch(-1234) }
29
+ assert_raises(IndexError) { @result.fetch(1234) }
30
+ end
31
+
32
+ def test_fetch_row_with_negative_index
33
+ assert_equal @result.fetch(0), @result.fetch(-(@result.size) + 0)
34
+ assert_equal @result.fetch(1), @result.fetch(-(@result.size) + 1)
35
+ end
36
+
37
+ def test_fetch_value_by_column_index
38
+ assert_equal 1, @result.fetch(0, 0)
39
+ assert_equal 2, @result.fetch(0, 1)
40
+ assert_raises(IndexError) { @result.fetch(0, 2) }
41
+ assert_raises(IndexError) { @result.fetch(0, -3) }
42
+ end
43
+
44
+ def test_fetch_value_by_column_name
45
+ assert_equal 1, @result.fetch(0, :a)
46
+ assert_equal 2, @result.fetch(0, 'b')
47
+ assert_raises(KeyError) { @result.fetch(0, :c) }
48
+ end
49
+
50
+ def test_value
51
+ assert_equal @result.value, @result[0, 0]
52
+ end
53
+
54
+ def test_enumerable
55
+ sum_a = @result.inject(0) { |carry, row| carry + row[:a] }
56
+ sum_b = @result.inject(0) { |carry, row| carry + row[1] }
57
+
58
+ assert_equal 4, sum_a
59
+ assert_equal 6, sum_b
60
+ end
61
+ end