ydbi 0.5.3 → 0.5.8

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/lib/dbi.rb CHANGED
@@ -9,16 +9,16 @@ module DBI; end
9
9
  #
10
10
  # Copyright (c) 2001, 2002, 2003 Michael Neumann <mneumann@ntecs.de>
11
11
  # Copyright (c) 2008 Erik Hollensbe <erik@hollensbe.org>
12
- #
12
+ #
13
13
  # All rights reserved.
14
14
  #
15
- # Redistribution and use in source and binary forms, with or without
16
- # modification, are permitted provided that the following conditions
15
+ # Redistribution and use in source and binary forms, with or without
16
+ # modification, are permitted provided that the following conditions
17
17
  # are met:
18
- # 1. Redistributions of source code must retain the above copyright
18
+ # 1. Redistributions of source code must retain the above copyright
19
19
  # notice, this list of conditions and the following disclaimer.
20
- # 2. Redistributions in binary form must reproduce the above copyright
21
- # notice, this list of conditions and the following disclaimer in the
20
+ # 2. Redistributions in binary form must reproduce the above copyright
21
+ # notice, this list of conditions and the following disclaimer in the
22
22
  # documentation and/or other materials provided with the distribution.
23
23
  # 3. The name of the author may not be used to endorse or promote products
24
24
  # derived from this software without specific prior written permission.
@@ -128,7 +128,7 @@ module DBI
128
128
 
129
129
  class << self
130
130
 
131
- # Establish a database connection.
131
+ # Establish a database connection.
132
132
  #
133
133
  # Format goes as such: "dbi:Driver:database_conn_args"
134
134
  #
@@ -179,7 +179,7 @@ module DBI
179
179
  # Return a list (of String) of the available drivers.
180
180
  #
181
181
  # NOTE:: This is non-functional for gem installations, due to the
182
- # nature of how it currently works. A better solution for
182
+ # nature of how it currently works. A better solution for
183
183
  # this will be provided in DBI 0.6.0.
184
184
  def collect_drivers
185
185
  drivers = { }
@@ -204,7 +204,7 @@ module DBI
204
204
  drivers = []
205
205
  collect_drivers.each do |key, value|
206
206
  drivers.push("dbi:#{key}:")
207
- end
207
+ end
208
208
  return drivers
209
209
  end
210
210
 
@@ -252,7 +252,7 @@ module DBI
252
252
  rescue LoadError => e1
253
253
  # see if you can find it in the path
254
254
  unless @@caseless_driver_name_map
255
- @@caseless_driver_name_map = { }
255
+ @@caseless_driver_name_map = { }
256
256
  collect_drivers.each do |key, value|
257
257
  @@caseless_driver_name_map[key.downcase] = value
258
258
  end
@@ -306,17 +306,13 @@ module DBI
306
306
  # FIXME trace
307
307
  # drh.trace(@@trace_mode, @@trace_output)
308
308
  @@driver_map[driver_name] = [drh, dbd_dr]
309
- return driver_name
309
+ return driver_name
310
310
  else
311
311
  return driver_name
312
312
  end
313
313
  end
314
314
  rescue LoadError, NameError
315
- if $SAFE >= 1
316
- raise InterfaceError, "Could not load driver (#{$!.message}). Note that in SAFE mode >= 1, driver URLs have to be case sensitive!"
317
- else
318
- raise InterfaceError, "Could not load driver (#{$!.message})"
319
- end
315
+ raise InterfaceError, "Could not load driver (#{$!.message})"
320
316
  end
321
317
 
322
318
  # Splits a DBI URL into two components - the database driver name
@@ -327,7 +323,7 @@ module DBI
327
323
  # the proper format for the URL. If it isn't correct, an Interface
328
324
  # error is raised.
329
325
  def parse_url(driver_url)
330
- if driver_url =~ /^(DBI|dbi):([^:]+)(:(.*))$/
326
+ if driver_url =~ /^(DBI|dbi):([^:]+)(:(.*))$/
331
327
  [$2, $4]
332
328
  else
333
329
  raise InterfaceError, "Invalid Data Source Name"
@@ -1,3 +1,7 @@
1
+ require 'deprecated'
2
+ require 'dbi/types'
3
+ require 'dbi/binary'
4
+ require 'dbi/typeutil'
1
5
  module DBI
2
6
  #
3
7
  # Represents a Date.
