ydbi 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/ChangeLog +3699 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/Rakefile +8 -0
  7. data/TODO +44 -0
  8. data/bench/bench.rb +79 -0
  9. data/bin/dbi +518 -0
  10. data/bin/test_broken_dbi +37 -0
  11. data/build/Rakefile.dbi.rb +60 -0
  12. data/build/rake_task_lib.rb +187 -0
  13. data/doc/DBD_SPEC.rdoc +88 -0
  14. data/doc/DBI_SPEC.rdoc +157 -0
  15. data/doc/homepage/contact.html +62 -0
  16. data/doc/homepage/development.html +124 -0
  17. data/doc/homepage/index.html +83 -0
  18. data/doc/homepage/ruby-dbi.css +91 -0
  19. data/examples/test1.pl +39 -0
  20. data/examples/test1.rb +20 -0
  21. data/examples/xmltest.rb +8 -0
  22. data/lib/dbd/Mysql.rb +137 -0
  23. data/lib/dbd/ODBC.rb +89 -0
  24. data/lib/dbd/Pg.rb +188 -0
  25. data/lib/dbd/SQLite.rb +97 -0
  26. data/lib/dbd/SQLite3.rb +124 -0
  27. data/lib/dbd/mysql/database.rb +405 -0
  28. data/lib/dbd/mysql/driver.rb +125 -0
  29. data/lib/dbd/mysql/statement.rb +188 -0
  30. data/lib/dbd/odbc/database.rb +128 -0
  31. data/lib/dbd/odbc/driver.rb +38 -0
  32. data/lib/dbd/odbc/statement.rb +137 -0
  33. data/lib/dbd/pg/database.rb +516 -0
  34. data/lib/dbd/pg/exec.rb +47 -0
  35. data/lib/dbd/pg/statement.rb +160 -0
  36. data/lib/dbd/pg/tuples.rb +121 -0
  37. data/lib/dbd/pg/type.rb +209 -0
  38. data/lib/dbd/sqlite/database.rb +151 -0
  39. data/lib/dbd/sqlite/statement.rb +125 -0
  40. data/lib/dbd/sqlite3/database.rb +201 -0
  41. data/lib/dbd/sqlite3/statement.rb +78 -0
  42. data/lib/dbi.rb +336 -0
  43. data/lib/dbi/base_classes.rb +12 -0
  44. data/lib/dbi/base_classes/database.rb +135 -0
  45. data/lib/dbi/base_classes/driver.rb +47 -0
  46. data/lib/dbi/base_classes/statement.rb +171 -0
  47. data/lib/dbi/binary.rb +25 -0
  48. data/lib/dbi/columninfo.rb +107 -0
  49. data/lib/dbi/exceptions.rb +65 -0
  50. data/lib/dbi/handles.rb +49 -0
  51. data/lib/dbi/handles/database.rb +241 -0
  52. data/lib/dbi/handles/driver.rb +60 -0
  53. data/lib/dbi/handles/statement.rb +408 -0
  54. data/lib/dbi/row.rb +269 -0
  55. data/lib/dbi/sql.rb +22 -0
  56. data/lib/dbi/sql/preparedstatement.rb +115 -0
  57. data/lib/dbi/sql_type_constants.rb +75 -0
  58. data/lib/dbi/trace.rb +91 -0
  59. data/lib/dbi/types.rb +218 -0
  60. data/lib/dbi/typeutil.rb +109 -0
  61. data/lib/dbi/utils.rb +60 -0
  62. data/lib/dbi/utils/date.rb +59 -0
  63. data/lib/dbi/utils/tableformatter.rb +112 -0
  64. data/lib/dbi/utils/time.rb +52 -0
  65. data/lib/dbi/utils/timestamp.rb +96 -0
  66. data/lib/dbi/utils/xmlformatter.rb +73 -0
  67. data/lib/dbi/version.rb +3 -0
  68. data/prototypes/types2.rb +237 -0
  69. data/readme.md +274 -0
  70. data/setup.rb +1585 -0
  71. data/test/DBD_TESTS +50 -0
  72. data/test/TESTING +16 -0
  73. data/test/dbd/general/test_database.rb +206 -0
  74. data/test/dbd/general/test_statement.rb +326 -0
  75. data/test/dbd/general/test_types.rb +296 -0
  76. data/test/dbd/mysql/base.rb +26 -0
  77. data/test/dbd/mysql/down.sql +19 -0
  78. data/test/dbd/mysql/test_blob.rb +18 -0
  79. data/test/dbd/mysql/test_new_methods.rb +7 -0
  80. data/test/dbd/mysql/test_patches.rb +111 -0
  81. data/test/dbd/mysql/up.sql +28 -0
  82. data/test/dbd/odbc/base.rb +30 -0
  83. data/test/dbd/odbc/down.sql +19 -0
  84. data/test/dbd/odbc/test_new_methods.rb +12 -0
  85. data/test/dbd/odbc/test_ping.rb +10 -0
  86. data/test/dbd/odbc/test_statement.rb +44 -0
  87. data/test/dbd/odbc/test_transactions.rb +58 -0
  88. data/test/dbd/odbc/up.sql +33 -0
  89. data/test/dbd/postgresql/base.rb +31 -0
  90. data/test/dbd/postgresql/down.sql +31 -0
  91. data/test/dbd/postgresql/test_arrays.rb +179 -0
  92. data/test/dbd/postgresql/test_async.rb +121 -0
  93. data/test/dbd/postgresql/test_blob.rb +36 -0
  94. data/test/dbd/postgresql/test_bytea.rb +87 -0
  95. data/test/dbd/postgresql/test_ping.rb +10 -0
  96. data/test/dbd/postgresql/test_timestamp.rb +77 -0
  97. data/test/dbd/postgresql/test_transactions.rb +58 -0
  98. data/test/dbd/postgresql/testdbipg.rb +307 -0
  99. data/test/dbd/postgresql/up.sql +60 -0
  100. data/test/dbd/sqlite/base.rb +32 -0
  101. data/test/dbd/sqlite/test_database.rb +30 -0
  102. data/test/dbd/sqlite/test_driver.rb +68 -0
  103. data/test/dbd/sqlite/test_statement.rb +112 -0
  104. data/test/dbd/sqlite/up.sql +25 -0
  105. data/test/dbd/sqlite3/base.rb +32 -0
  106. data/test/dbd/sqlite3/test_database.rb +77 -0
  107. data/test/dbd/sqlite3/test_driver.rb +67 -0
  108. data/test/dbd/sqlite3/test_statement.rb +88 -0
  109. data/test/dbd/sqlite3/up.sql +33 -0
  110. data/test/dbi/tc_columninfo.rb +94 -0
  111. data/test/dbi/tc_date.rb +88 -0
  112. data/test/dbi/tc_dbi.rb +184 -0
  113. data/test/dbi/tc_row.rb +256 -0
  114. data/test/dbi/tc_sqlbind.rb +168 -0
  115. data/test/dbi/tc_statementhandle.rb +29 -0
  116. data/test/dbi/tc_time.rb +77 -0
  117. data/test/dbi/tc_timestamp.rb +142 -0
  118. data/test/dbi/tc_types.rb +268 -0
  119. data/test/ts_dbd.rb +131 -0
  120. data/test/ts_dbi.rb +16 -0
  121. data/ydbi.gemspec +24 -0
  122. metadata +224 -0
