teradata-cli 0.0.1

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.
@@ -0,0 +1,153 @@
1
+ require 'teradata'
2
+ require 'test/unit'
3
+ libdir = File.dirname(__FILE__)
4
+ $LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
5
+ require 'rubyclitestutils'
6
+
7
+ class Test_Teradata_DBObject < Test::Unit::TestCase
8
+
9
+ include RubyCLITestUtils
10
+
11
+ def test_s_intern_string
12
+ t = Teradata::Table.intern('db.tab')
13
+ assert_instance_of Teradata::Table, t
14
+ assert_equal 'db.tab', t.name
15
+ end
16
+
17
+ def test_s_intern_class
18
+ t0 = Teradata::Table.new('db', 'tab')
19
+ t = Teradata::Table.intern(t0)
20
+ assert_instance_of Teradata::Table, t
21
+ assert_equal t0, t
22
+ assert_equal 'db.tab', t.name
23
+ end
24
+
25
+ def test_names_qualified
26
+ t = Teradata::Table.new('bwtest', 'tab')
27
+ assert_equal 'bwtest', t.database
28
+ assert_equal 'bwtest.tab', t.name
29
+ assert_equal 'tab', t.unqualified_name
30
+ end
31
+
32
+ def test_names_unqualified
33
+ t = Teradata::Table.new('tab')
34
+ assert_nil t.database
35
+ assert_equal 'tab', t.name
36
+ assert_equal 'tab', t.unqualified_name
37
+ end
38
+
39
+ def test_to_s
40
+ assert_equal 'db.tab', Teradata::Table.new('db', 'tab').to_s
41
+ assert_equal 'bwtest.tab', Teradata::Table.new('bwtest', 'tab').to_s
42
+ assert_equal 'tab', Teradata::Table.new('tab').to_s
43
+ end
44
+
45
+ def test_EQ
46
+ a = Teradata::Table.new('db', 'tab')
47
+ b = Teradata::Table.new('db', 'tab')
48
+ assert_equal a, a
49
+ assert_equal a, b
50
+ assert_equal b, a
51
+
52
+ # object name is different
53
+ c = Teradata::Table.new('db', 'other')
54
+ assert_not_equal a, c
55
+ assert_not_equal c, a
56
+
57
+ # database name is different
58
+ d = Teradata::Table.new('other', 'tab')
59
+ assert_not_equal a, d
60
+ assert_not_equal d, a
61
+
62
+ # database name is missing
63
+ e = Teradata::Table.new('tab')
64
+ assert_not_equal a, e
65
+ assert_not_equal e, a
66
+
67
+ # same name, but different type
68
+ v = Teradata::View.new('db', 'tab')
69
+ assert_not_equal a, v
70
+ assert_not_equal v, a
71
+ end
72
+
73
+ def test_type_char
74
+ assert_equal 'T', Teradata::Table.type_char
75
+ assert_equal 'V', Teradata::View.type_char
76
+ assert_equal 'M', Teradata::Macro.type_char
77
+ assert_equal 'N', Teradata::HashIndex.type_char
78
+ end
79
+
80
+ def test_type_name
81
+ assert_equal 'TABLE', Teradata::Table.type_name
82
+ assert_equal 'VIEW', Teradata::View.type_name
83
+ assert_equal 'MACRO', Teradata::Macro.type_name
84
+ assert_equal 'JOIN INDEX', Teradata::JoinIndex.type_name
85
+ assert_equal 'HASH INDEX', Teradata::HashIndex.type_name
86
+ assert_equal 'PROCEDURE', Teradata::Procedure.type_name
87
+ end
88
+
89
+ def test_table_size
90
+ t = Teradata::Table.new('db', 'tbl', 17, 39)
91
+ assert_equal 17, t.size
92
+ assert_equal 17, t.current_perm
93
+ assert_equal 39, t.peak_perm
94
+ end
95
+
96
+ def test_table_no_peak
97
+ t = Teradata::Table.new('db', 'tbl', 17)
98
+ assert_equal 17, t.size
99
+ assert_equal 17, t.current_perm
100
+ assert_nil t.peak_perm
101
+ end
102
+
103
+ def test_table_size_none
104
+ t = Teradata::Table.new('db', 'tbl')
105
+ assert_nil t.size
106
+ assert_nil t.current_perm
107
+ assert_nil t.peak_perm
108
+ end
109
+
110
+ def test_root_database
111
+ connect {|conn|
112
+ dbc = conn.root_database
113
+ assert_kind_of Teradata::Database, dbc
114
+ assert_instance_of Teradata::User, dbc
115
+ assert_equal 'dbc', dbc.name.downcase
116
+ assert_equal true, dbc.user?
117
+ }
118
+ end
119
+
120
+ def test_database
121
+ connect {|conn|
122
+ dbc = conn.database('dbc')
123
+ assert_instance_of Teradata::User, dbc
124
+ assert_equal 'dbc', dbc.name.downcase
125
+ assert_equal true, dbc.user?
126
+ }
127
+ end
128
+
129
+ def test_Database_hier
130
+ connect {|conn|
131
+ dbc = conn.dbc
132
+ assert_nil dbc.owner
133
+ assert_equal [], dbc.parents
134
+
135
+ cs = dbc.children
136
+ assert_equal true, (cs.size > 0)
137
+ assert_kind_of Teradata::Database, cs.first
138
+ assert_kind_of Teradata::Database, cs.first.owner
139
+ assert_equal 'dbc', cs.first.owner.name.downcase
140
+
141
+ sysdba = cs.detect {|c| c.name.downcase == 'sysdba' }
142
+ assert_instance_of Teradata::User, sysdba
143
+ assert_equal true, sysdba.user?
144
+ assert_instance_of Teradata::User, sysdba.parent
145
+
146
+ syslib = cs.detect {|c| c.name.downcase == 'syslib' }
147
+ assert_instance_of Teradata::Database, syslib
148
+ assert_equal false, syslib.user?
149
+ assert_instance_of Teradata::User, syslib.parent
150
+ }
151
+ end
152
+
153
+ end
@@ -0,0 +1,210 @@
1
+ require 'teradata'
2
+ require 'test/unit'
3
+ libdir = File.dirname(__FILE__)
4
+ $LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
5
+ require 'rubyclitestutils'
6
+
7
+ class Test_Record < Test::Unit::TestCase
8
+
9
+ include RubyCLITestUtils
10
+
11
+ def test_integers
12
+ using_table(get_table_name('ints'), 'b BYTEINT, s SMALLINT, i INTEGER, q BIGINT') {|name|
13
+ insert name, '7, 777, 777777, 777777777'
14
+ rec = select(name).first
15
+ assert_equal 4, rec.size
16
+ assert_equal 7, rec[:b]
17
+ assert_equal 777, rec[:s]
18
+ assert_equal 777777, rec[:i]
19
+ assert_equal 777777777, rec[:q]
20
+ }
21
+ end
22
+
23
+ def test_real_numbers
24
+ using_table(get_table_name('nums'), 'f FLOAT, d1 DECIMAL(3,0), d2 DECIMAL(15,1)') {|name|
25
+ insert name, '1.6, 123, 12345678901234.5'
26
+ rec = select(name).first
27
+ assert_equal 3, rec.size
28
+ assert_in_delta 1.6, rec[:f], 0.005
29
+ assert_equal '123', rec[:d1]
30
+ assert_equal '12345678901234.5', rec[:d2]
31
+ }
32
+ end
33
+
34
+ def test_strings
35
+ using_table(get_table_name('strs'), 'c CHAR(4), vc VARCHAR(4), b BYTE(4), vb VARBYTE(4)') {|name|
36
+ insert name, "'ab', 'cd', '6566'XBF, '6768'XBV"
37
+ rec = select(name).first
38
+ assert_equal 4, rec.size
39
+ assert_equal 'ab', rec[:c].rstrip
40
+ assert_equal 'cd', rec[:vc].rstrip
41
+ assert_equal 'ef', rec[:b].rstrip
42
+ assert_equal 'gh', rec[:vb].rstrip
43
+ }
44
+ end
45
+
46
+ def test_session_charset_UTF8
47
+ connect('UTF8') {
48
+ using_table(get_table_name('strs'), 'c CHAR(1) CHARACTER SET UNICODE, vc VARCHAR(1) CHARACTER SET UNICODE') {|name|
49
+ insert name, utf8("'\343\201\202', '\343\201\202'")
50
+ rec = select(name).first
51
+ assert_equal 2, rec.size
52
+ assert_equal utf8("\343\201\202"), rec[:c].rstrip
53
+ assert_equal utf8("\343\201\202"), rec[:vc].rstrip
54
+ }
55
+ }
56
+ end
57
+
58
+ # TODO Teradata::CLIError: CLI error: [EM_227] MTDP: EM_CHARNAME(227): invalid character set name specified.
59
+ #def test_session_charset_EUC
60
+ # connect('KANJIEUC_0U') {
61
+ # using_table(get_table_name('strs'), 'c CHAR(1) CHARACTER SET UNICODE, vc VARCHAR(1) CHARACTER SET UNICODE') {|name|
62
+ # insert name, euc("'\xA4\xA2', '\xA4\xA2'")
63
+ # rec = select(name).first
64
+ # assert_equal 2, rec.size
65
+ # assert_equal euc("\xA4\xA2"), rec[:c].rstrip
66
+ # assert_equal euc("\xA4\xA2"), rec[:vc].rstrip
67
+ # }
68
+ # }
69
+ #end
70
+
71
+ # TODO Teradata::CLIError: CLI error: [EM_227] MTDP: EM_CHARNAME(227): invalid character set name specified.
72
+ #def test_session_charset_SJIS
73
+ # connect('KANJISJIS_0S') {
74
+ # using_table(get_table_name('strs'), 'c CHAR(1) CHARACTER SET UNICODE, vc VARCHAR(1) CHARACTER SET UNICODE') {|name|
75
+ # insert name, sjis("'\202\240', '\202\240'")
76
+ # rec = select(name).first
77
+ # assert_equal 2, rec.size
78
+ # assert_equal sjis("\202\240"), rec[:c].rstrip
79
+ # assert_equal sjis("\202\240"), rec[:vc].rstrip
80
+ # }
81
+ # }
82
+ #end
83
+
84
+ if defined?(::Encoding) # Ruby 1.9
85
+ # with external encoding (session charset), without internal encoding
86
+ def test_encoding
87
+ connect('UTF8') {
88
+ using_table(get_table_name('strs'), 'c CHAR(1) CHARACTER SET UNICODE, vc VARCHAR(1) CHARACTER SET UNICODE') {|name|
89
+ insert name, utf8("'\343\201\202', '\343\201\202'")
90
+ rec = select(name).first
91
+ assert_equal 2, rec.size
92
+ assert_equal ::Encoding::UTF_8, rec[:c].encoding
93
+ assert_equal utf8("\343\201\202"), rec[:c].rstrip
94
+ assert_equal ::Encoding::UTF_8, rec[:vc].encoding
95
+ assert_equal utf8("\343\201\202"), rec[:vc].rstrip
96
+ }
97
+ }
98
+ end
99
+
100
+ # with external and internal encoding
101
+ def test_enc_conversion
102
+ connect('UTF8', Encoding::EUC_JP) {
103
+ using_table(get_table_name('strs'), 'c CHAR(1) CHARACTER SET UNICODE, vc VARCHAR(1) CHARACTER SET UNICODE') {|name|
104
+ insert name, euc("'\xA4\xA2', '\xA4\xA2'")
105
+ rec = select(name).first
106
+ assert_equal 2, rec.size
107
+ assert_equal ::Encoding::EUC_JP, rec[:c].encoding
108
+ assert_equal euc("\xA4\xA2"), rec[:c].rstrip
109
+ assert_equal ::Encoding::EUC_JP, rec[:vc].encoding
110
+ assert_equal euc("\xA4\xA2"), rec[:vc].rstrip
111
+ }
112
+ }
113
+ end
114
+ end
115
+
116
+ if defined?(::Encoding)
117
+ # Ruby 1.9
118
+ def utf8(str)
119
+ str.force_encoding ::Encoding::UTF_8
120
+ str
121
+ end
122
+
123
+ def euc(str)
124
+ str.force_encoding ::Encoding::EUC_JP
125
+ str
126
+ end
127
+
128
+ def sjis(str)
129
+ str.force_encoding ::Encoding::Windows_31J
130
+ str
131
+ end
132
+ else
133
+ # Ruby 1.8
134
+ def utf8(str) str end
135
+ def euc(str) str end
136
+ def sjis(str) str end
137
+ end
138
+
139
+ def test_datetimes
140
+ using_table(get_table_name('times'), 'd DATE, t TIME(1), ts TIMESTAMP(1)') {|name|
141
+ insert name, "DATE '2009-01-23', TIME '12:34:56.0', TIMESTAMP '2009-01-23 12:34:56.0'"
142
+ rec = select(name).first
143
+ assert_equal 3, rec.size
144
+ assert_equal '2009-01-23', rec[:d]
145
+ assert_equal '12:34:56.0', rec[:t]
146
+ assert_equal '2009-01-23 12:34:56.0', rec[:ts]
147
+ }
148
+ end
149
+
150
+ def test_values_at
151
+ using_table(get_table_name('t'), 'x INTEGER, y INTEGER, z INTEGER') {|name|
152
+ insert name, '1,2,3'
153
+ rec = select(name).first
154
+ assert_equal 3, rec.size
155
+ assert_equal [], rec.values_at
156
+ assert_equal [1], rec.values_at(:x)
157
+ assert_equal [2,3], rec.values_at(:y, :z)
158
+ assert_equal [3,2], rec.values_at(:z, :y)
159
+ assert_equal [1,2,3], rec.values_at(:x, :y, :z)
160
+ assert_equal [3,2,1], rec.values_at(:z, :y, :x)
161
+ assert_equal [3,1,2], rec.values_at(:z, :x, :y)
162
+ }
163
+ end
164
+
165
+ INTEGER_N = 497
166
+
167
+ def test_field
168
+ connect {
169
+ using_table(get_table_name('t'), 'x INTEGER, y INTEGER, z INTEGER') {|name|
170
+ insert name, '1,2,NULL'
171
+ rec = select(name).first
172
+ assert_equal 3, rec.size
173
+ assert_instance_of Teradata::Field, rec.field(:x)
174
+ assert_instance_of Teradata::Field, rec.field(:y)
175
+ assert_instance_of Teradata::Field, rec.field(:z)
176
+ assert_equal 1, rec.field(:x).value
177
+ assert_equal 2, rec.field(:y).value
178
+ assert_equal nil, rec.field(:z).value
179
+ assert_equal 'x', rec.field(:x).name
180
+ assert_equal 'y', rec.field(:y).name
181
+ assert_equal 'z', rec.field(:z).name
182
+ assert_equal :INTEGER_N, rec.field(:x).type
183
+ assert_equal INTEGER_N, rec.field(:x).type_code
184
+ assert_equal false, rec.field(:x).null?
185
+ assert_equal true, rec.field(:z).null?
186
+ }
187
+ }
188
+ end
189
+
190
+ def test_to_a
191
+ connect {|conn|
192
+ conn.execute_query('select 1, 2, 3') {|rs|
193
+ rs.each do |rec|
194
+ assert_equal [1,2,3], rec.to_a
195
+ end
196
+ }
197
+ }
198
+ end
199
+
200
+ def test_to_h
201
+ connect {|conn|
202
+ conn.execute_query('select 1 as a, 2 as b, 3 as c') {|rs|
203
+ rs.each do |rec|
204
+ assert_equal({"a" => 1, "b" => 2, "c" => 3}, rec.to_h)
205
+ end
206
+ }
207
+ }
208
+ end
209
+
210
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: teradata-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Giuseppe Privitera
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ruby extension for Teradata Cliv2
42
+ email:
43
+ - priviterag@gmail.com
44
+ executables: []
45
+ extensions:
46
+ - ext/teradata/cli/extconf.rb
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - COPYING
51
+ - Gemfile
52
+ - README.md
53
+ - Rakefile
54
+ - examples/query.rb
55
+ - examples/show-queryband.rb
56
+ - examples/tu/excel/excel.rb
57
+ - examples/tu/excel/fill.rb
58
+ - examples/tu/excel/template.xls
59
+ - examples/tu/tusample1.rb
60
+ - examples/tu/tusample2.rb
61
+ - examples/tu/web/bitdao.rb
62
+ - examples/tu/web/bitdao/teradata.rb
63
+ - examples/tu/web/bitweb.rb
64
+ - examples/tu/web/messages
65
+ - examples/tu/web/server.rb
66
+ - examples/tu/web/tdwalker.rb
67
+ - examples/tu/web/template/database/show
68
+ - examples/tu/web/template/footer
69
+ - examples/tu/web/template/header
70
+ - examples/update.rb
71
+ - ext/teradata/cli/cli.c
72
+ - ext/teradata/cli/extconf.rb
73
+ - lib/teradata.rb
74
+ - lib/teradata/cli.rb
75
+ - lib/teradata/cli/version.rb
76
+ - lib/teradata/connection.rb
77
+ - lib/teradata/dbobject.rb
78
+ - lib/teradata/exception.rb
79
+ - lib/teradata/utils.rb
80
+ - teradata-cli.gemspec
81
+ - test/all
82
+ - test/rubyclitestutils.rb
83
+ - test/test_connection.rb
84
+ - test/test_dbobject.rb
85
+ - test/test_record.rb
86
+ homepage: https://github.com/priviterag/teradata-cli
87
+ licenses:
88
+ - LGPL2
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.0.3
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: ruby extension for Teradata Cliv2
110
+ test_files:
111
+ - test/all
112
+ - test/rubyclitestutils.rb
113
+ - test/test_connection.rb
114
+ - test/test_dbobject.rb
115
+ - test/test_record.rb