mssql 0.0.2
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.
- data/.autotest +10 -0
- data/.gitignore +2 -0
- data/.rbenv-version +1 -0
- data/Gemfile +16 -0
- data/LICENSE +22 -0
- data/README.md +190 -0
- data/Rakefile +9 -0
- data/bin/mssql +7 -0
- data/emacs/sql-ms.el +120 -0
- data/lib/command.rb +133 -0
- data/lib/command_parser.rb +28 -0
- data/lib/connection.rb +58 -0
- data/lib/controller.rb +126 -0
- data/lib/mssql.rb +22 -0
- data/lib/params_parser.rb +49 -0
- data/lib/query_output.rb +55 -0
- data/lib/simple_update.in +50 -0
- data/lib/simple_update.sql +50 -0
- data/lib/table_output.rb +71 -0
- data/lib/version.rb +3 -0
- data/mssql.gemspec +21 -0
- data/test/in_out/authors.actual +29 -0
- data/test/in_out/authors.expected +29 -0
- data/test/in_out/authors.sql +1 -0
- data/test/in_out/authors_update.actual +1 -0
- data/test/in_out/authors_update.expected +1 -0
- data/test/in_out/authors_update.sql +1 -0
- data/test/in_out/sp_help.actual +74 -0
- data/test/in_out/sp_help.expected +74 -0
- data/test/in_out/sp_help.sql +1 -0
- data/test/test_command_parser.rb +25 -0
- data/test/test_connection.rb +103 -0
- data/test/test_helper.rb +48 -0
- data/test/test_input_output.rb +68 -0
- data/test/test_table.rb +26 -0
- data/todo +20 -0
- metadata +129 -0
data/lib/table_output.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
class TableOutput
|
2
|
+
|
3
|
+
def initialize(cols, rows)
|
4
|
+
@cols = cols
|
5
|
+
@rows = rows
|
6
|
+
calc_sizes
|
7
|
+
@ascii_encoding = Encoding.find("ASCII-8BIT")
|
8
|
+
end
|
9
|
+
|
10
|
+
def calc_sizes
|
11
|
+
@sizes = []
|
12
|
+
@align = []
|
13
|
+
@cols.each_with_index do |col, index|
|
14
|
+
@sizes[index] = col.to_s.length
|
15
|
+
@align[index] = '-'
|
16
|
+
|
17
|
+
end
|
18
|
+
@rows.each do |row|
|
19
|
+
row.each_with_index do |value, index|
|
20
|
+
row[index] = value = format_value(value, index)
|
21
|
+
size = value.length
|
22
|
+
if @sizes[index] < size
|
23
|
+
@sizes[index] = size
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
#FIXME - hard coded formating for floats and times
|
30
|
+
def format_value(value, index)
|
31
|
+
if value.class == String && value.encoding.to_s == "ASCII-8BIT" #timestamps and binary data
|
32
|
+
a = value.unpack("C" * value.size)
|
33
|
+
value = "%x"*a.size % a
|
34
|
+
elsif value.class == Float || value.class == BigDecimal
|
35
|
+
value = "%.4f" % [value]
|
36
|
+
@align[index] = "+"
|
37
|
+
elsif value.class == BigDecimal
|
38
|
+
value = value.to_s('F')
|
39
|
+
@align[index] = "+"
|
40
|
+
elsif value.class == Fixnum
|
41
|
+
@align[index] = "+"
|
42
|
+
elsif value.class == Time
|
43
|
+
value = value.
|
44
|
+
strftime("%F %T").
|
45
|
+
gsub(" 00:00:00", "")
|
46
|
+
@align[index] = "+"
|
47
|
+
end
|
48
|
+
#print "#{@cols[index]}\t#{value.class}\t#{value.to_s}\n"
|
49
|
+
value.to_s
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
format = @sizes.each_with_index.map{|s, i| " %#{@align[i]}#{s}s "}.join("|")
|
54
|
+
output = []
|
55
|
+
|
56
|
+
separator = @sizes.map{|s| "-" * (s+2)}.join("+")
|
57
|
+
separator = "+#{separator}+"
|
58
|
+
output << ""
|
59
|
+
output << separator
|
60
|
+
output << "|#{format}|" % @cols
|
61
|
+
output << separator
|
62
|
+
@rows.each do |row|
|
63
|
+
output << "|#{format}|" % row
|
64
|
+
end
|
65
|
+
output << separator
|
66
|
+
output << "#{@rows.size} rows affected"
|
67
|
+
output << ""
|
68
|
+
output.join("\n")
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
data/lib/version.rb
ADDED
data/mssql.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Igor Anic"]
|
6
|
+
gem.email = ["ianic@minus5.hr"]
|
7
|
+
gem.description = "mssql server command line tool"
|
8
|
+
gem.summary = "Command line tool for connecting to Microsoft Sql Server from Mac or Linux."
|
9
|
+
gem.homepage = "http://www.minus5.hr"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "mssql"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Mssql::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency('tiny_tds' , '~> 0.5.0')
|
19
|
+
gem.add_dependency('hashie' , '~> 1.0.0')
|
20
|
+
gem.add_dependency('activesupport' , '~> 3.1.1')
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
+-------------+----------------+-------------+--------------+----------------------+----------------+-------+-------+----------+
|
3
|
+
| au_id | au_lname | au_fname | phone | address | city | state | zip | contract |
|
4
|
+
+-------------+----------------+-------------+--------------+----------------------+----------------+-------+-------+----------+
|
5
|
+
| 172-32-1176 | White | Johnson | 408 496-7223 | 10932 Bigge Rd. | Menlo Park | CA | 94025 | true |
|
6
|
+
| 213-46-8915 | Green | Marjorie | 415 986-7020 | 309 63rd St. #411 | Oakland | CA | 94618 | true |
|
7
|
+
| 238-95-7766 | Carson | Cheryl | 415 548-7723 | 589 Darwin Ln. | Berkeley | CA | 94705 | true |
|
8
|
+
| 267-41-2394 | O'Leary | Michael | 408 286-2428 | 22 Cleveland Av. #14 | San Jose | CA | 95128 | true |
|
9
|
+
| 274-80-9391 | Straight | Dean | 415 834-2919 | 5420 College Av. | Oakland | CA | 94609 | true |
|
10
|
+
| 341-22-1782 | Smith | Meander | 913 843-0462 | 10 Mississippi Dr. | Lawrence | KS | 66044 | false |
|
11
|
+
| 409-56-7008 | Bennet | Abraham | 415 658-9932 | 6223 Bateman St. | Berkeley | CA | 94705 | true |
|
12
|
+
| 427-17-2319 | Dull | Ann | 415 836-7128 | 3410 Blonde St. | Palo Alto | CA | 94301 | true |
|
13
|
+
| 472-27-2349 | Gringlesby | Burt | 707 938-6445 | PO Box 792 | Covelo | CA | 95428 | true |
|
14
|
+
| 486-29-1786 | Locksley | Charlene | 415 585-4620 | 18 Broadway Av. | San Francisco | CA | 94130 | true |
|
15
|
+
| 527-72-3246 | Greene | Morningstar | 615 297-2723 | 22 Graybar House Rd. | Nashville | TN | 37215 | false |
|
16
|
+
| 648-92-1872 | Blotchet-Halls | Reginald | 503 745-6402 | 55 Hillsdale Bl. | Corvallis | OR | 97330 | true |
|
17
|
+
| 672-71-3249 | Yokomoto | Akiko | 415 935-4228 | 3 Silver Ct. | Walnut Creek | CA | 94595 | true |
|
18
|
+
| 712-45-1867 | del Castillo | Innes | 615 996-8275 | 2286 Cram Pl. #86 | Ann Arbor | MI | 48105 | true |
|
19
|
+
| 722-51-5454 | DeFrance | Michel | 219 547-9982 | 3 Balding Pl. | Gary | IN | 46403 | true |
|
20
|
+
| 724-08-9931 | Stringer | Dirk | 415 843-2991 | 5420 Telegraph Av. | Oakland | CA | 94609 | false |
|
21
|
+
| 724-80-9391 | MacFeather | Stearns | 415 354-7128 | 44 Upland Hts. | Oakland | CA | 94612 | true |
|
22
|
+
| 756-30-7391 | Karsen | Livia | 415 534-9219 | 5720 McAuley St. | Oakland | CA | 94609 | true |
|
23
|
+
| 807-91-6654 | Panteley | Sylvia | 301 946-8853 | 1956 Arlington Pl. | Rockville | MD | 20853 | true |
|
24
|
+
| 846-92-7186 | Hunter | Sheryl | 415 836-7128 | 3410 Blonde St. | Palo Alto | CA | 94301 | true |
|
25
|
+
| 893-72-1158 | McBadden | Heather | 707 448-4982 | 301 Putnam | Vacaville | CA | 95688 | false |
|
26
|
+
| 899-46-2035 | Ringer | Anne | 801 826-0752 | 67 Seventh Av. | Salt Lake City | UT | 84152 | true |
|
27
|
+
| 998-72-3567 | Ringer | Albert | 801 826-0752 | 67 Seventh Av. | Salt Lake City | UT | 84152 | true |
|
28
|
+
+-------------+----------------+-------------+--------------+----------------------+----------------+-------+-------+----------+
|
29
|
+
23 rows affected
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
+-------------+----------------+-------------+--------------+----------------------+----------------+-------+-------+----------+
|
3
|
+
| au_id | au_lname | au_fname | phone | address | city | state | zip | contract |
|
4
|
+
+-------------+----------------+-------------+--------------+----------------------+----------------+-------+-------+----------+
|
5
|
+
| 172-32-1176 | White | Johnson | 408 496-7223 | 10932 Bigge Rd. | Menlo Park | CA | 94025 | true |
|
6
|
+
| 213-46-8915 | Green | Marjorie | 415 986-7020 | 309 63rd St. #411 | Oakland | CA | 94618 | true |
|
7
|
+
| 238-95-7766 | Carson | Cheryl | 415 548-7723 | 589 Darwin Ln. | Berkeley | CA | 94705 | true |
|
8
|
+
| 267-41-2394 | O'Leary | Michael | 408 286-2428 | 22 Cleveland Av. #14 | San Jose | CA | 95128 | true |
|
9
|
+
| 274-80-9391 | Straight | Dean | 415 834-2919 | 5420 College Av. | Oakland | CA | 94609 | true |
|
10
|
+
| 341-22-1782 | Smith | Meander | 913 843-0462 | 10 Mississippi Dr. | Lawrence | KS | 66044 | false |
|
11
|
+
| 409-56-7008 | Bennet | Abraham | 415 658-9932 | 6223 Bateman St. | Berkeley | CA | 94705 | true |
|
12
|
+
| 427-17-2319 | Dull | Ann | 415 836-7128 | 3410 Blonde St. | Palo Alto | CA | 94301 | true |
|
13
|
+
| 472-27-2349 | Gringlesby | Burt | 707 938-6445 | PO Box 792 | Covelo | CA | 95428 | true |
|
14
|
+
| 486-29-1786 | Locksley | Charlene | 415 585-4620 | 18 Broadway Av. | San Francisco | CA | 94130 | true |
|
15
|
+
| 527-72-3246 | Greene | Morningstar | 615 297-2723 | 22 Graybar House Rd. | Nashville | TN | 37215 | false |
|
16
|
+
| 648-92-1872 | Blotchet-Halls | Reginald | 503 745-6402 | 55 Hillsdale Bl. | Corvallis | OR | 97330 | true |
|
17
|
+
| 672-71-3249 | Yokomoto | Akiko | 415 935-4228 | 3 Silver Ct. | Walnut Creek | CA | 94595 | true |
|
18
|
+
| 712-45-1867 | del Castillo | Innes | 615 996-8275 | 2286 Cram Pl. #86 | Ann Arbor | MI | 48105 | true |
|
19
|
+
| 722-51-5454 | DeFrance | Michel | 219 547-9982 | 3 Balding Pl. | Gary | IN | 46403 | true |
|
20
|
+
| 724-08-9931 | Stringer | Dirk | 415 843-2991 | 5420 Telegraph Av. | Oakland | CA | 94609 | false |
|
21
|
+
| 724-80-9391 | MacFeather | Stearns | 415 354-7128 | 44 Upland Hts. | Oakland | CA | 94612 | true |
|
22
|
+
| 756-30-7391 | Karsen | Livia | 415 534-9219 | 5720 McAuley St. | Oakland | CA | 94609 | true |
|
23
|
+
| 807-91-6654 | Panteley | Sylvia | 301 946-8853 | 1956 Arlington Pl. | Rockville | MD | 20853 | true |
|
24
|
+
| 846-92-7186 | Hunter | Sheryl | 415 836-7128 | 3410 Blonde St. | Palo Alto | CA | 94301 | true |
|
25
|
+
| 893-72-1158 | McBadden | Heather | 707 448-4982 | 301 Putnam | Vacaville | CA | 95688 | false |
|
26
|
+
| 899-46-2035 | Ringer | Anne | 801 826-0752 | 67 Seventh Av. | Salt Lake City | UT | 84152 | true |
|
27
|
+
| 998-72-3567 | Ringer | Albert | 801 826-0752 | 67 Seventh Av. | Salt Lake City | UT | 84152 | true |
|
28
|
+
+-------------+----------------+-------------+--------------+----------------------+----------------+-------+-------+----------+
|
29
|
+
23 rows affected
|
@@ -0,0 +1 @@
|
|
1
|
+
select * from authors
|
@@ -0,0 +1 @@
|
|
1
|
+
2 rows affected
|
@@ -0,0 +1 @@
|
|
1
|
+
2 rows affected
|
@@ -0,0 +1 @@
|
|
1
|
+
update authors set state = state where state = 'UT'
|
@@ -0,0 +1,74 @@
|
|
1
|
+
|
2
|
+
+---------+-------+------------+---------------------+
|
3
|
+
| Name | Owner | Type | Created_datetime |
|
4
|
+
+---------+-------+------------+---------------------+
|
5
|
+
| authors | dbo | user table | 2009-12-12 17:32:23 |
|
6
|
+
+---------+-------+------------+---------------------+
|
7
|
+
1 rows affected
|
8
|
+
|
9
|
+
+-------------+---------+----------+--------+-------+-------+----------+--------------------+----------------------+----------------+
|
10
|
+
| Column_name | Type | Computed | Length | Prec | Scale | Nullable | TrimTrailingBlanks | FixedLenNullInSource | Collation |
|
11
|
+
+-------------+---------+----------+--------+-------+-------+----------+--------------------+----------------------+----------------+
|
12
|
+
| au_id | id | no | 11 | | | no | no | no | Croatian_CI_AS |
|
13
|
+
| au_lname | varchar | no | 40 | | | no | no | no | Croatian_CI_AS |
|
14
|
+
| au_fname | varchar | no | 20 | | | no | no | no | Croatian_CI_AS |
|
15
|
+
| phone | char | no | 12 | | | no | no | no | Croatian_CI_AS |
|
16
|
+
| address | varchar | no | 40 | | | yes | no | yes | Croatian_CI_AS |
|
17
|
+
| city | varchar | no | 20 | | | yes | no | yes | Croatian_CI_AS |
|
18
|
+
| state | char | no | 2 | | | yes | no | yes | Croatian_CI_AS |
|
19
|
+
| zip | char | no | 5 | | | yes | no | yes | Croatian_CI_AS |
|
20
|
+
| contract | bit | no | 1 | | | no | (n/a) | (n/a) | |
|
21
|
+
+-------------+---------+----------+--------+-------+-------+----------+--------------------+----------------------+----------------+
|
22
|
+
9 rows affected
|
23
|
+
|
24
|
+
+-----------------------------+------+-----------+---------------------+
|
25
|
+
| Identity | Seed | Increment | Not For Replication |
|
26
|
+
+-----------------------------+------+-----------+---------------------+
|
27
|
+
| No identity column defined. | | | |
|
28
|
+
+-----------------------------+------+-----------+---------------------+
|
29
|
+
1 rows affected
|
30
|
+
|
31
|
+
+-------------------------------+
|
32
|
+
| RowGuidCol |
|
33
|
+
+-------------------------------+
|
34
|
+
| No rowguidcol column defined. |
|
35
|
+
+-------------------------------+
|
36
|
+
1 rows affected
|
37
|
+
|
38
|
+
+---------------------------+
|
39
|
+
| Data_located_on_filegroup |
|
40
|
+
+---------------------------+
|
41
|
+
| PRIMARY |
|
42
|
+
+---------------------------+
|
43
|
+
1 rows affected
|
44
|
+
|
45
|
+
+---------------+---------------------------------------------------+--------------------+
|
46
|
+
| index_name | index_description | index_keys |
|
47
|
+
+---------------+---------------------------------------------------+--------------------+
|
48
|
+
| aunmind | nonclustered located on PRIMARY | au_lname, au_fname |
|
49
|
+
| UPKCL_auidind | clustered, unique, primary key located on PRIMARY | au_id |
|
50
|
+
+---------------+---------------------------------------------------+--------------------+
|
51
|
+
2 rows affected
|
52
|
+
|
53
|
+
+-------------------------+------------------------------+---------------+---------------+----------------+------------------------+------------------------------------------------------------------+
|
54
|
+
| constraint_type | constraint_name | delete_action | update_action | status_enabled | status_for_replication | constraint_keys |
|
55
|
+
+-------------------------+------------------------------+---------------+---------------+----------------+------------------------+------------------------------------------------------------------+
|
56
|
+
| CHECK on column au_id | CK__authors__au_id__7D78A4E7 | (n/a) | (n/a) | Enabled | Is_For_Replication | ([au_id] like '[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]') |
|
57
|
+
| CHECK on column zip | CK__authors__zip__7F60ED59 | (n/a) | (n/a) | Enabled | Is_For_Replication | ([zip] like '[0-9][0-9][0-9][0-9][0-9]') |
|
58
|
+
| DEFAULT on column phone | DF__authors__phone__7E6CC920 | (n/a) | (n/a) | (n/a) | (n/a) | ('UNKNOWN') |
|
59
|
+
| PRIMARY KEY (clustered) | UPKCL_auidind | (n/a) | (n/a) | (n/a) | (n/a) | au_id |
|
60
|
+
+-------------------------+------------------------------+---------------+---------------+----------------+------------------------+------------------------------------------------------------------+
|
61
|
+
4 rows affected
|
62
|
+
|
63
|
+
+------------------------------------------------------+
|
64
|
+
| Table is referenced by foreign key |
|
65
|
+
+------------------------------------------------------+
|
66
|
+
| pubs.dbo.titleauthor: FK__titleauth__au_id__0AD2A005 |
|
67
|
+
+------------------------------------------------------+
|
68
|
+
1 rows affected
|
69
|
+
|
70
|
+
+------------------------------+
|
71
|
+
| Table is referenced by views |
|
72
|
+
+------------------------------+
|
73
|
+
+------------------------------+
|
74
|
+
0 rows affected
|
@@ -0,0 +1,74 @@
|
|
1
|
+
|
2
|
+
+---------+-------+------------+---------------------+
|
3
|
+
| Name | Owner | Type | Created_datetime |
|
4
|
+
+---------+-------+------------+---------------------+
|
5
|
+
| authors | dbo | user table | 2009-12-12 17:32:23 |
|
6
|
+
+---------+-------+------------+---------------------+
|
7
|
+
1 rows affected
|
8
|
+
|
9
|
+
+-------------+---------+----------+--------+-------+-------+----------+--------------------+----------------------+----------------+
|
10
|
+
| Column_name | Type | Computed | Length | Prec | Scale | Nullable | TrimTrailingBlanks | FixedLenNullInSource | Collation |
|
11
|
+
+-------------+---------+----------+--------+-------+-------+----------+--------------------+----------------------+----------------+
|
12
|
+
| au_id | id | no | 11 | | | no | no | no | Croatian_CI_AS |
|
13
|
+
| au_lname | varchar | no | 40 | | | no | no | no | Croatian_CI_AS |
|
14
|
+
| au_fname | varchar | no | 20 | | | no | no | no | Croatian_CI_AS |
|
15
|
+
| phone | char | no | 12 | | | no | no | no | Croatian_CI_AS |
|
16
|
+
| address | varchar | no | 40 | | | yes | no | yes | Croatian_CI_AS |
|
17
|
+
| city | varchar | no | 20 | | | yes | no | yes | Croatian_CI_AS |
|
18
|
+
| state | char | no | 2 | | | yes | no | yes | Croatian_CI_AS |
|
19
|
+
| zip | char | no | 5 | | | yes | no | yes | Croatian_CI_AS |
|
20
|
+
| contract | bit | no | 1 | | | no | (n/a) | (n/a) | |
|
21
|
+
+-------------+---------+----------+--------+-------+-------+----------+--------------------+----------------------+----------------+
|
22
|
+
9 rows affected
|
23
|
+
|
24
|
+
+-----------------------------+------+-----------+---------------------+
|
25
|
+
| Identity | Seed | Increment | Not For Replication |
|
26
|
+
+-----------------------------+------+-----------+---------------------+
|
27
|
+
| No identity column defined. | | | |
|
28
|
+
+-----------------------------+------+-----------+---------------------+
|
29
|
+
1 rows affected
|
30
|
+
|
31
|
+
+-------------------------------+
|
32
|
+
| RowGuidCol |
|
33
|
+
+-------------------------------+
|
34
|
+
| No rowguidcol column defined. |
|
35
|
+
+-------------------------------+
|
36
|
+
1 rows affected
|
37
|
+
|
38
|
+
+---------------------------+
|
39
|
+
| Data_located_on_filegroup |
|
40
|
+
+---------------------------+
|
41
|
+
| PRIMARY |
|
42
|
+
+---------------------------+
|
43
|
+
1 rows affected
|
44
|
+
|
45
|
+
+---------------+---------------------------------------------------+--------------------+
|
46
|
+
| index_name | index_description | index_keys |
|
47
|
+
+---------------+---------------------------------------------------+--------------------+
|
48
|
+
| aunmind | nonclustered located on PRIMARY | au_lname, au_fname |
|
49
|
+
| UPKCL_auidind | clustered, unique, primary key located on PRIMARY | au_id |
|
50
|
+
+---------------+---------------------------------------------------+--------------------+
|
51
|
+
2 rows affected
|
52
|
+
|
53
|
+
+-------------------------+------------------------------+---------------+---------------+----------------+------------------------+------------------------------------------------------------------+
|
54
|
+
| constraint_type | constraint_name | delete_action | update_action | status_enabled | status_for_replication | constraint_keys |
|
55
|
+
+-------------------------+------------------------------+---------------+---------------+----------------+------------------------+------------------------------------------------------------------+
|
56
|
+
| CHECK on column au_id | CK__authors__au_id__7D78A4E7 | (n/a) | (n/a) | Enabled | Is_For_Replication | ([au_id] like '[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]') |
|
57
|
+
| CHECK on column zip | CK__authors__zip__7F60ED59 | (n/a) | (n/a) | Enabled | Is_For_Replication | ([zip] like '[0-9][0-9][0-9][0-9][0-9]') |
|
58
|
+
| DEFAULT on column phone | DF__authors__phone__7E6CC920 | (n/a) | (n/a) | (n/a) | (n/a) | ('UNKNOWN') |
|
59
|
+
| PRIMARY KEY (clustered) | UPKCL_auidind | (n/a) | (n/a) | (n/a) | (n/a) | au_id |
|
60
|
+
+-------------------------+------------------------------+---------------+---------------+----------------+------------------------+------------------------------------------------------------------+
|
61
|
+
4 rows affected
|
62
|
+
|
63
|
+
+------------------------------------------------------+
|
64
|
+
| Table is referenced by foreign key |
|
65
|
+
+------------------------------------------------------+
|
66
|
+
| pubs.dbo.titleauthor: FK__titleauth__au_id__0AD2A005 |
|
67
|
+
+------------------------------------------------------+
|
68
|
+
1 rows affected
|
69
|
+
|
70
|
+
+------------------------------+
|
71
|
+
| Table is referenced by views |
|
72
|
+
+------------------------------+
|
73
|
+
+------------------------------+
|
74
|
+
0 rows affected
|
@@ -0,0 +1 @@
|
|
1
|
+
sp_help authors
|
@@ -0,0 +1,25 @@
|
|
1
|
+
$: << File.join(File.dirname(__FILE__))
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class TestCommandParser < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
def test_find
|
7
|
+
cp = CommandParser.new(' .find nesto')
|
8
|
+
assert_equal :find, cp.command
|
9
|
+
assert_equal ["nesto"], cp.params
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_explain
|
13
|
+
cp = CommandParser.new(' .explain dbo.authors')
|
14
|
+
assert_equal :explain, cp.command
|
15
|
+
assert_equal ["dbo", "authors"], cp.params
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_use
|
19
|
+
cp = CommandParser.new(' .use connection2')
|
20
|
+
assert_equal :use, cp.command
|
21
|
+
assert_equal ["connection2"], cp.params
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestConnection < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@authors_first_row = ["172-32-1176",
|
7
|
+
"White",
|
8
|
+
"Johnson",
|
9
|
+
"408 496-7223",
|
10
|
+
"10932 Bigge Rd.",
|
11
|
+
"Menlo Park",
|
12
|
+
"CA",
|
13
|
+
"94025",
|
14
|
+
true]
|
15
|
+
@authors_columns = [:au_id,
|
16
|
+
:au_lname,
|
17
|
+
:au_fname,
|
18
|
+
:phone,
|
19
|
+
:address,
|
20
|
+
:city,
|
21
|
+
:state,
|
22
|
+
:zip,
|
23
|
+
:contract]
|
24
|
+
|
25
|
+
conn1 = {
|
26
|
+
:username => 'ianic',
|
27
|
+
:password => 'ianic',
|
28
|
+
:host => 'iow',
|
29
|
+
:database => "pubs"}
|
30
|
+
conn2 = {
|
31
|
+
:name => 'conn2_name',
|
32
|
+
:username => 'ianic2',
|
33
|
+
:password => 'ianic2',
|
34
|
+
:host => 'iow',
|
35
|
+
:database => "pubs"}
|
36
|
+
options = Hashie::Mash.new({:default_connection => conn1, :conn1 => conn1, :conn2 => conn2})
|
37
|
+
@name = ''
|
38
|
+
@connection = Connection.new options, Proc.new {|name| @name = name}
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_simple_select
|
42
|
+
result = @connection.exec "select * from authors"
|
43
|
+
|
44
|
+
assert_equal 23, result.rows.size
|
45
|
+
assert_equal 9, result.columns.size
|
46
|
+
assert_equal @authors_columns, result.columns
|
47
|
+
assert_equal @authors_first_row, result.rows.first
|
48
|
+
assert_equal 23, result.affected
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_two_results
|
52
|
+
result = @connection.exec "select * from authors order by au_id; select * from employee"
|
53
|
+
|
54
|
+
assert_equal 2, result.columns.size
|
55
|
+
assert_equal 2, result.rows.size
|
56
|
+
assert_equal @authors_columns, result.columns[0]
|
57
|
+
assert_equal @authors_first_row, result.rows[0].first
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_no_results
|
61
|
+
result = @connection.exec "update authors set phone = phone where au_id in ('172-32-1176', '213-46-8915', '238-95-7766')"
|
62
|
+
assert_equal 3, result.affected
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_results_and_no_results
|
66
|
+
result = @connection.exec "select * from authors;
|
67
|
+
update authors set phone = phone where au_id in ('172-32-1176', '213-46-8915', '238-95-7766');
|
68
|
+
select * from employee"
|
69
|
+
|
70
|
+
assert_equal 2, result.columns.size
|
71
|
+
assert_equal 2, result.rows.size
|
72
|
+
assert_equal @authors_columns, result.columns[0]
|
73
|
+
assert_equal @authors_first_row, result.rows[0].first
|
74
|
+
assert_equal 43, result.affected
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_error
|
78
|
+
result = @connection.exec "select * from pero"
|
79
|
+
assert_equal "Invalid object name 'pero'.", result.error
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_update_and_error
|
83
|
+
result = @connection.exec "update authors set phone = phone where au_id in ('172-32-1176', '213-46-8915', '238-95-7766'); select * from pero;"
|
84
|
+
assert_equal "Invalid object name 'pero'.", result.error
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_change_connection
|
88
|
+
assert @connection.use :conn2
|
89
|
+
assert_equal 23, @connection.exec("select * from authors").rows.size
|
90
|
+
assert @connection.use :conn1
|
91
|
+
assert_equal 23, @connection.exec("select * from authors").rows.size
|
92
|
+
assert_equal "ianic@iow", @connection.name
|
93
|
+
|
94
|
+
assert !@connection.use(:unknown)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_connection_name
|
98
|
+
assert_equal 'ianic@iow', @name
|
99
|
+
assert @connection.use :conn2
|
100
|
+
assert_equal 'conn2_name', @name
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|