ydbi 0.5.8 → 0.6.0

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.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +3 -0
  3. data/.github/workflows/ruby.yml +65 -0
  4. data/.gitignore +19 -0
  5. data/ChangeLog +8 -0
  6. data/Gemfile +5 -0
  7. data/Rakefile +14 -0
  8. data/TODO +44 -0
  9. data/bench/bench.rb +79 -0
  10. data/build/rake_task_lib.rb +186 -0
  11. data/devenv.lock +228 -0
  12. data/devenv.nix +55 -0
  13. data/devenv.yaml +8 -0
  14. data/doc/DBD_SPEC.rdoc +88 -0
  15. data/doc/DBI_SPEC.rdoc +157 -0
  16. data/doc/homepage/contact.html +62 -0
  17. data/doc/homepage/development.html +124 -0
  18. data/doc/homepage/index.html +83 -0
  19. data/doc/homepage/ruby-dbi.css +91 -0
  20. data/lib/dbd/Mysql.rb +137 -0
  21. data/lib/dbd/ODBC.rb +89 -0
  22. data/lib/dbd/Pg.rb +189 -0
  23. data/lib/dbd/SQLite.rb +97 -0
  24. data/lib/dbd/SQLite3.rb +124 -0
  25. data/lib/dbd/mysql/database.rb +405 -0
  26. data/lib/dbd/mysql/driver.rb +125 -0
  27. data/lib/dbd/mysql/statement.rb +188 -0
  28. data/lib/dbd/odbc/database.rb +128 -0
  29. data/lib/dbd/odbc/driver.rb +38 -0
  30. data/lib/dbd/odbc/statement.rb +137 -0
  31. data/lib/dbd/pg/database.rb +508 -0
  32. data/lib/dbd/pg/exec.rb +47 -0
  33. data/lib/dbd/pg/statement.rb +160 -0
  34. data/lib/dbd/pg/tuples.rb +121 -0
  35. data/lib/dbd/pg/type.rb +209 -0
  36. data/lib/dbd/sqlite/database.rb +151 -0
  37. data/lib/dbd/sqlite/statement.rb +125 -0
  38. data/lib/dbd/sqlite3/database.rb +201 -0
  39. data/lib/dbd/sqlite3/statement.rb +78 -0
  40. data/lib/dbi/version.rb +1 -1
  41. data/prototypes/types2.rb +237 -0
  42. data/readme.md +3 -4
  43. data/setup.rb +1585 -0
  44. data/test/DBD_TESTS +50 -0
  45. data/test/TESTING +16 -0
  46. data/test/dbd/general/test_database.rb +206 -0
  47. data/test/dbd/general/test_statement.rb +325 -0
  48. data/test/dbd/general/test_types.rb +295 -0
  49. data/test/dbd/mysql/base.rb +26 -0
  50. data/test/dbd/mysql/down.sql +19 -0
  51. data/test/dbd/mysql/test_blob.rb +18 -0
  52. data/test/dbd/mysql/test_new_methods.rb +7 -0
  53. data/test/dbd/mysql/test_patches.rb +111 -0
  54. data/test/dbd/mysql/up.sql +28 -0
  55. data/test/dbd/odbc/base.rb +30 -0
  56. data/test/dbd/odbc/down.sql +19 -0
  57. data/test/dbd/odbc/test_new_methods.rb +12 -0
  58. data/test/dbd/odbc/test_ping.rb +10 -0
  59. data/test/dbd/odbc/test_statement.rb +44 -0
  60. data/test/dbd/odbc/test_transactions.rb +58 -0
  61. data/test/dbd/odbc/up.sql +33 -0
  62. data/test/dbd/postgresql/base.rb +31 -0
  63. data/test/dbd/postgresql/down.sql +31 -0
  64. data/test/dbd/postgresql/test_arrays.rb +179 -0
  65. data/test/dbd/postgresql/test_async.rb +121 -0
  66. data/test/dbd/postgresql/test_blob.rb +37 -0
  67. data/test/dbd/postgresql/test_bytea.rb +88 -0
  68. data/test/dbd/postgresql/test_ping.rb +10 -0
  69. data/test/dbd/postgresql/test_timestamp.rb +77 -0
  70. data/test/dbd/postgresql/test_transactions.rb +58 -0
  71. data/test/dbd/postgresql/testdbipg.rb +307 -0
  72. data/test/dbd/postgresql/up.sql +60 -0
  73. data/test/dbd/sqlite/base.rb +32 -0
  74. data/test/dbd/sqlite/test_database.rb +30 -0
  75. data/test/dbd/sqlite/test_driver.rb +68 -0
  76. data/test/dbd/sqlite/test_statement.rb +112 -0
  77. data/test/dbd/sqlite/up.sql +25 -0
  78. data/test/dbd/sqlite3/base.rb +32 -0
  79. data/test/dbd/sqlite3/test_database.rb +77 -0
  80. data/test/dbd/sqlite3/test_driver.rb +67 -0
  81. data/test/dbd/sqlite3/test_statement.rb +88 -0
  82. data/test/dbd/sqlite3/up.sql +33 -0
  83. data/test/dbi/tc_dbi.rb +1 -1
  84. data/test/ts_dbd.rb +136 -0
  85. data/ydbi.gemspec +25 -0
  86. metadata +148 -12