@@ -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'
@@ -0,0 +1,188 @@
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 'dbi'
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 = "0.3.9"
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
+ when Fixnum
82
+ generated.to_s
83
+ end
84
+ output += generated
85
+ end
86
+ output += "," # FIXME technically, delimiters are variable
87
+ end
88
+
89
+ output.sub(/,$/, '}')
90
+ end
91
+
92
+ #
93
+ # A quote helper, this uses the new syntax in PostgreSQL 8.2 and up.
94
+ #
95
+ def self.quote(value)
96
+ "E'#{ value.gsub(/\\/){ '\\\\' }.gsub(/'/){ '\\\'' } }'"
97
+ end
98
+
99
+ #
100
+ # Parse a postgresql type. Returns a hash with these fields (as Symbol)
101
+ #
102
+ # * ftype: the full type, as passed in to this method.
103
+ # * type: the type stripped of all attribute information.
104
+ # * size: the LHS of the attribute information, typically the precision.
105
+ # * decimal: the RHS of the attribute information, typically the scale.
106
+ # * array: true if this type is actually an array of that type.
107
+ #
108
+ def self.parse_type(ftype)
109
+ type = ftype
110
+ pos = ftype.index('(')
111
+ decimal = nil
112
+ size = nil
113
+ array_of_type = nil
114
+
115
+ if pos != nil
116
+ type = ftype[0..pos-1]
117
+ size = ftype[pos+1..-2]
118
+ pos = size.index(',')
119
+ if pos != nil
120
+ size, decimal = size.split(',', 2)
121
+ size = size.to_i
122
+ decimal = decimal.to_i
123
+ else
124
+ size = size.to_i
125
+ end
126
+ end
127
+
128
+ if type =~ /\[\]$/
129
+ type.sub!(/\[\]$/, '')
130
+ array_of_type = true
131
+ end
132
+
133
+ return {
134
+ :ftype => ftype.dup,
135
+ :type => type,
136
+ :size => size,
137
+ :decimal => decimal,
138
+ :array => array_of_type
139
+ }
140
+ end
141
+
142
+ #
143
+ # See DBI::BaseDriver.
144
+ #
145
+ class Driver < DBI::BaseDriver
146
+ def initialize
147
+ super("0.4.0")
148
+ end
149
+
150
+ ## List of datasources for this database.
151
+ def data_sources
152
+ []
153
+ end
154
+
155
+ ## Connect to a database.
156
+ def connect(dbname, user, auth, attr)
157
+ Database.new(dbname, user, auth, attr)
158
+ end
159
+ end
160
+ end # module Pg
161
+ end # module DBD
162
+ end # module DBI
163
+
164
+ require 'dbd/pg/type'
165
+ require 'dbd/pg/database'
166
+ require 'dbd/pg/statement'
167
+ require 'dbd/pg/tuples'
168
+ require 'dbd/pg/exec'
169
+
170
+ pg = DBI::DBD::Pg
171
+
172
+ DBI::TypeUtil.register_conversion(pg.driver_name) do |obj|
173
+ newobj = case obj
174
+ when ::DateTime
175
+ obj.strftime("%Y-%m-%dT%H:%M:%S.%N")
176
+ when ::Time
177
+ ::DateTime.parse(obj.to_s).strftime("%H:%M:%S.%N")
178
+ when ::Date
179
+ obj.strftime("%Y-%m-%d")
180
+ when ::Array
181
+ pg.generate_array(obj)
182
+ when DBI::DBD::Pg::Type::ByteA
183
+ obj.escaped
184
+ else
185
+ obj
186
+ end
187
+ [newobj, false]
188
+ end
@@ -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