@@ -30,7 +34,7 @@ module DBI
30
34
  sprintf("%04d-%02d-%02d", @year, @month, @day)
31
35
  end
32
36
 
33
- private
37
+ private
34
38
 
35
39
  # DBI::Date.new(year = 0, month = 0, day = 0)
36
40
  # DBI::Date.new(Date)
@@ -42,10 +46,10 @@ module DBI
42
46
  def initialize(year=0, month=0, day=0)
43
47
  case year
44
48
  when ::Date
45
- @year, @month, @day = year.year, year.month, year.day
49
+ @year, @month, @day = year.year, year.month, year.day
46
50
  @original_date = year
47
51
  when ::Time
48
- @year, @month, @day = year.year, year.month, year.day
52
+ @year, @month, @day = year.year, year.month, year.day
49
53
  @original_time = year
50
54
  else
51
55
  @year, @month, @day = year, month, day
data/lib/dbi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DBI
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.8"
3
3
  end
data/readme.md CHANGED
@@ -1,3 +1,10 @@
1
+ # Release a new ydbi gem
2
+
3
+ * bundle exec rake test test_dbd test_dbi
4
+ * rake ydbd-pg:clobber_package; rake ydbd-pg:clobber_package; rake ydbi:gem ydbd-pg:gem
5
+ * bundle exec gem push pkg/ydbd-*.gem
6
+ * bundle exec gem push pkg/ydbi-*.gem
7
+
1
8
  # Description
2
9
  The DBI package is a vendor independent interface for accessing databases.
3
10
  It is similar, but not identical to, Perl's DBI module.
@@ -75,6 +82,15 @@
75
82
  gem install dbd-sqlite3
76
83
  gem install dbd-sqlite
77
84
 
85
+ If you have a non standard path of postgres use something like
86
+
87
+ gem install pg -- --with-pg-config=/usr/local/pgsql-10.1/bin/pg_config
88
+
89
+ Or if you are using bundler
90
+
91
+ bundle config build.pg --with-pg-config=/usr/local/pgsql-10.1/bin/pg_config
92
+ bundle install
93
+
78
94
  ## Without rubygems:
79
95
 
80
96
  ruby setup.rb config
@@ -3,17 +3,12 @@
3
3
  #
4
4
  # Test case for the DBI::ColumnInfo class.
5
5
  ############################################################
6
- $LOAD_PATH.unshift(Dir.pwd)
7
- $LOAD_PATH.unshift(File.dirname(Dir.pwd))
8
- $LOAD_PATH.unshift("../../lib")
9
- $LOAD_PATH.unshift("../../lib/dbi")
10
- $LOAD_PATH.unshift("lib")
11
-
12
- require "dbi/columninfo"
13
6
  require "test/unit"
7
+ require_relative "../../lib/dbi/columninfo"
14
8
 
15
9
  class TC_DBI_ColumnInfo < Test::Unit::TestCase
16
10
  def setup
