dbd-mysql 0.3.3

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,26 @@
1
+ DBDConfig.set_testbase(:mysql, Class.new(Test::Unit::TestCase) do
2
+ def dbtype
3
+ "mysql"
4
+ end
5
+
6
+ def test_base
7
+ assert_equal(@dbh.driver_name, "Mysql")
8
+ assert_kind_of(DBI::DBD::Mysql::Database, @dbh.instance_variable_get(:@handle))
9
+ end
10
+
11
+ def set_base_dbh
12
+ config = DBDConfig.get_config["mysql"]
13
+ @dbh = DBI.connect("dbi:Mysql:"+config["dbname"], config["username"], config["password"], { })
14
+ end
15
+
16
+ def setup
17
+ set_base_dbh
18
+ DBDConfig.inject_sql(@dbh, dbtype, "dbd/mysql/up.sql")
19
+ end
20
+
21
+ def teardown
22
+ DBDConfig.inject_sql(@dbh, dbtype, "dbd/mysql/down.sql")
23
+ @dbh.disconnect
24
+ end
25
+ end
26
+ )
@@ -0,0 +1,17 @@
1
+ drop view view_names;
2
+ ---
3
+ drop table names;
4
+ ---
5
+ drop table blob_test;
6
+ ---
7
+ drop table boolean_test;
8
+ ---
9
+ drop table time_test;
10
+ ---
11
+ drop table timestamp_test;
12
+ ---
13
+ drop table bit_test;
14
+ ---
15
+ drop table field_types_test;
16
+ ---
17
+ drop table precision_test;
@@ -0,0 +1,18 @@
1
+ class TestMySQLBlob < DBDConfig.testbase(:mysql)
2
+ def test_blob_round_trip
3
+ data =(0..255).collect{|n| n.chr}.join("")
4
+ sql = "INSERT INTO blob_test (name, data) VALUES (?, ?)"
5
+
6
+ @dbh.do(sql, 'test1', DBI::Binary.new(data))
7
+ @dbh.do(sql, 'test2', data)
8
+
9
+ @dbh.prepare(sql) do |sth|
10
+ sth.execute('test3', DBI::Binary.new(data))
11
+ sth.execute('test4', data)
12
+ end
13
+
14
+ @dbh.select_all("SELECT name, data FROM blob_test") do |name, fetch_data|
15
+ assert_equal fetch_data, data
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,66 @@
1
+ class TestMysqlPatches < DBDConfig.testbase(:mysql)
2
+ def test_exception_on_aggregate
3
+ assert_nothing_raised do
4
+ sth = @dbh.prepare("select sum(age) from names")
5
+ sth.execute
6
+ row = sth.fetch
7
+ # FIXME: this is BROKEN - should not be a string, should be fixnum
8
+ assert_equal(70.0, row[0])
9
+ sth.finish
10
+ end
11
+ end
12
+
13
+ # FIXME when the spec is more solid, this should be in the general tests
14
+ def test_columns
15
+ assert_nothing_raised do
16
+ assert_equal [
17
+ {
18
+ :name =>"foo",
19
+ :default =>"1",
20
+ :primary =>true,
21
+ :scale =>nil,
22
+ :sql_type =>4,
23
+ :nullable =>false,
24
+ :indexed =>true,
25
+ :precision =>11,
26
+ :type_name =>"int",
27
+ :unique =>true
28
+ }
29
+ ], @dbh.columns("field_types_test")
30
+ end
31
+
32
+ assert_nothing_raised do
33
+ sth = @dbh.prepare("insert into field_types_test (foo) values (?)")
34
+ sth.execute(2)
35
+ sth.finish
36
+ end
37
+
38
+ assert_nothing_raised do
39
+ sth = @dbh.prepare("select * from field_types_test")
40
+ sth.execute
41
+ row = sth.fetch
42
+ columns = sth.column_info
43
+ sth.finish
44
+
45
+ assert_equal [2], row
46
+ assert_equal [
47
+ {
48
+ :name =>"foo",
49
+ :mysql_type_name =>"INT",
50
+ :mysql_max_length =>1,
51
+ :primary =>true,
52
+ :scale =>0,
53
+ :mysql_flags =>49155,
54
+ :sql_type =>4,
55
+ :nullable =>false,
56
+ :mysql_type =>3,
57
+ :indexed =>true,
58
+ :mysql_length =>11,
59
+ :precision =>11,
60
+ :type_name =>"INTEGER",
61
+ :unique =>true
62
+ }
63
+ ], columns
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,26 @@
1
+ create table names (
2
+ name varchar(255),
3
+ age integer
4
+ ) Engine=InnoDB;
5
+ ---
6
+ insert into names (name, age) values ('Joe', 19);
7
+ ---
8
+ insert into names (name, age) values ('Jim', 30);
9
+ ---
10
+ insert into names (name, age) values ('Bob', 21);
11
+ ---
12
+ create table precision_test (text_field varchar(20) primary key not null, integer_field decimal(2,1));
13
+ ---
14
+ CREATE TABLE blob_test (name VARCHAR(30), data BLOB) Engine=InnoDB;
15
+ ---
16
+ create view view_names as select * from names;
17
+ ---
18
+ create table boolean_test (num integer, mybool boolean) Engine=InnoDB;
19
+ ---
20
+ create table time_test (mytime time) Engine=InnoDB;
21
+ ---
22
+ create table timestamp_test (mytimestamp timestamp) Engine=InnoDB;
23
+ ---
24
+ create table bit_test (mybit bit) Engine=InnoDB;
25
+ ---
26
+ create table field_types_test (foo integer not null primary key default 1);
data/test/ts_dbd.rb ADDED
@@ -0,0 +1,118 @@
1
+ # figure out what tests to run
2
+ require 'yaml'
3
+ require 'test/unit/testsuite'
4
+ require 'test/unit/ui/console/testrunner'
5
+
6
+ if File.basename(Dir.pwd) == "test"
7
+ $:.unshift('../lib')
8
+ else
9
+ $:.unshift('lib')
10
+ end
11
+
12
+ module Test::Unit::Assertions
13
+ def build_message(head, template=nil, *arguments)
14
+ template += "\n" + "DATABASE: " + dbtype
15
+ template &&= template.chomp
16
+ return AssertionMessage.new(head, template, arguments)
17
+ end
18
+ end
19
+
20
+ module DBDConfig
21
+ @testbase = { }
22
+ @current_dbtype = nil
23
+
24
+ def self.get_config
25
+ config = nil
26
+
27
+ begin
28
+ config = YAML.load_file(File.join(ENV["HOME"], ".ruby-dbi.test-config.yaml"))
29
+ rescue Exception => e
30
+ config = { }
31
+ config["dbtypes"] = [ ]
32
+ end
33
+
34
+ return config
35
+ end
36
+
37
+ def self.inject_sql(dbh, dbtype, file)
38
+ # splits by --- in the file, strips newlines and the semicolons.
39
+ # this way we can still manually import the file, but use it with our
40
+ # drivers for client-independent injection.
41
+ File.open(file).read.split(/\n*---\n*/, -1).collect { |x| x.gsub!(/\n/, ''); x.sub(/;\z/, '') }.each do |stmt|
42
+ tmp = STDERR.dup
43
+ STDERR.reopen('sql.log', 'a')
44
+ begin
45
+ dbh.commit rescue nil
46
+ dbh["AutoCommit"] = true rescue nil
47
+ dbh.do(stmt)
48
+ dbh.commit unless dbtype == 'sqlite3'
49
+ rescue Exception => e
50
+ tmp.puts "Error injecting '#{stmt}' for db #{dbtype}"
51
+ tmp.puts "Error: #{e.message}"
52
+ end
53
+ STDERR.reopen(tmp)
54
+ end
55
+ end
56
+
57
+ def self.current_dbtype
58
+ @current_dbtype
59
+ end
60
+
61
+ def self.current_dbtype=(setting)
62
+ @current_dbtype = setting
63
+ end
64
+
65
+ def self.testbase(klass_name)
66
+ return @testbase[klass_name]
67
+ end
68
+
69
+ def self.set_testbase(klass_name, klass)
70
+ @testbase[klass_name] = klass
71
+ end
72
+
73
+ def self.suite
74
+ @suite ||= []
75
+ end
76
+ end
77
+
78
+ if __FILE__ == $0
79
+ Dir.chdir("..") if File.basename(Dir.pwd) == "test"
80
+ $LOAD_PATH.unshift(File.join(Dir.pwd, "lib"))
81
+ Dir.chdir("test") rescue nil
82
+
83
+ begin
84
+ require 'dbi'
85
+ rescue LoadError => e
86
+ begin
87
+ require 'rubygems'
88
+ gem 'dbi'
89
+ require 'dbi'
90
+ rescue LoadError => e
91
+ abort "DBI must already be installed or must come with this package for tests to work."
92
+ end
93
+ end
94
+
95
+ Deprecate.set_action(proc { })
96
+
97
+ config = DBDConfig.get_config
98
+
99
+ config["dbtypes"] = ENV["DBTYPES"].split(/\s+/) if ENV["DBTYPES"]
100
+
101
+ if config and config["dbtypes"]
102
+ config["dbtypes"].each do |dbtype|
103
+ unless config[dbtype]
104
+ warn "#{dbtype} is selected for testing but not configured; see test/DBD_TESTS"
105
+ next
106
+ end
107
+
108
+ # base.rb is special, see DBD_TESTS
109
+ require "dbd/#{dbtype}/base.rb"
110
+ Dir["dbd/#{dbtype}/test*.rb"].each { |file| require file }
111
+ # run the general tests
112
+ DBDConfig.current_dbtype = dbtype.to_sym
113
+ Dir["dbd/general/test*.rb"].each { |file| load file; DBDConfig.suite << @class }
114
+ end
115
+ elsif !config["dbtypes"]
116
+ warn "Please see test/DBD_TESTS for information on configuring DBD tests."
117
+ end
118
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dbd-mysql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3
5
+ platform: ruby
6
+ authors:
7
+ - Erik Hollensbe
8
+ - Christopher Maujean
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2008-08-23 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: dbi
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.4.0
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: mysql
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ version:
36
+ description: MySQL DBI DBD, Leverages 'mysql' low-level driver
37
+ email: ruby-dbi-users@rubyforge.org
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - README
44
+ - LICENSE
45
+ - ChangeLog
46
+ files:
47
+ - test/dbd/general/test_types.rb
48
+ - test/dbd/general/test_database.rb
49
+ - test/dbd/general/test_statement.rb
50
+ - test/dbd/mysql/down.sql
51
+ - test/dbd/mysql/test_patches.rb
52
+ - test/dbd/mysql/up.sql
53
+ - test/dbd/mysql/base.rb
54
+ - test/dbd/mysql/test_blob.rb
55
+ - lib/dbd/Mysql.rb
56
+ - lib/dbd/mysql/driver.rb
57
+ - lib/dbd/mysql/database.rb
58
+ - lib/dbd/mysql/statement.rb
59
+ - test/DBD_TESTS
60
+ - README
61
+ - LICENSE
62
+ - ChangeLog
63
+ has_rdoc: true
64
+ homepage: http://www.rubyforge.org/projects/ruby-dbi
65
+ post_install_message:
66
+ rdoc_options: []
67
+
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.8.0
75
+ version:
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ requirements: []
83
+
84
+ rubyforge_project: ruby-dbi
85
+ rubygems_version: 1.2.0
86
+ signing_key:
87
+ specification_version: 2
88
+ summary: MySQL DBI DBD, Leverages 'mysql' low-level driver
89
+ test_files:
90
+ - test/ts_dbd.rb