data/lib/dbd/Mysql.rb ADDED
@@ -0,0 +1,137 @@
1
+ #--
2
+ # Copyright (c) 2001, 2002 Michael Neumann <neumann@s-direktnet.de>
3
+ #
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions
8
+ # are met:
9
+ # 1. Redistributions of source code must retain the above copyright
10
+ # notice, this list of conditions and the following disclaimer.
11
+ # 2. Redistributions in binary form must reproduce the above copyright
12
+ # notice, this list of conditions and the following disclaimer in the
13
+ # documentation and/or other materials provided with the distribution.
14
+ # 3. The name of the author may not be used to endorse or promote products
15
+ # derived from this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
+ # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19
+ # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20
+ # THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23
+ # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25
+ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #
28
+ # $Id$
29
+ #++
30
+
31
+ begin
32
+ require 'rubygems'
33
+ gem 'mysql'
34
+ gem 'dbi'
35
+ rescue LoadError => e
36
+ end
37
+
38
+ require 'dbi'
39
+ require "mysql"
40
+ require "thread" # for Mutex
41
+
42
+ module DBI
43
+ module DBD
44
+ #
45
+ # DBD::Mysql - Database Driver for the MySQL database system.
46
+ #
47
+ # Requires DBI and the 'mysql' gem or package to work.
48
+ #
49
+ # Only things that extend DBI's results are documented.
50
+ #
51
+ module Mysql
52
+ VERSION = "0.4.4"
53
+ DESCRIPTION = "MySQL DBI DBD, Leverages 'mysql' low-level driver"
54
+
55
+ MyError = ::MysqlError
56
+
57
+ #
58
+ # returns 'Mysql'
59
+ #
60
+ # See DBI::TypeUtil#convert for more information.
61
+ #
62
+ def self.driver_name
63
+ "Mysql"
64
+ end
65
+
66
+ DBI::TypeUtil.register_conversion(driver_name) do |obj|
67
+ newobj = case obj
68
+ when ::DBI::Binary
69
+ obj = obj.to_s.gsub(/\\/) { "\\\\" }
70
+ obj = obj.to_s.gsub(/'/) { "''" }
71
+ "'#{obj}'"
72
+ when ::DateTime
73
+ "'#{obj.strftime("%Y-%m-%d %H:%M:%S")}'"
74
+ when ::Time
75
+ "'#{obj.strftime("%H:%M:%S")}'"
76
+ when ::Date
77
+ "'#{obj.strftime("%Y-%m-%d")}'"
78
+ when ::NilClass
79
+ "NULL"
80
+ else
81
+ obj
82
+ end
83
+
84
+ if newobj.object_id == obj.object_id
85
+ [newobj, true]
86
+ else
87
+ [newobj, false]
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ #
95
+ # Utility Methods for the MySQL DBD.
96
+ #
97
+
98
+ module DBI::DBD::Mysql::Util
99
+ private
100
+
101
+ # Raise exception using information from MysqlError object e.
102
+ # For state value, use SQLSTATE value if mysql-ruby defines
103
+ # sqlstate method, otherwise nil.
104
+ def error(e)
105
+ sqlstate = e.respond_to?("sqlstate") ? e.sqlstate : nil
106
+ raise DBI::DatabaseError.new(e.message, e.errno, sqlstate)
107
+ end
108
+
109
+ end # module Util
110
+
111
+ module DBI::DBD::Mysql::Type
112
+ #
113
+ # Custom handling for DATE types in MySQL. See DBI::Type for more
114
+ # information.
115
+ #
116
+ class Date < DBI::Type::Null
117
+ def self.parse(obj)
118
+ obj = super
119
+ return obj unless obj
120
+
121
+ case obj.class
122
+ when ::Date
123
+ return obj
124
+ when ::String
125
+ return ::Date.strptime(obj, "%Y-%m-%d")
126
+ else
127
+ return ::Date.parse(obj.to_s) if obj.respond_to? :to_s
128
+ return ::Date.parse(obj.to_str) if obj.respond_to? :to_str
129
+ return obj
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ require 'dbd/mysql/driver'
136
+ require 'dbd/mysql/database'
137
+ require 'dbd/mysql/statement'
data/lib/dbd/ODBC.rb ADDED
@@ -0,0 +1,89 @@
1
+ #--
2
+ # DBD::ODBC
3
+ #
4
+ # Copyright (c) 2001-2004 Michael Neumann <mneumann@ntecs.de>
5
+ #
6
+ # All rights reserved.
7
+ #
8
+ # Redistribution and use in source and binary forms, with or without
9
+ # modification, are permitted provided that the following conditions
10
+ # are met:
11
+ # 1. Redistributions of source code must retain the above copyright
12
+ # notice, this list of conditions and the following disclaimer.
13
+ # 2. Redistributions in binary form must reproduce the above copyright
14
+ # notice, this list of conditions and the following disclaimer in the
15
+ # documentation and/or other materials provided with the distribution.
16
+ # 3. The name of the author may not be used to endorse or promote products
17
+ # derived from this software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
+ # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
+ # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22
+ # THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25
+ # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27
+ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ #
30
+ # $Id$
31
+ #++
32
+
33
+ $:.delete(".") # FIXME oh for the love of pete..
34
+ require "odbc"
35
+ $: << "."
36
+
37
+ begin
38
+ require 'rubygems'
39
+ gem 'dbi'
40
+ rescue LoadError => e
41
+ end
42
+
43
+ require 'dbi'
44
+
45
+ module DBI
46
+ module DBD
47
+ #
48
+ # DBD::ODBC - ODBC Database Driver
49
+ #
50
+ # Requires DBI and the 'ruby-odbc' package to work, and unixodbc (iodbc
51
+ # WILL NOT WORK).
52
+ #
53
+ # Only things that extend DBI's results are documented.
54
+ #
55
+ module ODBC
56
+
57
+ VERSION = "0.2.5"
58
+ DESCRIPTION = "ODBC DBI DBD"
59
+
60
+ def self.driver_name
61
+ "odbc"
62
+ end
63
+
64
+ DBI::TypeUtil.register_conversion(driver_name) do |obj|
65
+ newobj = if obj.nil?
66
+ nil
67
+ else
68
+ case obj
69
+ when ::Date
70
+ ::ODBC::Date.new(obj)
71
+ when ::Time
72
+ ::ODBC::Time.new(obj)
73
+ when ::DateTime
74
+ ::ODBC::Timestamp.new(obj)
75
+ else
76
+ obj.to_s
77
+ end
78
+ end
79
+ [newobj, false]
80
+ end
81
+
82
+ ODBCErr = ::ODBC::Error
83
+ end # module ODBC
84
+ end # module DBD
85
+ end # module DBI
86
+
87
+ require 'dbd/odbc/driver'
88
+ require 'dbd/odbc/database'
89
+ require 'dbd/odbc/statement'
data/lib/dbd/Pg.rb ADDED
@@ -0,0 +1,189 @@
1
+ #--
2
+ # DBD::Pg
3
+ #
4
+ # Copyright (c) 2001, 2002, 2003 Jim Weirich, Michael Neumann <mneumann@ntecs.de>
5
+ # Copyright (c) 2008 Erik Hollensbe, Christopher Maujean
6
+ #
7
+ # All rights reserved.
8
+ #
9
+ # Redistribution and use in source and binary forms, with or without
10
+ # modification, are permitted provided that the following conditions
11
+ # are met:
12
+ # 1. Redistributions of source code must retain the above copyright
13
+ # notice, this list of conditions and the following disclaimer.
14
+ # 2. Redistributions in binary form must reproduce the above copyright
15
+ # notice, this list of conditions and the following disclaimer in the
16
+ # documentation and/or other materials provided with the distribution.
17
+ # 3. The name of the author may not be used to endorse or promote products
18
+ # derived from this software without specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
+ # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
+ # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23
+ # THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26
+ # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28
+ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ #++
31
+
32
+ begin
33
+ require 'rubygems'
34
+ gem 'pg'
35
+ gem 'ydbi'
36
+ rescue Exception => e
37
+ end
38
+
39
+ require 'dbi'
40
+ require 'pg'
41
+
42
+ module DBI
43
+ module DBD
44
+ #
45
+ # DBD::Pg - Database Driver for the PostgreSQL database system.
46
+ #
47
+ # Requires DBI and the 'pg' gem or package to work.
48
+ #
49
+ # Only things that extend DBI's results are documented.
50
+ #
51
+ module Pg
52
+ VERSION = DBI::VERSION
53
+ DESCRIPTION = "PostgreSQL DBI DBD"
54
+
55
+ #
56
+ # returns 'Pg'
57
+ #
58
+ # See DBI::TypeUtil#convert for more information.
59
+ #
60
+ def self.driver_name
61
+ "Pg"
62
+ end
63
+
64
+ #
65
+ # This method takes a ruby Array and converts it to PostgreSQL array syntax.
66
+ #
67
+ def self.generate_array(obj)
68
+ # XXX yarr, there be recursion here, and it's probably not a good idea.
69
+ output = "{"
70
+ obj.each do |item|
71
+ case item
72
+ when ::Array
73
+ output += generate_array(item)
74
+ else
75
+ generated = DBI::TypeUtil.convert(driver_name, item)
76
+ generated = case item
77
+ when String
78
+ # in strings, escapes are doubled and the quotes are different.
79
+ # this gets *really* ugly and needs to be well-tested
80
+ "\"#{generated.gsub(/\\/) { "\\\\" }}\""
81
+ # Since Ruby 2.4 Fixnum was deprecated, see https://bugs.ruby-lang.org/issues/12005
82
+ when Integer
83
+ generated.to_s
84
+ end
85
+ output += generated
86
+ end
87
+ output += "," # FIXME technically, delimiters are variable
88
+ end
89
+
90
+ output.sub(/,$/, '}')
91
+ end
92
+
93
+ #
94
+ # A quote helper, this uses the new syntax in PostgreSQL 8.2 and up.
95
+ #
96
+ def self.quote(value)
97
+ "E'#{ value.gsub(/\\/){ '\\\\' }.gsub(/'/){ '\\\'' } }'"
98
+ end
99
+
100
+ #
101
+ # Parse a postgresql type. Returns a hash with these fields (as Symbol)
102
+ #
103
+ # * ftype: the full type, as passed in to this method.
104
+ # * type: the type stripped of all attribute information.
105
+ # * size: the LHS of the attribute information, typically the precision.
106
+ # * decimal: the RHS of the attribute information, typically the scale.
107
+ # * array: true if this type is actually an array of that type.
108
+ #
109
+ def self.parse_type(ftype)
110
+ type = ftype
111
+ pos = ftype.index('(')
112
+ decimal = nil
113
+ size = nil
114
+ array_of_type = nil
115
+
116
+ if pos != nil
117
+ type = ftype[0..pos-1]
118
+ size = ftype[pos+1..-2]
119
+ pos = size.index(',')
120
+ if pos != nil
121
+ size, decimal = size.split(',', 2)
122
+ size = size.to_i
123
+ decimal = decimal.to_i
124
+ else
125
+ size = size.to_i
126
+ end
127
+ end
128
+
129
+ if type =~ /\[\]$/
130
+ type.sub!(/\[\]$/, '')
131
+ array_of_type = true
132
+ end
133
+
134
+ return {
135
+ :ftype => ftype.dup,
136
+ :type => type,
137
+ :size => size,
138
+ :decimal => decimal,
139
+ :array => array_of_type
140
+ }
141
+ end
142
+
143
+ #
144
+ # See DBI::BaseDriver.
145
+ #
146
+ class Driver < DBI::BaseDriver
147
+ def initialize
148
+ super(DBI::VERSION)
149
+ end
150
+
151
+ ## List of datasources for this database.
152
+ def data_sources
153
+ []
154
+ end
155
+
156
+ ## Connect to a database.
157
+ def connect(dbname, user, auth, attr)
158
+ Database.new(dbname, user, auth, attr)
159
+ end
160
+ end
161
+ end # module Pg
162
+ end # module DBD
163
+ end # module DBI
164
+
165
+ require 'dbd/pg/type'
166
+ require 'dbd/pg/database'
167
+ require 'dbd/pg/statement'
168
+ require 'dbd/pg/tuples'
169
+ require 'dbd/pg/exec'
170
+
171
+ pg = DBI::DBD::Pg
172
+
173
+ DBI::TypeUtil.register_conversion(pg.driver_name) do |obj|
174
+ newobj = case obj
175
+ when ::DateTime
176
+ obj.strftime("%Y-%m-%dT%H:%M:%S.%N")
177
+ when ::Time
178
+ ::DateTime.parse(obj.to_s).strftime("%H:%M:%S.%N")
179
+ when ::Date
180
+ obj.strftime("%Y-%m-%d")
181
+ when ::Array
182
+ pg.generate_array(obj)
183
+ when DBI::DBD::Pg::Type::ByteA
184
+ obj.escaped
185
+ else
186
+ obj
187
+ end
188
+ [newobj, false]
189
+ end
data/lib/dbd/SQLite.rb ADDED
@@ -0,0 +1,97 @@
1
+ #--
2
+ ###############################################################################
3
+ #
4
+ # DBD::SQLite - a DBD for SQLite for versions < 3
5
+ #
6
+ # Uses Jamis Buck's 'sqlite-ruby' driver to interface with SQLite directly
7
+ #
8
+ # (c) 2008 Erik Hollensbe & Christopher Maujean.
9
+ #
10
+ # TODO
11
+ #
12
+ # fetch_scroll implementation?
13
+ # columns and column_info differ too much and have too much copied code, refactor
14
+ # there are probably some edge cases with transactions
15
+ #
16
+ ################################################################################
17
+ #++
18
+
19
+ begin
20
+ require 'rubygems'
21
+ gem 'sqlite-ruby'
22
+ gem 'dbi'
23
+ rescue Exception => e
24
+ end
25
+
26
+ require 'dbi'
27
+ require 'sqlite'
28
+
29
+ module DBI
30
+ module DBD
31
+ #
32
+ # DBD::SQLite - Database Driver for SQLite versions 2.x and lower.
33
+ #
34
+ # Requires DBI and the 'sqlite-ruby' gem to work.
35
+ #
36
+ # Only things that extend DBI's results are documented.
37
+ #
38
+ class SQLite
39
+ VERSION = "0.1.2"
40
+ DESCRIPTION = "SQLite 2.x DBI DBD"
41
+
42
+ #
43
+ # returns 'SQLite'
44
+ #
45
+ # See DBI::TypeUtil#convert for more information.
46
+ #
47
+ def self.driver_name
48
+ "SQLite"
49
+ end
50
+
51
+ #
52
+ # Validates that the SQL has no literal NUL characters. (ASCII 0)
53
+ #
54
+ # SQLite apparently really hates it when you do that.
55
+ #
56
+ # It will raise DBI::DatabaseError should it find any.
57
+ #
58
+ def self.check_sql(sql)
59
+ # XXX I'm starting to think this is less of a problem with SQLite
60
+ # and more with the old C DBD
61
+ raise DBI::DatabaseError, "Bad SQL: SQL cannot contain nulls" if sql =~ /\0/
62
+ end
63
+
64
+ #
65
+ # Split a type definition into parts via String#match and return the whole result.
66
+ #
67
+ def self.parse_type(type_name)
68
+ type_name.match(/^([^\(]+)(\((\d+)(,(\d+))?\))?$/)
69
+ end
70
+
71
+ #
72
+ # See DBI::BaseDriver.
73
+ #
74
+ class Driver < DBI::BaseDriver
75
+ def initialize
76
+ super "0.4.0"
77
+ end
78
+
79
+ def connect(dbname, user, auth, attr_hash)
80
+ return Database.new(dbname, user, auth, attr_hash)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ require 'dbd/sqlite/database'
88
+ require 'dbd/sqlite/statement'
89
+
90
+ DBI::TypeUtil.register_conversion(DBI::DBD::SQLite.driver_name) do |obj|
91
+ case obj
92
+ when ::NilClass
93
+ ["NULL", false]
94
+ else
95
+ [obj, true]
96
+ end
97
+ end
@@ -0,0 +1,124 @@
1
+ #--
2
+ # DBD::SQLite3
3
+ #
4
+ # copyright (c) 2005 Jun Mukai <mukai@jmuk.org>
5
+ # Compatibility patches by Erik Hollensbe <erik@hollensbe.org>
6
+ #
7
+ # All rights reserved.
8
+ #
9
+ # Redistribution and use in source and binary forms, with or without
10
+ # modification, are permitted provided that the following conditions
11
+ # are met:
12
+ # 1. Redistributions of source code must retain the above copyright
13
+ # notice, this list of conditions and the following disclaimer.
14
+ # 2. Redistributions in binary form must reproduce the above copyright
15
+ # notice, this list of conditions and the following disclaimer in the
16
+ # documentation and/or other materials provided with the distribution.
17
+ # 3. The name of the author may not be used to endorse or promote products
18
+ # derived from this software without specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
+ # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
+ # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23
+ # THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26
+ # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28
+ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ #++
31
+
32
+ begin
33
+ require 'rubygems'
34
+ gem 'sqlite3-ruby'
35
+ gem 'dbi'
36
+ rescue LoadError
37
+ end
38
+
39
+ require 'dbi'
40
+ require 'sqlite3'
41
+ require 'sqlite3/version'
42
+
43
+ module DBI
44
+ module DBD
45
+ #
46
+ # DBD::SQLite3 - Database Driver for SQLite versions 3.x
47
+ #
48
+ # Requires DBI and the 'sqlite3-ruby' gem to work.
49
+ #
50
+ # Only things that extend DBI's results are documented.
51
+ #
52
+ module SQLite3
53
+ VERSION = "1.2.5"
54
+ DESCRIPTION = "SQLite 3.x DBD for DBI"
55
+
56
+ #
57
+ # returns 'SQLite3'
58
+ #
59
+ # See DBI::TypeUtil#convert for more information.
60
+ #
61
+ def self.driver_name
62
+ "SQLite3"
63
+ end
64
+
65
+ #
66
+ # Validates that the SQL has no literal NUL characters. (ASCII 0)
67
+ #
68
+ # SQLite apparently really hates it when you do that.
69
+ #
70
+ # It will raise DBI::DatabaseError should it find any.
71
+ #
72
+ def self.parse_type(type_name)
73
+ # FIXME plucked from SQLite driver, this needs to be in DBI proper
74
+ return ['varchar'] unless type_name
75
+ type_name.match(/^([^\(\s]+)\s*(\(\s*(\d+)\s*(,\s*(\d+))?\s*\))?$/)
76
+ end
77
+
78
+ #
79
+ # See DBI::BaseDriver.
80
+ #
81
+ class Driver < DBI::BaseDriver
82
+ def initialize
83
+ @dbs = []
84
+ super "0.4.0"
85
+ end
86
+
87
+ def connect(dbname, user, auth, attr)
88
+ raise DBI::InterfaceError, "dbname must be a string" unless dbname.kind_of? String
89
+ raise DBI::InterfaceError, "dbname must have some length" unless dbname.length > 0
90
+ raise DBI::InterfaceError, "attrs must be a hash" unless attr.kind_of? Hash
91
+ db = DBI::DBD::SQLite3::Database.new(dbname, attr)
92
+ @dbs.push(db)
93
+ db
94
+ end
95
+
96
+ def disconnect_all()
97
+ @dbs.each{|db| db.disconnect()}
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ require 'dbd/sqlite3/database'
105
+ require 'dbd/sqlite3/statement'
106
+
107
+ DBI::TypeUtil.register_conversion(DBI::DBD::SQLite3.driver_name) do |obj|
108
+ newobj = case obj
109
+ when ::TrueClass
110
+ '1'
111
+ when ::FalseClass
112
+ '0'
113
+ else
114
+ # SQLite3 is managing its own conversion right now, until I'm happy let's keep it that way
115
+ obj.dup rescue obj
116
+ end
117
+ if newobj.kind_of?(::Symbol)
118
+ newobj.to_s
119
+ elsif newobj.object_id == obj.object_id
120
+ [newobj, true]
121
+ else
122
+ [newobj, false]
123
+ end
124
+ end