11
+ super
17
12
  @colinfo = DBI::ColumnInfo.new(
18
13
  "name" => "test",
19
14
  "sql_type" => "numeric",
@@ -30,7 +25,7 @@ class TC_DBI_ColumnInfo < Test::Unit::TestCase
30
25
  indexed primary unique
31
26
  /
32
27
  end
33
-
28
+
34
29
  def test_constructor
35
30
  assert_nothing_raised{ DBI::ColumnInfo.new }
36
31
 
@@ -81,7 +76,7 @@ class TC_DBI_ColumnInfo < Test::Unit::TestCase
81
76
  assert_respond_to(@colinfo, :keys)
82
77
  assert_equal(@keys.sort, @colinfo.keys.collect { |x| x.to_s }.sort)
83
78
  end
84
-
79
+
85
80
  def test_respond_to_hash_methods
86
81
  assert_respond_to(@colinfo, :each)
87
82
  assert_respond_to(@colinfo, :empty?)
data/test/dbi/tc_date.rb CHANGED
@@ -3,15 +3,8 @@
3
3
  #
4
4
  # Test case for the DBI::Date class (currently) located in the utils.rb file.
5
5
  ##############################################################################
6
- $LOAD_PATH.unshift(Dir.pwd)
7
- $LOAD_PATH.unshift(File.dirname(Dir.pwd))
8
- $LOAD_PATH.unshift("../../lib")
9
- $LOAD_PATH.unshift("../../lib/dbi")
10
- $LOAD_PATH.unshift("lib")
11
-
12
- require 'date'
13
- require 'dbi'
14
- require 'test/unit'
6
+ require "test/unit"
7
+ require_relative "../../lib/dbi"
15
8
 
16
9
  Deprecate.set_action(proc { })
17
10
 
data/test/dbi/tc_dbi.rb CHANGED
@@ -3,14 +3,8 @@
3
3
  #
4
4
  # Test case for the DBI module (dbi.rb).
5
5
  ######################################################################
6
- $LOAD_PATH.unshift(Dir.pwd)
7
- $LOAD_PATH.unshift(File.dirname(Dir.pwd))
8
- $LOAD_PATH.unshift("../../lib")
9
- $LOAD_PATH.unshift("../../lib/dbi")
10
- $LOAD_PATH.unshift("lib")
11
-
12
- require 'dbi'
13
- require 'test/unit'
6
+ require "test/unit"
7
+ require_relative "../../lib/dbi"
14
8
 
15
9
  class TC_DBI < Test::Unit::TestCase
16
10
  def setup
@@ -22,7 +16,7 @@ class TC_DBI < Test::Unit::TestCase
22
16
  end
23
17
 
24
18
  def test_dbi_version
25
- assert_equal("0.5.2", DBI::VERSION)
19
+ assert_equal("0.5.8", DBI::VERSION)
26
20
  end
27
21
 
28
22
  def test_dbd_module
data/test/dbi/tc_row.rb CHANGED
@@ -1,16 +1,10 @@
1
1
  ######################################################################
2
2
  # tc_row.rb
3
3
  #
4
- # Test case for the DBI::Row class.
4
+ # Test case for the DBI::Row class.
5
5
  ######################################################################
6
- $LOAD_PATH.unshift(Dir.pwd)
7
- $LOAD_PATH.unshift(File.dirname(Dir.pwd))
8
- $LOAD_PATH.unshift("../../lib")
9
- $LOAD_PATH.unshift("../../lib/dbi")
10
- $LOAD_PATH.unshift("lib")
11
-
12
- require 'test/unit'
13
- require 'dbi'
6
+ require "test/unit"
7
+ require_relative "../../lib/dbi"
14
8
 
15
9
  class TC_DBI_Row < Test::Unit::TestCase
16
10
  def setup
@@ -18,7 +12,7 @@ class TC_DBI_Row < Test::Unit::TestCase
18
12
  @cols = %w/first last age/
19
13
  @coltypes = [DBI::Type::Varchar, DBI::Type::Varchar, DBI::Type::Integer]
20
14
  @row = DBI::Row.new(@cols, @coltypes, @data.clone)
21
- @row_noconv = DBI::Row.new(@cols, @coltypes, @data.clone, false)
15
+ @row_noconv = DBI::Row.new(@cols, @coltypes, @data.clone, false)
22
16
  end
23
17
 
24
18
  def teardown
@@ -46,7 +40,7 @@ class TC_DBI_Row < Test::Unit::TestCase
46
40
  assert_equal(@data, @row_noconv)
47
41
  end
48
42
  end
49
-
43
+
50
44
  # Ensure that constructor only allows Integers or Arrays (or nil)
51
45
  def test_row_constructor
52
46
  assert_nothing_raised{ DBI::Row.new(@cols, @coltypes) }
@@ -67,14 +61,14 @@ class TC_DBI_Row < Test::Unit::TestCase
67
61
  assert_equal(@data[2].to_s, @row.at(2).to_s)
68
62
  assert_equal(@data[99].to_s, @row.at(99).to_s)
69
63
  end
70
-
64
+
71
65
  # Should respond to Array and Enumerable methods
72
66
  def test_row_delegate
73
67
  assert_respond_to(@row, :length)
74
68
  assert_respond_to(@row, :each)
75
69
  assert_respond_to(@row, :grep)
76
70
  end
77
-
71
+
78
72
  def test_row_length
79
73
  assert_equal(3, @row.length)
80
74
  assert_equal(3, DBI::Row.new(@cols, @coltypes).length)
@@ -86,14 +80,14 @@ class TC_DBI_Row < Test::Unit::TestCase
86
80
  assert_equal(@data[2], @row.by_index(2).to_s)
87
81
  assert_nil(@row.by_index(3))
88
82
  end
89
-
83
+
90
84
  def test_row_data_by_field
91
85
  assert_equal @data[0], @row.by_field('first')
92
86
  assert_equal @data[1], @row.by_field('last')
93
87
  assert_equal @data[2], @row.by_field('age').to_s
94
88
  assert_equal nil, @row.by_field('unknown')
95
89
  end
96
-
90
+
97
91
  def test_row_set_values
98
92
  assert_respond_to(@row, :set_values)
99
93
  assert_nothing_raised{ @row.set_values(["John", "Doe", 23]) }
@@ -101,14 +95,14 @@ class TC_DBI_Row < Test::Unit::TestCase
101
95
  assert_equal("Doe", @row.by_index(1))
102
96
  assert_equal(23, @row.by_index(2))
103
97
  end
104
-
98
+
105
99
  def test_row_to_h
106
100
  assert_respond_to(@row, :to_h)
107
101
  assert_nothing_raised{ @row.to_h }
108
102
  assert_kind_of(Hash, @row.to_h)
109
103
  assert_equal({"first"=>"Daniel", "last"=>"Berger", "age"=>36}, @row.to_h)
110
104
  end
111
-
105
+
112
106
  def test_row_column_names
113
107
  assert_respond_to(@row, :column_names)
114
108
  assert_nothing_raised{ @row.column_names }
@@ -123,13 +117,13 @@ class TC_DBI_Row < Test::Unit::TestCase
123
117
  assert_kind_of(Array, @row.column_names)
124
118
  assert_equal(["first", "last", "age"], @row.column_names)
125
119
  end
126
-
120
+
127
121
  def test_indexing_numeric
128
- assert_equal(@data[0], @row[0])
129
- assert_equal(@data[1], @row[1])
130
- assert_equal(@data[2], @row[2].to_s)
122
+ assert_equal(@data[0], @row[0])
123
+ assert_equal(@data[1], @row[1])
124
+ assert_equal(@data[2], @row[2].to_s)
131
125
  end
132
-
126
+
133
127
  def test_indexing_string_or_symbol
134
128
  assert_equal(@data[0], @row['first'])
135
129
  assert_equal(@data[0], @row[:first])
@@ -137,7 +131,7 @@ class TC_DBI_Row < Test::Unit::TestCase
137
131
  assert_equal(@data[2], @row['age'].to_s)
138
132
  assert_equal(nil, @row['unknown'])
139
133
  end
140
-
134
+
141
135
  def test_indexing_regexp
142
136
  assert_equal(["Daniel"], @row[/first/])
143
137
  assert_equal(["Berger"], @row[/last/])
@@ -1,6 +1,5 @@
1
- $: << 'lib'
2
- require 'test/unit'
3
- require "dbi/sql"
1
+ require "test/unit"
2
+ require_relative "../../lib/dbi/sql"
4
3
 
5
4
  # ====================================================================
6
5
  class TestSqlBind < Test::Unit::TestCase
@@ -60,18 +59,18 @@ class TestSqlBind < Test::Unit::TestCase
60
59
  def test_minus_bug
61
60
  sql = "SELECT 1 - 3"
62
61
  res = "SELECT 1 - 3"
63
- assert_equal res, bind(self, sql, [])
62
+ assert_equal res, bind(self, sql, [])
64
63
  end
65
64
 
66
65
  def test_minus2
67
- sql = "SELECT * from test --Dan's query"
68
- assert_equal sql, bind(self, sql, [])
66
+ sql = "SELECT * from test --Dan's query"
67
+ assert_equal sql, bind(self, sql, [])
69
68
  end
70
69
 
71
70
  def test_slash
72
71
  sql = "SELECT 5 / 4"
73
72
  res = "SELECT 5 / 4"
74
- assert_equal res, bind(self, sql, [])
73
+ assert_equal res, bind(self, sql, [])
75
74
  end
76
75
 
77
76
  def test_much
@@ -1,6 +1,5 @@
1
- $: << 'lib'
2
- require 'test/unit'
3
- require 'dbi'
1
+ require "test/unit"
2
+ require_relative "../../lib/dbi"
4
3
 
5
4
  class TC_DBI_StatementHandle < Test::Unit::TestCase
6
5
  def test_fetch
@@ -9,7 +8,7 @@ class TC_DBI_StatementHandle < Test::Unit::TestCase
9
8
  def mock_handle.column_info; {}; end
10
9
  def mock_handle.fetch; nil; end
11
10
  sth = DBI::StatementHandle.new( mock_handle, true, true, false, true)
12
-
11
+
13
12
  10.times do
14
13
  assert_nil sth.fetch
15
14
  end
data/test/dbi/tc_time.rb CHANGED
@@ -3,14 +3,8 @@
3
3
  #
4
4
  # Test case for the DBI::Time class (currently) located in the utils.rb file.
5
5
  ##############################################################################
6
- $LOAD_PATH.unshift(Dir.pwd)
7
- $LOAD_PATH.unshift(File.dirname(Dir.pwd))
8
- $LOAD_PATH.unshift("../../lib")
9
- $LOAD_PATH.unshift("../../lib/dbi")
10
- $LOAD_PATH.unshift("lib")
11
-
12
- require 'dbi'
13
- require 'test/unit'
6
+ require "test/unit"
7
+ require_relative "../../lib/dbi"
14
8
 
15
9
  Deprecate.set_action(proc { })
16
10
 
@@ -4,17 +4,8 @@
4
4
  # Test case for the DBI::Timestamp class (currently) located in the
5
5
  # utils.rb file.
6
6
  ##############################################################################
7
- $LOAD_PATH.unshift(Dir.pwd)
8
- $LOAD_PATH.unshift(File.dirname(Dir.pwd))
9
- $LOAD_PATH.unshift("../../lib")
10
- $LOAD_PATH.unshift("../../lib/dbi")
11
- $LOAD_PATH.unshift("lib")
12
-
13
- require 'date'
14
- require 'dbi'
15
- require 'test/unit'
16
-
17
- Deprecate.set_action(proc { })
7
+ require "test/unit"
8
+ require_relative "../../lib/dbi"
18
9
 
19
10
  class TC_DBI_Date < Test::Unit::TestCase
20
11
  def setup
@@ -134,9 +125,4 @@ class TC_DBI_Date < Test::Unit::TestCase
134
125
  assert_equal(2006, @dbi_ts.year)
135
126
  end
136
127
 
137
- def teardown
138
- @date = nil
139
- @time = nil
140
- @dbi_ts = nil
141
- end
142
128
  end
data/test/dbi/tc_types.rb CHANGED
@@ -1,11 +1,5 @@
1
- $LOAD_PATH.unshift(Dir.pwd)
2
- $LOAD_PATH.unshift(File.dirname(Dir.pwd))
3
- $LOAD_PATH.unshift("../../lib")
4
- $LOAD_PATH.unshift("../../lib/dbi")
5
- $LOAD_PATH.unshift("lib")
6
-
7
- require "dbi"
8
1
  require "test/unit"
2
+ require_relative "../../lib/dbi"
9
3
 
10
4
  class MyType
11
5
  def initialize(obj)
@@ -107,7 +101,7 @@ class TC_DBI_Type < Test::Unit::TestCase
107
101
  # string coercion
108
102
  dt = DateTime.now
109
103
  assert_equal(dt.to_s, klass.parse(dt).to_s)
110
-
104
+
111
105
  t = Time.now
112
106
  assert_equal(DateTime.parse(t.to_s).to_s, klass.parse(t).to_s)
113
107
 
@@ -137,7 +131,7 @@ class TC_DBI_Type < Test::Unit::TestCase
137
131
  )
138
132
 
139
133
  # precision tests, related to ticket #27182
140
-
134
+
141
135
  # iso8601 (bypasses regex)
142
136
  [
143
137
  '2009-09-27T19:41:00-05:00',
@@ -158,7 +152,7 @@ class TC_DBI_Type < Test::Unit::TestCase
158
152
  )
159
153
 
160
154
  # unix convention (uses regex)
161
-
155
+
162
156
  [
163
157
  '2009-09-27 19:41:00 -05:00',
164
158
  '2009-09-27 19:41:00.123 -05:00'
@@ -208,7 +202,7 @@ class TC_DBI_TypeUtil < Test::Unit::TestCase
208
202
  assert_kind_of(String, cast(Time.now))
209
203
  assert_kind_of(String, cast(Date.today))
210
204
  assert_kind_of(String, cast(DateTime.now))
211
-
205
+
212
206
  obj = Time.now
213
207
  assert_equal(datecast(obj), cast(obj))
214
208
  obj = Date.today