dbd-mysql 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -49,7 +49,7 @@ module DBI
49
49
  # Only things that extend DBI's results are documented.
50
50
  #
51
51
  module Mysql
52
- VERSION = "0.4.1"
52
+ VERSION = "0.4.2"
53
53
  DESCRIPTION = "MySQL DBI DBD, Leverages 'mysql' low-level driver"
54
54
 
55
55
  MyError = ::MysqlError
@@ -140,7 +140,7 @@ module DBI::DBD::Mysql
140
140
  'sql_type' => sql_type,
141
141
  'type_name' => type_name,
142
142
  # XXX it seems mysql counts the literal decimal point when weighing in the "length".
143
- 'precision' => col.decimals > 0 ? col.length - col.decimals - 1 : col.length,
143
+ 'precision' => type_name == "NUMERIC" ? col.length - 2 : col.length,
144
144
  'scale' => col.decimals,
145
145
  'nullable' => !col.is_not_null?,
146
146
  'indexed' => ((col.flags & indexed) != 0) ||
@@ -11,7 +11,7 @@
11
11
 
12
12
  assert(cols)
13
13
  assert_kind_of(Array, cols)
14
- assert_equal(2, cols.length)
14
+ assert_equal(4, cols.length)
15
15
 
16
16
  # the first column should always be "text_field" and have the following
17
17
  # properties:
@@ -30,19 +30,41 @@
30
30
  end
31
31
 
32
32
  assert_equal(
33
- DBI::Type::Varchar,
34
- DBI::TypeUtil.type_name_to_module(cols[0]["type_name"])
33
+ DBI::Type::Varchar.object_id,
34
+ DBI::TypeUtil.type_name_to_module(cols[0]["type_name"]).object_id
35
35
  )
36
36
 
37
37
  # the second column should always be "integer_field" and have the following
38
38
  # properties:
39
39
  assert_equal("integer_field", cols[1]["name"])
40
40
  assert(cols[1]["nullable"])
41
- assert_equal(1, cols[1]["scale"])
42
- assert_equal(2, cols[1]["precision"])
41
+ assert_equal(1, cols[2]["scale"])
42
+ assert_equal(2, cols[2]["precision"])
43
43
  assert_equal(
44
- DBI::Type::Decimal,
45
- DBI::TypeUtil.type_name_to_module(cols[1]["type_name"])
44
+ DBI::Type::Integer.object_id,
45
+ DBI::TypeUtil.type_name_to_module(cols[1]["type_name"]).object_id
46
+ )
47
+
48
+ # the second column should always be "integer_field" and have the following
49
+ # properties:
50
+ assert_equal("decimal_field", cols[2]["name"])
51
+ assert(cols[2]["nullable"])
52
+ assert_equal(1, cols[2]["scale"])
53
+ assert_equal(2, cols[2]["precision"])
54
+ assert_equal(
55
+ DBI::Type::Decimal.object_id,
56
+ DBI::TypeUtil.type_name_to_module(cols[2]["type_name"]).object_id
57
+ )
58
+
59
+ # the second column should always be "numeric_field" and have the following
60
+ # properties:
61
+ assert_equal("numeric_field", cols[3]["name"])
62
+ assert(cols[3]["nullable"])
63
+ assert_equal(6, cols[3]["scale"])
64
+ assert_equal(30, cols[3]["precision"])
65
+ assert_equal(
66
+ DBI::Type::Decimal.object_id,
67
+ DBI::TypeUtil.type_name_to_module(cols[3]["type_name"]).object_id
46
68
  )
47
69
 
48
70
  # finally, we ensure that every column in the array is a ColumnInfo
@@ -44,7 +44,7 @@
44
44
 
45
45
  assert(cols)
46
46
  assert_kind_of(Array, cols)
47
- assert_equal(2, cols.length)
47
+ assert_equal(4, cols.length)
48
48
 
49
49
  # the first column should always be "text_field" and have the following
50
50
  # properties:
@@ -61,18 +61,49 @@
61
61
  end
62
62
 
63
63
  assert_equal(
64
- DBI::Type::Varchar,
65
- DBI::TypeUtil.type_name_to_module(cols[0]["type_name"])
64
+ DBI::Type::Varchar.object_id,
65
+ DBI::TypeUtil.type_name_to_module(cols[0]["type_name"]).object_id
66
66
  )
67
67
 
68
68
  # the second column should always be "integer_field" and have the following
69
69
  # properties:
70
70
  assert_equal("integer_field", cols[1]["name"])
71
- assert_equal(1, cols[1]["scale"])
72
- assert_equal(2, cols[1]["precision"])
71
+ # if these aren't set on the field, they should not exist
72
+ # FIXME mysql does not follow this rule, neither does ODBC
73
+ if dbtype == "mysql"
74
+ assert_equal(0, cols[1]["scale"])
75
+ assert_equal(11, cols[1]["precision"])
76
+ elsif dbtype == "odbc"
77
+ assert_equal(0, cols[1]["scale"])
78
+ assert_equal(10, cols[1]["precision"])
79
+ else
80
+ assert(!cols[1]["scale"])
81
+ assert(!cols[1]["precision"])
82
+ end
83
+
84
+ assert_equal(
85
+ DBI::Type::Integer.object_id,
86
+ DBI::TypeUtil.type_name_to_module(cols[1]["type_name"]).object_id
87
+ )
88
+
89
+ # the second column should always be "integer_field" and have the following
90
+ # properties:
91
+ assert_equal("decimal_field", cols[2]["name"])
92
+ assert_equal(1, cols[2]["scale"])
93
+ assert_equal(2, cols[2]["precision"])
94
+ assert_equal(
95
+ DBI::Type::Decimal.object_id,
96
+ DBI::TypeUtil.type_name_to_module(cols[2]["type_name"]).object_id
97
+ )
98
+
99
+ # the second column should always be "numeric_field" and have the following
100
+ # properties:
101
+ assert_equal("numeric_field", cols[3]["name"])
102
+ assert_equal(6, cols[3]["scale"])
103
+ assert_equal(30, cols[3]["precision"])
73
104
  assert_equal(
74
- DBI::Type::Decimal,
75
- DBI::TypeUtil.type_name_to_module(cols[1]["type_name"])
105
+ DBI::Type::Decimal.object_id,
106
+ DBI::TypeUtil.type_name_to_module(cols[3]["type_name"]).object_id
76
107
  )
77
108
 
78
109
  cols.each { |col| assert_kind_of(DBI::ColumnInfo, col) }
@@ -25,6 +25,34 @@
25
25
  end
26
26
  end
27
27
 
28
+ def test_numeric_types
29
+ assert(@dbh.convert_types)
30
+
31
+ @sth = @dbh.prepare("insert into precision_test (text_field, integer_field, decimal_field, numeric_field) values (?, ?, ?, ?)")
32
+ assert(@sth.convert_types)
33
+ 1.step(5) do |x|
34
+ @sth.execute("poop#{x}", x, x + 0.123, x + 0.234)
35
+ end
36
+
37
+ @sth.finish
38
+
39
+ @sth = @dbh.prepare("select integer_field, decimal_field, numeric_field from precision_test")
40
+ @sth.execute
41
+ col_info = @sth.column_info
42
+ 1.step(5) do |x|
43
+ row = @sth.fetch
44
+
45
+ assert_kind_of(Integer, row[0])
46
+ assert_kind_of(BigDecimal, row[1])
47
+ assert_kind_of(BigDecimal, row[2])
48
+
49
+ # FIXME BigDecimal requires a string and some databases will pad
50
+ # decimal/numeric with constrained precision. We should account for
51
+ # this, but I'm not quite sure how yet.
52
+ end
53
+ @sth.finish
54
+ end
55
+
28
56
  # FIXME
29
57
  # Ideally, this test should be split across the DBI tests and DBD, but for
30
58
  # now testing against the DBDs really doesn't cost us anything other than
@@ -9,7 +9,7 @@ insert into names (name, age) values ('Jim', 30);
9
9
  ---
10
10
  insert into names (name, age) values ('Bob', 21);
11
11
  ---
12
- create table precision_test (text_field varchar(20) primary key not null, integer_field decimal(2,1));
12
+ create table precision_test (text_field varchar(20) primary key not null, integer_field integer, decimal_field decimal(2,1), numeric_field numeric(30,6));
13
13
  ---
14
14
  CREATE TABLE blob_test (name VARCHAR(30), data BLOB) Engine=InnoDB;
15
15
  ---
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: dbd-mysql
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.4.1
7
- date: 2008-09-27 00:00:00 -07:00
6
+ version: 0.4.2
7
+ date: 2008-11-09 00:00:00 -08:00
8
8
  summary: MySQL DBI DBD, Leverages 'mysql' low-level driver
9
9
  require_paths:
10
10
  - lib